Finally, _actually delete the machine code_ for a function, after it has
[oota-llvm.git] / lib / Target / X86 / X86TargetMachine.cpp
1 //===-- X86TargetMachine.cpp - Define TargetMachine for the X86 -----------===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 // 
10 // This file defines the X86 specific subclass of TargetMachine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "X86TargetMachine.h"
15 #include "X86.h"
16 #include "llvm/Module.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/Target/TargetMachineImpls.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Transforms/Scalar.h"
22 #include "Support/CommandLine.h"
23 #include "Support/Statistic.h"
24 using namespace llvm;
25
26 namespace {
27   cl::opt<bool> PrintCode("print-machineinstrs",
28                           cl::desc("Print generated machine code"));
29   cl::opt<bool> NoPatternISel("disable-pattern-isel", cl::init(true),
30                         cl::desc("Use the 'simple' X86 instruction selector"));
31   cl::opt<bool> NoSSAPeephole("disable-ssa-peephole", cl::init(true),
32                         cl::desc("Disable the ssa-based peephole optimizer (defaults to disabled)"));
33 }
34
35 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
36 // that implements the X86 backend.
37 //
38 TargetMachine *llvm::allocateX86TargetMachine(const Module &M) {
39   return new X86TargetMachine(M);
40 }
41
42
43 /// X86TargetMachine ctor - Create an ILP32 architecture model
44 ///
45 X86TargetMachine::X86TargetMachine(const Module &M)
46   : TargetMachine("X86", true, 4, 4, 4, 4, 4),
47     FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4),
48     JITInfo(*this) {
49 }
50
51
52 // addPassesToEmitAssembly - We currently use all of the same passes as the JIT
53 // does to emit statically compiled machine code.
54 bool X86TargetMachine::addPassesToEmitAssembly(PassManager &PM,
55                                                std::ostream &Out) {
56   // FIXME: Implement the switch instruction in the instruction selector!
57   PM.add(createLowerSwitchPass());
58
59   // FIXME: Implement the invoke/unwind instructions!
60   PM.add(createLowerInvokePass());
61
62   // FIXME: The code generator does not properly handle functions with
63   // unreachable basic blocks.
64   PM.add(createCFGSimplificationPass());
65
66   if (NoPatternISel)
67     PM.add(createX86SimpleInstructionSelector(*this));
68   else
69     PM.add(createX86PatternInstructionSelector(*this));
70
71   // Run optional SSA-based machine code optimizations next...
72   if (!NoSSAPeephole)
73     PM.add(createX86SSAPeepholeOptimizerPass());
74
75   // Print the instruction selected machine code...
76   if (PrintCode)
77     PM.add(createMachineFunctionPrinterPass());
78
79   // kill floating point registers at the end of basic blocks. this is
80   // done because the floating point register stackifier cannot handle
81   // floating point regs that are live across basic blocks.
82   //PM.add(createX86FloatingPointKillerPass());
83
84   // Perform register allocation to convert to a concrete x86 representation
85   PM.add(createRegisterAllocator());
86
87   if (PrintCode)
88     PM.add(createMachineFunctionPrinterPass());
89
90   PM.add(createX86FloatingPointStackifierPass());
91
92   if (PrintCode)
93     PM.add(createMachineFunctionPrinterPass());
94
95   // Insert prolog/epilog code.  Eliminate abstract frame index references...
96   PM.add(createPrologEpilogCodeInserter());
97
98   PM.add(createX86PeepholeOptimizerPass());
99
100   if (PrintCode)  // Print the register-allocated code
101     PM.add(createX86CodePrinterPass(std::cerr, *this));
102
103   PM.add(createX86CodePrinterPass(Out, *this));
104
105   // Delete machine code for this function
106   PM.add(createMachineCodeDeleter());
107
108   return false; // success!
109 }
110
111 /// addPassesToJITCompile - Add passes to the specified pass manager to
112 /// implement a fast dynamic compiler for this target.  Return true if this is
113 /// not supported for this target.
114 ///
115 void X86JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
116   // FIXME: Implement the switch instruction in the instruction selector!
117   PM.add(createLowerSwitchPass());
118
119   // FIXME: Implement the invoke/unwind instructions!
120   PM.add(createLowerInvokePass());
121
122   // FIXME: The code generator does not properly handle functions with
123   // unreachable basic blocks.
124   PM.add(createCFGSimplificationPass());
125
126   if (NoPatternISel)
127     PM.add(createX86SimpleInstructionSelector(TM));
128   else
129     PM.add(createX86PatternInstructionSelector(TM));
130
131   // Run optional SSA-based machine code optimizations next...
132   if (!NoSSAPeephole)
133     PM.add(createX86SSAPeepholeOptimizerPass());
134
135   // FIXME: Add SSA based peephole optimizer here.
136
137   // Print the instruction selected machine code...
138   if (PrintCode)
139     PM.add(createMachineFunctionPrinterPass());
140
141   // kill floating point registers at the end of basic blocks. this is
142   // done because the floating point register stackifier cannot handle
143   // floating point regs that are live across basic blocks.
144   //PM.add(createX86FloatingPointKillerPass());
145
146   // Perform register allocation to convert to a concrete x86 representation
147   PM.add(createRegisterAllocator());
148
149   if (PrintCode)
150     PM.add(createMachineFunctionPrinterPass());
151
152   PM.add(createX86FloatingPointStackifierPass());
153
154   if (PrintCode)
155     PM.add(createMachineFunctionPrinterPass());
156
157   // Insert prolog/epilog code.  Eliminate abstract frame index references...
158   PM.add(createPrologEpilogCodeInserter());
159
160   PM.add(createX86PeepholeOptimizerPass());
161
162   if (PrintCode)  // Print the register-allocated code
163     PM.add(createX86CodePrinterPass(std::cerr, TM));
164 }
165