Switch optimization level from metadata to bitcode wrapper.
Change-Id: Ieb547d38f2ad1c84af30717da9172d0ac928e52d
diff --git a/Android.mk b/Android.mk
index 2d1245b..72723e8 100644
--- a/Android.mk
+++ b/Android.mk
@@ -133,7 +133,7 @@
libLLVMCore \
libLLVMSupport
-LOCAL_SHARED_LIBRARIES := libdl libcutils libutils libstlport
+LOCAL_SHARED_LIBRARIES := libbcinfo libdl libcutils libutils libstlport
# Modules that need get installed if and only if the target libbcc.so is installed.
LOCAL_REQUIRED_MODULES := libclcore.bc libbcc.so.sha1
@@ -210,6 +210,8 @@
libLLVMCore \
libLLVMSupport
+LOCAL_SHARED_LIBRARIES := libbcinfo
+
LOCAL_LDLIBS := -ldl -lpthread
# Generate build stamp (Build time + Build git revision + Build Semi SHA1)
diff --git a/bcinfo/BitcodeWrapper.cpp b/bcinfo/BitcodeWrapper.cpp
index 67f95b8..e04db88 100644
--- a/bcinfo/BitcodeWrapper.cpp
+++ b/bcinfo/BitcodeWrapper.cpp
@@ -31,7 +31,8 @@
BitcodeWrapper::BitcodeWrapper(const char *bitcode, size_t bitcodeSize)
: mFileType(BC_NOT_BC), mBitcode(bitcode),
mBitcodeEnd(bitcode + bitcodeSize - 1), mBitcodeSize(bitcodeSize),
- mHeaderVersion(0), mTargetAPI(0) {
+ mHeaderVersion(0), mTargetAPI(0), mCompilerVersion(0),
+ mOptimizationLevel(3) {
InMemoryWrapperInput inMem(mBitcode, mBitcodeSize);
BitcodeWrapperer wrapperer(&inMem, NULL);
if (wrapperer.IsInputBitcodeWrapper()) {
diff --git a/bcinfo/MetadataExtractor.cpp b/bcinfo/MetadataExtractor.cpp
index dadca08..4351d46 100644
--- a/bcinfo/MetadataExtractor.cpp
+++ b/bcinfo/MetadataExtractor.cpp
@@ -16,6 +16,8 @@
#include "bcinfo/MetadataExtractor.h"
+#include "bcinfo/BitcodeWrapper.h"
+
#define LOG_TAG "bcinfo"
#include <cutils/log.h>
@@ -50,17 +52,15 @@
// synced with slang_rs_metadata.h)
static const llvm::StringRef ObjectSlotMetadataName = "#rs_object_slots";
-// Name of metadata node where RS optimization level resides (should be
-// synced with slang_rs_metadata.h)
-static const llvm::StringRef OptimizationLevelMetadataName = "#optimization_level";
-
MetadataExtractor::MetadataExtractor(const char *bitcode, size_t bitcodeSize)
: mBitcode(bitcode), mBitcodeSize(bitcodeSize), mExportVarCount(0),
mExportFuncCount(0), mExportForEachSignatureCount(0),
mExportForEachSignatureList(NULL), mPragmaCount(0), mPragmaKeyList(NULL),
- mPragmaValueList(NULL), mObjectSlotCount(0), mObjectSlotList(NULL),
- mOptimizationLevel(3) {
+ mPragmaValueList(NULL), mObjectSlotCount(0), mObjectSlotList(NULL) {
+ BitcodeWrapper wrapper(bitcode, bitcodeSize);
+ mCompilerVersion = wrapper.getCompilerVersion();
+ mOptimizationLevel = wrapper.getOptimizationLevel();
}
@@ -247,8 +247,6 @@
module->getNamedMetadata(PragmaMetadataName);
const llvm::NamedMDNode *ObjectSlotMetadata =
module->getNamedMetadata(ObjectSlotMetadataName);
- const llvm::NamedMDNode *OptimizationLevelMetadata =
- module->getNamedMetadata(OptimizationLevelMetadataName);
if (ExportVarMetadata) {
@@ -271,13 +269,6 @@
return false;
}
- if (OptimizationLevelMetadata) {
- llvm::ConstantInt* OL = llvm::dyn_cast<llvm::ConstantInt>(
- OptimizationLevelMetadata->getOperand(0)->getOperand(0));
- mOptimizationLevel = OL->getZExtValue();
- }
-
-
return true;
}
diff --git a/include/bcinfo/MetadataExtractor.h b/include/bcinfo/MetadataExtractor.h
index b773dd7..065fd1a 100644
--- a/include/bcinfo/MetadataExtractor.h
+++ b/include/bcinfo/MetadataExtractor.h
@@ -43,6 +43,7 @@
size_t mObjectSlotCount;
const uint32_t *mObjectSlotList;
+ uint32_t mCompilerVersion;
uint32_t mOptimizationLevel;
// Helper functions for extraction
@@ -132,6 +133,16 @@
return mObjectSlotList;
}
+ /**
+ * \return compiler version that generated this bitcode.
+ */
+ uint32_t getCompilerVersion() const {
+ return mCompilerVersion;
+ }
+
+ /**
+ * \return compiler optimization level for this bitcode.
+ */
uint32_t getOptimizationLevel() const {
return mOptimizationLevel;
}
diff --git a/lib/ExecutionEngine/Android.mk b/lib/ExecutionEngine/Android.mk
index 4aa6a3f..2e9b8f2 100644
--- a/lib/ExecutionEngine/Android.mk
+++ b/lib/ExecutionEngine/Android.mk
@@ -72,6 +72,7 @@
LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
LOCAL_SRC_FILES := $(libbcc_executionengine_SRC_FILES)
+LOCAL_SHARED_LIBRARIES := libbcinfo
include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
@@ -94,6 +95,7 @@
LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
LOCAL_SRC_FILES := $(libbcc_executionengine_SRC_FILES)
+LOCAL_SHARED_LIBRARIES := libbcinfo
include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
diff --git a/lib/ExecutionEngine/Compiler.cpp b/lib/ExecutionEngine/Compiler.cpp
index b35b191..8f7a292 100644
--- a/lib/ExecutionEngine/Compiler.cpp
+++ b/lib/ExecutionEngine/Compiler.cpp
@@ -121,11 +121,6 @@
// synced with slang_rs_metadata.h)
const llvm::StringRef Compiler::ObjectSlotMetadataName = "#rs_object_slots";
-// Name of metadata node where RS optimization level resides (should be
-// synced with slang_rs_metadata.h)
-const llvm::StringRef OptimizationLevelMetadataName = "#optimization_level";
-
-
//////////////////////////////////////////////////////////////////////////////
// Compiler
@@ -292,16 +287,7 @@
llvm::NamedMDNode const *ExportFuncMetadata;
llvm::NamedMDNode const *ObjectSlotMetadata;
- llvm::NamedMDNode const *OptimizationLevelMetadata =
- mModule->getNamedMetadata(OptimizationLevelMetadataName);
-
- // Default to maximum optimization in the absence of named metadata node
- int OptimizationLevel = 3;
- if (OptimizationLevelMetadata) {
- llvm::ConstantInt* OL = llvm::dyn_cast<llvm::ConstantInt>(
- OptimizationLevelMetadata->getOperand(0)->getOperand(0));
- OptimizationLevel = OL->getZExtValue();
- }
+ uint32_t OptimizationLevel = mpResult->getOptimizationLevel();
if (OptimizationLevel == 0) {
CodeGenOptLevel = llvm::CodeGenOpt::None;
diff --git a/lib/ExecutionEngine/Script.cpp b/lib/ExecutionEngine/Script.cpp
index 97d8803..b1306a8 100644
--- a/lib/ExecutionEngine/Script.cpp
+++ b/lib/ExecutionEngine/Script.cpp
@@ -17,6 +17,7 @@
#include "Script.h"
#include "Config.h"
+#include "bcinfo/BitcodeWrapper.h"
#if USE_OLD_JIT
#include "OldJIT/CacheReader.h"
@@ -105,6 +106,10 @@
return 1;
}
+ bcinfo::BitcodeWrapper wrapper(bitcode, bitcodeSize);
+ mCompilerVersion = wrapper.getCompilerVersion();
+ mOptimizationLevel = wrapper.getOptimizationLevel();
+
mSourceList[idx] = SourceInfo::createFromBuffer(resName,
bitcode, bitcodeSize,
flags);
diff --git a/lib/ExecutionEngine/Script.h b/lib/ExecutionEngine/Script.h
index ebe9f38..0cf2266 100644
--- a/lib/ExecutionEngine/Script.h
+++ b/lib/ExecutionEngine/Script.h
@@ -80,10 +80,14 @@
BCCSymbolLookupFn mpExtSymbolLookupFn;
void *mpExtSymbolLookupFnContext;
+ uint32_t mCompilerVersion;
+ uint32_t mOptimizationLevel;
+
public:
Script() : mErrorCode(BCC_NO_ERROR), mStatus(ScriptStatus::Unknown),
mIsContextSlotNotAvail(false),
- mpExtSymbolLookupFn(NULL), mpExtSymbolLookupFnContext(NULL) {
+ mpExtSymbolLookupFn(NULL), mpExtSymbolLookupFnContext(NULL),
+ mCompilerVersion(0), mOptimizationLevel(3) {
Compiler::GlobalInitialization();
mSourceList[0] = NULL;
@@ -126,6 +130,13 @@
void *lookup(const char *name);
+ uint32_t getCompilerVersion() const {
+ return mCompilerVersion;
+ }
+
+ uint32_t getOptimizationLevel() const {
+ return mOptimizationLevel;
+ }
size_t getExportVarCount() const;
diff --git a/lib/ExecutionEngine/ScriptCompiled.h b/lib/ExecutionEngine/ScriptCompiled.h
index 6a1a9e8..42739e9 100644
--- a/lib/ExecutionEngine/ScriptCompiled.h
+++ b/lib/ExecutionEngine/ScriptCompiled.h
@@ -97,6 +97,13 @@
void *lookup(const char *name);
+ uint32_t getCompilerVersion() const {
+ return mpOwner->getCompilerVersion();
+ }
+
+ uint32_t getOptimizationLevel() const {
+ return mpOwner->getOptimizationLevel();
+ }
size_t getExportVarCount() const {
return mExportVars.size();