Add RSGlobalInfoPass information to RS driver.

Bug: 20306487

This change enables vendor drivers to configure support for including
additional information about global variables in the emitted CPU code.
This information includes the number of total global variables, the
names of these variables, the addresses of these variables and the
sizes of these variables. The driver can also select whether the
information includes constant (immutable) globals or not.

The reference driver defaults to embedding information about each of
the existing, non-constant global variables.

Change-Id: I1e55fc3f08e518f04eeee3e4f9dc7b6ea3b80d7c
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 3f64534..7e024bc 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -55,6 +55,9 @@
 #endif
 
 namespace {
+
+static const bool kDebugGlobalVariables = false;
+
 #ifndef RS_COMPATIBILITY_LIB
 
 static bool is_force_recompile() {
@@ -83,11 +86,18 @@
                                 const std::string& bcFileName,
                                 const char* cacheDir, const char* resName,
                                 const char* core_lib, bool useRSDebugContext,
-                                const char* bccPluginName) {
+                                const char* bccPluginName, bool emitGlobalInfo,
+                                bool emitGlobalInfoSkipConstant) {
     rsAssert(cacheDir && resName && core_lib);
     args->push_back(android::renderscript::RsdCpuScriptImpl::BCC_EXE_PATH);
     args->push_back("-unroll-runtime");
     args->push_back("-scalarize-load-store");
+    if (emitGlobalInfo) {
+        args->push_back("-rs-global-info");
+        if (emitGlobalInfoSkipConstant) {
+            args->push_back("-rs-global-info-skip-constant");
+        }
+    }
     args->push_back("-o");
     args->push_back(resName);
     args->push_back("-output_path");
@@ -276,6 +286,10 @@
     mIsThreadable = mScriptExec->getThreadable();
     //ALOGE("Script isThreadable? %d", mIsThreadable);
 
+    if (kDebugGlobalVariables) {
+        mScriptExec->dumpGlobalInfo();
+    }
+
     return true;
 }
 
@@ -326,8 +340,11 @@
     bcFileName.append(".bc");
 
     std::vector<const char*> compileArguments;
+    bool emitGlobalInfo = mCtx->getEmbedGlobalInfo();
+    bool emitGlobalInfoSkipConstant = mCtx->getEmbedGlobalInfoSkipConstant();
     setCompileArguments(&compileArguments, bcFileName, cacheDir, resName, core_lib,
-                        useRSDebugContext, bccPluginName);
+                        useRSDebugContext, bccPluginName, emitGlobalInfo,
+                        emitGlobalInfoSkipConstant);
 
     mChecksumNeeded = isChecksumNeeded();
     if (mChecksumNeeded) {
@@ -888,6 +905,22 @@
     return nullptr;
 }
 
+int RsdCpuScriptImpl::getGlobalEntries() const {
+    return mScriptExec->getGlobalEntries();
+}
+
+const char * RsdCpuScriptImpl::getGlobalName(int i) const {
+    return mScriptExec->getGlobalName(i);
+}
+
+const void * RsdCpuScriptImpl::getGlobalAddress(int i) const {
+    return mScriptExec->getGlobalAddress(i);
+}
+
+size_t RsdCpuScriptImpl::getGlobalSize(int i) const {
+    return mScriptExec->getGlobalSize(i);
+}
+
 void RsdCpuScriptImpl::preLaunch(uint32_t slot, const Allocation ** ains,
                                  uint32_t inLen, Allocation * aout,
                                  const void * usr, uint32_t usrLen,