llvm.org GIT mirror llvm / 81b6ed7
Refactor things a bit to allow the ELF code emitter to run the X86 machine code emitter after itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22376 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 15 years ago
4 changed file(s) with 32 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
1919 namespace llvm {
2020
2121 class TargetMachine;
22 class PassManager;
2223 class FunctionPass;
2324 class IntrinsicLowering;
25 class MachineCodeEmitter;
2426
2527 enum X86VectorEnum {
2628 NoSSE, SSE, SSE2, SSE3
5860
5961 /// createX86CodePrinterPass - Returns a pass that prints the X86
6062 /// assembly code for a MachineFunction to the given output stream,
61 /// using the given target machine description. This should work
62 /// regardless of whether the function is in SSA form.
63 /// using the given target machine description.
6364 ///
64 FunctionPass *createX86CodePrinterPass(std::ostream &o,TargetMachine &tm);
65 FunctionPass *createX86CodePrinterPass(std::ostream &o, TargetMachine &tm);
6566
66 /// createX86ELFObjectWriterPass - Returns a pass that outputs the generated
67 /// createX86CodeEmitterPass - Return a pass that emits the collected X86 code
68 /// to the specified MCE object.
69 FunctionPass *createX86CodeEmitterPass(MachineCodeEmitter &MCE);
70
71 /// addX86ELFObjectWriterPass - Add passes to the FPM that output the generated
6772 /// code as an ELF object file.
6873 ///
69 FunctionPass *createX86ELFObjectWriterPass(std::ostream &o, TargetMachine &tm);
70
74 void addX86ELFObjectWriterPass(PassManager &FPM,
75 std::ostream &o, TargetMachine &tm);
7176
7277 /// createX86EmitCodeToMemory - Returns a pass that converts a register
7378 /// allocated function into raw machine code in a dynamically
6767 };
6868 }
6969
70 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to get
71 /// machine code emitted. This uses a MachineCodeEmitter object to handle
72 /// actually outputting the machine code and resolving things like the address
73 /// of functions. This method should returns true if machine code emission is
74 /// not supported.
75 ///
76 bool X86TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
77 MachineCodeEmitter &MCE) {
78 PM.add(new Emitter(MCE));
79 // Delete machine code for this function
80 PM.add(createMachineCodeDeleter());
81 return false;
70 /// createX86CodeEmitterPass - Return a pass that emits the collected X86 code
71 /// to the specified MCE object.
72 FunctionPass *llvm::createX86CodeEmitterPass(MachineCodeEmitter &MCE) {
73 return new Emitter(MCE);
8274 }
8375
8476 bool Emitter::runOnMachineFunction(MachineFunction &MF) {
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "X86.h"
15 #include "llvm/PassManager.h"
1516 #include "llvm/CodeGen/ELFWriter.h"
17 #include "llvm/Target/TargetMachine.h"
1618 using namespace llvm;
1719
1820 namespace {
2426 };
2527 }
2628
27 /// createX86ELFObjectWriterPass - Returns a pass that outputs the generated
28 /// code as an ELF object file.
29 /// addX86ELFObjectWriterPass - Returns a pass that outputs the generated code
30 /// as an ELF object file.
2931 ///
30 FunctionPass *llvm::createX86ELFObjectWriterPass(std::ostream &O,
31 TargetMachine &TM) {
32 return new X86ELFWriter(O, TM);
32 void llvm::addX86ELFObjectWriterPass(PassManager &FPM,
33 std::ostream &O, TargetMachine &TM) {
34 X86ELFWriter *EW = new X86ELFWriter(O, TM);
35 FPM.add(EW);
36 FPM.add(createX86CodeEmitterPass(EW->getMachineCodeEmitter()));
3337 }
161161 // FIXME: We only support emission of ELF files for now, this should check
162162 // the target triple and decide on the format to write (e.g. COFF on
163163 // win32).
164 PM.add(createX86ELFObjectWriterPass(Out, *this));
164 addX86ELFObjectWriterPass(PM, Out, *this);
165165 break;
166166 }
167167
224224 PM.add(createX86CodePrinterPass(std::cerr, TM));
225225 }
226226
227 bool X86TargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM,
228 MachineCodeEmitter &MCE) {
229 PM.add(createX86CodeEmitterPass(MCE));
230 // Delete machine code for this function
231 PM.add(createMachineCodeDeleter());
232 return false;
233 }