Revert "Merge lib/Transforms into lib/ExecutionEngine."

This reverts commit cd52b55716a2e4d78b0a6609b041c3aeb45b40f2.
diff --git a/lib/ExecutionEngine/Android.mk b/lib/ExecutionEngine/Android.mk
index f9877d5..d101107 100644
--- a/lib/ExecutionEngine/Android.mk
+++ b/lib/ExecutionEngine/Android.mk
@@ -39,7 +39,6 @@
   ObjectLoader.cpp \
   OutputFile.cpp \
   RSExecutable.cpp \
-  RSForEachExpand.cpp \
   RSInfo.cpp \
   RSInfoExtractor.cpp \
   RSInfoReader.cpp \
diff --git a/lib/ExecutionEngine/Compiler.cpp b/lib/ExecutionEngine/Compiler.cpp
index 458d835..c4a0870 100644
--- a/lib/ExecutionEngine/Compiler.cpp
+++ b/lib/ExecutionEngine/Compiler.cpp
@@ -33,7 +33,7 @@
 
 #include "librsloader.h"
 
-#include "RSTransforms.h"
+#include "Transforms/BCCTransforms.h"
 
 #include "llvm/ADT/StringRef.h"
 
@@ -270,7 +270,8 @@
   std::vector<std::string> &VarNameList = mpResult->mExportVarsName;
   std::vector<std::string> &FuncNameList = mpResult->mExportFuncsName;
   std::vector<std::string> &ForEachExpandList = mpResult->mExportForEachName;
-  RSInfo::ExportForeachFuncListTy ForEachFuncList;
+  std::vector<std::string> ForEachNameList;
+  std::vector<uint32_t> ForEachSigList;
   std::vector<const char*> ExportSymbols;
 
   // Defaults to maximum optimization level from MetadataExtractor.
@@ -366,9 +367,10 @@
     const char **ForEachNames = ME.getExportForEachNameList();
     const uint32_t *ForEachSigs = ME.getExportForEachSignatureList();
     for (size_t i = 0; i < ForEachSigCount; i++) {
-      ForEachFuncList.push_back(std::make_pair(ForEachNames[i],
-                                               ForEachSigs[i]));
-      ForEachExpandList.push_back(std::string(ForEachNames[i]) + ".expand");
+      std::string Name(ForEachNames[i]);
+      ForEachNameList.push_back(Name);
+      ForEachExpandList.push_back(Name + ".expand");
+      ForEachSigList.push_back(ForEachSigs[i]);
     }
 
     // Need to wait until ForEachExpandList is fully populated to fill in
@@ -386,7 +388,7 @@
     }
   }
 
-  runInternalPasses(ForEachFuncList);
+  runInternalPasses(ForEachNameList, ForEachSigList);
 
   // Perform link-time optimization if we have multiple modules
   if (option.RunLTO) {
@@ -514,11 +516,12 @@
   return 0;
 }
 
