[llvm-commits] CVS: llvm/lib/Target/X86/X86.h X86ELFWriter.cpp X86JITInfo.h X86TargetMachine.cpp X86TargetMachine.h

Chris Lattner lattner at cs.uiuc.edu
Sun Sep 3 21:15:26 PDT 2006



Changes in directory llvm/lib/Target/X86:

X86.h updated: 1.47 -> 1.48
X86ELFWriter.cpp updated: 1.6 -> 1.7
X86JITInfo.h updated: 1.10 -> 1.11
X86TargetMachine.cpp updated: 1.123 -> 1.124
X86TargetMachine.h updated: 1.37 -> 1.38
---
Log message:

Completely rearchitect the interface between targets and the pass manager.
This pass:

1. Splits TargetMachine into TargetMachine (generic targets, can be implemented
any way, like the CBE) and LLVMTargetMachine (subclass of TM that is used by
things using libcodegen and other support).
2. Instead of having each target fully populate the passmgr for file or JIT
   output, move all this to common code, and give targets hooks they can
   implement.
3. Commonalize the target population stuff between file emission and JIT
   emission.
4. All (native code) codegen stuff now happens in a FunctionPassManager, which
   paves the way for "fast -O0" stuff in the CFE later, and now LLC could
   lazily stream .bc files from disk to use less memory.
5. There are now many fewer #includes and the targets don't depend on the 
   scalar xforms or libanalysis anymore (but codegen does).
6. Changing common code generator pass ordering stuff no longer requires 
   touching all targets.
7. The JIT now has the option of "-fast" codegen or normal optimized codegen,
   which is now orthogonal to the fact that JIT'ing is being done.


---
Diffs of the changes:  (+38 -128)

 X86.h                |    4 -
 X86ELFWriter.cpp     |    2 
 X86JITInfo.h         |    6 --
 X86TargetMachine.cpp |  134 ++++++++-------------------------------------------
 X86TargetMachine.h   |   20 ++++---
 5 files changed, 38 insertions(+), 128 deletions(-)


