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