RSCompilerDriver.h revision 3d740780dfc4c446d89b9d130d739b4aa90c8298
1/*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef BCC_RS_COMPILER_DRIVER_H
18#define BCC_RS_COMPILER_DRIVER_H
19
20#include "bcc/ExecutionEngine/CompilerRTSymbolResolver.h"
21#include "bcc/ExecutionEngine/SymbolResolvers.h"
22#include "bcc/ExecutionEngine/SymbolResolverProxy.h"
23#include "bcc/Renderscript/RSInfo.h"
24#include "bcc/Renderscript/RSCompiler.h"
25
26namespace bcc {
27
28class BCCContext;
29class CompilerConfig;
30class RSExecutable;
31class RSScript;
32
33class RSCompilerDriver {
34private:
35  CompilerConfig *mConfig;
36  RSCompiler mCompiler;
37
38  CompilerRTSymbolResolver *mCompilerRuntime;
39  LookupFunctionSymbolResolver<void*> mRSRuntime;
40  SymbolResolverProxy mResolver;
41
42  // Are we compiling under an RS debug context with additional checks?
43  bool mDebugContext;
44
45  RSExecutable *loadScriptCache(const char *pOutputPath,
46                                const RSInfo::DependencyTableTy &pDeps);
47
48  // Do we merge global variables on ARM using LLVM's optimization pass?
49  // Disabling LLVM's global merge pass allows static globals to be correctly
50  // emitted to ELF. This can result in decreased performance due to increased
51  // register pressure, but it does make the resulting code easier to debug
52  // and work with.
53  bool mEnableGlobalMerge;
54
55  // Setup the compiler config for the given script. Return true if mConfig has
56  // been changed and false if it remains unchanged.
57  bool setupConfig(const RSScript &pScript);
58
59  RSExecutable *compileScript(RSScript &pScript,
60                              const char* pScriptName,
61                              const char *pOutputPath,
62                              const char *pRuntimePath,
63                              const RSInfo::DependencyTableTy &pDeps,
64                              bool pSkipLoad);
65
66public:
67  RSCompilerDriver(bool pUseCompilerRT = true);
68  ~RSCompilerDriver();
69
70  inline void setRSRuntimeLookupFunction(
71      LookupFunctionSymbolResolver<>::LookupFunctionTy pLookupFunc)
72  { mRSRuntime.setLookupFunction(pLookupFunc); }
73  inline void setRSRuntimeLookupContext(void *pContext)
74  { mRSRuntime.setContext(pContext); }
75
76  RSCompiler *getCompiler() {
77    return &mCompiler;
78  }
79
80  void setConfig(CompilerConfig *config) {
81    mConfig = config;
82  }
83
84  void setDebugContext(bool v) {
85    mDebugContext = v;
86  }
87
88  // This function enables/disables merging of global static variables.
89  // Note that it only takes effect on ARM architectures (other architectures
90  // do not offer this option).
91  void setEnableGlobalMerge(bool v) {
92    mEnableGlobalMerge = v;
93  }
94
95  bool getEnableGlobalMerge() const {
96    return mEnableGlobalMerge;
97  }
98
99  // FIXME: This method accompany with loadScriptCache and compileScript should
100  //        all be const-methods. They're not now because the getAddress() in
101  //        SymbolResolverInterface is not a const-method.
102  RSExecutable *build(BCCContext &pContext,
103                      const char *pCacheDir, const char *pResName,
104                      const char *pBitcode, size_t pBitcodeSize,
105                      const char *pRuntimePath,
106                      RSLinkRuntimeCallback pLinkRuntimeCallback = NULL);
107  RSExecutable *build(RSScript &pScript, const char *pOut,
108                      const char *pRuntimePath);
109};
110
111} // end namespace bcc
112
113#endif // BCC_RS_COMPILER_DRIVER_H
114