blob: 18656af41383c766d2181100db7c6316ac3c7426 [file] [log] [blame]
Chris Lattner02a3d832002-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 Lattnera32b4052002-12-24 00:04:01 +00008#include "X86.h"
Brian Gaeke4e2c30d2002-12-13 06:46:31 +00009#include "llvm/Transforms/Scalar.h"
Chris Lattner02a3d832002-10-29 22:37:54 +000010#include "llvm/Target/TargetMachineImpls.h"
Chris Lattnerd7a85562002-10-30 00:47:49 +000011#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner02a3d832002-10-29 22:37:54 +000012#include "llvm/PassManager.h"
Chris Lattnere0c25aa2002-12-16 16:15:51 +000013#include "Support/CommandLine.h"
14#include "Support/Statistic.h"
Chris Lattner02a3d832002-10-29 22:37:54 +000015#include <iostream>
16
Chris Lattnere0c25aa2002-12-16 16:15:51 +000017namespace {
Chris Lattnerd9c6f2a2002-12-17 02:51:15 +000018 cl::opt<bool> NoLocalRA("no-local-ra",
19 cl::desc("Use Simple RA instead of Local RegAlloc"));
Chris Lattnera32b4052002-12-24 00:04:01 +000020 cl::opt<bool> PrintCode("print-machineinstrs",
21 cl::desc("Print generated machine code"));
Chris Lattnere0c25aa2002-12-16 16:15:51 +000022}
23
Chris Lattner02a3d832002-10-29 22:37:54 +000024// allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
25// that implements the X86 backend.
26//
Chris Lattnera32b4052002-12-24 00:04:01 +000027TargetMachine *allocateX86TargetMachine(unsigned Configuration) {
28 return new X86TargetMachine(Configuration);
29}
Chris Lattner02a3d832002-10-29 22:37:54 +000030
31
32/// X86TargetMachine ctor - Create an ILP32 architecture model
33///
Chris Lattnera32b4052002-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,
39 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4) {
Chris Lattner02a3d832002-10-29 22:37:54 +000040}
41
42
43/// 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) {
Brian Gaeke4e2c30d2002-12-13 06:46:31 +000048 // For the moment we have decided that malloc and free will be
49 // taken care of by converting them to calls, using the existing
50 // LLVM scalar transforms pass to do this.
51 PM.add(createLowerAllocationsPass());
52
Chris Lattner02a3d832002-10-29 22:37:54 +000053 PM.add(createSimpleX86InstructionSelector(*this));
54
55 // TODO: optional optimizations go here
56
Chris Lattnerd7a85562002-10-30 00:47:49 +000057 // Print the instruction selected machine code...
Chris Lattnera32b4052002-12-24 00:04:01 +000058 if (PrintCode)
59 PM.add(createMachineFunctionPrinterPass());
Chris Lattnerd7a85562002-10-30 00:47:49 +000060
Chris Lattner02a3d832002-10-29 22:37:54 +000061 // Perform register allocation to convert to a concrete x86 representation
Chris Lattnerd9c6f2a2002-12-17 02:51:15 +000062 if (NoLocalRA)
Chris Lattnere0c25aa2002-12-16 16:15:51 +000063 PM.add(createSimpleRegisterAllocator(*this));
Chris Lattnerd9c6f2a2002-12-17 02:51:15 +000064 else
65 PM.add(createLocalRegisterAllocator(*this));
Chris Lattner02a3d832002-10-29 22:37:54 +000066
Misha Brukman55cf6bf2002-11-22 22:45:07 +000067 // Print the instruction selected machine code...
68 // PM.add(createMachineFunctionPrinterPass());
69
70 // Print the register-allocated code
Chris Lattnera32b4052002-12-24 00:04:01 +000071 if (PrintCode)
72 PM.add(createX86CodePrinterPass(*this, std::cerr));
Chris Lattner02a3d832002-10-29 22:37:54 +000073
74 return false; // success!
75}
76