blob: 9137f6befc9ac26c14b728dd7f64044be46f96c4 [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
Brian Gaekede3aa4f2003-06-18 21:43:21 +000044// llc backend for x86
45bool X86TargetMachine::addPassesToEmitAssembly(PassManager &PM,
46 std::ostream &Out) {
47 PM.add(createLowerSwitchPass());
48 PM.add(createSimpleX86InstructionSelector(*this));
49 PM.add(createLocalRegisterAllocator());
50 PM.add(createX86FloatingPointStackifierPass());
51 PM.add(createPrologEpilogCodeInserter());
52 PM.add(createX86PeepholeOptimizerPass());
Brian Gaekede420ae2003-07-23 20:25:08 +000053 PM.add(createX86CodePrinterPass(Out, *this));
Brian Gaekede3aa4f2003-06-18 21:43:21 +000054 return false; // success!
55}
56
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000057/// addPassesToJITCompile - Add passes to the specified pass manager to
58/// implement a fast dynamic compiler for this target. Return true if this is
59/// not supported for this target.
60///
61bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) {
Chris Lattner155e68f2003-04-23 16:24:55 +000062 // FIXME: Implement the switch instruction in the instruction selector!
63 PM.add(createLowerSwitchPass());
64
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000065 PM.add(createSimpleX86InstructionSelector(*this));
66
67 // TODO: optional optimizations go here
68
Chris Lattnerd91d86f2003-01-13 00:51:23 +000069 // FIXME: Add SSA based peephole optimizer here.
70
Chris Lattner3dffa792002-10-30 00:47:49 +000071 // Print the instruction selected machine code...
Chris Lattner5bcd95c2002-12-24 00:04:01 +000072 if (PrintCode)
73 PM.add(createMachineFunctionPrinterPass());
Chris Lattner3dffa792002-10-30 00:47:49 +000074
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000075 // Perform register allocation to convert to a concrete x86 representation
Chris Lattner14322cd32002-12-17 02:51:15 +000076 if (NoLocalRA)
Chris Lattnerd282cfe2002-12-28 20:33:32 +000077 PM.add(createSimpleRegisterAllocator());
Chris Lattner14322cd32002-12-17 02:51:15 +000078 else
Chris Lattnerd282cfe2002-12-28 20:33:32 +000079 PM.add(createLocalRegisterAllocator());
80
81 if (PrintCode)
82 PM.add(createMachineFunctionPrinterPass());
83
Chris Lattnerd91d86f2003-01-13 00:51:23 +000084 PM.add(createX86FloatingPointStackifierPass());
85
86 if (PrintCode)
87 PM.add(createMachineFunctionPrinterPass());
88
Chris Lattnerd282cfe2002-12-28 20:33:32 +000089 // Insert prolog/epilog code. Eliminate abstract frame index references...
90 PM.add(createPrologEpilogCodeInserter());
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000091
Chris Lattnerd91d86f2003-01-13 00:51:23 +000092 PM.add(createX86PeepholeOptimizerPass());
93
Chris Lattner430cda72002-12-25 05:06:21 +000094 if (PrintCode) // Print the register-allocated code
Brian Gaekede420ae2003-07-23 20:25:08 +000095 PM.add(createX86CodePrinterPass(std::cerr, *this));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000096
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000097 return false; // success!
98}
99