7075a3324a0c8296680032a5ba6089befcc008b0
[oota-llvm.git] / lib / Target / X86 / X86TargetMachine.cpp
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/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"
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, 1/*16*/, 0) {
41 }
42
43
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.
47 ///
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());
53
54   PM.add(createSimpleX86InstructionSelector(*this));
55
56   // TODO: optional optimizations go here
57
58   // Print the instruction selected machine code...
59   if (PrintCode)
60     PM.add(createMachineFunctionPrinterPass());
61
62   // Perform register allocation to convert to a concrete x86 representation
63   if (NoLocalRA)
64     PM.add(createSimpleRegisterAllocator());
65   else
66     PM.add(createLocalRegisterAllocator());
67
68   if (PrintCode)
69     PM.add(createMachineFunctionPrinterPass());
70
71   // Insert prolog/epilog code.  Eliminate abstract frame index references...
72   PM.add(createPrologEpilogCodeInserter());
73
74   if (PrintCode)  // Print the register-allocated code
75     PM.add(createX86CodePrinterPass(std::cerr));
76
77   PM.add(createMachineCodeDestructionPass());
78
79   return false; // success!
80 }
81