[llvm-commits] CVS: llvm/tools/jello/jello.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 29 15:08:04 PST 2002


Changes in directory llvm/tools/jello:

jello.cpp updated: 1.1 -> 1.2

---
Log message:

Convert jello to use PassManager


---
Diffs of the changes:

Index: llvm/tools/jello/jello.cpp
diff -u llvm/tools/jello/jello.cpp:1.1 llvm/tools/jello/jello.cpp:1.2
--- llvm/tools/jello/jello.cpp:1.1	Fri Oct 25 17:58:53 2002
+++ llvm/tools/jello/jello.cpp	Tue Oct 29 15:06:58 2002
@@ -9,10 +9,10 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Module.h"
+#include "llvm/PassManager.h"
 #include "llvm/Bytecode/Reader.h"
-#include "llvm/CodeGen/MFunction.h"
-#include "../lib/Target/X86/X86.h"   // FIXME: become generic eventually
-#include "../lib/Target/X86/X86InstructionInfo.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetMachineImpls.h"
 #include "Support/CommandLine.h"
 #include "Support/Statistic.h"
 
@@ -25,52 +25,39 @@
                cl::value_desc("function name"));
 }
 
-
-/// ExecuteFunction - Compile the specified function to machine code, and
-/// execute it.
-///
-static void ExecuteFunction(Function &F) {
-  X86InstructionInfo II;
-
-  // Perform instruction selection to turn the function into an x86 SSA form
-  MFunction *MF = X86SimpleInstructionSelection(F);
-
-  // TODO: optional optimizations go here
-
-  // If -debug is specified, output selected code to stderr
-  /*DEBUG*/(MF->print(std::cerr, II));
-
-  // Perform register allocation to convert to a concrete x86 representation
-  X86SimpleRegisterAllocation(MF);
-  
-  // If -debug is specified, output compiled code to stderr
-  /*DEBUG*/(X86PrintCode(MF, std::cerr));
-
-  // Emit register allocated X86 code now...
-  void *PFun = X86EmitCodeToMemory(MF);
-
-  // We don't need the machine specific representation for this function anymore
-  delete MF;
-}
-
-
 //===----------------------------------------------------------------------===//
 // main Driver function
 //
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv, " llvm just in time compiler\n");
 
+  // Allocate a target... in the future this will be controllable on the
+  // command line.
+  std::auto_ptr<TargetMachine> target(allocateX86TargetMachine());
+  assert(target.get() && "Could not allocate target machine!");
+
+  TargetMachine &Target = *target.get();
+
+  // Parse the input bytecode file...
   std::string ErrorMsg;
-  if (Module *M = ParseBytecodeFile(InputFile, &ErrorMsg)) {
-    for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
-      if (I->getName() == MainFunction)
-        ExecuteFunction(*I);
+  std::auto_ptr<Module> M(ParseBytecodeFile(InputFile, &ErrorMsg));
+  if (M.get() == 0) {
+    std::cerr << argv[0] << ": bytecode '" << InputFile
+              << "' didn't read correctly: << " << ErrorMsg << "\n";
+    return 1;
+  }
 
-    delete M;
-    return 0;
+  PassManager Passes;
+  if (Target.addPassesToJITCompile(Passes)) {
+    std::cerr << argv[0] << ": target '" << Target.TargetName
+              << "' doesn't support JIT compilation!\n";
+    return 1;
   }
+
+  // JIT all of the methods in the module.  Eventually this will JIT functions
+  // on demand.
+  Passes.run(*M.get());
   
-  std::cerr << "Error parsing '" << InputFile << "': " << ErrorMsg << "\n";
   return 1;
 }
 





More information about the llvm-commits mailing list