Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 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 | |
Zonr Chang | c72c4dd | 2012-04-12 15:38:53 +0800 | [diff] [blame] | 17 | #ifndef BCC_RS_COMPILER_DRIVER_H |
| 18 | #define BCC_RS_COMPILER_DRIVER_H |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 19 | |
Chris Wailes | b4447cd | 2014-08-19 16:22:20 -0700 | [diff] [blame] | 20 | #include "bcc/Compiler.h" |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 21 | #include "bcc/Script.h" |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 22 | |
Yang Ni | a4ded13 | 2014-11-17 17:44:08 -0800 | [diff] [blame] | 23 | #include "bcinfo/MetadataExtractor.h" |
| 24 | |
Yang Ni | 0ab50b8 | 2015-02-16 12:31:56 -0800 | [diff] [blame] | 25 | #include <list> |
Pirama Arumuga Nainar | 5525379 | 2015-03-24 16:22:09 -0700 | [diff] [blame] | 26 | #include <string> |
Yang Ni | a4ded13 | 2014-11-17 17:44:08 -0800 | [diff] [blame] | 27 | #include <vector> |
| 28 | |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 29 | namespace bcc { |
| 30 | |
Shih-wei Liao | 7bcec85 | 2012-04-25 04:07:09 -0700 | [diff] [blame] | 31 | class BCCContext; |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 32 | class CompilerConfig; |
Stephen Hines | c3437f0 | 2014-01-30 17:57:21 -0800 | [diff] [blame] | 33 | class RSCompilerDriver; |
Yang Ni | a4ded13 | 2014-11-17 17:44:08 -0800 | [diff] [blame] | 34 | class Source; |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 35 | |
Stephen Hines | c3437f0 | 2014-01-30 17:57:21 -0800 | [diff] [blame] | 36 | // Type signature for dynamically loaded initialization of an RSCompilerDriver. |
| 37 | typedef void (*RSCompilerDriverInit_t) (bcc::RSCompilerDriver *); |
| 38 | // Name of the function that we attempt to dynamically load/execute. |
| 39 | #define RS_COMPILER_DRIVER_INIT_FN rsCompilerDriverInit |
| 40 | |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 41 | class RSCompilerDriver { |
| 42 | private: |
| 43 | CompilerConfig *mConfig; |
Chris Wailes | b4447cd | 2014-08-19 16:22:20 -0700 | [diff] [blame] | 44 | Compiler mCompiler; |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 45 | |
Stephen Hines | 1d4a9e4 | 2013-04-18 01:03:59 -0700 | [diff] [blame] | 46 | // Are we compiling under an RS debug context with additional checks? |
| 47 | bool mDebugContext; |
| 48 | |
Stephen Hines | c3437f0 | 2014-01-30 17:57:21 -0800 | [diff] [blame] | 49 | // Callback before linking with the runtime library. |
| 50 | RSLinkRuntimeCallback mLinkRuntimeCallback; |
| 51 | |
Stephen Hines | c06cd06 | 2013-07-12 10:51:29 -0700 | [diff] [blame] | 52 | // Do we merge global variables on ARM using LLVM's optimization pass? |
Stephen Hines | ad69476 | 2013-04-29 18:59:47 -0700 | [diff] [blame] | 53 | // Disabling LLVM's global merge pass allows static globals to be correctly |
| 54 | // emitted to ELF. This can result in decreased performance due to increased |
| 55 | // register pressure, but it does make the resulting code easier to debug |
| 56 | // and work with. |
| 57 | bool mEnableGlobalMerge; |
| 58 | |
Stephen Hines | 750ee65 | 2015-04-16 16:24:18 -0700 | [diff] [blame] | 59 | // Specifies whether we should embed global variable information in the |
| 60 | // code via special RS variables that can be examined later by the driver. |
| 61 | bool mEmbedGlobalInfo; |
| 62 | |
| 63 | // Specifies whether we should skip constant (immutable) global variables |
| 64 | // when potentially embedding information about globals. |
| 65 | bool mEmbedGlobalInfoSkipConstant; |
| 66 | |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 67 | // Setup the compiler config for the given script. Return true if mConfig has |
| 68 | // been changed and false if it remains unchanged. |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 69 | bool setupConfig(const Script &pScript); |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 70 | |
Jean-Luc Brouillet | f2ac317 | 2014-06-25 18:21:36 -0700 | [diff] [blame] | 71 | // Compiles the provided bitcode, placing the binary at pOutputPath. |
Jean-Luc Brouillet | f2ac317 | 2014-06-25 18:21:36 -0700 | [diff] [blame] | 72 | // - If pDumpIR is true, a ".ll" file will also be created. |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 73 | Compiler::ErrorCode compileScript(Script& pScript, const char* pScriptName, |
Pirama Arumuga Nainar | 51ee77b | 2015-02-19 16:33:27 -0800 | [diff] [blame] | 74 | const char* pOutputPath, |
Pirama Arumuga Nainar | a65fba6 | 2015-02-19 11:01:30 -0800 | [diff] [blame] | 75 | const char* pRuntimePath, |
Pirama Arumuga Nainar | 51ee77b | 2015-02-19 16:33:27 -0800 | [diff] [blame] | 76 | const char* pBuildChecksum, |
Pirama Arumuga Nainar | a65fba6 | 2015-02-19 11:01:30 -0800 | [diff] [blame] | 77 | bool pDumpIR); |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 78 | |
| 79 | public: |
David Gross | efe1434 | 2016-02-18 11:46:57 -0800 | [diff] [blame] | 80 | RSCompilerDriver(); |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 81 | ~RSCompilerDriver(); |
| 82 | |
Chris Wailes | b4447cd | 2014-08-19 16:22:20 -0700 | [diff] [blame] | 83 | Compiler *getCompiler() { |
Stephen Hines | 331310e | 2012-10-26 19:27:55 -0700 | [diff] [blame] | 84 | return &mCompiler; |
| 85 | } |
| 86 | |
| 87 | void setConfig(CompilerConfig *config) { |
| 88 | mConfig = config; |
| 89 | } |
| 90 | |
Stephen Hines | 1d4a9e4 | 2013-04-18 01:03:59 -0700 | [diff] [blame] | 91 | void setDebugContext(bool v) { |
| 92 | mDebugContext = v; |
| 93 | } |
| 94 | |
Stephen Hines | c3437f0 | 2014-01-30 17:57:21 -0800 | [diff] [blame] | 95 | void setLinkRuntimeCallback(RSLinkRuntimeCallback c) { |
| 96 | mLinkRuntimeCallback = c; |
| 97 | } |
| 98 | |
| 99 | RSLinkRuntimeCallback getLinkRuntimeCallback() const { |
| 100 | return mLinkRuntimeCallback; |
| 101 | } |
| 102 | |
Stephen Hines | c06cd06 | 2013-07-12 10:51:29 -0700 | [diff] [blame] | 103 | // This function enables/disables merging of global static variables. |
| 104 | // Note that it only takes effect on ARM architectures (other architectures |
| 105 | // do not offer this option). |
Stephen Hines | ad69476 | 2013-04-29 18:59:47 -0700 | [diff] [blame] | 106 | void setEnableGlobalMerge(bool v) { |
| 107 | mEnableGlobalMerge = v; |
| 108 | } |
| 109 | |
| 110 | bool getEnableGlobalMerge() const { |
| 111 | return mEnableGlobalMerge; |
| 112 | } |
| 113 | |
Stephen McGroarty | 656325b | 2015-07-17 15:37:06 +0100 | [diff] [blame] | 114 | const CompilerConfig * getConfig() const { |
| 115 | return mConfig; |
| 116 | } |
| 117 | |
Stephen Hines | 750ee65 | 2015-04-16 16:24:18 -0700 | [diff] [blame] | 118 | // Set to true if we should embed global variable information in the code. |
| 119 | void setEmbedGlobalInfo(bool v) { |
| 120 | mEmbedGlobalInfo = v; |
| 121 | } |
| 122 | |
| 123 | // Returns true if we should embed global variable information in the code. |
| 124 | bool getEmbedGlobalInfo() const { |
| 125 | return mEmbedGlobalInfo; |
| 126 | } |
| 127 | |
| 128 | // Set to true if we should skip constant (immutable) global variables when |
| 129 | // potentially embedding information about globals. |
| 130 | void setEmbedGlobalInfoSkipConstant(bool v) { |
| 131 | mEmbedGlobalInfoSkipConstant = v; |
| 132 | } |
| 133 | |
| 134 | // Returns true if we should skip constant (immutable) global variables when |
| 135 | // potentially embedding information about globals. |
| 136 | bool getEmbedGlobalInfoSkipConstant() const { |
| 137 | return mEmbedGlobalInfoSkipConstant; |
| 138 | } |
| 139 | |
Stephen Hines | 47f0d5a | 2013-06-05 00:27:38 -0700 | [diff] [blame] | 140 | // FIXME: This method accompany with loadScript and compileScript should |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 141 | // all be const-methods. They're not now because the getAddress() in |
| 142 | // SymbolResolverInterface is not a const-method. |
Stephen Hines | 47f0d5a | 2013-06-05 00:27:38 -0700 | [diff] [blame] | 143 | // Returns true if script is successfully compiled. |
Jean-Luc Brouillet | f2ac317 | 2014-06-25 18:21:36 -0700 | [diff] [blame] | 144 | bool build(BCCContext& pContext, const char* pCacheDir, const char* pResName, |
Pirama Arumuga Nainar | a65fba6 | 2015-02-19 11:01:30 -0800 | [diff] [blame] | 145 | const char* pBitcode, size_t pBitcodeSize, |
Pirama Arumuga Nainar | 51ee77b | 2015-02-19 16:33:27 -0800 | [diff] [blame] | 146 | const char *pBuildChecksum, const char* pRuntimePath, |
Chris Wailes | 900c6c1 | 2014-08-13 15:40:00 -0700 | [diff] [blame] | 147 | RSLinkRuntimeCallback pLinkRuntimeCallback = nullptr, |
Tobias Grosser | 7b980e1 | 2013-06-20 10:12:13 -0700 | [diff] [blame] | 148 | bool pDumpIR = false); |
Stephen Hines | 47f0d5a | 2013-06-05 00:27:38 -0700 | [diff] [blame] | 149 | |
Yang Ni | a4ded13 | 2014-11-17 17:44:08 -0800 | [diff] [blame] | 150 | bool buildScriptGroup( |
| 151 | BCCContext& Context, const char* pOutputFilepath, const char* pRuntimePath, |
Yang Ni | 186d2f3 | 2015-04-07 14:51:47 -0700 | [diff] [blame] | 152 | const char* pRuntimeRelaxedPath, bool dumpIR, const char* buildChecksum, |
Yang Ni | 6da4e25 | 2015-03-11 10:00:42 -0700 | [diff] [blame] | 153 | const std::vector<Source*>& sources, |
Yang Ni | 0ab50b8 | 2015-02-16 12:31:56 -0800 | [diff] [blame] | 154 | const std::list<std::list<std::pair<int, int>>>& toFuse, |
| 155 | const std::list<std::string>& fused, |
| 156 | const std::list<std::list<std::pair<int, int>>>& invokes, |
| 157 | const std::list<std::string>& invokeBatchNames); |
Yang Ni | a4ded13 | 2014-11-17 17:44:08 -0800 | [diff] [blame] | 158 | |
Stephen Hines | 47f0d5a | 2013-06-05 00:27:38 -0700 | [diff] [blame] | 159 | // Returns true if script is successfully compiled. |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 160 | bool buildForCompatLib(Script &pScript, const char *pOut, |
Pirama Arumuga Nainar | 51ee77b | 2015-02-19 16:33:27 -0800 | [diff] [blame] | 161 | const char *pBuildChecksum, const char *pRuntimePath, |
| 162 | bool pDumpIR); |
Zonr Chang | 0fffa7e | 2012-04-12 19:43:53 +0800 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | } // end namespace bcc |
| 166 | |
Zonr Chang | c72c4dd | 2012-04-12 15:38:53 +0800 | [diff] [blame] | 167 | #endif // BCC_RS_COMPILER_DRIVER_H |