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/Transforms/Scalar.h"
10 #include "llvm/Target/TargetMachineImpls.h"
11 #include "llvm/CodeGen/MachineFunction.h"
12 #include "llvm/PassManager.h"
13 #include "Support/CommandLine.h"
14 #include "Support/Statistic.h"
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"));
24 // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
25 // that implements the X86 backend.
27 TargetMachine *allocateX86TargetMachine(unsigned Configuration) {
28 return new X86TargetMachine(Configuration);
32 /// X86TargetMachine ctor - Create an ILP32 architecture model
34 X86TargetMachine::X86TargetMachine(unsigned Config)
35 : TargetMachine("X86",
36 (Config & TM::EndianMask) == TM::LittleEndian,
38 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
39 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4),
40 FrameInfo(TargetFrameInfo::StackGrowsDown, 1/*16*/, 0) {
44 /// addPassesToJITCompile - Add passes to the specified pass manager to
45 /// implement a fast dynamic compiler for this target. Return true if this is
46 /// not supported for this target.
48 bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) {
49 // For the moment we have decided that malloc and free will be
50 // taken care of by converting them to calls, using the existing
51 // LLVM scalar transforms pass to do this.
52 PM.add(createLowerAllocationsPass());
54 PM.add(createSimpleX86InstructionSelector(*this));
56 // TODO: optional optimizations go here
58 // Print the instruction selected machine code...
60 PM.add(createMachineFunctionPrinterPass());
62 // Perform register allocation to convert to a concrete x86 representation
64 PM.add(createSimpleRegisterAllocator());
66 PM.add(createLocalRegisterAllocator());
69 PM.add(createMachineFunctionPrinterPass());
71 // Insert prolog/epilog code. Eliminate abstract frame index references...
72 PM.add(createPrologEpilogCodeInserter());
74 if (PrintCode) // Print the register-allocated code
75 PM.add(createX86CodePrinterPass(std::cerr));
77 PM.add(createMachineCodeDestructionPass());
79 return false; // success!