1 //===-- X86TargetMachine.cpp - Define TargetMachine for the X86 -----------===//
3 // This file defines the X86 specific subclass of TargetMachine.
5 //===----------------------------------------------------------------------===//
7 #include "X86TargetMachine.h"
9 #include "llvm/Module.h"
10 #include "llvm/PassManager.h"
11 #include "llvm/Target/TargetMachineImpls.h"
12 #include "llvm/CodeGen/MachineFunction.h"
13 #include "llvm/CodeGen/Passes.h"
14 #include "llvm/Transforms/Scalar.h"
15 #include "Support/CommandLine.h"
16 #include "Support/Statistic.h"
21 cl::desc("Register allocator to use:"), cl::Prefix,
22 cl::values(clEnumVal(simple, "simple register allocator)"),
23 clEnumVal(local, "local register allocator"),
24 clEnumVal(linearscan, "linear scan global register allocator")),
27 cl::opt<bool> NoLocalRA("disable-local-ra",
28 cl::desc("Use Simple RA instead of Local RegAlloc"));
29 cl::opt<bool> PrintCode("print-machineinstrs",
30 cl::desc("Print generated machine code"));
31 cl::opt<bool> NoPatternISel("disable-pattern-isel", cl::init(true),
32 cl::desc("Use the 'simple' X86 instruction selector"));
35 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
36 // that implements the X86 backend.
38 TargetMachine *allocateX86TargetMachine(const Module &M) {
39 return new X86TargetMachine(M);
43 /// X86TargetMachine ctor - Create an ILP32 architecture model
45 X86TargetMachine::X86TargetMachine(const Module &M)
46 : TargetMachine("X86",
47 M.getEndianness() != Module::BigEndian,
48 M.getPointerSize() != Module::Pointer64 ? 4 : 8,
49 M.getPointerSize() != Module::Pointer64 ? 4 : 8,
50 M.getPointerSize() != Module::Pointer64 ? 4 : 8,
51 4, M.getPointerSize() != Module::Pointer64 ? 4 : 8),
52 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
56 // addPassesToEmitAssembly - We currently use all of the same passes as the JIT
57 // does to emit statically compiled machine code.
58 bool X86TargetMachine::addPassesToEmitAssembly(PassManager &PM,
60 // FIXME: Implement the switch instruction in the instruction selector!
61 PM.add(createLowerSwitchPass());
64 PM.add(createX86SimpleInstructionSelector(*this));
66 PM.add(createX86PatternInstructionSelector(*this));
68 // TODO: optional optimizations go here
70 // FIXME: Add SSA based peephole optimizer here.
72 // Print the instruction selected machine code...
74 PM.add(createMachineFunctionPrinterPass());
76 // Perform register allocation to convert to a concrete x86 representation
78 PM.add(createSimpleRegisterAllocator());
80 PM.add(createLocalRegisterAllocator());
83 PM.add(createMachineFunctionPrinterPass());
85 PM.add(createX86FloatingPointStackifierPass());
88 PM.add(createMachineFunctionPrinterPass());
90 // Insert prolog/epilog code. Eliminate abstract frame index references...
91 PM.add(createPrologEpilogCodeInserter());
93 PM.add(createX86PeepholeOptimizerPass());
95 if (PrintCode) // Print the register-allocated code
96 PM.add(createX86CodePrinterPass(std::cerr, *this));
98 PM.add(createX86CodePrinterPass(Out, *this));
99 return false; // success!
102 /// addPassesToJITCompile - Add passes to the specified pass manager to
103 /// implement a fast dynamic compiler for this target. Return true if this is
104 /// not supported for this target.
106 bool X86TargetMachine::addPassesToJITCompile(FunctionPassManager &PM) {
107 // FIXME: Implement the switch instruction in the instruction selector!
108 PM.add(createLowerSwitchPass());
111 PM.add(createX86SimpleInstructionSelector(*this));
113 PM.add(createX86PatternInstructionSelector(*this));
115 // TODO: optional optimizations go here
117 // FIXME: Add SSA based peephole optimizer here.
119 // Print the instruction selected machine code...
121 PM.add(createMachineFunctionPrinterPass());
123 // Perform register allocation to convert to a concrete x86 representation
126 PM.add(createSimpleRegisterAllocator());
129 PM.add(createLocalRegisterAllocator());
132 PM.add(createLinearScanRegisterAllocator());
135 assert(0 && "no register allocator selected");
139 PM.add(createMachineFunctionPrinterPass());
141 PM.add(createX86FloatingPointStackifierPass());
144 PM.add(createMachineFunctionPrinterPass());
146 // Insert prolog/epilog code. Eliminate abstract frame index references...
147 PM.add(createPrologEpilogCodeInserter());
149 PM.add(createX86PeepholeOptimizerPass());
151 if (PrintCode) // Print the register-allocated code
152 PM.add(createX86CodePrinterPass(std::cerr, *this));
153 return false; // success!