Index: llvm/lib/Target/X86/X86.h
diff -u llvm/lib/Target/X86/X86.h:1.47 llvm/lib/Target/X86/X86.h:1.48
--- llvm/lib/Target/X86/X86.h:1.47	Tue Aug 29 13:28:33 2006
+++ llvm/lib/Target/X86/X86.h	Sun Sep  3 23:14:57 2006
@@ -20,7 +20,7 @@
 namespace llvm {
 
 class X86TargetMachine;
-class PassManager;
+class FunctionPassManager;
 class FunctionPass;
 class IntrinsicLowering;
 class MachineCodeEmitter;
@@ -50,7 +50,7 @@
 /// addX86ELFObjectWriterPass - Add passes to the FPM that output the generated
 /// code as an ELF object file.
 ///
-void addX86ELFObjectWriterPass(PassManager &FPM,
+void addX86ELFObjectWriterPass(FunctionPassManager &FPM,
                                std::ostream &o, X86TargetMachine &tm);
 
 /// createX86EmitCodeToMemory - Returns a pass that converts a register


Index: llvm/lib/Target/X86/X86ELFWriter.cpp
diff -u llvm/lib/Target/X86/X86ELFWriter.cpp:1.6 llvm/lib/Target/X86/X86ELFWriter.cpp:1.7
--- llvm/lib/Target/X86/X86ELFWriter.cpp:1.6	Sun Aug 27 07:54:01 2006
+++ llvm/lib/Target/X86/X86ELFWriter.cpp	Sun Sep  3 23:14:57 2006
@@ -31,7 +31,7 @@
 /// addX86ELFObjectWriterPass - Returns a pass that outputs the generated code
 /// as an ELF object file.
 ///
-void llvm::addX86ELFObjectWriterPass(PassManager &FPM,
+void llvm::addX86ELFObjectWriterPass(FunctionPassManager &FPM,
                                      std::ostream &O, X86TargetMachine &TM) {
   X86ELFWriter *EW = new X86ELFWriter(O, TM);
   FPM.add(EW);


Index: llvm/lib/Target/X86/X86JITInfo.h
diff -u llvm/lib/Target/X86/X86JITInfo.h:1.10 llvm/lib/Target/X86/X86JITInfo.h:1.11
--- llvm/lib/Target/X86/X86JITInfo.h:1.10	Thu Jul 27 13:21:10 2006
+++ llvm/lib/Target/X86/X86JITInfo.h	Sun Sep  3 23:14:57 2006
@@ -25,12 +25,6 @@
   public:
     X86JITInfo(X86TargetMachine &tm) : TM(tm) {useGOT = 0;}
 
-    /// addPassesToJITCompile - Add passes to the specified pass manager to
-    /// implement a fast dynamic compiler for this target.  Return true if this
-    /// is not supported for this target.
-    ///
-    virtual void addPassesToJITCompile(FunctionPassManager &PM);
-
     /// replaceMachineCodeForFunction - Make it so that calling the function
     /// whose machine code is at OLD turns into a call to NEW, perhaps by
     /// overwriting OLD with a branch to NEW.  This is used for self-modifying


Index: llvm/lib/Target/X86/X86TargetMachine.cpp
diff -u llvm/lib/Target/X86/X86TargetMachine.cpp:1.123 llvm/lib/Target/X86/X86TargetMachine.cpp:1.124
--- llvm/lib/Target/X86/X86TargetMachine.cpp:1.123	Sun Sep  3 13:44:02 2006
+++ llvm/lib/Target/X86/X86TargetMachine.cpp	Sun Sep  3 23:14:57 2006
@@ -20,8 +20,6 @@
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Target/TargetMachineRegistry.h"
 #include "llvm/Transforms/Scalar.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/ADT/Statistic.h"
 #include <iostream>
 using namespace llvm;
 
@@ -33,9 +31,6 @@
 int X86TargetMachineModule = 0;
 
 namespace {
-  cl::opt<bool> DisableOutput("disable-x86-llc-output", cl::Hidden,
-                              cl::desc("Disable the X86 asm printer, for use "
-                                       "when profiling the code generator."));
   // Register the target.
   RegisterTarget<X86TargetMachine> X("x86", "  IA-32 (Pentium and above)");
 }
@@ -79,121 +74,38 @@
       setRelocationModel(Reloc::PIC_);
 }
 
+//===----------------------------------------------------------------------===//
+// Pass Pipeline Configuration
+//===----------------------------------------------------------------------===//
 
-// addPassesToEmitFile - We currently use all of the same passes as the JIT
-// does to emit statically compiled machine code.
-bool X86TargetMachine::addPassesToEmitFile(PassManager &PM, std::ostream &Out,
-                                           CodeGenFileType FileType,
-                                           bool Fast) {
-  if (FileType != TargetMachine::AssemblyFile &&
-      FileType != TargetMachine::ObjectFile) return true;
-
-  // Run loop strength reduction before anything else.
-  if (!Fast) PM.add(createLoopStrengthReducePass(&TLInfo));
-
-  // FIXME: Implement efficient support for garbage collection intrinsics.
-  PM.add(createLowerGCPass());
-
-  // FIXME: Implement the invoke/unwind instructions!
-  PM.add(createLowerInvokePass());
-
-  // Make sure that no unreachable blocks are instruction selected.
-  PM.add(createUnreachableBlockEliminationPass());
-
+bool X86TargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
   // Install an instruction selector.
   PM.add(createX86ISelDag(*this, Fast));
+  return false;
+}
 
-  // Print the instruction selected machine code...
-  if (PrintMachineCode)
-    PM.add(createMachineFunctionPrinterPass(&std::cerr));
-
-  // Perform register allocation to convert to a concrete x86 representation
-  PM.add(createRegisterAllocator());
-
-  if (PrintMachineCode)
-    PM.add(createMachineFunctionPrinterPass(&std::cerr));
-
-  PM.add(createX86FloatingPointStackifierPass());
-
-  if (PrintMachineCode)
-    PM.add(createMachineFunctionPrinterPass(&std::cerr));
-
-  // Insert prolog/epilog code.  Eliminate abstract frame index references...
-  PM.add(createPrologEpilogCodeInserter());
-
-  if (PrintMachineCode)  // Print the register-allocated code
-    PM.add(createX86CodePrinterPass(std::cerr, *this));
-
-  if (!DisableOutput)
-    switch (FileType) {
-    default:
-      assert(0 && "Unexpected filetype here!");
-    case TargetMachine::AssemblyFile:
-      PM.add(createX86CodePrinterPass(Out, *this));
-      break;
-    case TargetMachine::ObjectFile:
-      // FIXME: We only support emission of ELF files for now, this should check
-      // the target triple and decide on the format to write (e.g. COFF on
-      // win32 or Mach-O on darwin).
-      addX86ELFObjectWriterPass(PM, Out, *this);
-      break;
-    }
-
-  // Delete machine code for this function
-  PM.add(createMachineCodeDeleter());
-
-  return false; // success!
-}
-
-/// addPassesToJITCompile - Add passes to the specified pass manager to
-/// implement a fast dynamic compiler for this target.  Return true if this is
-/// not supported for this target.
-///
-void X86JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
-  // The JIT should use static relocation model.
-  TM.setRelocationModel(Reloc::Static);
-
-  // Run loop strength reduction before anything else.
-  PM.add(createLoopStrengthReducePass(TM.getTargetLowering()));
-
-  // FIXME: Implement efficient support for garbage collection intrinsics.
-  PM.add(createLowerGCPass());
-
-  // FIXME: Implement the invoke/unwind instructions!
-  PM.add(createLowerInvokePass());
-
-  // Make sure that no unreachable blocks are instruction selected.
-  PM.add(createUnreachableBlockEliminationPass());
-
-  // Install an instruction selector.
-  PM.add(createX86ISelDag(TM, false));
-
-  // Print the instruction selected machine code...
-  if (PrintMachineCode)
-    PM.add(createMachineFunctionPrinterPass(&std::cerr));
-
-  // Perform register allocation to convert to a concrete x86 representation
-  PM.add(createRegisterAllocator());
-
-  if (PrintMachineCode)
-    PM.add(createMachineFunctionPrinterPass(&std::cerr));
-
+bool X86TargetMachine::addPostRegAlloc(FunctionPassManager &PM, bool Fast) {
   PM.add(createX86FloatingPointStackifierPass());
+  return true;  // -print-machineinstr should print after this.
+}
 
-  if (PrintMachineCode)
-    PM.add(createMachineFunctionPrinterPass(&std::cerr));
-
-  // Insert prolog/epilog code.  Eliminate abstract frame index references...
-  PM.add(createPrologEpilogCodeInserter());
+bool X86TargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
+                                          std::ostream &Out) {
+  PM.add(createX86CodePrinterPass(Out, *this));
+  return false;
+}
 
-  if (PrintMachineCode)  // Print the register-allocated code
-    PM.add(createX86CodePrinterPass(std::cerr, TM));
+bool X86TargetMachine::addObjectWriter(FunctionPassManager &PM, bool Fast,
+                                       std::ostream &Out) {
+  if (Subtarget.isTargetELF()) {
+    addX86ELFObjectWriterPass(PM, Out, *this);
+    return false;
+  }
+  return true;
 }
 
-bool X86TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
-                                                  MachineCodeEmitter &MCE) {
+bool X86TargetMachine::addCodeEmitter(FunctionPassManager &PM, bool Fast,
+                                      MachineCodeEmitter &MCE) {
   PM.add(createX86CodeEmitterPass(*this, MCE));
-  // Delete machine code for this function
-  PM.add(createMachineCodeDeleter());
   return false;
 }


Index: llvm/lib/Target/X86/X86TargetMachine.h
diff -u llvm/lib/Target/X86/X86TargetMachine.h:1.37 llvm/lib/Target/X86/X86TargetMachine.h:1.38
--- llvm/lib/Target/X86/X86TargetMachine.h:1.37	Tue May 30 16:45:53 2006
+++ llvm/lib/Target/X86/X86TargetMachine.h	Sun Sep  3 23:14:57 2006
@@ -17,7 +17,6 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Target/TargetFrameInfo.h"
-#include "llvm/PassManager.h"
 #include "X86.h"
 #include "X86InstrInfo.h"
 #include "X86JITInfo.h"
@@ -26,7 +25,7 @@
 
 namespace llvm {
 
-class X86TargetMachine : public TargetMachine {
+class X86TargetMachine : public LLVMTargetMachine {
   X86Subtarget      Subtarget;
   const TargetData DataLayout;       // Calculates type size & alignment
   TargetFrameInfo   FrameInfo;
@@ -48,14 +47,19 @@
   }
   virtual const TargetData       *getTargetData() const { return &DataLayout; }
 
-  virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
-                                          MachineCodeEmitter &MCE);
-
-  virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
-                                   CodeGenFileType FileType, bool Fast);
-
   static unsigned getModuleMatchQuality(const Module &M);
   static unsigned getJITMatchQuality();
+  
+  
+  // Set up the pass pipeline.
+  virtual bool addInstSelector(FunctionPassManager &PM, bool Fast);  
+  virtual bool addPostRegAlloc(FunctionPassManager &PM, bool Fast);
+  virtual bool addAssemblyEmitter(FunctionPassManager &PM, bool Fast, 
+                                  std::ostream &Out);
+  virtual bool addObjectWriter(FunctionPassManager &PM, bool Fast,
+                               std::ostream &Out);
+  virtual bool addCodeEmitter(FunctionPassManager &PM, bool Fast,
+                              MachineCodeEmitter &MCE);
 };
 } // End llvm namespace
 






More information about the llvm-commits mailing list