-int Compiler::runInternalPasses(RSInfo::ExportForeachFuncListTy pForEachFuncs) {
+int Compiler::runInternalPasses(std::vector<std::string>& Names,
+                                std::vector<uint32_t>& Signatures) {
   llvm::PassManager BCCPasses;
 
   // Expand ForEach on CPU path to reduce launch overhead.
-  BCCPasses.add(createRSForEachExpandPass(pForEachFuncs));
+  BCCPasses.add(createForEachExpandPass(Names, Signatures));
 
   BCCPasses.run(*mModule);
 
diff --git a/lib/ExecutionEngine/Compiler.h b/lib/ExecutionEngine/Compiler.h
index f0e75d1..b5872d6 100644
--- a/lib/ExecutionEngine/Compiler.h
+++ b/lib/ExecutionEngine/Compiler.h
@@ -36,8 +36,6 @@
 #include <vector>
 #include <utility>
 
-#include "RSInfo.h"
-
 
 namespace llvm {
   class Module;
@@ -141,7 +139,8 @@
 
     int runMCCodeGen(llvm::TargetData *TD, llvm::TargetMachine *TM);
 
-    int runInternalPasses(RSInfo::ExportForeachFuncListTy pForEachFuncs);
+    int runInternalPasses(std::vector<std::string>& Names,
+                          std::vector<uint32_t>& Signatures);
 
     int runLTO(llvm::TargetData *TD,
                std::vector<const char*>& ExportSymbols,
diff --git a/lib/ExecutionEngine/RSScript.h b/lib/ExecutionEngine/RSScript.h
index 4fc1f90..50a3eb3 100644
--- a/lib/ExecutionEngine/RSScript.h
+++ b/lib/ExecutionEngine/RSScript.h
@@ -24,12 +24,12 @@
 #include <stddef.h>
 
 #include <llvm/ADT/SmallVector.h>
-#include <llvm/Support/CodeGen.h>
 
 #include <bcc/bcc.h>
 #include <bcc/bcc_mccache.h>
 #include "bcc_internal.h"
 
+#include "Compiler.h"
 #include "Script.h"
 
 namespace llvm {
diff --git a/lib/Transforms/Android.mk b/lib/Transforms/Android.mk
new file mode 100644
index 0000000..c30dd29
--- /dev/null
+++ b/lib/Transforms/Android.mk
@@ -0,0 +1,70 @@
+#
+# Copyright (C) 2012 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.
+#
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(LOCAL_PATH)/../../libbcc-config.mk
+
+#=====================================================================
+# Common: libbccTransforms
+#=====================================================================
+
+libbcc_transforms_SRC_FILES := \
+  ForEachExpand.cpp
+
+#=====================================================================
+# Device Static Library: libbccTransforms
+#=====================================================================
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libbccTransforms
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+
+LOCAL_CFLAGS += $(libbcc_CFLAGS)
+LOCAL_CFLAGS += -DTARGET_BUILD
+
+LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
+LOCAL_SRC_FILES := $(libbcc_transforms_SRC_FILES)
+
+include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
+include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
+include $(LLVM_ROOT_PATH)/llvm-device-build.mk
+include $(BUILD_STATIC_LIBRARY)
+
+
+#=====================================================================
+# Host Static Library: libbccTransforms
+#=====================================================================
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := libbccTransforms
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+LOCAL_IS_HOST_MODULE := true
+
+LOCAL_CFLAGS += $(libbcc_CFLAGS)
+LOCAL_CFLAGS += -D__HOST__
+LOCAL_C_INCLUDES := $(libbcc_C_INCLUDES)
+
+LOCAL_SRC_FILES := $(libbcc_transforms_SRC_FILES)
+
+include $(LIBBCC_ROOT_PATH)/libbcc-gen-config-from-mk.mk
+include $(LIBBCC_ROOT_PATH)/libbcc-build-rules.mk
+include $(LLVM_ROOT_PATH)/llvm-host-build.mk
+include $(BUILD_HOST_STATIC_LIBRARY)
diff --git a/lib/ExecutionEngine/RSTransforms.h b/lib/Transforms/BCCTransforms.h
similarity index 66%
rename from lib/ExecutionEngine/RSTransforms.h
rename to lib/Transforms/BCCTransforms.h
index ec5f690..1ac8174 100644
--- a/lib/ExecutionEngine/RSTransforms.h
+++ b/lib/Transforms/BCCTransforms.h
@@ -14,20 +14,11 @@
  * limitations under the License.
  */
 
-#ifndef BCC_EXECUTION_ENGINE_RS_TRANSFORMS_H
-#define BCC_EXECUTION_ENGINE_RS_TRANSFORMS_H
-
-#include "RSInfo.h"
-
-namespace llvm {
-  class ModulePass;
-}
+#include "llvm/Pass.h"
 
 namespace bcc {
 
-llvm::ModulePass *
-createRSForEachExpandPass(const RSInfo::ExportForeachFuncListTy &pForeachFuncs);
+llvm::ModulePass *createForEachExpandPass(std::vector<std::string>& Names,
+                                          std::vector<uint32_t>& Signatures);
 
-} // end namespace bcc
-
-#endif // BCC_EXECUTION_ENGINE_RS_TRANSFORMS_H
+}  // namespace bcc
diff --git a/lib/ExecutionEngine/RSForEachExpand.cpp b/lib/Transforms/ForEachExpand.cpp
similarity index 82%
rename from lib/ExecutionEngine/RSForEachExpand.cpp
rename to lib/Transforms/ForEachExpand.cpp
index b30dd23..53d6bdc 100644
--- a/lib/ExecutionEngine/RSForEachExpand.cpp
+++ b/lib/Transforms/ForEachExpand.cpp
@@ -14,15 +14,10 @@
  * limitations under the License.
  */
 
-//#define RS_FOREACH_EXPAND_PASS_NDEBUG 0
-#include "RSTransforms.h"
-
-#include <cstdlib>
-
 #include "Config.h"
+#include "bcc/bcc_assert.h"
 
 #include "DebugHelper.h"
-#include "RSInfo.h"
 
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
@@ -32,26 +27,24 @@
 #include "llvm/Type.h"
 #include "llvm/Support/IRBuilder.h"
 
-using namespace bcc;
-
 namespace {
-
-/* RSForEachExpandPass - This pass operates on functions that are able to be
- * called via rsForEach() or "foreach_<NAME>". We create an inner loop for the
- * ForEach-able 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-able compute kernels. The new function
- * name is the original function name followed by ".expand". Note that we
- * still generate code for the original function.
- */
-class RSForEachExpandPass : public llvm::ModulePass {
-private:
+  /* ForEachExpandPass - This pass operates on functions that are able to be
+   * called via rsForEach() or "foreach_<NAME>". We create an inner loop for
+   * the ForEach-able 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-able compute kernels.
+   * The new function name is the original function name followed by
+   * ".expand". Note that we still generate code for the original function.
+   */
+  class ForEachExpandPass : public llvm::ModulePass {
+  private:
   static char ID;
 
   llvm::Module *M;
   llvm::LLVMContext *C;
 
-  const RSInfo::ExportForeachFuncListTy &mFuncs;
+  std::vector<std::string>& mNames;
+  std::vector<uint32_t>& mSignatures;
 
   uint32_t getRootSignature(llvm::Function *F) {
     const llvm::NamedMDNode *ExportForEachMetadata =
@@ -72,13 +65,7 @@
       return (1 << RootArgTys.size()) - 1;
     }
 
-#if !RS_FOREACH_EXPAND_PASS_NDEBUG
-    if (ExportForEachMetadata->getNumOperands() <= 0) {
-      ALOGE("Assert failed at %s:%d: Invalid #rs_export_foreach metadata in "
-            " '%s'!", __FILE__, __LINE__, M->getModuleIdentifier().c_str());
-      ::abort();
-    }
-#endif
+    bccAssert(ExportForEachMetadata->getNumOperands() > 0);
 
     // We only handle the case for legacy root() functions here, so this is
     // hard-coded to look at only the first such function.
@@ -120,9 +107,11 @@
     return Signature & 16;
   }
 
-public:
-  RSForEachExpandPass(const RSInfo::ExportForeachFuncListTy &pForeachFuncs)
-      : ModulePass(ID), M(NULL), C(NULL), mFuncs(pForeachFuncs) {
+  public:
+  ForEachExpandPass(std::vector<std::string>& Names,
+                    std::vector<uint32_t>& Signatures)
+      : ModulePass(ID), M(NULL), C(NULL), mNames(Names),
+        mSignatures(Signatures) {
   }
 
   /* Performs the actual optimization on a selected function. On success, the
@@ -271,13 +260,7 @@
       Args++;
     }
 
-#if !RS_FOREACH_EXPAND_PASS_NDEBUG
-    if (Args != F->arg_end()) {
-      ALOGE("Assert failed at %s:%d: Invalid signature to the foreach function "
-            "'%s'!", __FILE__, __LINE__, F->getName().str().c_str());
-      ::abort();
-    }
-#endif
+    bccAssert(Args == F->arg_end());
 
     llvm::BasicBlock *Loop = llvm::BasicBlock::Create(*C, "Loop", ExpandedFunc);
     llvm::BasicBlock *Exit = llvm::BasicBlock::Create(*C, "Exit", ExpandedFunc);
@@ -356,14 +339,11 @@
     this->M = &M;
     C = &M.getContext();
 
-    for (RSInfo::ExportForeachFuncListTy::const_iterator
-             func_iter = mFuncs.begin(), func_end = mFuncs.end();
-         func_iter != func_end; func_iter++) {
-      const char *name = func_iter->first;
-      uint32_t signature = func_iter->second;
-      llvm::Function *kernel = M.getFunction(name);
+    bccAssert(mNames.size() == mSignatures.size());
+    for (int i = 0, e = mNames.size(); i != e; i++) {
+      llvm::Function *kernel = M.getFunction(mNames[i]);
       if (kernel && kernel->getReturnType()->isVoidTy()) {
-        Changed |= ExpandFunction(kernel, signature);
+        Changed |= ExpandFunction(kernel, mSignatures[i]);
       }
     }
 
@@ -374,17 +354,16 @@
     return "ForEach-able Function Expansion";
   }
 
-}; // end RSForEachExpandPass
+  };
+}  // end anonymous namespace
 
-} // end anonymous namespace
-
-char RSForEachExpandPass::ID = 0;
+char ForEachExpandPass::ID = 0;
 
 namespace bcc {
 
-llvm::ModulePass *
-createRSForEachExpandPass(const RSInfo::ExportForeachFuncListTy &pForeachFuncs){
-  return new RSForEachExpandPass(pForeachFuncs);
-}
+  llvm::ModulePass *createForEachExpandPass(std::vector<std::string>& Names,
+                                            std::vector<uint32_t>& Signatures) {
+    return new ForEachExpandPass(Names, Signatures);
+  }
 
-} // end namespace bcc
+}  // namespace bcc