blob: 6a88390963c714fdd02727ecbd5b25238de5ead9 [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 Lattner75405652003-08-17 23:20:40 +000042 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
43 4, (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4),
Chris Lattnerf158da22003-01-16 02:20:12 +000044 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000045}
46
Chris Lattnerc9bbfbc2003-08-05 16:34:44 +000047
48// addPassesToEmitAssembly - We currently use all of the same passes as the JIT
49// does to emit statically compiled machine code.
Brian Gaekede3aa4f2003-06-18 21:43:21 +000050bool X86TargetMachine::addPassesToEmitAssembly(PassManager &PM,
51 std::ostream &Out) {
Brian Gaekeb4286542003-08-13 18:15:52 +000052 // FIXME: Implement the switch instruction in the instruction selector!
53 PM.add(createLowerSwitchPass());
54
55 if (NoPatternISel)
56 PM.add(createX86SimpleInstructionSelector(*this));
57 else
58 PM.add(createX86PatternInstructionSelector(*this));
59
60 // TODO: optional optimizations go here
61
62 // FIXME: Add SSA based peephole optimizer here.
63
64 // Print the instruction selected machine code...
65 if (PrintCode)
66 PM.add(createMachineFunctionPrinterPass());
67
68 // Perform register allocation to convert to a concrete x86 representation
69 if (NoLocalRA)
70 PM.add(createSimpleRegisterAllocator());
71 else
72 PM.add(createLocalRegisterAllocator());
73
74 if (PrintCode)
75 PM.add(createMachineFunctionPrinterPass());
76
77 PM.add(createX86FloatingPointStackifierPass());
78
79 if (PrintCode)
80 PM.add(createMachineFunctionPrinterPass());
81
82 // Insert prolog/epilog code. Eliminate abstract frame index references...
83 PM.add(createPrologEpilogCodeInserter());
84
85 PM.add(createX86PeepholeOptimizerPass());
86
87 if (PrintCode) // Print the register-allocated code
88 PM.add(createX86CodePrinterPass(std::cerr, *this));
89
Brian Gaekede420ae2003-07-23 20:25:08 +000090 PM.add(createX86CodePrinterPass(Out, *this));
Brian Gaekede3aa4f2003-06-18 21:43:21 +000091 return false; // success!
92}
93
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000094/// addPassesToJITCompile - Add passes to the specified pass manager to
95/// implement a fast dynamic compiler for this target. Return true if this is
96/// not supported for this target.
97///
Brian Gaekeb4286542003-08-13 18:15:52 +000098bool X86TargetMachine::addPassesToJITCompile(FunctionPassManager &PM) {
Chris Lattner155e68f2003-04-23 16:24:55 +000099 // FIXME: Implement the switch instruction in the instruction selector!
100 PM.add(createLowerSwitchPass());
101
Chris Lattnerac0c8682003-08-11 14:59:22 +0000102 if (NoPatternISel)
103 PM.add(createX86SimpleInstructionSelector(*this));
104 else
105 PM.add(createX86PatternInstructionSelector(*this));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +0000106
107 // TODO: optional optimizations go here
108
Chris Lattnerd91d86f2003-01-13 00:51:23 +0000109 // FIXME: Add SSA based peephole optimizer here.
110
Chris Lattner3dffa792002-10-30 00:47:49 +0000111 // Print the instruction selected machine code...
Chris Lattner5bcd95c2002-12-24 00:04:01 +0000112 if (PrintCode)
113 PM.add(createMachineFunctionPrinterPass());
Chris Lattner3dffa792002-10-30 00:47:49 +0000114
Chris Lattnerb4f68ed2002-10-29 22:37:54 +0000115 // Perform register allocation to convert to a concrete x86 representation
Chris Lattner14322cd32002-12-17 02:51:15 +0000116 if (NoLocalRA)
Chris Lattnerd282cfe2002-12-28 20:33:32 +0000117 PM.add(createSimpleRegisterAllocator());
Chris Lattner14322cd32002-12-17 02:51:15 +0000118 else
Chris Lattnerd282cfe2002-12-28 20:33:32 +0000119 PM.add(createLocalRegisterAllocator());
120
121 if (PrintCode)
122 PM.add(createMachineFunctionPrinterPass());
123
Chris Lattnerd91d86f2003-01-13 00:51:23 +0000124 PM.add(createX86FloatingPointStackifierPass());
125
126 if (PrintCode)
127 PM.add(createMachineFunctionPrinterPass());
128
Chris Lattnerd282cfe2002-12-28 20:33:32 +0000129 // Insert prolog/epilog code. Eliminate abstract frame index references...
130 PM.add(createPrologEpilogCodeInserter());
Chris Lattnerb4f68ed2002-10-29 22:37:54 +0000131
Chris Lattnerd91d86f2003-01-13 00:51:23 +0000132 PM.add(createX86PeepholeOptimizerPass());
133
Chris Lattner430cda72002-12-25 05:06:21 +0000134 if (PrintCode) // Print the register-allocated code
Brian Gaekede420ae2003-07-23 20:25:08 +0000135 PM.add(createX86CodePrinterPass(std::cerr, *this));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +0000136 return false; // success!
137}
138