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/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"
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"));
25 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
26 // that implements the X86 backend.
28 TargetMachine *allocateX86TargetMachine(unsigned Configuration) {
29 return new X86TargetMachine(Configuration);
33 /// X86TargetMachine ctor - Create an ILP32 architecture model
35 X86TargetMachine::X86TargetMachine(unsigned Config)
36 : TargetMachine("X86",
37 (Config & TM::EndianMask) == TM::LittleEndian,
39 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
40 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
41 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4),
42 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
45 /// addPassesToJITCompile - Add passes to the specified pass manager to
46 /// implement a fast dynamic compiler for this target. Return true if this is
47 /// not supported for this target.
49 bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) {
50 // FIXME: Implement the switch instruction in the instruction selector!
51 PM.add(createLowerSwitchPass());
53 PM.add(createSimpleX86InstructionSelector(*this));
55 // TODO: optional optimizations go here
57 // FIXME: Add SSA based peephole optimizer here.
59 // Print the instruction selected machine code...
61 PM.add(createMachineFunctionPrinterPass());
63 // Perform register allocation to convert to a concrete x86 representation
65 PM.add(createSimpleRegisterAllocator());
67 PM.add(createLocalRegisterAllocator());
70 PM.add(createMachineFunctionPrinterPass());
72 PM.add(createX86FloatingPointStackifierPass());
75 PM.add(createMachineFunctionPrinterPass());
77 // Insert prolog/epilog code. Eliminate abstract frame index references...
78 PM.add(createPrologEpilogCodeInserter());
80 PM.add(createX86PeepholeOptimizerPass());
82 if (PrintCode) // Print the register-allocated code
83 PM.add(createX86CodePrinterPass(std::cerr));
85 return false; // success!