Revert "Remove all deprecated BCC C APIs."
This reverts commit 170d420231f10d5b914fde505202c58f11f43e27.
diff --git a/lib/RenderScript/RSCompilerDriver.cpp b/lib/RenderScript/RSCompilerDriver.cpp
index 0ccb625..da87968 100644
--- a/lib/RenderScript/RSCompilerDriver.cpp
+++ b/lib/RenderScript/RSCompilerDriver.cpp
@@ -16,25 +16,17 @@
#include "bcc/RenderScript/RSCompilerDriver.h"
-#include <llvm/Support/Path.h>
-
-#include "bcinfo/BitcodeWrapper.h"
-
#include "bcc/RenderScript/RSExecutable.h"
-#include "bcc/RenderScript/RSScript.h"
#include "bcc/Support/CompilerConfig.h"
#include "bcc/Support/TargetCompilerConfigs.h"
-#include "bcc/Source.h"
#include "bcc/Support/FileMutex.h"
#include "bcc/Support/Log.h"
#include "bcc/Support/InputFile.h"
#include "bcc/Support/Initialization.h"
-#include "bcc/Support/Sha1Util.h"
#include "bcc/Support/OutputFile.h"
#include <cutils/properties.h>
#include <utils/String8.h>
-#include <utils/StopWatch.h>
using namespace bcc;
@@ -64,10 +56,8 @@
delete mConfig;
}
-RSExecutable *
-RSCompilerDriver::loadScriptCache(const char *pOutputPath,
- const RSInfo::DependencyTableTy &pDeps) {
- android::StopWatch load_time("bcc: RSCompilerDriver::loadScriptCache time");
+RSExecutable *RSCompilerDriver::loadScriptCache(const RSScript &pScript,
+ const std::string &pOutputPath){
RSExecutable *result = NULL;
if (is_force_recompile())
@@ -79,7 +69,7 @@
FileMutex<FileBase::kReadLock> read_output_mutex(pOutputPath);
if (read_output_mutex.hasError() || !read_output_mutex.lock()) {
- ALOGE("Unable to acquire the read lock for %s! (%s)", pOutputPath,
+ ALOGE("Unable to acquire the read lock for %s! (%s)", pOutputPath.c_str(),
read_output_mutex.getErrorMessage().c_str());
return NULL;
}
@@ -90,7 +80,7 @@
InputFile *output_file = new (std::nothrow) InputFile(pOutputPath);
if ((output_file == NULL) || output_file->hasError()) {
- ALOGE("Unable to open the %s for read! (%s)", pOutputPath,
+ ALOGE("Unable to open the %s for read! (%s)", pOutputPath.c_str(),
output_file->getErrorMessage().c_str());
delete output_file;
return NULL;
@@ -103,7 +93,7 @@
if (!output_file->lock()) {
ALOGE("Unable to acquire the read lock on %s for reading %s! (%s)",
- pOutputPath, info_path.string(),
+ pOutputPath.c_str(), info_path.string(),
output_file->getErrorMessage().c_str());
delete output_file;
return NULL;
@@ -113,7 +103,8 @@
// Open and load the RS info file.
//===--------------------------------------------------------------------===//
InputFile info_file(info_path.string());
- RSInfo *info = RSInfo::ReadFromFile(info_file, pDeps);
+ RSInfo *info = RSInfo::ReadFromFile(info_file,
+ pScript.getSourceDependencies());
// Release the lock on output_file.
output_file->unlock();
@@ -133,6 +124,12 @@
return NULL;
}
+ // TODO: Dirty hack for libRS. This can be removed once RSExecutable is public
+ // to libRS.
+ if (!result->isThreadable()) {
+ mRSRuntime.getAddress("__clearThreadable");
+ }
+
return result;
}
@@ -173,11 +170,8 @@
return changed;
}
-RSExecutable *
-RSCompilerDriver::compileScript(RSScript &pScript,
- const char *pOutputPath,
- const RSInfo::DependencyTableTy &pDeps) {
- android::StopWatch compile_time("bcc: RSCompilerDriver::compileScript time");
+RSExecutable *RSCompilerDriver::compileScript(RSScript &pScript,
+ const std::string &pOutputPath) {
RSExecutable *result = NULL;
RSInfo *info = NULL;
@@ -186,7 +180,8 @@
//===--------------------------------------------------------------------===//
// RS info may contains configuration (such as #optimization_level) to the
// compiler therefore it should be extracted before compilation.
- info = RSInfo::ExtractFromSource(pScript.getSource(), pDeps);
+ info = RSInfo::ExtractFromSource(pScript.getSource(),
+ pScript.getSourceDependencies());
if (info == NULL) {
return NULL;
}
@@ -205,7 +200,7 @@
if (write_output_mutex.hasError() || !write_output_mutex.lock()) {
ALOGE("Unable to acquire the lock for writing %s! (%s)",
- pOutputPath, write_output_mutex.getErrorMessage().c_str());
+ pOutputPath.c_str(), write_output_mutex.getErrorMessage().c_str());
return NULL;
}
@@ -215,7 +210,7 @@
OutputFile *output_file = new (std::nothrow) OutputFile(pOutputPath);
if ((output_file == NULL) || output_file->hasError()) {
- ALOGE("Unable to open the %s for write! (%s)", pOutputPath,
+ ALOGE("Unable to open the %s for write! (%s)", pOutputPath.c_str(),
output_file->getErrorMessage().c_str());
delete info;
delete output_file;
@@ -228,7 +223,8 @@
bool compiler_need_reconfigure = setupConfig(pScript);
if (mConfig == NULL) {
- ALOGE("Failed to setup config for RS compiler to compile %s!", pOutputPath);
+ ALOGE("Failed to setup config for RS compiler to compile %s!",
+ pOutputPath.c_str());
delete info;
delete output_file;
return NULL;
@@ -239,7 +235,7 @@
if (compiler_need_reconfigure) {
Compiler::ErrorCode err = mCompiler.config(*mConfig);
if (err != Compiler::kSuccess) {
- ALOGE("Failed to config the RS compiler for %s! (%s)",pOutputPath,
+ ALOGE("Failed to config the RS compiler for %s! (%s)",pOutputPath.c_str(),
Compiler::GetErrorString(err));
delete info;
delete output_file;
@@ -252,7 +248,7 @@
//===--------------------------------------------------------------------===//
Compiler::ErrorCode compile_result = mCompiler.compile(pScript, *output_file);
if (compile_result != Compiler::kSuccess) {
- ALOGE("Unable to compile the source to file %s! (%s)", pOutputPath,
+ ALOGE("Unable to compile the source to file %s! (%s)", pOutputPath.c_str(),
Compiler::GetErrorString(compile_result));
delete info;
delete output_file;
@@ -269,6 +265,10 @@
return NULL;
}
+ // TODO: Dirty hack for libRS. This can be removed once RSExecutable is public
+ // to libRS.
+ result->setThreadable(mRSRuntime.getAddress("__isThreadable") != NULL);
+
//===--------------------------------------------------------------------===//
// Write out the RS info file.
//===--------------------------------------------------------------------===//
@@ -276,107 +276,20 @@
// successfully compiled and loaded.
if (!result->syncInfo(/* pForce */true)) {
ALOGW("%s was successfully compiled and loaded but its RS info file failed "
- "to write out!", pOutputPath);
+ "to write out!", pOutputPath.c_str());
}
return result;
}
-RSExecutable *RSCompilerDriver::build(BCCContext &pContext,
- const char *pCacheDir,
- const char *pResName,
- const char *pBitcode,
- size_t pBitcodeSize) {
- android::StopWatch build_time("bcc: RSCompilerDriver::build time");
- //===--------------------------------------------------------------------===//
- // Check parameters.
- //===--------------------------------------------------------------------===//
- if ((pCacheDir == NULL) || (pResName == NULL)) {
- ALOGE("Invalid parameter passed to RSCompilerDriver::build()! (cache dir: "
- "%s, resource name: %s)", ((pCacheDir) ? pCacheDir : "(null)"),
- ((pResName) ? pResName : "(null)"));
- return NULL;
- }
-
- if ((pBitcode == NULL) || (pBitcodeSize <= 0)) {
- ALOGE("No bitcode supplied! (bitcode: %p, size of bitcode: %u)",
- pBitcode, static_cast<unsigned>(pBitcodeSize));
- return NULL;
- }
-
- //===--------------------------------------------------------------------===//
- // Prepare dependency information.
- //===--------------------------------------------------------------------===//
- RSInfo::DependencyTableTy dep_info;
- uint8_t bitcode_sha1[20];
- Sha1Util::GetSHA1DigestFromBuffer(bitcode_sha1, pBitcode, pBitcodeSize);
- dep_info.push(std::make_pair(pResName, bitcode_sha1));
-
- //===--------------------------------------------------------------------===//
- // Construct output path.
- //===--------------------------------------------------------------------===//
- llvm::sys::Path output_path(pCacheDir);
-
- // {pCacheDir}/{pResName}
- if (!output_path.appendComponent(pResName)) {
- ALOGE("Failed to construct output path %s/%s!", pCacheDir, pResName);
- return NULL;
- }
-
- // {pCacheDir}/{pResName}.o
- output_path.appendSuffix("o");
-
- //===--------------------------------------------------------------------===//
- // Load cache.
- //===--------------------------------------------------------------------===//
- RSExecutable *result = loadScriptCache(output_path.c_str(), dep_info);
+RSExecutable *RSCompilerDriver::build(RSScript &pScript,
+ const std::string &pOutputPath) {
+ RSExecutable *result = loadScriptCache(pScript, pOutputPath);
if (result != NULL) {
// Cache hit
return result;
}
- //===--------------------------------------------------------------------===//
- // Load the bitcode and create script.
- //===--------------------------------------------------------------------===//
- Source *source = Source::CreateFromBuffer(pContext, pResName,
- pBitcode, pBitcodeSize);
- if (source == NULL) {
- return NULL;
- }
-
- RSScript *script = new (std::nothrow) RSScript(*source);
- if (script == NULL) {
- ALOGE("Out of memory when create Script object for '%s'! (output: %s)",
- pResName, output_path.c_str());
- delete source;
- return NULL;
- }
-
- // Link RS script with RenderScript runtime.
- if (!RSScript::LinkRuntime(*script)) {
- ALOGE("Failed to link script '%s' with RenderScript runtime!", pResName);
- delete script;
- return NULL;
- }
-
- // Read information from bitcode wrapper.
- bcinfo::BitcodeWrapper wrapper(pBitcode, pBitcodeSize);
- script->setCompilerVersion(wrapper.getCompilerVersion());
- script->setOptimizationLevel(static_cast<RSScript::OptimizationLevel>(
- wrapper.getOptimizationLevel()));
-
- //===--------------------------------------------------------------------===//
- // Compile the script
- //===--------------------------------------------------------------------===//
- result = compileScript(*script, output_path.c_str(), dep_info);
-
- // Script is no longer used. Free it to get more memory.
- delete script;
-
- if (result == NULL) {
- return NULL;
- }
-
- return result;
+ return compileScript(pScript, pOutputPath);
}