RSScript.h revision 750ee65e129a2baef2dc5bb9ad210b45c9184926
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_SCRIPT_H 18#define BCC_RS_SCRIPT_H 19 20#include "bcc/Script.h" 21#include "bcc/Support/Sha1Util.h" 22 23namespace llvm { 24 class Module; 25} 26 27namespace bcc { 28 29class RSScript; 30class Source; 31 32typedef llvm::Module* (*RSLinkRuntimeCallback) (bcc::RSScript *, llvm::Module *, llvm::Module *); 33 34 35class RSScript : public Script { 36public: 37 // This is one-one mapping with the llvm::CodeGenOpt::Level in 38 // llvm/Support/CodeGen.h. Therefore, value of this type can safely cast 39 // to llvm::CodeGenOpt::Level. This makes RSScript LLVM-free. 40 enum OptimizationLevel { 41 kOptLvl0, // -O0 42 kOptLvl1, // -O1 43 kOptLvl2, // -O2, -Os 44 kOptLvl3 // -O3 45 }; 46 47private: 48 unsigned mCompilerVersion; 49 50 OptimizationLevel mOptimizationLevel; 51 52 RSLinkRuntimeCallback mLinkRuntimeCallback; 53 54 bool mEmbedInfo; 55 56 // Specifies whether we should embed global variable information in the 57 // code via special RS variables that can be examined later by the driver. 58 bool mEmbedGlobalInfo; 59 60 // Specifies whether we should skip constant (immutable) global variables 61 // when potentially embedding information about globals. 62 bool mEmbedGlobalInfoSkipConstant; 63 64private: 65 // This will be invoked when the containing source has been reset. 66 virtual bool doReset(); 67 68public: 69 static bool LinkRuntime(RSScript &pScript, const char *rt_path = nullptr); 70 71 RSScript(Source &pSource); 72 73 virtual ~RSScript() { } 74 75 void setCompilerVersion(unsigned pCompilerVersion) { 76 mCompilerVersion = pCompilerVersion; 77 } 78 79 unsigned getCompilerVersion() const { 80 return mCompilerVersion; 81 } 82 83 void setOptimizationLevel(OptimizationLevel pOptimizationLevel) { 84 mOptimizationLevel = pOptimizationLevel; 85 } 86 87 OptimizationLevel getOptimizationLevel() const { 88 return mOptimizationLevel; 89 } 90 91 void setLinkRuntimeCallback(RSLinkRuntimeCallback fn){ 92 mLinkRuntimeCallback = fn; 93 } 94 95 void setEmbedInfo(bool pEnable) { 96 mEmbedInfo = pEnable; 97 } 98 99 bool getEmbedInfo() const { 100 return mEmbedInfo; 101 } 102 103 // Set to true if we should embed global variable information in the code. 104 void setEmbedGlobalInfo(bool pEnable) { 105 mEmbedGlobalInfo = pEnable; 106 } 107 108 // Returns true if we should embed global variable information in the code. 109 bool getEmbedGlobalInfo() const { 110 return mEmbedGlobalInfo; 111 } 112 113 // Set to true if we should skip constant (immutable) global variables when 114 // potentially embedding information about globals. 115 void setEmbedGlobalInfoSkipConstant(bool pEnable) { 116 mEmbedGlobalInfoSkipConstant = pEnable; 117 } 118 119 // Returns true if we should skip constant (immutable) global variables when 120 // potentially embedding information about globals. 121 bool getEmbedGlobalInfoSkipConstant() const { 122 return mEmbedGlobalInfoSkipConstant; 123 } 124}; 125 126} // end namespace bcc 127 128#endif // BCC_RS_SCRIPT_H 129