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