RSCompilerDriver.h revision c5e607adff80a66bc5420baffd299862abdf368d
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#include "bcc/Renderscript/RSScript.h" 26 27namespace bcc { 28 29class BCCContext; 30class CompilerConfig; 31class RSCompilerDriver; 32class RSExecutable; 33 34// Type signature for dynamically loaded initialization of an RSCompilerDriver. 35typedef void (*RSCompilerDriverInit_t) (bcc::RSCompilerDriver *); 36// Name of the function that we attempt to dynamically load/execute. 37#define RS_COMPILER_DRIVER_INIT_FN rsCompilerDriverInit 38 39class RSCompilerDriver { 40private: 41 CompilerConfig *mConfig; 42 RSCompiler mCompiler; 43 44 // Are we compiling under an RS debug context with additional checks? 45 bool mDebugContext; 46 47 // Callback before linking with the runtime library. 48 RSLinkRuntimeCallback mLinkRuntimeCallback; 49 50 // Do we merge global variables on ARM using LLVM's optimization pass? 51 // Disabling LLVM's global merge pass allows static globals to be correctly 52 // emitted to ELF. This can result in decreased performance due to increased 53 // register pressure, but it does make the resulting code easier to debug 54 // and work with. 55 bool mEnableGlobalMerge; 56 57 // Setup the compiler config for the given script. Return true if mConfig has 58 // been changed and false if it remains unchanged. 59 bool setupConfig(const RSScript &pScript); 60 61 Compiler::ErrorCode compileScript(RSScript &pScript, 62 const char* pScriptName, 63 const char *pOutputPath, 64 const char *pRuntimePath, 65 const RSInfo::DependencyHashTy &pSourceHash, 66 bool pSkipLoad, bool pDumpIR = false); 67 68public: 69 RSCompilerDriver(bool pUseCompilerRT = true); 70 ~RSCompilerDriver(); 71 72 RSCompiler *getCompiler() { 73 return &mCompiler; 74 } 75 76 void setConfig(CompilerConfig *config) { 77 mConfig = config; 78 } 79 80 void setDebugContext(bool v) { 81 mDebugContext = v; 82 } 83 84 void setLinkRuntimeCallback(RSLinkRuntimeCallback c) { 85 mLinkRuntimeCallback = c; 86 } 87 88 RSLinkRuntimeCallback getLinkRuntimeCallback() const { 89 return mLinkRuntimeCallback; 90 } 91 92 // This function enables/disables merging of global static variables. 93 // Note that it only takes effect on ARM architectures (other architectures 94 // do not offer this option). 95 void setEnableGlobalMerge(bool v) { 96 mEnableGlobalMerge = v; 97 } 98 99 bool getEnableGlobalMerge() const { 100 return mEnableGlobalMerge; 101 } 102 103 // FIXME: This method accompany with loadScript and compileScript should 104 // all be const-methods. They're not now because the getAddress() in 105 // SymbolResolverInterface is not a const-method. 106 // Returns true if script is successfully compiled. 107 bool build(BCCContext &pContext, const char *pCacheDir, const char *pResName, 108 const char *pBitcode, size_t pBitcodeSize, 109 const char *pRuntimePath, 110 RSLinkRuntimeCallback pLinkRuntimeCallback = NULL, 111 bool pDumpIR = false); 112 113 // Returns true if script is successfully compiled. 114 bool buildForCompatLib(RSScript &pScript, const char *pOut, const char *pRuntimePath); 115 116 static RSExecutable *loadScript(const char *pCacheDir, const char *pResName, 117 const char *pBitcode, size_t pBitcodeSize, 118 SymbolResolverProxy &pResolver); 119}; 120 121} // end namespace bcc 122 123#endif // BCC_RS_COMPILER_DRIVER_H 124