blob: 72dfc40c6ee8522aa310836dcb994f1650f56f8f [file] [log] [blame]
Zonr Chang0fffa7e2012-04-12 19:43:53 +08001/*
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
Stephen Hinese198abe2012-07-27 18:05:41 -070017#include "bcc/Renderscript/RSCompilerDriver.h"
Zonr Chang0fffa7e2012-04-12 19:43:53 +080018
Yang Nia4ded132014-11-17 17:44:08 -080019#include "llvm/IR/AssemblyAnnotationWriter.h"
Tobias Grosser7b980e12013-06-20 10:12:13 -070020#include <llvm/IR/Module.h>
Stephen Hinesad694762013-04-29 18:59:47 -070021#include <llvm/Support/CommandLine.h>
Stephen Hinesb10c3a72013-08-07 23:15:22 -070022#include <llvm/Support/Path.h>
Tobias Grosser7b980e12013-06-20 10:12:13 -070023#include <llvm/Support/raw_ostream.h>
Shih-wei Liao7bcec852012-04-25 04:07:09 -070024
25#include "bcinfo/BitcodeWrapper.h"
Yang Nia4ded132014-11-17 17:44:08 -080026#include "bcc/BCCContext.h"
Stephen Hines47f0d5a2013-06-05 00:27:38 -070027#include "bcc/Compiler.h"
Stephen Hinesbde1a252014-05-15 18:02:33 -070028#include "bcc/Config/Config.h"
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -070029#include "bcc/Renderscript/RSInfo.h"
Stephen Hinese198abe2012-07-27 18:05:41 -070030#include "bcc/Renderscript/RSScript.h"
Yang Nia4ded132014-11-17 17:44:08 -080031#include "bcc/Renderscript/RSScriptGroupFusion.h"
Zonr Changc72c4dd2012-04-12 15:38:53 +080032#include "bcc/Support/CompilerConfig.h"
Shih-wei Liao7bcec852012-04-25 04:07:09 -070033#include "bcc/Source.h"
Zonr Changc72c4dd2012-04-12 15:38:53 +080034#include "bcc/Support/FileMutex.h"
Zonr Changef73a242012-04-12 16:44:01 +080035#include "bcc/Support/Log.h"
Zonr Changc72c4dd2012-04-12 15:38:53 +080036#include "bcc/Support/InputFile.h"
37#include "bcc/Support/Initialization.h"
Shih-wei Liao7bcec852012-04-25 04:07:09 -070038#include "bcc/Support/Sha1Util.h"
Zonr Changc72c4dd2012-04-12 15:38:53 +080039#include "bcc/Support/OutputFile.h"
Zonr Chang0fffa7e2012-04-12 19:43:53 +080040
Yang Nia4ded132014-11-17 17:44:08 -080041#include <string>
42
Nick Kralevichb81d6972013-05-21 16:52:35 -070043#ifdef HAVE_ANDROID_OS
Zonr Chang0fffa7e2012-04-12 19:43:53 +080044#include <cutils/properties.h>
Nick Kralevichb81d6972013-05-21 16:52:35 -070045#endif
Shih-wei Liao7bcec852012-04-25 04:07:09 -070046#include <utils/StopWatch.h>
Zonr Chang0fffa7e2012-04-12 19:43:53 +080047
48using namespace bcc;
49
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -070050// Get the build fingerprint of the Android device we are running on.
51static std::string getBuildFingerPrint() {
52#ifdef HAVE_ANDROID_OS
53 char fingerprint[PROPERTY_VALUE_MAX];
54 property_get("ro.build.fingerprint", fingerprint, "");
55 return fingerprint;
56#else
57 return "HostBuild";
58#endif
59}
60
Stephen Hines3ab9da12013-02-01 18:39:15 -080061RSCompilerDriver::RSCompilerDriver(bool pUseCompilerRT) :
Chris Wailes900c6c12014-08-13 15:40:00 -070062 mConfig(nullptr), mCompiler(), mDebugContext(false),
63 mLinkRuntimeCallback(nullptr), mEnableGlobalMerge(true) {
Zonr Chang0fffa7e2012-04-12 19:43:53 +080064 init::Initialize();
Zonr Chang0fffa7e2012-04-12 19:43:53 +080065}
66
67RSCompilerDriver::~RSCompilerDriver() {
68 delete mConfig;
69}
70
Zonr Chang0fffa7e2012-04-12 19:43:53 +080071
Stephen Hinesbde1a252014-05-15 18:02:33 -070072#if defined(PROVIDE_ARM_CODEGEN)
Stephen Hinesad694762013-04-29 18:59:47 -070073extern llvm::cl::opt<bool> EnableGlobalMerge;
Stephen Hinesc06cd062013-07-12 10:51:29 -070074#endif
75
Zonr Chang0fffa7e2012-04-12 19:43:53 +080076bool RSCompilerDriver::setupConfig(const RSScript &pScript) {
77 bool changed = false;
78
79 const llvm::CodeGenOpt::Level script_opt_level =
80 static_cast<llvm::CodeGenOpt::Level>(pScript.getOptimizationLevel());
81
Stephen Hinesbde1a252014-05-15 18:02:33 -070082#if defined(PROVIDE_ARM_CODEGEN)
Stephen Hines045558b2014-02-18 14:07:15 -080083 EnableGlobalMerge = mEnableGlobalMerge;
84#endif
85
Chris Wailes900c6c12014-08-13 15:40:00 -070086 if (mConfig != nullptr) {
Zonr Chang0fffa7e2012-04-12 19:43:53 +080087 // Renderscript bitcode may have their optimization flag configuration
88 // different than the previous run of RS compilation.
89 if (mConfig->getOptimizationLevel() != script_opt_level) {
90 mConfig->setOptimizationLevel(script_opt_level);
91 changed = true;
92 }
93 } else {
94 // Haven't run the compiler ever.
Stephen Hinesbde1a252014-05-15 18:02:33 -070095 mConfig = new (std::nothrow) CompilerConfig(DEFAULT_TARGET_TRIPLE_STRING);
Chris Wailes900c6c12014-08-13 15:40:00 -070096 if (mConfig == nullptr) {
Zonr Chang0fffa7e2012-04-12 19:43:53 +080097 // Return false since mConfig remains NULL and out-of-memory.
98 return false;
99 }
100 mConfig->setOptimizationLevel(script_opt_level);
101 changed = true;
102 }
103
Stephen Hinesbde1a252014-05-15 18:02:33 -0700104#if defined(PROVIDE_ARM_CODEGEN)
Chris Wailes900c6c12014-08-13 15:40:00 -0700105 assert((pScript.getInfo() != nullptr) && "NULL RS info!");
Stephen Hinesbde1a252014-05-15 18:02:33 -0700106 bool script_full_prec = (pScript.getInfo()->getFloatPrecisionRequirement() ==
107 RSInfo::FP_Full);
108 if (mConfig->getFullPrecision() != script_full_prec) {
109 mConfig->setFullPrecision(script_full_prec);
110 changed = true;
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800111 }
112#endif
113
114 return changed;
115}
116
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700117Compiler::ErrorCode RSCompilerDriver::compileScript(RSScript& pScript, const char* pScriptName,
118 const char* pOutputPath,
119 const char* pRuntimePath,
120 const RSInfo::DependencyHashTy& pSourceHash,
121 const char* compileCommandLineToEmbed,
122 bool saveInfoFile, bool pDumpIR) {
123 // android::StopWatch compile_time("bcc: RSCompilerDriver::compileScript time");
Chris Wailes900c6c12014-08-13 15:40:00 -0700124 RSInfo *info = nullptr;
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800125
126 //===--------------------------------------------------------------------===//
127 // Extract RS-specific information from source bitcode.
128 //===--------------------------------------------------------------------===//
129 // RS info may contains configuration (such as #optimization_level) to the
130 // compiler therefore it should be extracted before compilation.
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700131 info = RSInfo::ExtractFromSource(pScript.getSource(), pSourceHash, compileCommandLineToEmbed,
132 getBuildFingerPrint().c_str());
Chris Wailes900c6c12014-08-13 15:40:00 -0700133 if (info == nullptr) {
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700134 return Compiler::kErrInvalidSource;
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800135 }
136
137 //===--------------------------------------------------------------------===//
138 // Associate script with its info
139 //===--------------------------------------------------------------------===//
140 // This is required since RS compiler may need information in the info file
141 // to do some transformation (e.g., expand foreach-able function.)
142 pScript.setInfo(info);
143
144 //===--------------------------------------------------------------------===//
Stephen Hinese198abe2012-07-27 18:05:41 -0700145 // Link RS script with Renderscript runtime.
Shih-wei Liaoba420642012-06-30 11:27:37 -0700146 //===--------------------------------------------------------------------===//
Stephen Hines331310e2012-10-26 19:27:55 -0700147 if (!RSScript::LinkRuntime(pScript, pRuntimePath)) {
Stephen Hinese198abe2012-07-27 18:05:41 -0700148 ALOGE("Failed to link script '%s' with Renderscript runtime!", pScriptName);
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700149 return Compiler::kErrInvalidSource;
Shih-wei Liaoba420642012-06-30 11:27:37 -0700150 }
151
Stephen Hines01f05d42013-05-31 20:51:27 -0700152 {
Stephen Hines07843652013-08-15 15:41:47 -0700153 // FIXME(srhines): Windows compilation can't use locking like this, but
154 // we also don't need to worry about concurrent writers of the same file.
Stephen Hinesd7a95262013-08-08 16:03:19 -0700155#ifndef USE_MINGW
Stephen Hines07843652013-08-15 15:41:47 -0700156 //===------------------------------------------------------------------===//
Stephen Hines01f05d42013-05-31 20:51:27 -0700157 // Acquire the write lock for writing output object file.
Stephen Hines07843652013-08-15 15:41:47 -0700158 //===------------------------------------------------------------------===//
Stephen Hines01f05d42013-05-31 20:51:27 -0700159 FileMutex<FileBase::kWriteLock> write_output_mutex(pOutputPath);
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800160
Stephen Hines01f05d42013-05-31 20:51:27 -0700161 if (write_output_mutex.hasError() || !write_output_mutex.lock()) {
162 ALOGE("Unable to acquire the lock for writing %s! (%s)",
163 pOutputPath, write_output_mutex.getErrorMessage().c_str());
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700164 return Compiler::kErrInvalidSource;
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800165 }
Stephen Hinesd7a95262013-08-08 16:03:19 -0700166#endif
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800167
Stephen Hines01f05d42013-05-31 20:51:27 -0700168 // Open the output file for write.
Stephen Hinesacf9c9e2013-09-26 16:32:31 -0700169 OutputFile output_file(pOutputPath,
170 FileBase::kTruncate | FileBase::kBinary);
Stephen Hines01f05d42013-05-31 20:51:27 -0700171
172 if (output_file.hasError()) {
173 ALOGE("Unable to open %s for write! (%s)", pOutputPath,
174 output_file.getErrorMessage().c_str());
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700175 return Compiler::kErrInvalidSource;
Stephen Hines01f05d42013-05-31 20:51:27 -0700176 }
177
178 // Setup the config to the compiler.
179 bool compiler_need_reconfigure = setupConfig(pScript);
180
Chris Wailes900c6c12014-08-13 15:40:00 -0700181 if (mConfig == nullptr) {
Stephen Hines01f05d42013-05-31 20:51:27 -0700182 ALOGE("Failed to setup config for RS compiler to compile %s!",
183 pOutputPath);
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700184 return Compiler::kErrInvalidSource;
Stephen Hines01f05d42013-05-31 20:51:27 -0700185 }
186
187 if (compiler_need_reconfigure) {
188 Compiler::ErrorCode err = mCompiler.config(*mConfig);
189 if (err != Compiler::kSuccess) {
190 ALOGE("Failed to config the RS compiler for %s! (%s)",pOutputPath,
191 Compiler::GetErrorString(err));
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700192 return Compiler::kErrInvalidSource;
Stephen Hines01f05d42013-05-31 20:51:27 -0700193 }
194 }
195
Chris Wailes900c6c12014-08-13 15:40:00 -0700196 OutputFile *ir_file = nullptr;
197 llvm::raw_fd_ostream *IRStream = nullptr;
Tobias Grosser27fb7ed2013-06-21 18:34:56 -0700198 if (pDumpIR) {
Chris Wailes35978e72014-08-11 14:01:47 -0700199 std::string path(pOutputPath);
Tobias Grosser27fb7ed2013-06-21 18:34:56 -0700200 path.append(".ll");
Chris Wailes35978e72014-08-11 14:01:47 -0700201 ir_file = new OutputFile(path.c_str(), FileBase::kTruncate);
Tobias Grosser27fb7ed2013-06-21 18:34:56 -0700202 IRStream = ir_file->dup();
203 }
204
Stephen Hines01f05d42013-05-31 20:51:27 -0700205 // Run the compiler.
Chris Wailes35978e72014-08-11 14:01:47 -0700206 Compiler::ErrorCode compile_result =
207 mCompiler.compile(pScript, output_file, IRStream);
Tobias Grosser27fb7ed2013-06-21 18:34:56 -0700208
209 if (ir_file) {
210 ir_file->close();
211 delete ir_file;
212 }
Stephen Hines01f05d42013-05-31 20:51:27 -0700213
214 if (compile_result != Compiler::kSuccess) {
215 ALOGE("Unable to compile the source to file %s! (%s)", pOutputPath,
216 Compiler::GetErrorString(compile_result));
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700217 return Compiler::kErrInvalidSource;
Stephen Hines01f05d42013-05-31 20:51:27 -0700218 }
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800219 }
220
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700221 if (saveInfoFile) {
Chris Wailes35978e72014-08-11 14:01:47 -0700222 std::string info_path = RSInfo::GetPath(pOutputPath);
223 OutputFile info_file(info_path.c_str(), FileBase::kTruncate);
Stephen Hines01f05d42013-05-31 20:51:27 -0700224
225 if (info_file.hasError()) {
226 ALOGE("Failed to open the info file %s for write! (%s)",
Chris Wailes35978e72014-08-11 14:01:47 -0700227 info_path.c_str(), info_file.getErrorMessage().c_str());
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700228 return Compiler::kErrInvalidSource;
Stephen Hines01f05d42013-05-31 20:51:27 -0700229 }
230
Chris Wailes35978e72014-08-11 14:01:47 -0700231 FileMutex<FileBase::kWriteLock> write_info_mutex(info_path.c_str());
Stephen Hines01f05d42013-05-31 20:51:27 -0700232 if (write_info_mutex.hasError() || !write_info_mutex.lock()) {
233 ALOGE("Unable to acquire the lock for writing %s! (%s)",
Chris Wailes35978e72014-08-11 14:01:47 -0700234 info_path.c_str(), write_info_mutex.getErrorMessage().c_str());
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700235 return Compiler::kErrInvalidSource;
Stephen Hines01f05d42013-05-31 20:51:27 -0700236 }
237
238 // Perform the write.
239 if (!info->write(info_file)) {
Chris Wailes35978e72014-08-11 14:01:47 -0700240 ALOGE("Failed to sync the RS info file %s!", info_path.c_str());
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700241 return Compiler::kErrInvalidSource;
Stephen Hines01f05d42013-05-31 20:51:27 -0700242 }
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800243 }
244
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700245 return Compiler::kSuccess;
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800246}
247
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700248bool RSCompilerDriver::build(BCCContext &pContext,
249 const char *pCacheDir,
250 const char *pResName,
251 const char *pBitcode,
252 size_t pBitcodeSize,
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700253 const char *commandLine,
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700254 const char *pRuntimePath,
Tobias Grosser7b980e12013-06-20 10:12:13 -0700255 RSLinkRuntimeCallback pLinkRuntimeCallback,
256 bool pDumpIR) {
Tim Murrayc89f78b2013-05-09 11:57:12 -0700257 // android::StopWatch build_time("bcc: RSCompilerDriver::build time");
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700258 //===--------------------------------------------------------------------===//
259 // Check parameters.
260 //===--------------------------------------------------------------------===//
Chris Wailes900c6c12014-08-13 15:40:00 -0700261 if ((pCacheDir == nullptr) || (pResName == nullptr)) {
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700262 ALOGE("Invalid parameter passed to RSCompilerDriver::build()! (cache dir: "
263 "%s, resource name: %s)", ((pCacheDir) ? pCacheDir : "(null)"),
264 ((pResName) ? pResName : "(null)"));
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700265 return false;
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700266 }
267
Chris Wailes900c6c12014-08-13 15:40:00 -0700268 if ((pBitcode == nullptr) || (pBitcodeSize <= 0)) {
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700269 ALOGE("No bitcode supplied! (bitcode: %p, size of bitcode: %u)",
270 pBitcode, static_cast<unsigned>(pBitcodeSize));
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700271 return false;
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700272 }
273
274 //===--------------------------------------------------------------------===//
275 // Prepare dependency information.
276 //===--------------------------------------------------------------------===//
Jean-Luc Brouilletc5e607a2014-06-18 18:14:02 -0700277 uint8_t bitcode_sha1[SHA1_DIGEST_LENGTH];
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700278 Sha1Util::GetSHA1DigestFromBuffer(bitcode_sha1, pBitcode, pBitcodeSize);
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700279
280 //===--------------------------------------------------------------------===//
281 // Construct output path.
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700282 // {pCacheDir}/{pResName}.o
Stephen Hinesb10c3a72013-08-07 23:15:22 -0700283 //===--------------------------------------------------------------------===//
284 llvm::SmallString<80> output_path(pCacheDir);
285 llvm::sys::path::append(output_path, pResName);
286 llvm::sys::path::replace_extension(output_path, ".o");
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700287
288 //===--------------------------------------------------------------------===//
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700289 // Load the bitcode and create script.
290 //===--------------------------------------------------------------------===//
291 Source *source = Source::CreateFromBuffer(pContext, pResName,
292 pBitcode, pBitcodeSize);
Chris Wailes900c6c12014-08-13 15:40:00 -0700293 if (source == nullptr) {
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700294 return false;
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700295 }
296
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700297 RSScript script(*source);
Stephen Hinesc3437f02014-01-30 17:57:21 -0800298 if (pLinkRuntimeCallback) {
299 setLinkRuntimeCallback(pLinkRuntimeCallback);
300 }
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700301
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700302 script.setLinkRuntimeCallback(getLinkRuntimeCallback());
Stephen Hines06731a62013-02-12 19:29:42 -0800303
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700304 // Read information from bitcode wrapper.
305 bcinfo::BitcodeWrapper wrapper(pBitcode, pBitcodeSize);
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700306 script.setCompilerVersion(wrapper.getCompilerVersion());
307 script.setOptimizationLevel(static_cast<RSScript::OptimizationLevel>(
308 wrapper.getOptimizationLevel()));
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700309
310 //===--------------------------------------------------------------------===//
311 // Compile the script
312 //===--------------------------------------------------------------------===//
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700313 Compiler::ErrorCode status = compileScript(script, pResName,
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700314 output_path.c_str(),
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700315 pRuntimePath, bitcode_sha1, commandLine,
316 true, pDumpIR);
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700317
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700318 return status == Compiler::kSuccess;
Zonr Chang0fffa7e2012-04-12 19:43:53 +0800319}
Stephen Hines331310e2012-10-26 19:27:55 -0700320
Yang Nia4ded132014-11-17 17:44:08 -0800321bool RSCompilerDriver::buildScriptGroup(
322 BCCContext& Context, const char* pOutputFilepath, const char*pRuntimePath,
323 const std::vector<const Source*>& sources, const std::vector<int>& slots,
324 bool dumpIR) {
325 llvm::Module* module = fuseKernels(Context, sources, slots);
326 if (module == nullptr) {
327 return false;
328 }
329
330 const std::unique_ptr<Source> source(
331 Source::CreateFromModule(Context, pOutputFilepath, *module));
332 RSScript script(*source);
333
334 uint8_t bitcode_sha1[SHA1_DIGEST_LENGTH];
335 const char* compileCommandLineToEmbed = "";
336
337 llvm::SmallString<80> output_path(pOutputFilepath);
338 llvm::sys::path::replace_extension(output_path, ".o");
339
340 compileScript(script, pOutputFilepath, output_path.c_str(), pRuntimePath,
341 bitcode_sha1, compileCommandLineToEmbed, true, dumpIR);
342
343 return true;
344}
Stephen Hines331310e2012-10-26 19:27:55 -0700345
Jean-Luc Brouilletc5e607a2014-06-18 18:14:02 -0700346bool RSCompilerDriver::buildForCompatLib(RSScript &pScript, const char *pOut,
Tim Murray77c1d552015-01-22 15:15:17 -0800347 const char *pRuntimePath,
348 bool pDumpIR) {
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700349 // For compat lib, we don't check the RS info file so we don't need the source hash,
350 // compile command, and build fingerprint.
351 // TODO We may want to make them optional or embed real values.
352 uint8_t bitcode_sha1[SHA1_DIGEST_LENGTH] = {0};
353 const char* compileCommandLineToEmbed = "";
354 const char* buildFingerprintToEmbed = "";
355
356 RSInfo* info = RSInfo::ExtractFromSource(pScript.getSource(), bitcode_sha1,
357 compileCommandLineToEmbed, buildFingerprintToEmbed);
Chris Wailes900c6c12014-08-13 15:40:00 -0700358 if (info == nullptr) {
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700359 return false;
Stephen Hines331310e2012-10-26 19:27:55 -0700360 }
361 pScript.setInfo(info);
362
Stephen Hines86a0b792012-11-06 20:04:47 -0800363 // Embed the info string directly in the ELF, since this path is for an
364 // offline (host) compilation.
365 pScript.setEmbedInfo(true);
366
Jean-Luc Brouilletf2ac3172014-06-25 18:21:36 -0700367 Compiler::ErrorCode status = compileScript(pScript, pOut, pOut, pRuntimePath, bitcode_sha1,
Tim Murray77c1d552015-01-22 15:15:17 -0800368 compileCommandLineToEmbed, false, pDumpIR);
Stephen Hines47f0d5a2013-06-05 00:27:38 -0700369 if (status != Compiler::kSuccess) {
370 return false;
371 }
372
373 return true;
Stephen Hines331310e2012-10-26 19:27:55 -0700374}