blob: 0eb71da814a22e575749f8bfd546d6172f496a9f [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"
Brian Gaekee48ec012002-12-13 06:46:31 +00008#include "llvm/Transforms/Scalar.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 Lattnerb4f68ed2002-10-29 22:37:54 +000011#include "llvm/PassManager.h"
12#include "X86.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 Lattner439a27a2002-12-16 16:15:51 +000020}
21
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000022// allocateX86TargetMachine - Allocate and return a subclass of TargetMachine
23// that implements the X86 backend.
24//
25TargetMachine *allocateX86TargetMachine() { return new X86TargetMachine(); }
26
27
28/// X86TargetMachine ctor - Create an ILP32 architecture model
29///
30X86TargetMachine::X86TargetMachine() : TargetMachine("X86", 1, 4, 4, 4) {
31}
32
33
34/// addPassesToJITCompile - Add passes to the specified pass manager to
35/// implement a fast dynamic compiler for this target. Return true if this is
36/// not supported for this target.
37///
38bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) {
Brian Gaekee48ec012002-12-13 06:46:31 +000039 // For the moment we have decided that malloc and free will be
40 // taken care of by converting them to calls, using the existing
41 // LLVM scalar transforms pass to do this.
42 PM.add(createLowerAllocationsPass());
43
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000044 PM.add(createSimpleX86InstructionSelector(*this));
45
46 // TODO: optional optimizations go here
47
Chris Lattner3dffa792002-10-30 00:47:49 +000048 // Print the instruction selected machine code...
Misha Brukmanb8ead9d2002-12-13 13:16:14 +000049 DEBUG(PM.add(createMachineFunctionPrinterPass()));
Chris Lattner3dffa792002-10-30 00:47:49 +000050
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000051 // Perform register allocation to convert to a concrete x86 representation
Chris Lattner14322cd32002-12-17 02:51:15 +000052 if (NoLocalRA)
Chris Lattner439a27a2002-12-16 16:15:51 +000053 PM.add(createSimpleRegisterAllocator(*this));
Chris Lattner14322cd32002-12-17 02:51:15 +000054 else
55 PM.add(createLocalRegisterAllocator(*this));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000056
Misha Brukmanf88a2852002-11-22 22:45:07 +000057 // Print the instruction selected machine code...
58 // PM.add(createMachineFunctionPrinterPass());
59
60 // Print the register-allocated code
Misha Brukmanb8ead9d2002-12-13 13:16:14 +000061 DEBUG(PM.add(createX86CodePrinterPass(*this, std::cerr)));
Chris Lattnerb4f68ed2002-10-29 22:37:54 +000062
63 return false; // success!
64}
65