blob: e3cc88078cfe63204fc4257b3dbf946b710e4256 [file] [log] [blame]
Chris Lattnerb4f68ed2002-10-29 22:37:54 +00001//===-- 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"
Chris Lattner5bcd95c2002-12-24 00:04:01 +00008#include "X86.h"
Chris Lattner155e68f2003-04-23 16:24:55 +00009#include "llvm/PassManager.h"
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000010#include "llvm/Target/TargetMachineImpls.h"
Chris Lattner3dffa792002-10-30 00:47:49 +000011#include "llvm/CodeGen/MachineFunction.h"
Chris Lattnerd91d86f2003-01-13 00:51:23 +000012#include "llvm/CodeGen/Passes.h"
Chris Lattner155e68f2003-04-23 16:24:55 +000013#include "llvm/Transforms/Scalar.h"
Chris Lattner439a27a2002-12-16 16:15:51 +000014#include "Support/CommandLine.h"
15#include "Support/Statistic.h"
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000016#include <iostream>
17
Chris Lattner439a27a2002-12-16 16:15:51 +000018namespace {
Chris Lattnerddd5b412003-02-26 20:00:41 +000019 cl::opt<bool> NoLocalRA("disable-local-ra",
Chris Lattner14322cd32002-12-17 02:51:15 +000020 cl::desc("Use Simple RA instead of Local RegAlloc"));
Chris Lattner5bcd95c2002-12-24 00:04:01 +000021 cl::opt<bool> PrintCode("print-machineinstrs",
22 cl::desc("Print generated machine code"));
Chris Lattnerac0c8682003-08-11 14:59:22 +000023 cl::opt<bool> NoPatternISel("disable-pattern-isel", cl::init(true),
24 cl::desc("Use the 'simple' X86 instruction selector"));
Chris Lattner439a27a2002-12-16 16:15:51 +000025}
26
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000027// allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
28// that implements the X86 backend.
29//
Chris Lattner5bcd95c2002-12-24 00:04:01 +000030TargetMachine *allocateX86TargetMachine(unsigned Configuration) {
31 return new X86TargetMachine(Configuration);
32}
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000033
34
35/// X86TargetMachine ctor - Create an ILP32 architecture model
36///
Chris Lattner5bcd95c2002-12-24 00:04:01 +000037X86TargetMachine::X86TargetMachine(unsigned Config)
38 : TargetMachine("X86",
39 (Config & TM::EndianMask) == TM::LittleEndian,
Chris Lattner5bcd95c2002-12-24 00:04:01 +000040 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
Chris Lattner98938f82003-04-25 06:05:57 +000041 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
Chris Lattnerd282cfe2002-12-28 20:33:32 +000042 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4),
Chris Lattnerf158da22003-01-16 02:20:12 +000043 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000044}
45
Chris Lattnerc9bbfbc2003-08-05 16:34:44 +000046
47// addPassesToEmitAssembly - We currently use all of the same passes as the JIT
48// does to emit statically compiled machine code.
Brian Gaekede3aa4f2003-06-18 21:43:21 +000049bool X86TargetMachine::addPassesToEmitAssembly(PassManager &PM,
50 std::ostream &Out) {
Brian Gaekeb4286542003-08-13 18:15:52 +000051 // FIXME: Implement the switch instruction in the instruction selector!
52 PM.add(createLowerSwitchPass());
53
54 if (NoPatternISel)
55 PM.add(createX86SimpleInstructionSelector(*this));
56 else
57 PM.add(createX86PatternInstructionSelector(*this));
58
59 // TODO: optional optimizations go here
60
61 // FIXME: Add SSA based peephole optimizer here.
62
63 // Print the instruction selected machine code...
64 if (PrintCode)
65 PM.add(createMachineFunctionPrinterPass());
66
67 // Perform register allocation to convert to a concrete x86 representation
68 if (NoLocalRA)
69 PM.add(createSimpleRegisterAllocator());
70 else
71 PM.add(createLocalRegisterAllocator());
72
73 if (PrintCode)
74 PM.add(createMachineFunctionPrinterPass());
75
76 PM.add(createX86FloatingPointStackifierPass());
77
78 if (PrintCode)
79 PM.add(createMachineFunctionPrinterPass());
80
81 // Insert prolog/epilog code. Eliminate abstract frame index references...
82 PM.add(createPrologEpilogCodeInserter());
83
84 PM.add(createX86PeepholeOptimizerPass());
85
86 if (PrintCode) // Print the register-allocated code
87 PM.add(createX86CodePrinterPass(std::cerr, *this));
88
Brian Gaekede420ae2003-07-23 20:25:08 +000089 PM.add(createX86CodePrinterPass(Out, *this));
Brian Gaekede3aa4f2003-06-18 21:43:21 +000090 return false; // success!
91}
92
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000093/// addPassesToJITCompile - Add passes to the specified pass manager to
94/// implement a fast dynamic compiler for this target. Return true if this is
95/// not supported for this target.
96///
Brian Gaekeb4286542003-08-13 18:15:52 +000097bool X86TargetMachine::addPassesToJITCompile(FunctionPassManager &PM) {
Chris Lattner155e68f2003-04-23 16:24:55 +000098 // FIXME: Implement the switch instruction in the instruction selector!
99 PM.add(createLowerSwitchPass());
100
Chris Lattnerac0c8682003-08-11 14:59:22 +0000101 if (NoPatternISel)
102 PM.add(createX86SimpleInstructionSelector(*this));
103 else
104 PM.add(createX86PatternInstructionSelector(*this));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +0000105
106 // TODO: optional optimizations go here
107
Chris Lattnerd91d86f2003-01-13 00:51:23 +0000108 // FIXME: Add SSA based peephole optimizer here.
109
Chris Lattner3dffa792002-10-30 00:47:49 +0000110 // Print the instruction selected machine code...
Chris Lattner5bcd95c2002-12-24 00:04:01 +0000111 if (PrintCode)
112 PM.add(createMachineFunctionPrinterPass());
Chris Lattner3dffa792002-10-30 00:47:49 +0000113
Chris Lattnerb4f68ed2002-10-29 22:37:54 +0000114 // Perform register allocation to convert to a concrete x86 representation
Chris Lattner14322cd32002-12-17 02:51:15 +0000115 if (NoLocalRA)
Chris Lattnerd282cfe2002-12-28 20:33:32 +0000116 PM.add(createSimpleRegisterAllocator());
Chris Lattner14322cd32002-12-17 02:51:15 +0000117 else
Chris Lattnerd282cfe2002-12-28 20:33:32 +0000118 PM.add(createLocalRegisterAllocator());
119
120 if (PrintCode)
121 PM.add(createMachineFunctionPrinterPass());
122
Chris Lattnerd91d86f2003-01-13 00:51:23 +0000123 PM.add(createX86FloatingPointStackifierPass());
124
125 if (PrintCode)
126 PM.add(createMachineFunctionPrinterPass());
127
Chris Lattnerd282cfe2002-12-28 20:33:32 +0000128 // Insert prolog/epilog code. Eliminate abstract frame index references...
129 PM.add(createPrologEpilogCodeInserter());
Chris Lattnerb4f68ed2002-10-29 22:37:54 +0000130
Chris Lattnerd91d86f2003-01-13 00:51:23 +0000131 PM.add(createX86PeepholeOptimizerPass());
132
Chris Lattner430cda72002-12-25 05:06:21 +0000133 if (PrintCode) // Print the register-allocated code
Brian Gaekede420ae2003-07-23 20:25:08 +0000134 PM.add(createX86CodePrinterPass(std::cerr, *this));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +0000135 return false; // success!
136}
137