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