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

Chris Lattner lattner at cs.uiuc.edu
Sun Jul 10 22:17:59 PDT 2005



Changes in directory llvm/lib/Target/X86:

X86.h updated: 1.34 -> 1.35
X86CodeEmitter.cpp updated: 1.81 -> 1.82
X86ELFWriter.cpp updated: 1.1 -> 1.2
X86TargetMachine.cpp updated: 1.81 -> 1.82
---
Log message:

Refactor things a bit to allow the ELF code emitter to run the X86 machine code emitter
after itself.


---
Diffs of the changes:  (+32 -24)

 X86.h                |   17 +++++++++++------
 X86CodeEmitter.cpp   |   16 ++++------------
 X86ELFWriter.cpp     |   14 +++++++++-----
 X86TargetMachine.cpp |    9 ++++++++-
 4 files changed, 32 insertions(+), 24 deletions(-)


Index: llvm/lib/Target/X86/X86.h
diff -u llvm/lib/Target/X86/X86.h:1.34 llvm/lib/Target/X86/X86.h:1.35
--- llvm/lib/Target/X86/X86.h:1.34	Sun Jul 10 23:20:55 2005
+++ llvm/lib/Target/X86/X86.h	Mon Jul 11 00:17:48 2005
@@ -20,8 +20,10 @@
 namespace llvm {
 
 class TargetMachine;
+class PassManager;
 class FunctionPass;
 class IntrinsicLowering;
+class MachineCodeEmitter;
 
 enum X86VectorEnum {
   NoSSE, SSE, SSE2, SSE3
@@ -59,16 +61,19 @@
 
 /// createX86CodePrinterPass - Returns a pass that prints the X86
 /// assembly code for a MachineFunction to the given output stream,
-/// using the given target machine description.  This should work
-/// regardless of whether the function is in SSA form.
+/// using the given target machine description.
 ///
-FunctionPass *createX86CodePrinterPass(std::ostream &o,TargetMachine &tm);
+FunctionPass *createX86CodePrinterPass(std::ostream &o, TargetMachine &tm);
 
-/// createX86ELFObjectWriterPass - Returns a pass that outputs the generated
+/// createX86CodeEmitterPass - Return a pass that emits the collected X86 code
+/// to the specified MCE object.
+FunctionPass *createX86CodeEmitterPass(MachineCodeEmitter &MCE);
+
+/// addX86ELFObjectWriterPass - Add passes to the FPM that output the generated
 /// code as an ELF object file.
 ///
-FunctionPass *createX86ELFObjectWriterPass(std::ostream &o, TargetMachine &tm);
-
+void addX86ELFObjectWriterPass(PassManager &FPM,
+                               std::ostream &o, TargetMachine &tm);
 
 /// createX86EmitCodeToMemory - Returns a pass that converts a register
 /// allocated function into raw machine code in a dynamically


Index: llvm/lib/Target/X86/X86CodeEmitter.cpp
diff -u llvm/lib/Target/X86/X86CodeEmitter.cpp:1.81 llvm/lib/Target/X86/X86CodeEmitter.cpp:1.82
--- llvm/lib/Target/X86/X86CodeEmitter.cpp:1.81	Wed Jul  6 13:59:03 2005
+++ llvm/lib/Target/X86/X86CodeEmitter.cpp	Mon Jul 11 00:17:48 2005
@@ -68,18 +68,10 @@
   };
 }
 
-/// addPassesToEmitMachineCode - Add passes to the specified pass manager to get
-/// machine code emitted.  This uses a MachineCodeEmitter object to handle
-/// actually outputting the machine code and resolving things like the address
-/// of functions.  This method should returns true if machine code emission is
-/// not supported.
-///
-bool X86TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
-                                                  MachineCodeEmitter &MCE) {
-  PM.add(new Emitter(MCE));
-  // Delete machine code for this function
-  PM.add(createMachineCodeDeleter());
-  return false;
+/// createX86CodeEmitterPass - Return a pass that emits the collected X86 code
+/// to the specified MCE object.
+FunctionPass *llvm::createX86CodeEmitterPass(MachineCodeEmitter &MCE) {
+  return new Emitter(MCE);
 }
 
 bool Emitter::runOnMachineFunction(MachineFunction &MF) {


Index: llvm/lib/Target/X86/X86ELFWriter.cpp
diff -u llvm/lib/Target/X86/X86ELFWriter.cpp:1.1 llvm/lib/Target/X86/X86ELFWriter.cpp:1.2
--- llvm/lib/Target/X86/X86ELFWriter.cpp:1.1	Mon Jun 27 01:30:12 2005
+++ llvm/lib/Target/X86/X86ELFWriter.cpp	Mon Jul 11 00:17:48 2005
@@ -13,7 +13,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "X86.h"
+#include "llvm/PassManager.h"
 #include "llvm/CodeGen/ELFWriter.h"
+#include "llvm/Target/TargetMachine.h"
 using namespace llvm;
 
 namespace {
@@ -25,10 +27,12 @@
   };
 }
 
-/// createX86ELFObjectWriterPass - Returns a pass that outputs the generated
-/// code as an ELF object file.
+/// addX86ELFObjectWriterPass - Returns a pass that outputs the generated code
+/// as an ELF object file.
 ///
-FunctionPass *llvm::createX86ELFObjectWriterPass(std::ostream &O,
-                                                 TargetMachine &TM) {
-  return new X86ELFWriter(O, TM);
+void llvm::addX86ELFObjectWriterPass(PassManager &FPM,
+                                     std::ostream &O, TargetMachine &TM) {
+  X86ELFWriter *EW = new X86ELFWriter(O, TM);
+  FPM.add(EW);
+  FPM.add(createX86CodeEmitterPass(EW->getMachineCodeEmitter()));
 }


Index: llvm/lib/Target/X86/X86TargetMachine.cpp
diff -u llvm/lib/Target/X86/X86TargetMachine.cpp:1.81 llvm/lib/Target/X86/X86TargetMachine.cpp:1.82
--- llvm/lib/Target/X86/X86TargetMachine.cpp:1.81	Wed Jul  6 13:59:04 2005
+++ llvm/lib/Target/X86/X86TargetMachine.cpp	Mon Jul 11 00:17:48 2005
@@ -162,7 +162,7 @@
       // 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).
-      PM.add(createX86ELFObjectWriterPass(Out, *this));
+      addX86ELFObjectWriterPass(PM, Out, *this);
       break;
     }
 
@@ -225,3 +225,10 @@
     PM.add(createX86CodePrinterPass(std::cerr, TM));
 }
 
+bool X86TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
+                                                  MachineCodeEmitter &MCE) {
+  PM.add(createX86CodeEmitterPass(MCE));
+  // Delete machine code for this function
+  PM.add(createMachineCodeDeleter());
+  return false;
+}






More information about the llvm-commits mailing list