De-cruft the libbcc compiler infrastructure.

This patch removes the RSCompiler subclass of Compiler and moves most of its
functionality over to the original Compiler class.  Methods and variables are
re-named to make the code clearer.  In addition, unused functions have been
removed.

Change-Id: I121463df6309c377496cebea8cbb82bb49624ed1
diff --git a/include/bcc/Compiler.h b/include/bcc/Compiler.h
index 630be08..fabbadc 100644
--- a/include/bcc/Compiler.h
+++ b/include/bcc/Compiler.h
@@ -64,14 +64,7 @@
     kErrPrepareOutput,
     kPrepareCodeGenPass,
 
-    kErrHookBeforeAddLTOPasses,
-    kErrHookAfterAddLTOPasses,
-    kErrHookAfterExecuteLTOPasses,
-
-    kErrHookBeforeAddCodeGenPasses,
-    kErrHookAfterAddCodeGenPasses,
-    kErrHookBeforeExecuteCodeGenPasses,
-    kErrHookAfterExecuteCodeGenPasses,
+    kErrCustomPasses,
 
     kErrInvalidSource
   };
@@ -80,11 +73,14 @@
 
 private:
   llvm::TargetMachine *mTarget;
-  // LTO is enabled by default.
-  bool mEnableLTO;
+  // Optimization is enabled by default.
+  bool mEnableOpt;
 
-  enum ErrorCode runLTO(Script &pScript);
-  enum ErrorCode runCodeGen(Script &pScript, llvm::raw_ostream &pResult);
+  enum ErrorCode runPasses(Script &pScript, llvm::raw_ostream &pResult);
+
+  bool addCustomPasses(Script &pScript, llvm::PassManager &pPM);
+  bool addInternalizeSymbolsPass(Script &pScript, llvm::PassManager &pPM);
+  bool addExpandForEachPass(Script &pScript, llvm::PassManager &pPM);
 
 public:
   Compiler();
@@ -106,48 +102,10 @@
   const llvm::TargetMachine& getTargetMachine() const
   { return *mTarget; }
 
-  void enableLTO(bool pEnable = true)
-  { mEnableLTO = pEnable; }
+  void enableOpt(bool pEnable = true)
+  { mEnableOpt = pEnable; }
 
-  virtual ~Compiler();
-
-protected:
-  //===--------------------------------------------------------------------===//
-  // Plugin callbacks for sub-class.
-  //===--------------------------------------------------------------------===//
-  // Called before adding first pass to code-generation passes.
-  virtual bool beforeAddLTOPasses(Script &pScript, llvm::PassManager &pPM)
-  { return true; }
-
-  // Called after adding last pass to code-generation passes.
-  virtual bool afterAddLTOPasses(Script &pScript, llvm::PassManager &pPM)
-  { return true; }
-
-  // Called before executing code-generation passes.
-  virtual bool beforeExecuteLTOPasses(Script &pScript,
-                                          llvm::PassManager &pPM)
-  { return true; }
-
-  // Called after executing code-generation passes.
-  virtual bool afterExecuteLTOPasses(Script &pScript)
-  { return true; }
-
-  // Called before adding first pass to code-generation passes.
-  virtual bool beforeAddCodeGenPasses(Script &pScript, llvm::PassManager &pPM)
-  { return true; }
-
-  // Called after adding last pass to code-generation passes.
-  virtual bool afterAddCodeGenPasses(Script &pScript, llvm::PassManager &pPM)
-  { return true; }
-
-  // Called before executing code-generation passes.
-  virtual bool beforeExecuteCodeGenPasses(Script &pScript,
-                                          llvm::PassManager &pPM)
-  { return true; }
-
-  // Called after executing code-generation passes.
-  virtual bool afterExecuteCodeGenPasses(Script &pScript)
-  { return true; }
+  ~Compiler();
 };
 
 } // end namespace bcc
diff --git a/include/bcc/Renderscript/RSCompiler.h b/include/bcc/Renderscript/RSCompiler.h
deleted file mode 100644
index a46d558..0000000
--- a/include/bcc/Renderscript/RSCompiler.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 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.
- */
-
-#ifndef BCC_RS_COMPILER_H
-#define BCC_RS_COMPILER_H
-
-#include "bcc/Compiler.h"
-
-namespace bcc {
-
-class RSCompiler : public Compiler {
-private:
-  virtual bool beforeAddLTOPasses(Script &pScript, llvm::PassManager &pPM);
-  bool addInternalizeSymbolsPass(Script &pScript, llvm::PassManager &pPM);
-  bool addExpandForEachPass(Script &pScript, llvm::PassManager &pPM);
-};
-
-} // end namespace bcc
-
-#endif // BCC_RS_COMPILER_H
diff --git a/include/bcc/Renderscript/RSCompilerDriver.h b/include/bcc/Renderscript/RSCompilerDriver.h
index a2a68d1..3ad9e01 100644
--- a/include/bcc/Renderscript/RSCompilerDriver.h
+++ b/include/bcc/Renderscript/RSCompilerDriver.h
@@ -17,11 +17,11 @@
 #ifndef BCC_RS_COMPILER_DRIVER_H
 #define BCC_RS_COMPILER_DRIVER_H
 
+#include "bcc/Compiler.h"
 #include "bcc/ExecutionEngine/CompilerRTSymbolResolver.h"
 #include "bcc/ExecutionEngine/SymbolResolvers.h"
 #include "bcc/ExecutionEngine/SymbolResolverProxy.h"
 #include "bcc/Renderscript/RSInfo.h"
-#include "bcc/Renderscript/RSCompiler.h"
 #include "bcc/Renderscript/RSScript.h"
 
 namespace bcc {
@@ -39,7 +39,7 @@
 class RSCompilerDriver {
 private:
   CompilerConfig *mConfig;
-  RSCompiler mCompiler;
+  Compiler mCompiler;
 
   // Are we compiling under an RS debug context with additional checks?
   bool mDebugContext;
@@ -73,7 +73,7 @@
   RSCompilerDriver(bool pUseCompilerRT = true);
   ~RSCompilerDriver();
 
-  RSCompiler *getCompiler() {
+  Compiler *getCompiler() {
     return &mCompiler;
   }