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/Target/TargetMachineImpls.h" 10 #include "llvm/CodeGen/MachineFunction.h" 11 #include "llvm/CodeGen/Passes.h" 12 #include "llvm/PassManager.h" 13 #include "Support/CommandLine.h" 14 #include "Support/Statistic.h" 15 #include <iostream> 16 17 namespace { 18 cl::opt<bool> NoLocalRA("no-local-ra", 19 cl::desc("Use Simple RA instead of Local RegAlloc")); 20 cl::opt<bool> PrintCode("print-machineinstrs", 21 cl::desc("Print generated machine code")); 22 } 23 24 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine 25 // that implements the X86 backend. 26 // 27 TargetMachine *allocateX86TargetMachine(unsigned Configuration) { 28 return new X86TargetMachine(Configuration); 29 } 30 31 32 /// X86TargetMachine ctor - Create an ILP32 architecture model 33 /// 34 X86TargetMachine::X86TargetMachine(unsigned Config) 35 : TargetMachine("X86", 36 (Config & TM::EndianMask) == TM::LittleEndian, 37 1, 4, 38 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4, 39 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4), 40 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) { 41 } 42 43 /// addPassesToJITCompile - Add passes to the specified pass manager to 44 /// implement a fast dynamic compiler for this target. Return true if this is 45 /// not supported for this target. 46 /// 47 bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) { 48 PM.add(createSimpleX86InstructionSelector(*this)); 49 50 // TODO: optional optimizations go here 51 52 // FIXME: Add SSA based peephole optimizer here. 53 54 // Print the instruction selected machine code... 55 if (PrintCode) 56 PM.add(createMachineFunctionPrinterPass()); 57 58 // Perform register allocation to convert to a concrete x86 representation 59 if (NoLocalRA) 60 PM.add(createSimpleRegisterAllocator()); 61 else 62 PM.add(createLocalRegisterAllocator()); 63 64 if (PrintCode) 65 PM.add(createMachineFunctionPrinterPass()); 66 67 PM.add(createX86FloatingPointStackifierPass()); 68 69 if (PrintCode) 70 PM.add(createMachineFunctionPrinterPass()); 71 72 // Insert prolog/epilog code. Eliminate abstract frame index references... 73 PM.add(createPrologEpilogCodeInserter()); 74 75 PM.add(createX86PeepholeOptimizerPass()); 76 77 if (PrintCode) // Print the register-allocated code 78 PM.add(createX86CodePrinterPass(std::cerr)); 79 80 return false; // success! 81 } 82 83