blob: be0102f93387cb327d71f26258c475b08ad91a9f [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 Lattner439a27a2002-12-16 16:15:51 +000023}
24
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000025// allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
26// that implements the X86 backend.
27//
Chris Lattner5bcd95c2002-12-24 00:04:01 +000028TargetMachine *allocateX86TargetMachine(unsigned Configuration) {
29 return new X86TargetMachine(Configuration);
30}
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000031
32
33/// X86TargetMachine ctor - Create an ILP32 architecture model
34///
Chris Lattner5bcd95c2002-12-24 00:04:01 +000035X86TargetMachine::X86TargetMachine(unsigned Config)
36 : TargetMachine("X86",
37 (Config & TM::EndianMask) == TM::LittleEndian,
38 1, 4,
39 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
Chris Lattner98938f82003-04-25 06:05:57 +000040 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
Chris Lattnerd282cfe2002-12-28 20:33:32 +000041 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4),
Chris Lattnerf158da22003-01-16 02:20:12 +000042 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000043}
44
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000045/// addPassesToJITCompile - Add passes to the specified pass manager to
46/// implement a fast dynamic compiler for this target. Return true if this is
47/// not supported for this target.
48///
49bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) {
Chris Lattner155e68f2003-04-23 16:24:55 +000050 // FIXME: Implement the switch instruction in the instruction selector!
51 PM.add(createLowerSwitchPass());
52
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000053 PM.add(createSimpleX86InstructionSelector(*this));
54
55 // TODO: optional optimizations go here
56
Chris Lattnerd91d86f2003-01-13 00:51:23 +000057 // FIXME: Add SSA based peephole optimizer here.
58
Chris Lattner3dffa792002-10-30 00:47:49 +000059 // Print the instruction selected machine code...
Chris Lattner5bcd95c2002-12-24 00:04:01 +000060 if (PrintCode)
61 PM.add(createMachineFunctionPrinterPass());
Chris Lattner3dffa792002-10-30 00:47:49 +000062
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000063 // Perform register allocation to convert to a concrete x86 representation
Chris Lattner14322cd32002-12-17 02:51:15 +000064 if (NoLocalRA)
Chris Lattnerd282cfe2002-12-28 20:33:32 +000065 PM.add(createSimpleRegisterAllocator());
Chris Lattner14322cd32002-12-17 02:51:15 +000066 else
Chris Lattnerd282cfe2002-12-28 20:33:32 +000067 PM.add(createLocalRegisterAllocator());
68
69 if (PrintCode)
70 PM.add(createMachineFunctionPrinterPass());
71
Chris Lattnerd91d86f2003-01-13 00:51:23 +000072 PM.add(createX86FloatingPointStackifierPass());
73
74 if (PrintCode)
75 PM.add(createMachineFunctionPrinterPass());
76
Chris Lattnerd282cfe2002-12-28 20:33:32 +000077 // Insert prolog/epilog code. Eliminate abstract frame index references...
78 PM.add(createPrologEpilogCodeInserter());
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000079
Chris Lattnerd91d86f2003-01-13 00:51:23 +000080 PM.add(createX86PeepholeOptimizerPass());
81
Chris Lattner430cda72002-12-25 05:06:21 +000082 if (PrintCode) // Print the register-allocated code
Chris Lattnerd282cfe2002-12-28 20:33:32 +000083 PM.add(createX86CodePrinterPass(std::cerr));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000084
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000085 return false; // success!
86}
87