Remove dead blocks
[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/CodeGen/IntrinsicLowering.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Target/TargetMachineImpls.h"
22 #include "llvm/Transforms/Scalar.h"
23 #include "Support/CommandLine.h"
24 #include "Support/Statistic.h"
25 using namespace llvm;
26
27 namespace {
28   cl::opt<bool> NoPatternISel("disable-pattern-isel", cl::init(true),
29                         cl::desc("Use the 'simple' X86 instruction selector"));
30   cl::opt<bool> NoSSAPeephole("disable-ssa-peephole", cl::init(true),
31                         cl::desc("Disable the ssa-based peephole optimizer "
32                                  "(defaults to disabled)"));
33   cl::opt<bool> DisableOutput("disable-x86-llc-output", cl::Hidden,
34                               cl::desc("Disable the X86 asm printer, for use "
35                                        "when profiling the code generator."));
36   cl::opt<bool> NoSimpleISel("disable-simple-isel", cl::init(true),
37              cl::desc("Use the hand coded 'simple' X86 instruction selector"));
38 }
39
40 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
41 // that implements the X86 backend.
42 //
43 TargetMachine *llvm::allocateX86TargetMachine(const Module &M,
44                                               IntrinsicLowering *IL) {
45   return new X86TargetMachine(M, IL);
46 }
47
48
49 /// X86TargetMachine ctor - Create an ILP32 architecture model
50 ///
51 X86TargetMachine::X86TargetMachine(const Module &M, IntrinsicLowering *IL)
52   : TargetMachine("X86", IL, true, 4, 4, 4, 4, 4),
53     FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, -4),
54     JITInfo(*this) {
55 }
56
57
58 // addPassesToEmitAssembly - We currently use all of the same passes as the JIT
59 // does to emit statically compiled machine code.
60 bool X86TargetMachine::addPassesToEmitAssembly(PassManager &PM,
61                                                std::ostream &Out) {
62   // FIXME: Implement efficient support for garbage collection intrinsics.
63   PM.add(createLowerGCPass());
64
65   // FIXME: Implement the invoke/unwind instructions!
66   PM.add(createLowerInvokePass());
67
68   // FIXME: Implement the switch instruction in the instruction selector!
69   PM.add(createLowerSwitchPass());
70
71   // Make sure that no unreachable blocks are instruction selected.
72   PM.add(createUnreachableBlockEliminationPass());
73
74   if (NoPatternISel && NoSimpleISel)
75     PM.add(createX86SimpleInstructionSelector(*this));
76   else if (NoPatternISel)
77     PM.add(createX86ReallySimpleInstructionSelector(*this));
78   else
79     PM.add(createX86PatternInstructionSelector(*this));
80
81   // Run optional SSA-based machine code optimizations next...
82   if (!NoSSAPeephole)
83     PM.add(createX86SSAPeepholeOptimizerPass());
84
85   // Print the instruction selected machine code...
86   if (PrintMachineCode)
87     PM.add(createMachineFunctionPrinterPass(&std::cerr));
88
89   // Perform register allocation to convert to a concrete x86 representation
90   PM.add(createRegisterAllocator());
91
92   if (PrintMachineCode)
93     PM.add(createMachineFunctionPrinterPass(&std::cerr));
94
95   PM.add(createX86FloatingPointStackifierPass());
96
97   if (PrintMachineCode)
98     PM.add(createMachineFunctionPrinterPass(&std::cerr));
99
100   // Insert prolog/epilog code.  Eliminate abstract frame index references...
101   PM.add(createPrologEpilogCodeInserter());
102
103   PM.add(createX86PeepholeOptimizerPass());
104
105   if (PrintMachineCode)  // Print the register-allocated code
106     PM.add(createX86CodePrinterPass(std::cerr, *this));
107
108   if (!DisableOutput)
109     PM.add(createX86CodePrinterPass(Out, *this));
110
111   // Delete machine code for this function
112   PM.add(createMachineCodeDeleter());
113
114   return false; // success!
115 }
116
117 /// addPassesToJITCompile - Add passes to the specified pass manager to
118 /// implement a fast dynamic compiler for this target.  Return true if this is
119 /// not supported for this target.
120 ///
121 void X86JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
122   // FIXME: Implement efficient support for garbage collection intrinsics.
123   PM.add(createLowerGCPass());
124
125   // FIXME: Implement the invoke/unwind instructions!
126   PM.add(createLowerInvokePass());
127
128   // FIXME: Implement the switch instruction in the instruction selector!
129   PM.add(createLowerSwitchPass());
130
131   // Make sure that no unreachable blocks are instruction selected.
132   PM.add(createUnreachableBlockEliminationPass());
133
134   if (NoPatternISel)
135     PM.add(createX86SimpleInstructionSelector(TM));
136   else
137     PM.add(createX86PatternInstructionSelector(TM));
138
139   // Run optional SSA-based machine code optimizations next...
140   if (!NoSSAPeephole)
141     PM.add(createX86SSAPeepholeOptimizerPass());
142
143   // FIXME: Add SSA based peephole optimizer here.
144
145   // Print the instruction selected machine code...
146   if (PrintMachineCode)
147     PM.add(createMachineFunctionPrinterPass(&std::cerr));
148
149   // Perform register allocation to convert to a concrete x86 representation
150   PM.add(createRegisterAllocator());
151
152   if (PrintMachineCode)
153     PM.add(createMachineFunctionPrinterPass(&std::cerr));
154
155   PM.add(createX86FloatingPointStackifierPass());
156
157   if (PrintMachineCode)
158     PM.add(createMachineFunctionPrinterPass(&std::cerr));
159
160   // Insert prolog/epilog code.  Eliminate abstract frame index references...
161   PM.add(createPrologEpilogCodeInserter());
162
163   PM.add(createX86PeepholeOptimizerPass());
164
165   if (PrintMachineCode)  // Print the register-allocated code
166     PM.add(createX86CodePrinterPass(std::cerr, TM));
167 }
168