blob: 18656af41383c766d2181100db7c6316ac3c7426 [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"
Brian Gaekee48ec012002-12-13 06:46:31 +00009#include "llvm/Transforms/Scalar.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 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,
39 (Config & TM::PtrSizeMask) == TM::PtrSize64 ? 8 : 4) {
Chris Lattnerb4f68ed2002-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 Gaekee48ec012002-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 Lattnerb4f68ed2002-10-29 22:37:54 +000053 PM.add(createSimpleX86InstructionSelector(*this));
54
55 // TODO: optional optimizations go here
56
Chris Lattner3dffa792002-10-30 00:47:49 +000057 // Print the instruction selected machine code...
Chris Lattner5bcd95c2002-12-24 00:04:01 +000058 if (PrintCode)
59 PM.add(createMachineFunctionPrinterPass());
Chris Lattner3dffa792002-10-30 00:47:49 +000060
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000061 // Perform register allocation to convert to a concrete x86 representation
Chris Lattner14322cd32002-12-17 02:51:15 +000062 if (NoLocalRA)
Chris Lattner439a27a2002-12-16 16:15:51 +000063 PM.add(createSimpleRegisterAllocator(*this));
Chris Lattner14322cd32002-12-17 02:51:15 +000064 else
65 PM.add(createLocalRegisterAllocator(*this));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000066
Misha Brukmanf88a2852002-11-22 22:45:07 +000067 // Print the instruction selected machine code...
68 // PM.add(createMachineFunctionPrinterPass());
69
70 // Print the register-allocated code
Chris Lattner5bcd95c2002-12-24 00:04:01 +000071 if (PrintCode)
72 PM.add(createX86CodePrinterPass(*this, std::cerr));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000073
74 return false; // success!
75}
76