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 "X86TargetAsmInfo.h"
15 #include "X86TargetMachine.h"
17 #include "llvm/Module.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/Target/TargetOptions.h"
22 #include "llvm/Target/TargetMachineRegistry.h"
23 #include "llvm/Transforms/Scalar.h"
27 /// X86TargetMachineModule - Note that this is used on hosts that cannot link
28 /// in a library unless there are references into the library. In particular,
29 /// it seems that it is not possible to get things to work on Win32 without
30 /// this. Though it is unused, do not remove it.
31 extern "C" int X86TargetMachineModule;
32 int X86TargetMachineModule = 0;
35 // Register the target.
36 RegisterTarget<X86TargetMachine> X("x86", " IA-32 (Pentium and above)");
39 const TargetAsmInfo *X86TargetMachine::createTargetAsmInfo() const {
40 return new X86TargetAsmInfo(*this);
43 unsigned X86TargetMachine::getJITMatchQuality() {
44 #if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
51 unsigned X86TargetMachine::getModuleMatchQuality(const Module &M) {
52 // We strongly match "i[3-9]86-*".
53 std::string TT = M.getTargetTriple();
54 if (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
55 TT[4] == '-' && TT[1] - '3' < 6)
58 if (M.getEndianness() == Module::LittleEndian &&
59 M.getPointerSize() == Module::Pointer32)
60 return 10; // Weak match
61 else if (M.getEndianness() != Module::AnyEndianness ||
62 M.getPointerSize() != Module::AnyPointerSize)
63 return 0; // Match for some other target
65 return getJITMatchQuality()/2;
68 /// X86TargetMachine ctor - Create an ILP32 architecture model
70 X86TargetMachine::X86TargetMachine(const Module &M, const std::string &FS)
71 : Subtarget(M, FS), DataLayout("e-p:32:32-d:32-l:32"),
72 FrameInfo(TargetFrameInfo::StackGrowsDown,
73 Subtarget.getStackAlignment(), -4),
74 InstrInfo(*this), JITInfo(*this), TLInfo(*this) {
75 if (getRelocationModel() == Reloc::Default)
76 if (Subtarget.isTargetDarwin())
77 setRelocationModel(Reloc::DynamicNoPIC);
79 setRelocationModel(Reloc::PIC_);
82 //===----------------------------------------------------------------------===//
83 // Pass Pipeline Configuration
84 //===----------------------------------------------------------------------===//
86 bool X86TargetMachine::addInstSelector(FunctionPassManager &PM, bool Fast) {
87 // Install an instruction selector.
88 PM.add(createX86ISelDag(*this, Fast));
92 bool X86TargetMachine::addPostRegAlloc(FunctionPassManager &PM, bool Fast) {
93 PM.add(createX86FloatingPointStackifierPass());
94 return true; // -print-machineinstr should print after this.
97 bool X86TargetMachine::addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
99 PM.add(createX86CodePrinterPass(Out, *this));
103 bool X86TargetMachine::addObjectWriter(FunctionPassManager &PM, bool Fast,
105 if (Subtarget.isTargetELF()) {
106 addX86ELFObjectWriterPass(PM, Out, *this);
112 bool X86TargetMachine::addCodeEmitter(FunctionPassManager &PM, bool Fast,
113 MachineCodeEmitter &MCE) {
114 // FIXME: Move this to TargetJITInfo!
115 setRelocationModel(Reloc::Static);
117 PM.add(createX86CodeEmitterPass(*this, MCE));