Merge changes from topic \'struct-fix\' into nyc-dev
am: c6c9c1f

* commit 'c6c9c1f04b480a395daa1bdd5d634060e505bd80':
  Translate GEP instructions on structs to GEP on int8*
  X86: Fix kernel Input/Output GetElementPtr offset issue

Change-Id: I12cf5b0a98481b2408993f8d3e25f7bf028e7df8
diff --git a/include/bcc/Renderscript/RSCompilerDriver.h b/include/bcc/Renderscript/RSCompilerDriver.h
index cf22ce8..76c9f98 100644
--- a/include/bcc/Renderscript/RSCompilerDriver.h
+++ b/include/bcc/Renderscript/RSCompilerDriver.h
@@ -77,7 +77,7 @@
                                     bool pDumpIR);
 
 public:
-  RSCompilerDriver(bool pUseCompilerRT = true);
+  RSCompilerDriver();
   ~RSCompilerDriver();
 
   Compiler *getCompiler() {
diff --git a/lib/Renderscript/RSAddDebugInfoPass.cpp b/lib/Renderscript/RSAddDebugInfoPass.cpp
index 27aa5de..e89af4e 100644
--- a/lib/Renderscript/RSAddDebugInfoPass.cpp
+++ b/lib/Renderscript/RSAddDebugInfoPass.cpp
@@ -94,7 +94,7 @@
     llvm::LLVMContext &ctx = Module.getContext();
 
     // Start generating debug information for bcc-generated code.
-    DebugInfo.createCompileUnit(llvm::dwarf::DW_LANG_C99,
+    DebugInfo.createCompileUnit(llvm::dwarf::DW_LANG_GOOGLE_RenderScript,
                                 DEBUG_GENERATED_FILE, DEBUG_SOURCE_PATH,
                                 "RS", false, "", 0);
 
@@ -175,6 +175,7 @@
         sourceFileName, 1, kernelTypeMD,
         false, true, 1, 0, false
     );
+    Func.setSubprogram(ExpandedFunc);
 
     // IRBuilder for allocating variables for arguments.
     llvm::IRBuilder<> ir(&*Func.getEntryBlock().begin());
diff --git a/lib/Renderscript/RSCompilerDriver.cpp b/lib/Renderscript/RSCompilerDriver.cpp
index 0370e42..1dfc699 100644
--- a/lib/Renderscript/RSCompilerDriver.cpp
+++ b/lib/Renderscript/RSCompilerDriver.cpp
@@ -51,7 +51,7 @@
 
 using namespace bcc;
 
-RSCompilerDriver::RSCompilerDriver(bool pUseCompilerRT) :
+RSCompilerDriver::RSCompilerDriver() :
     mConfig(nullptr), mCompiler(), mDebugContext(false),
     mLinkRuntimeCallback(nullptr), mEnableGlobalMerge(true),
     mEmbedGlobalInfo(false), mEmbedGlobalInfoSkipConstant(false) {
diff --git a/lib/Renderscript/RSKernelExpand.cpp b/lib/Renderscript/RSKernelExpand.cpp
index d7e4996..893b186 100644
--- a/lib/Renderscript/RSKernelExpand.cpp
+++ b/lib/Renderscript/RSKernelExpand.cpp
@@ -56,15 +56,35 @@
 
 static const bool gEnableRsTbaa = true;
 
-/* RSKernelExpandPass - This pass operates on functions that are able
- * to be called via rsForEach(), "foreach_<NAME>", or
- * "reduce_<NAME>". We create an inner loop for the function to be
- * invoked over the appropriate data cells of the input/output
- * allocations (adjusting other relevant parameters as we go). We
- * support doing this for any forEach or reduce style compute
- * kernels. The new function name is the original function name
- * followed by ".expand". Note that we still generate code for the
- * original function.
+/* RSKernelExpandPass
+ *
+ * This pass generates functions used to implement calls via
+ * rsForEach(), "foreach_<NAME>", or "reduce_<NAME>". We create an
+ * inner loop for the function to be invoked over the appropriate data
+ * cells of the input/output allocations (adjusting other relevant
+ * parameters as we go). We support doing this for any forEach or
+ * reduce style compute kernels.
+ *
+ * In the case of a foreach kernel or a simple reduction kernel, the
+ * new function name is the original function name "<NAME>" followed
+ * by ".expand" -- "<NAME>.expand".
+ *
+ * In the case of a general reduction kernel, the kernel's accumulator
+ * function is the one transformed, and the new function name is the
+ * original accumulator function name "<ACCUMFN>" followed by
+ * ".expand" -- "<ACCUMFN>.expand". Using the name "<ACCUMFN>.expand"
+ * for the function generated from the accumulator should not
+ * introduce any possibility for name clashes today: The accumulator
+ * function <ACCUMFN> must be static, so it cannot also serve as a
+ * foreach kernel; and the code for <ACCUMFN>.expand depends only on
+ * <ACCUMFN>, not on any other properties of the reduction kernel, so
+ * any reduction kernels that share the accumulator <ACCUMFN> can
+ * share <ACCUMFN>.expand also.
+ *
+ * Note that this pass does not delete the original function <NAME> or
+ * <ACCUMFN>. However, if it is inlined into the newly-generated
+ * function and not otherwise referenced, then a subsequent pass may
+ * delete it.
  */
 class RSKernelExpandPass : public llvm::ModulePass {
 public:
diff --git a/lib/Renderscript/generate-whitelist.sh b/lib/Renderscript/generate-whitelist.sh
deleted file mode 100755
index 0932f20..0000000
--- a/lib/Renderscript/generate-whitelist.sh
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/bin/bash
-
-# This shell script automatically extracts RenderScript stub functions .
-# To regenerate files RSStubsWhiteList.{cpp,h} run the following command
-# sh generate-whitelist.sh RSStubsWhiteList $ANDROID_BUILD_TOP/frameworks/rs/driver/rsdRuntimeStubs.cpp $ANDROID_BUILD_TOP/frameworks/rs/cpu_ref/rsCpuRuntimeStubs.cpp $ANDROID_BUILD_TOP/frameworks/rs/cpu_ref/rsCpuRuntimeMath.cpp
-
-OUT_PATH_PREFIX=$1
-OUT_PREFIX=`basename $OUT_PATH_PREFIX`
-STUB_FILES=${@:2}
-
-whitelist=`grep "{ \"_Z" $STUB_FILES | awk '{print $3}' | sort | uniq`
-
-OUT_HEADER=$OUT_PATH_PREFIX\.h
-OUT_CPP=$OUT_PATH_PREFIX\.cpp
-
-read -d '' COPYRIGHT << EOF
-/*
- * Copyright 2014, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-EOF
-
-
-cat > $OUT_HEADER << EOF
-$COPYRIGHT
-
-#ifndef ${OUT_PREFIX}_H
-#define ${OUT_PREFIX}_H
-
-#include <cstdlib>
-#include <vector>
-#include <string>
-
-extern std::vector<std::string> stubList;
-
-#endif // ${OUT_PREFIX}_H
-EOF
-
-cat > $OUT_CPP  << EOF
-$COPYRIGHT
-
-#include "$OUT_PREFIX.h"
-
-std::vector<std::string> stubList = {
-$whitelist
-};
-EOF
-
-echo Wrote to $OUT_HEADER $OUT_CPP
diff --git a/tools/bcc/Android.mk b/tools/bcc/Android.mk
index 653a946..b2a8410 100644
--- a/tools/bcc/Android.mk
+++ b/tools/bcc/Android.mk
@@ -49,7 +49,7 @@
 
 LOCAL_SRC_FILES := Main.cpp
 
-LOCAL_SHARED_LIBRARIES := libdl libbcinfo libbcc libLLVM libutils libcutils
+LOCAL_SHARED_LIBRARIES := libdl liblog libbcinfo libbcc libLLVM libutils libcutils
 
 include $(LIBBCC_DEVICE_BUILD_MK)
 include $(LLVM_DEVICE_BUILD_MK)
diff --git a/tools/bcc_compat/Main.cpp b/tools/bcc_compat/Main.cpp
index 7dfc3de..79b0f70 100644
--- a/tools/bcc_compat/Main.cpp
+++ b/tools/bcc_compat/Main.cpp
@@ -262,7 +262,7 @@
   }
 
   BCCContext context;
-  RSCompilerDriver rscd(false);
+  RSCompilerDriver rscd;
   Compiler compiler;
 
   if (!ConfigCompiler(rscd)) {