Started to remove the useless crap from CBackend. We only keep the code as a pass...
authorBenjamin Segovia <segovia.benjamin@gmail.com>
Mon, 27 Feb 2012 14:20:39 +0000 (14:20 +0000)
committerKeith Packard <keithp@keithp.com>
Fri, 10 Aug 2012 23:15:27 +0000 (16:15 -0700)
backend/src/llvm/GenBackend.cpp
backend/src/llvm/GenTargetMachine.h
backend/src/llvm/TargetInfo/GenBackendTargetInfo.cpp
backend/src/llvm/llvm2gen.cpp
backend/src/utest/utest_llvm.cpp

index daebb47..1e7d8e3 100644 (file)
  * Author: Benjamin Segovia <benjamin.segovia@intel.com>
  */
 
-//===-- CBackend.cpp - Library for converting LLVM code to C --------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This library converts LLVM code to C code, compilable by GCC and other C
-// compilers.
-//
-//===----------------------------------------------------------------------===//
-
 #include "GenTargetMachine.h"
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
 #include <algorithm>
 
 using namespace llvm;
-
+#if 0
 extern "C" void LLVMInitializeGenBackendTarget() {
   // Register the target.
   RegisterTargetMachine<GenTargetMachine> X(TheGenBackendTarget);
 }
