Switch to MetadataExtractor path.
Change-Id: Iabef9abb1c770ffe1e753cfd2fac808f60c19d8a
diff --git a/lib/Renderscript/RSEmbedInfo.cpp b/lib/Renderscript/RSEmbedInfo.cpp
index dc17f4c..b19519f 100644
--- a/lib/Renderscript/RSEmbedInfo.cpp
+++ b/lib/Renderscript/RSEmbedInfo.cpp
@@ -30,8 +30,8 @@
#include <llvm/IR/Type.h>
#include "bcc/Config/Config.h"
-#include "bcc/Renderscript/RSInfo.h"
#include "bcc/Support/Log.h"
+#include "bcinfo/MetadataExtractor.h"
using namespace bcc;
@@ -51,17 +51,32 @@
llvm::Module *M;
llvm::LLVMContext *C;
- const RSInfo *mInfo;
-
public:
- RSEmbedInfoPass(const RSInfo *info)
+ RSEmbedInfoPass()
: ModulePass(ID),
- mInfo(info) {
+ M(NULL) {
}
- static std::string getRSInfoString(const RSInfo *info) {
+ static std::string getRSInfoString(const llvm::Module *module) {
std::string str;
llvm::raw_string_ostream s(str);
+ bcinfo::MetadataExtractor me(module);
+ if (!me.extract()) {
+ bccAssert(false && "Could not extract RS metadata for module!");
+ return std::string("");
+ }
+
+ size_t exportVarCount = me.getExportVarCount();
+ size_t exportFuncCount = me.getExportFuncCount();
+ size_t exportForEachCount = me.getExportForEachSignatureCount();
+ size_t objectSlotCount = me.getObjectSlotCount();
+ const char **exportVarNameList = me.getExportVarNameList();
+ const char **exportFuncNameList = me.getExportFuncNameList();
+ const char **exportForEachNameList = me.getExportForEachNameList();
+ const uint32_t *exportForEachSignatureList =
+ me.getExportForEachSignatureList();
+ const uint32_t *objectSlotList = me.getObjectSlotList();
+ size_t i;
// We use a simple text format here that the compatibility library can
// easily parse. Each section starts out with its name followed by a count.
@@ -70,54 +85,25 @@
// on the line, while ForEach kernels have the encoded int signature,
// followed by a hyphen followed by the identifier (function to look up).
// Object Slots are just listed as one integer per line.
- const RSInfo::ExportVarNameListTy &export_vars = info->getExportVarNames();
- s << "exportVarCount: " << (unsigned int) export_vars.size() << "\n";
- for (RSInfo::ExportVarNameListTy::const_iterator
- export_var_iter = export_vars.begin(),
- export_var_end = export_vars.end();
- export_var_iter != export_var_end; export_var_iter++) {
- s << *export_var_iter << "\n";
+ s << "exportVarCount: " << exportVarCount << "\n";
+ for (i = 0; i < exportVarCount; ++i) {
+ s << exportVarNameList[i] << "\n";
}
- const RSInfo::ExportFuncNameListTy &export_funcs =
- info->getExportFuncNames();
- s << "exportFuncCount: " << (unsigned int) export_funcs.size() << "\n";
- for (RSInfo::ExportFuncNameListTy::const_iterator
- export_func_iter = export_funcs.begin(),
- export_func_end = export_funcs.end();
- export_func_iter != export_func_end; export_func_iter++) {
- s << *export_func_iter << "\n";
+ s << "exportFuncCount: " << exportFuncCount << "\n";
+ for (i = 0; i < exportFuncCount; ++i) {
+ s << exportFuncNameList[i] << "\n";
}
- const RSInfo::ExportForeachFuncListTy &export_foreach_funcs =
- info->getExportForeachFuncs();
- s << "exportForEachCount: "
- << (unsigned int) export_foreach_funcs.size() << "\n";
- for (RSInfo::ExportForeachFuncListTy::const_iterator
- foreach_func_iter = export_foreach_funcs.begin(),
- foreach_func_end = export_foreach_funcs.end();
- foreach_func_iter != foreach_func_end; foreach_func_iter++) {
- std::string name(foreach_func_iter->first);
- s << foreach_func_iter->second << " - "
- << foreach_func_iter->first << "\n";
+ s << "exportForEachCount: " << exportForEachCount << "\n";
+ for (i = 0; i < exportForEachCount; ++i) {
+ s << exportForEachSignatureList[i] << " - "
+ << exportForEachNameList[i] << "\n";
}
- std::vector<unsigned int> object_slot_numbers;
- unsigned int i = 0;
- const RSInfo::ObjectSlotListTy &object_slots = info->getObjectSlots();
- for (RSInfo::ObjectSlotListTy::const_iterator
- slots_iter = object_slots.begin(),
- slots_end = object_slots.end();
- slots_iter != slots_end; slots_iter++) {
- if (*slots_iter) {
- object_slot_numbers.push_back(i);
- }
- i++;
- }
- s << "objectSlotCount: " << (unsigned int) object_slot_numbers.size()
- << "\n";
- for (i = 0; i < object_slot_numbers.size(); i++) {
- s << object_slot_numbers[i] << "\n";
+ s << "objectSlotCount: " << objectSlotCount << "\n";
+ for (i = 0; i < objectSlotCount; ++i) {
+ s << objectSlotList[i] << "\n";
}
s.flush();
@@ -131,7 +117,7 @@
// Embed this as the global variable .rs.info so that it will be
// accessible from the shared object later.
llvm::Constant *Init = llvm::ConstantDataArray::getString(*C,
- getRSInfoString(mInfo));
+ getRSInfoString(&M));
llvm::GlobalVariable *InfoGV =
new llvm::GlobalVariable(M, Init->getType(), true,
llvm::GlobalValue::ExternalLinkage, Init,
@@ -154,8 +140,8 @@
namespace bcc {
llvm::ModulePass *
-createRSEmbedInfoPass(const RSInfo *info) {
- return new RSEmbedInfoPass(info);
+createRSEmbedInfoPass() {
+ return new RSEmbedInfoPass();
}
} // end namespace bcc