Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 1 | //===-- 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 Lattner | 5bcd95c | 2002-12-24 00:04:01 +0000 | [diff] [blame^] | 8 | #include "X86.h" |
Brian Gaeke | e48ec01 | 2002-12-13 06:46:31 +0000 | [diff] [blame] | 9 | #include "llvm/Transforms/Scalar.h" |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 10 | #include "llvm/Target/TargetMachineImpls.h" |
Chris Lattner | 3dffa79 | 2002-10-30 00:47:49 +0000 | [diff] [blame] | 11 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 12 | #include "llvm/PassManager.h" |
Chris Lattner | 439a27a | 2002-12-16 16:15:51 +0000 | [diff] [blame] | 13 | #include "Support/CommandLine.h" |
| 14 | #include "Support/Statistic.h" |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 15 | #include <iostream> |
| 16 | |
Chris Lattner | 439a27a | 2002-12-16 16:15:51 +0000 | [diff] [blame] | 17 | namespace { |
Chris Lattner | 14322cd3 | 2002-12-17 02:51:15 +0000 | [diff] [blame] | 18 | cl::opt<bool> NoLocalRA("no-local-ra", |
| 19 | cl::desc("Use Simple RA instead of Local RegAlloc")); |
Chris Lattner | 5bcd95c | 2002-12-24 00:04:01 +0000 | [diff] [blame^] | 20 | cl::opt<bool> PrintCode("print-machineinstrs", |
| 21 | cl::desc("Print generated machine code")); |
Chris Lattner | 439a27a | 2002-12-16 16:15:51 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 24 | // allocateX86TargetMachine - Allocate and return a subclass of TargetMachine |
| 25 | // that implements the X86 backend. |
| 26 | // |
Chris Lattner | 5bcd95c | 2002-12-24 00:04:01 +0000 | [diff] [blame^] | 27 | TargetMachine *allocateX86TargetMachine(unsigned Configuration) { |
| 28 | return new X86TargetMachine(Configuration); |
| 29 | } |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | /// X86TargetMachine ctor - Create an ILP32 architecture model |
| 33 | /// |
Chris Lattner | 5bcd95c | 2002-12-24 00:04:01 +0000 | [diff] [blame^] | 34 | X86TargetMachine::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 Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 40 | } |
| 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 | /// |
| 47 | bool X86TargetMachine::addPassesToJITCompile(PassManager &PM) { |
Brian Gaeke | e48ec01 | 2002-12-13 06:46:31 +0000 | [diff] [blame] | 48 | // 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 Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 53 | PM.add(createSimpleX86InstructionSelector(*this)); |
| 54 | |
| 55 | // TODO: optional optimizations go here |
| 56 | |
Chris Lattner | 3dffa79 | 2002-10-30 00:47:49 +0000 | [diff] [blame] | 57 | // Print the instruction selected machine code... |
Chris Lattner | 5bcd95c | 2002-12-24 00:04:01 +0000 | [diff] [blame^] | 58 | if (PrintCode) |
| 59 | PM.add(createMachineFunctionPrinterPass()); |
Chris Lattner | 3dffa79 | 2002-10-30 00:47:49 +0000 | [diff] [blame] | 60 | |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 61 | // Perform register allocation to convert to a concrete x86 representation |
Chris Lattner | 14322cd3 | 2002-12-17 02:51:15 +0000 | [diff] [blame] | 62 | if (NoLocalRA) |
Chris Lattner | 439a27a | 2002-12-16 16:15:51 +0000 | [diff] [blame] | 63 | PM.add(createSimpleRegisterAllocator(*this)); |
Chris Lattner | 14322cd3 | 2002-12-17 02:51:15 +0000 | [diff] [blame] | 64 | else |
| 65 | PM.add(createLocalRegisterAllocator(*this)); |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 66 | |
Misha Brukman | f88a285 | 2002-11-22 22:45:07 +0000 | [diff] [blame] | 67 | // Print the instruction selected machine code... |
| 68 | // PM.add(createMachineFunctionPrinterPass()); |
| 69 | |
| 70 | // Print the register-allocated code |
Chris Lattner | 5bcd95c | 2002-12-24 00:04:01 +0000 | [diff] [blame^] | 71 | if (PrintCode) |
| 72 | PM.add(createX86CodePrinterPass(*this, std::cerr)); |
Chris Lattner | b4f68ed | 2002-10-29 22:37:54 +0000 | [diff] [blame] | 73 | |
| 74 | return false; // success! |
| 75 | } |
| 76 | |