blob: c578ba83a67d1fb9bd35734bddafb5739309efc1 [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 Lattnerb4f68ed2002-10-29 22:37:54 +00009#include "llvm/Target/TargetMachineImpls.h"
Chris Lattner3dffa792002-10-30 00:47:49 +000010#include "llvm/CodeGen/MachineFunction.h"
Chris Lattnerd91d86f2003-01-13 00:51:23 +000011#include "llvm/CodeGen/Passes.h"
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000012#include "llvm/PassManager.h"
Chris Lattner439a27a2002-12-16 16:15:51 +000013#include "Support/CommandLine.h"
14#include "Support/Statistic.h"
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000015#include <iostream>
16
Chris Lattner439a27a2002-12-16 16:15:51 +000017namespace {
Chris Lattner14322cd32002-12-17 02:51:15 +000018 cl::opt<bool> NoLocalRA("no-local-ra",
19 cl::desc("Use Simple RA instead of Local RegAlloc"));
Chris Lattner5bcd95c2002-12-24 00:04:01 +000020 cl::opt<bool> PrintCode("print-machineinstrs",
21 cl::desc("Print generated machine code"));
Chris Lattner439a27a2002-12-16 16:15:51 +000022}
23
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000024// allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
25// that implements the X86 backend.
26//
Chris Lattner5bcd95c2002-12-24 00:04:01 +000027TargetMachine *allocateX86TargetMachine(unsigned Configuration) {
28 return new X86TargetMachine(Configuration);
29}
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000030
31
32/// X86TargetMachine ctor - Create an ILP32 architecture model
33///
Chris Lattner5bcd95c2002-12-24 00:04:01 +000034X86TargetMachine::X86TargetMachine(unsigned Config)
35 : TargetMachine("X86",
36 (Config & TM::EndianMask) == TM::LittleEndian,
37 1, 4,
38 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4,
Chris Lattnerd282cfe2002-12-28 20:33:32 +000039 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4),
Chris Lattnerf158da22003-01-16 02:20:12 +000040 FrameInfo(TargetFrameInfo::StackGrowsDown, 8/*16 for SSE*/, 4) {
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000041}
42
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000043/// addPassesToJITCompile - Add passes to the specified pass manager to
44/// implement a fast dynamic compiler for this target. Return true if this is
45/// not supported for this target.
46///
47bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) {
48 PM.add(createSimpleX86InstructionSelector(*this));
49
50 // TODO: optional optimizations go here
51
Chris Lattnerd91d86f2003-01-13 00:51:23 +000052 // FIXME: Add SSA based peephole optimizer here.
53
Chris Lattner3dffa792002-10-30 00:47:49 +000054 // Print the instruction selected machine code...
Chris Lattner5bcd95c2002-12-24 00:04:01 +000055 if (PrintCode)
56 PM.add(createMachineFunctionPrinterPass());
Chris Lattner3dffa792002-10-30 00:47:49 +000057
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000058 // Perform register allocation to convert to a concrete x86 representation
Chris Lattner14322cd32002-12-17 02:51:15 +000059 if (NoLocalRA)
Chris Lattnerd282cfe2002-12-28 20:33:32 +000060 PM.add(createSimpleRegisterAllocator());
Chris Lattner14322cd32002-12-17 02:51:15 +000061 else
Chris Lattnerd282cfe2002-12-28 20:33:32 +000062 PM.add(createLocalRegisterAllocator());
63
64 if (PrintCode)
65 PM.add(createMachineFunctionPrinterPass());
66
Chris Lattnerd91d86f2003-01-13 00:51:23 +000067 PM.add(createX86FloatingPointStackifierPass());
68
69 if (PrintCode)
70 PM.add(createMachineFunctionPrinterPass());
71
Chris Lattnerd282cfe2002-12-28 20:33:32 +000072 // Insert prolog/epilog code. Eliminate abstract frame index references...
73 PM.add(createPrologEpilogCodeInserter());
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000074
Chris Lattnerd91d86f2003-01-13 00:51:23 +000075 PM.add(createX86PeepholeOptimizerPass());
76
Chris Lattner430cda72002-12-25 05:06:21 +000077 if (PrintCode) // Print the register-allocated code
Chris Lattnerd282cfe2002-12-28 20:33:32 +000078 PM.add(createX86CodePrinterPass(std::cerr));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000079
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000080 return false; // success!
81}
82