blob: d5a628cb67085958998b75ca7582bd4843a5a090 [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,
Chris Lattner5bcd95c2002-12-24 00:04:01 +000038 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
Chris Lattner98938f82003-04-25 06:05:57 +000039 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
Chris Lattnerd282cfe2002-12-28 20:33:32 +000040 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4),
Chris Lattnerf158da22003-01-16 02:20:12 +000041 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000042}
43
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000044/// addPassesToJITCompile - Add passes to the specified pass manager to
45/// implement a fast dynamic compiler for this target. Return true if this is
46/// not supported for this target.
47///
48bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) {
Chris Lattner155e68f2003-04-23 16:24:55 +000049 // FIXME: Implement the switch instruction in the instruction selector!
50 PM.add(createLowerSwitchPass());
51
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000052 PM.add(createSimpleX86InstructionSelector(*this));
53
54 // TODO: optional optimizations go here
55
Chris Lattnerd91d86f2003-01-13 00:51:23 +000056 // FIXME: Add SSA based peephole optimizer here.
57
Chris Lattner3dffa792002-10-30 00:47:49 +000058 // Print the instruction selected machine code...
Chris Lattner5bcd95c2002-12-24 00:04:01 +000059 if (PrintCode)
60 PM.add(createMachineFunctionPrinterPass());
Chris Lattner3dffa792002-10-30 00:47:49 +000061
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000062 // Perform register allocation to convert to a concrete x86 representation
Chris Lattner14322cd32002-12-17 02:51:15 +000063 if (NoLocalRA)
Chris Lattnerd282cfe2002-12-28 20:33:32 +000064 PM.add(createSimpleRegisterAllocator());
Chris Lattner14322cd32002-12-17 02:51:15 +000065 else
Chris Lattnerd282cfe2002-12-28 20:33:32 +000066 PM.add(createLocalRegisterAllocator());
67
68 if (PrintCode)
69 PM.add(createMachineFunctionPrinterPass());
70
Chris Lattnerd91d86f2003-01-13 00:51:23 +000071 PM.add(createX86FloatingPointStackifierPass());
72
73 if (PrintCode)
74 PM.add(createMachineFunctionPrinterPass());
75
Chris Lattnerd282cfe2002-12-28 20:33:32 +000076 // Insert prolog/epilog code. Eliminate abstract frame index references...
77 PM.add(createPrologEpilogCodeInserter());
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000078
Chris Lattnerd91d86f2003-01-13 00:51:23 +000079 PM.add(createX86PeepholeOptimizerPass());
80
Chris Lattner430cda72002-12-25 05:06:21 +000081 if (PrintCode) // Print the register-allocated code
Chris Lattnerd282cfe2002-12-28 20:33:32 +000082 PM.add(createX86CodePrinterPass(std::cerr));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000083
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000084 return false; // success!
85}
86