Add a flag to the API to specify -O0 on the bcc command line.

Add a flag RS_CONTEXT_OPT_LEVEL_0 which sets a field mOptLevel in the Context
to 0 when calling bcc.
Using this flag will result in an object file that is easier to debug.

Change-Id: I9673506710cc9f34c415b694fe5d6bc7e967f1db
Signed-off-by: verena beckham <verena@codeplay.com>
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 1909e13..09e7ab7 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -79,7 +79,7 @@
                                 const char* cacheDir, const char* resName,
                                 const char* core_lib, bool useRSDebugContext,
                                 const char* bccPluginName, bool emitGlobalInfo,
-                                bool emitGlobalInfoSkipConstant) {
+                                int optLevel, bool emitGlobalInfoSkipConstant) {
     rsAssert(cacheDir && resName && core_lib);
     args->push_back(android::renderscript::RsdCpuScriptImpl::BCC_EXE_PATH);
     args->push_back("-unroll-runtime");
@@ -98,6 +98,20 @@
     args->push_back(core_lib);
     args->push_back("-mtriple");
     args->push_back(DEFAULT_TARGET_TRIPLE_STRING);
+    args->push_back("-O");
+
+    switch (optLevel) {
+    case (0):
+        args->push_back("0");
+        break;
+    case (3):
+        args->push_back("3");
+        break;
+    default:
+        ALOGW("Expected optimization level of 0 or 3. Received %d", optLevel);
+        args->push_back("3");
+        break;
+    }
 
     // Enable workaround for A53 codegen by default.
 #if defined(__aarch64__) && !defined(DISABLE_A53_WORKAROUND)
@@ -317,6 +331,8 @@
         useRSDebugContext = true;
     }
 
+    int optLevel = mCtx->getContext()->getOptLevel();
+
     std::string bcFileName(cacheDir);
     bcFileName.append("/");
     bcFileName.append(resName);
@@ -327,7 +343,7 @@
     bool emitGlobalInfoSkipConstant = mCtx->getEmbedGlobalInfoSkipConstant();
     setCompileArguments(&compileArguments, bcFileName, cacheDir, resName, core_lib,
                         useRSDebugContext, bccPluginName, emitGlobalInfo,
-                        emitGlobalInfoSkipConstant);
+                        optLevel, emitGlobalInfoSkipConstant);
 
     mChecksumNeeded = isChecksumNeeded(cacheDir);
     if (mChecksumNeeded) {