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"
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"));
27 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
28 // that implements the X86 backend.
30 TargetMachine *allocateX86TargetMachine(const Module &M) {
31 return new X86TargetMachine(M);
35 /// X86TargetMachine ctor - Create an ILP32 architecture model
37 X86TargetMachine::X86TargetMachine(const Module &M)
38 : TargetMachine("X86",
39 M.getEndianness() != Module::BigEndian,
40 M.getPointerSize() != Module::Pointer64 ? 4 : 8,
41 M.getPointerSize() != Module::Pointer64 ? 4 : 8,
42 M.getPointerSize() != Module::Pointer64 ? 4 : 8,
43 4, M.getPointerSize() != Module::Pointer64 ? 4 : 8),
44 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
48 // addPassesToEmitAssembly - We currently use all of the same passes as the JIT
49 // does to emit statically compiled machine code.
50 bool X86TargetMachine::addPassesToEmitAssembly(PassManager &PM,
52 // FIXME: Implement the switch instruction in the instruction selector!
53 PM.add(createLowerSwitchPass());
56 PM.add(createX86SimpleInstructionSelector(*this));
58 PM.add(createX86PatternInstructionSelector(*this));
60 // TODO: optional optimizations go here
62 // FIXME: Add SSA based peephole optimizer here.
64 // Print the instruction selected machine code...
66 PM.add(createMachineFunctionPrinterPass());
68 // Perform register allocation to convert to a concrete x86 representation
70 PM.add(createSimpleRegisterAllocator());
72 PM.add(createLocalRegisterAllocator());
75 PM.add(createMachineFunctionPrinterPass());
77 PM.add(createX86FloatingPointStackifierPass());
80 PM.add(createMachineFunctionPrinterPass());
82 // Insert prolog/epilog code. Eliminate abstract frame index references...
83 PM.add(createPrologEpilogCodeInserter());
85 PM.add(createX86PeepholeOptimizerPass());
87 if (PrintCode) // Print the register-allocated code
88 PM.add(createX86CodePrinterPass(std::cerr, *this));
90 PM.add(createX86CodePrinterPass(Out, *this));
91 return false; // success!
94 /// addPassesToJITCompile - Add passes to the specified pass manager to
95 /// implement a fast dynamic compiler for this target. Return true if this is
96 /// not supported for this target.
98 bool X86TargetMachine::addPassesToJITCompile(FunctionPassManager &PM) {
99 // FIXME: Implement the switch instruction in the instruction selector!
100 PM.add(createLowerSwitchPass());
103 PM.add(createX86SimpleInstructionSelector(*this));
105 PM.add(createX86PatternInstructionSelector(*this));
107 // TODO: optional optimizations go here
109 // FIXME: Add SSA based peephole optimizer here.
111 // Print the instruction selected machine code...
113 PM.add(createMachineFunctionPrinterPass());
115 // Perform register allocation to convert to a concrete x86 representation
117 PM.add(createSimpleRegisterAllocator());
119 PM.add(createLocalRegisterAllocator());
122 PM.add(createMachineFunctionPrinterPass());
124 PM.add(createX86FloatingPointStackifierPass());
127 PM.add(createMachineFunctionPrinterPass());
129 // Insert prolog/epilog code. Eliminate abstract frame index references...
130 PM.add(createPrologEpilogCodeInserter());
132 PM.add(createX86PeepholeOptimizerPass());
134 if (PrintCode) // Print the register-allocated code
135 PM.add(createX86CodePrinterPass(std::cerr, *this));
136 return false; // success!