1 //===-- X86TargetMachine.cpp - Define TargetMachine for the X86 -----------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines the X86 specific subclass of TargetMachine.
12 //===----------------------------------------------------------------------===//
14 #include "X86TargetMachine.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"
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"));
40 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
41 // that implements the X86 backend.
43 TargetMachine *llvm::allocateX86TargetMachine(const Module &M,
44 IntrinsicLowering *IL) {
45 return new X86TargetMachine(M, IL);
49 /// X86TargetMachine ctor - Create an ILP32 architecture model
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),
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,
62 // FIXME: Implement efficient support for garbage collection intrinsics.
63 PM.add(createLowerGCPass());
65 // FIXME: Implement the invoke/unwind instructions!
66 PM.add(createLowerInvokePass());
68 // FIXME: The code generator does not properly handle functions with
69 // unreachable basic blocks.
70 PM.add(createCFGSimplificationPass());
72 // FIXME: Implement the switch instruction in the instruction selector!
73 PM.add(createLowerSwitchPass());
75 if (NoPatternISel && NoSimpleISel)
76 PM.add(createX86SimpleInstructionSelector(*this));
77 else if (NoPatternISel)
78 PM.add(createX86ReallySimpleInstructionSelector(*this));
80 PM.add(createX86PatternInstructionSelector(*this));
82 // Run optional SSA-based machine code optimizations next...
84 PM.add(createX86SSAPeepholeOptimizerPass());
86 // Print the instruction selected machine code...
88 PM.add(createMachineFunctionPrinterPass(&std::cerr));
90 // Perform register allocation to convert to a concrete x86 representation
91 PM.add(createRegisterAllocator());
94 PM.add(createMachineFunctionPrinterPass(&std::cerr));
96 PM.add(createX86FloatingPointStackifierPass());
99 PM.add(createMachineFunctionPrinterPass(&std::cerr));
101 // Insert prolog/epilog code. Eliminate abstract frame index references...
102 PM.add(createPrologEpilogCodeInserter());
104 PM.add(createX86PeepholeOptimizerPass());
106 if (PrintMachineCode) // Print the register-allocated code
107 PM.add(createX86CodePrinterPass(std::cerr, *this));
110 PM.add(createX86CodePrinterPass(Out, *this));
112 // Delete machine code for this function
113 PM.add(createMachineCodeDeleter());
115 return false; // success!
118 /// addPassesToJITCompile - Add passes to the specified pass manager to
119 /// implement a fast dynamic compiler for this target. Return true if this is
120 /// not supported for this target.
122 void X86JITInfo::addPassesToJITCompile(FunctionPassManager &PM) {
123 // FIXME: Implement efficient support for garbage collection intrinsics.
124 PM.add(createLowerGCPass());
126 // FIXME: Implement the invoke/unwind instructions!
127 PM.add(createLowerInvokePass());
129 // FIXME: The code generator does not properly handle functions with
130 // unreachable basic blocks.
131 PM.add(createCFGSimplificationPass());
133 // FIXME: Implement the switch instruction in the instruction selector!
134 PM.add(createLowerSwitchPass());
137 PM.add(createX86SimpleInstructionSelector(TM));
139 PM.add(createX86PatternInstructionSelector(TM));
141 // Run optional SSA-based machine code optimizations next...
143 PM.add(createX86SSAPeepholeOptimizerPass());
145 // FIXME: Add SSA based peephole optimizer here.
147 // Print the instruction selected machine code...
148 if (PrintMachineCode)
149 PM.add(createMachineFunctionPrinterPass(&std::cerr));
151 // Perform register allocation to convert to a concrete x86 representation
152 PM.add(createRegisterAllocator());
154 if (PrintMachineCode)
155 PM.add(createMachineFunctionPrinterPass(&std::cerr));
157 PM.add(createX86FloatingPointStackifierPass());
159 if (PrintMachineCode)
160 PM.add(createMachineFunctionPrinterPass(&std::cerr));
162 // Insert prolog/epilog code. Eliminate abstract frame index references...
163 PM.add(createPrologEpilogCodeInserter());
165 PM.add(createX86PeepholeOptimizerPass());
167 if (PrintMachineCode) // Print the register-allocated code
168 PM.add(createX86CodePrinterPass(std::cerr, TM));