RSCompilerDriver.h revision 51ee77bd31e7d8ca6c89e37b5806c8fc2afcf0dc
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/RSInfo.h" 22#include "bcc/Renderscript/RSScript.h" 23 24#include "bcinfo/MetadataExtractor.h" 25 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 saveInfoFile is true, it also stores the RSInfo data in a file with a path derived from 64 // pOutputPath. 65 // - pSourceHash and commandLineToEmbed are values to embed in the RSInfo for future cache 66 // invalidation decision. 67 // - If pDumpIR is true, a ".ll" file will also be created. 68 Compiler::ErrorCode compileScript(RSScript& pScript, const char* pScriptName, 69 const char* pOutputPath, 70 const char *pRuntimePath, 71 const RSInfo::DependencyHashTy& pSourceHash, 72 const char* commandLineToEmbed, 73 const char* pBuildChecksum, 74 bool saveInfoFile, bool pDumpIR); 75 76public: 77 RSCompilerDriver(bool pUseCompilerRT = true); 78 ~RSCompilerDriver(); 79 80 Compiler *getCompiler() { 81 return &mCompiler; 82 } 83 84 void setConfig(CompilerConfig *config) { 85 mConfig = config; 86 } 87 88 void setDebugContext(bool v) { 89 mDebugContext = v; 90 } 91 92 void setLinkRuntimeCallback(RSLinkRuntimeCallback c) { 93 mLinkRuntimeCallback = c; 94 } 95 96 RSLinkRuntimeCallback getLinkRuntimeCallback() const { 97 return mLinkRuntimeCallback; 98 } 99 100 // This function enables/disables merging of global static variables. 101 // Note that it only takes effect on ARM architectures (other architectures 102 // do not offer this option). 103 void setEnableGlobalMerge(bool v) { 104 mEnableGlobalMerge = v; 105 } 106 107 bool getEnableGlobalMerge() const { 108 return mEnableGlobalMerge; 109 } 110 111 // FIXME: This method accompany with loadScript and compileScript should 112 // all be const-methods. They're not now because the getAddress() in 113 // SymbolResolverInterface is not a const-method. 114 // Returns true if script is successfully compiled. 115 bool build(BCCContext& pContext, const char* pCacheDir, const char* pResName, 116 const char* pBitcode, size_t pBitcodeSize, const char* commandLine, 117 const char *pBuildChecksum, const char* pRuntimePath, 118 RSLinkRuntimeCallback pLinkRuntimeCallback = nullptr, 119 bool pDumpIR = false); 120 121 bool buildScriptGroup( 122 BCCContext& Context, const char* pOutputFilepath, const char* pRuntimePath, 123 const std::vector<const Source*>& sources, const std::vector<int>& slots, 124 bool dumpIR); 125 126 // Returns true if script is successfully compiled. 127 bool buildForCompatLib(RSScript &pScript, const char *pOut, 128 const char *pBuildChecksum, const char *pRuntimePath, 129 bool pDumpIR); 130}; 131 132} // end namespace bcc 133 134#endif // BCC_RS_COMPILER_DRIVER_H 135