+#endif
 
 namespace {
   class CBEMCAsmInfo : public MCAsmInfo {
@@ -127,7 +114,7 @@ namespace {
       FPCounter = 0;
     }
 
-    virtual const char *getPassName() const { return "Gen backend"; }
+    virtual const char *getPassName() const { return "Gen Back-End"; }
 
     void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.addRequired<LoopInfo>();
@@ -184,7 +171,7 @@ namespace {
                                               PointerType *Ty);
 
     std::string getStructName(StructType *ST);
-    
+
     /// writeOperandDeref - Print the result of dereferencing the specified
     /// operand with '*'.  This is equivalent to printing '*' then using
     /// writeOperand, but avoids excess syntax in some cases.
@@ -364,7 +351,6 @@ namespace {
 char GenWriter::ID = 0;
 
 
-
 static std::string CBEMangle(const std::string &S) {
   std::string Result;
 
@@ -2250,6 +2236,7 @@ static inline bool isFPIntBitCast(const Instruction &I) {
 }
 
 void GenWriter::printFunction(Function &F) {
+
   /// isStructReturn - Should this function actually return a struct by-value?
   bool isStructReturn = F.hasStructRetAttr();
 
@@ -2792,54 +2779,6 @@ void GenWriter::printIntrinsicDefinition(const Function &F, raw_ostream &Out) {
   switch (F.getIntrinsicID()) {
   default:
     llvm_unreachable("Unsupported Intrinsic.");
-  case Intrinsic::uadd_with_overflow:
-    // static inline Rty uadd_ixx(unsigned ixx a, unsigned ixx b) {
-    //   Rty r;
-    //   r.field0 = a + b;
-    //   r.field1 = (r.field0 < a);
-    //   return r;
-    // }
-    Out << "static inline ";
-    printType(Out, retT);
-    Out << GetValueName(&F);
-    Out << "(";
-    printSimpleType(Out, elemT, false);
-    Out << "a,";
-    printSimpleType(Out, elemT, false);
-    Out << "b) {\n  ";
-    printType(Out, retT);
-    Out << "r;\n";
-    Out << "  r.field0 = a + b;\n";
-    Out << "  r.field1 = (r.field0 < a);\n";
-    Out << "  return r;\n}\n";
-    break;
-    
-  case Intrinsic::sadd_with_overflow:            
-    // static inline Rty sadd_ixx(ixx a, ixx b) {
-    //   Rty r;
-    //   r.field1 = (b > 0 && a > XX_MAX - b) ||
-    //              (b < 0 && a < XX_MIN - b);
-    //   r.field0 = r.field1 ? 0 : a + b;
-    //   return r;
-    // }
-    Out << "static ";
-    printType(Out, retT);
-    Out << GetValueName(&F);
-    Out << "(";
-    printSimpleType(Out, elemT, true);
-    Out << "a,";
-    printSimpleType(Out, elemT, true);
-    Out << "b) {\n  ";
-    printType(Out, retT);
-    Out << "r;\n";
-    Out << "  r.field1 = (b > 0 && a > ";
-    printLimitValue(*elemT, true, true, Out);
-    Out << " - b) || (b < 0 && a < ";
-    printLimitValue(*elemT, true, false, Out);
-    Out << " - b);\n";
-    Out << "  r.field0 = r.field1 ? 0 : a + b;\n";
-    Out << "  return r;\n}\n";
-    break;
   }
 }
 
@@ -3030,8 +2969,7 @@ void GenWriter::visitCallInst(CallInst &I) {
 /// visitBuiltinCall - Handle the call to the specified builtin.  Returns true
 /// if the entire call is handled, return false if it wasn't handled, and
 /// optionally set 'WroteCallee' if the callee has already been printed out.
-bool GenWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID,
-                               bool &WroteCallee) {
+bool GenWriter::visitBuiltinCall(CallInst &I, Intrinsic::ID ID, bool &WroteCallee) {
   switch (ID) {
   default: {
     // If this is an intrinsic that directly corresponds to a GCC
@@ -3618,7 +3556,7 @@ void GenWriter::visitExtractValueInst(ExtractValueInst &EVI) {
 //===----------------------------------------------------------------------===//
 //                       External Interface declaration
 //===----------------------------------------------------------------------===//
-
+#if 0
 bool GenTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
                                            formatted_raw_ostream &o,
                                            CodeGenFileType FileType,
@@ -3632,4 +3570,10 @@ bool GenTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
   PM.add(createGCInfoDeleter());
   return false;
 }
+#endif
+
+llvm::FunctionPass *createGenPass(formatted_raw_ostream &o) {
+  return new GenWriter(o);
+}
+
 
index 767f8bd..a720674 100644 (file)
@@ -37,7 +37,7 @@
 #include "llvm/Target/TargetData.h"
 
 namespace llvm {
-
+#if 0
 struct GenTargetMachine : public TargetMachine {
   GenTargetMachine(const Target &T, StringRef TT,
                  StringRef CPU, StringRef FS,
@@ -54,7 +54,7 @@ struct GenTargetMachine : public TargetMachine {
 };
 
 extern Target TheGenBackendTarget;
-
+#endif
 } // End llvm namespace
 
 
index dec6a46..835737c 100644 (file)
@@ -30,7 +30,7 @@
 #include "llvm/Module.h"
 #include "llvm/Support/TargetRegistry.h"
 using namespace llvm;
-
+#if 0
 Target llvm::TheGenBackendTarget;
 
 extern "C" void LLVMInitializeGenBackendTargetInfo() { 
@@ -38,4 +38,5 @@ extern "C" void LLVMInitializeGenBackendTargetInfo() {
 }
 
 extern "C" void LLVMInitializeGenBackendTargetMC() {}
+#endif
 
index bd53cbf..06fcda2 100644 (file)
@@ -41,6 +41,7 @@
 #include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
 #include "llvm/CodeGen/LinkAllCodegenComponents.h"
 #include "llvm/Config/config.h"
+#include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/MC/SubtargetFeature.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
@@ -239,6 +240,7 @@ static tool_output_file *GetOutputStream(const char *TargetName,
 extern "C" void LLVMInitializeGenBackendTarget();
 extern "C" void LLVMInitializeGenBackendTargetInfo();
 
+#if 0
 extern "C" int llvmToGen(int argc, char **argv)
 {
   sys::PrintStackTraceOnErrorSignal();
@@ -249,13 +251,8 @@ extern "C" int llvmToGen(int argc, char **argv)
 
   LLVMContext &Context = getGlobalContext();
   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
-
-  // Initialize targets first, so that --version shows registered targets.
   LLVMInitializeGenBackendTarget();
   LLVMInitializeGenBackendTargetInfo();
-  //InitializeAllTargetMCs();
-  //InitializeAllAsmPrinters();
-  //InitializeAllAsmParsers();
 
   // Register the target printer for --version.
   cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
@@ -397,8 +394,39 @@ extern "C" int llvmToGen(int argc, char **argv)
 
   // Declare success.
   Out->keep();
-
   return 0;
 }
 
+#else
+#include <iostream>
+extern llvm::FunctionPass *createGenPass(formatted_raw_ostream &o);
+extern "C" int llvmToGen(const char *fileName)
+{
+  // Get the global LLVM context
+  llvm::LLVMContext& c = llvm::getGlobalContext();
+
+  // Get the module from its file
+  SMDiagnostic Err;
+  std::auto_ptr<Module> M;
+  M.reset(ParseIRFile(fileName, Err, c));
+  if (M.get() == 0) {
+    Err.Print(fileName, errs());
+    return 1;
+  }
+  Module &mod = *M.get();
+
+  llvm::PassManager passes;
+  std::string error;
+
+  llvm::tool_output_file *FDOut = new llvm::tool_output_file("hop.ll", error, 0);
+  llvm::formatted_raw_ostream outstream(FDOut->os());
+
+  passes.add(llvm::createPrintModulePass(&outstream));
+  passes.add(createGenPass(outstream));
+  passes.run(mod);
+
+  FDOut->keep();
+  return 0;
+}
+#endif
 
index 5f48cea..0a00536 100644 (file)
 #include <cstdlib>
 
 // Transform some llvm code to gen code
+#if 0
 extern "C" int llvmToGen(int argc, char **argv);
+#else
+extern "C" int llvmToGen(const char *fileName);
+#endif
 
 /*! Where the kernels to test are */
 static std::string kernelPath;
@@ -44,6 +48,7 @@ char *copyString(const char *src) {
 static void utestLLVM2Gen(const char *kernel)
 {
   const std::string path = kernelPath + kernel;
+#if 0
   char *toFree[] = {
     copyString(""),
     copyString("-march=gen"),
@@ -54,6 +59,9 @@ static void utestLLVM2Gen(const char *kernel)
   GBE_DELETE_ARRAY(toFree[0]);
   GBE_DELETE_ARRAY(toFree[1]);
   GBE_DELETE_ARRAY(toFree[2]);
+#else
+  llvmToGen(path.c_str());
+#endif
 }
 
 static void utestLLVM(void)