Factory methods for FunctionPasses now return type FunctionPass *.
[oota-llvm.git] / lib / Target / X86 / X86TargetMachine.cpp
1 //===-- X86TargetMachine.cpp - Define TargetMachine for the X86 -----------===//
2 // 
3 // This file defines the X86 specific subclass of TargetMachine.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #include "X86TargetMachine.h"
8 #include "X86.h"
9 #include "llvm/PassManager.h"
10 #include "llvm/Target/TargetMachineImpls.h"
11 #include "llvm/CodeGen/MachineFunction.h"
12 #include "llvm/CodeGen/Passes.h"
13 #include "llvm/Transforms/Scalar.h"
14 #include "Support/CommandLine.h"
15 #include "Support/Statistic.h"
16 #include <iostream>
17
18 namespace {
19   cl::opt<bool> NoLocalRA("disable-local-ra",
20                           cl::desc("Use Simple RA instead of Local RegAlloc"));
21   cl::opt<bool> PrintCode("print-machineinstrs",
22                           cl::desc("Print generated machine code"));
23   cl::opt<bool> NoPatternISel("disable-pattern-isel", cl::init(true),
24                         cl::desc("Use the 'simple' X86 instruction selector"));
25 }
26
27 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
28 // that implements the X86 backend.
29 //
30 TargetMachine *allocateX86TargetMachine(unsigned Configuration) {
31   return new X86TargetMachine(Configuration);
32 }
33
34
35 /// X86TargetMachine ctor - Create an ILP32 architecture model
36 ///
37 X86TargetMachine::X86TargetMachine(unsigned Config)
38   : TargetMachine("X86", 
39                   (Config & TM::EndianMask) == TM::LittleEndian,
40                   (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
41                   (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
42                   (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4),
43   FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
44 }
45
46
47 // addPassesToEmitAssembly - We currently use all of the same passes as the JIT
48 // does to emit statically compiled machine code.
49 bool X86TargetMachine::addPassesToEmitAssembly(PassManager &PM,
50                                                std::ostream &Out) {
51   addPassesToJITCompile(PM);
52   PM.add(createX86CodePrinterPass(Out, *this));
53   return false; // success!
54 }
55
56 /// addPassesToJITCompile - Add passes to the specified pass manager to
57 /// implement a fast dynamic compiler for this target.  Return true if this is
58 /// not supported for this target.
59 ///
60 bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) {
61   // FIXME: Implement the switch instruction in the instruction selector!
62   PM.add(createLowerSwitchPass());
63
64   if (NoPatternISel)
65     PM.add(createX86SimpleInstructionSelector(*this));
66   else
67     PM.add(createX86PatternInstructionSelector(*this));
68
69   // TODO: optional optimizations go here
70
71   // FIXME: Add SSA based peephole optimizer here.
72
73   // Print the instruction selected machine code...
74   if (PrintCode)
75     PM.add(createMachineFunctionPrinterPass());
76
77   // Perform register allocation to convert to a concrete x86 representation
78   if (NoLocalRA)
79     PM.add(createSimpleRegisterAllocator());
80   else
81     PM.add(createLocalRegisterAllocator());
82
83   if (PrintCode)
84     PM.add(createMachineFunctionPrinterPass());
85
86   PM.add(createX86FloatingPointStackifierPass());
87
88   if (PrintCode)
89     PM.add(createMachineFunctionPrinterPass());
90
91   // Insert prolog/epilog code.  Eliminate abstract frame index references...
92   PM.add(createPrologEpilogCodeInserter());
93
94   PM.add(createX86PeepholeOptimizerPass());
95
96   if (PrintCode)  // Print the register-allocated code
97     PM.add(createX86CodePrinterPass(std::cerr, *this));
98   return false; // success!
99 }
100