Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 1 | //===-- IA64TargetMachine.cpp - Define TargetMachine for IA64 -------------===// |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2 | // |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Duraid Madina and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 7 | // |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 9 | // |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 10 | // This file defines the IA64 specific subclass of TargetMachine. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "IA64TargetMachine.h" |
| 15 | #include "IA64.h" |
| 16 | #include "llvm/Module.h" |
| 17 | #include "llvm/PassManager.h" |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineFunction.h" |
| 19 | #include "llvm/CodeGen/Passes.h" |
| 20 | #include "llvm/Target/TargetOptions.h" |
| 21 | #include "llvm/Target/TargetMachineRegistry.h" |
| 22 | #include "llvm/Transforms/Scalar.h" |
| 23 | #include "llvm/Support/CommandLine.h" |
| 24 | #include "llvm/ADT/Statistic.h" |
Chris Lattner | 2c2c6c6 | 2006-01-22 23:41:00 +0000 | [diff] [blame] | 25 | #include <iostream> |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
| 28 | /// IA64TargetMachineModule - Note that this is used on hosts that cannot link |
| 29 | /// in a library unless there are references into the library. In particular, |
| 30 | /// it seems that it is not possible to get things to work on Win32 without |
| 31 | /// this. Though it is unused, do not remove it. |
| 32 | extern "C" int IA64TargetMachineModule; |
| 33 | int IA64TargetMachineModule = 0; |
| 34 | |
| 35 | namespace { |
| 36 | cl::opt<bool> DisableOutput("disable-ia64-llc-output", cl::Hidden, |
| 37 | cl::desc("Disable the IA64 asm printer, for use " |
| 38 | "when profiling the code generator.")); |
| 39 | |
Duraid Madina | f2db9b8 | 2005-10-28 17:46:35 +0000 | [diff] [blame] | 40 | cl::opt<bool> EnableDAGIsel("enable-ia64-dag-isel", cl::Hidden, |
| 41 | cl::desc("Enable the IA64 DAG->DAG isel")); |
| 42 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 43 | // Register the target. |
| 44 | RegisterTarget<IA64TargetMachine> X("ia64", " IA-64 (Itanium)"); |
| 45 | } |
| 46 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 47 | unsigned IA64TargetMachine::getModuleMatchQuality(const Module &M) { |
| 48 | // we match [iI][aA]*64 |
| 49 | bool seenIA64=false; |
| 50 | std::string TT = M.getTargetTriple(); |
| 51 | |
| 52 | if (TT.size() >= 4) { |
| 53 | if( (TT[0]=='i' || TT[0]=='I') && |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 54 | (TT[1]=='a' || TT[1]=='A') ) { |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 55 | for(unsigned int i=2; i<(TT.size()-1); i++) |
Misha Brukman | 7847fca | 2005-04-22 17:54:37 +0000 | [diff] [blame] | 56 | if(TT[i]=='6' && TT[i+1]=='4') |
| 57 | seenIA64=true; |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Chris Lattner | 16c7fe5 | 2006-08-26 21:33:05 +0000 | [diff] [blame^] | 60 | if (seenIA64) |
| 61 | return 20; // strong match |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Chris Lattner | 16c7fe5 | 2006-08-26 21:33:05 +0000 | [diff] [blame^] | 64 | #if defined(__ia64__) || defined(__IA64__) |
| 65 | return 5; |
| 66 | #else |
| 67 | return 0; |
| 68 | #endif |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /// IA64TargetMachine ctor - Create an LP64 architecture model |
| 72 | /// |
Chris Lattner | bc641b9 | 2006-03-23 05:43:16 +0000 | [diff] [blame] | 73 | IA64TargetMachine::IA64TargetMachine(const Module &M, const std::string &FS) |
Chris Lattner | 1790d44 | 2006-06-16 18:22:52 +0000 | [diff] [blame] | 74 | : TargetMachine("IA64"), DataLayout("e"), |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 75 | FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), |
| 76 | TLInfo(*this) { // FIXME? check this stuff |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 79 | // addPassesToEmitFile - We currently use all of the same passes as the JIT |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 80 | // does to emit statically compiled machine code. |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 81 | bool IA64TargetMachine::addPassesToEmitFile(PassManager &PM, |
| 82 | std::ostream &Out, |
Chris Lattner | ce8eb0c | 2005-11-08 02:11:51 +0000 | [diff] [blame] | 83 | CodeGenFileType FileType, |
| 84 | bool Fast) { |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 85 | if (FileType != TargetMachine::AssemblyFile) return true; |
| 86 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 87 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 88 | PM.add(createLowerGCPass()); |
| 89 | |
| 90 | // FIXME: Implement the invoke/unwind instructions! |
Duraid Madina | 21687e8 | 2005-11-06 04:29:30 +0000 | [diff] [blame] | 91 | PM.add(createLowerInvokePass(704, 16)); // on ia64 linux, jmpbufs are 704 |
| 92 | // bytes and must be 16byte aligned |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 93 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 94 | // Make sure that no unreachable blocks are instruction selected. |
| 95 | PM.add(createUnreachableBlockEliminationPass()); |
| 96 | |
Duraid Madina | f2db9b8 | 2005-10-28 17:46:35 +0000 | [diff] [blame] | 97 | // Add an instruction selector |
Duraid Madina | c5f2470 | 2006-01-19 14:13:11 +0000 | [diff] [blame] | 98 | // FIXME: reap this option one day: if(EnableDAGIsel) |
| 99 | PM.add(createIA64DAGToDAGInstructionSelector(*this)); |
Duraid Madina | badf0d9 | 2006-01-25 02:23:38 +0000 | [diff] [blame] | 100 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 101 | /* XXX not yet. ;) |
| 102 | // Run optional SSA-based machine code optimizations next... |
| 103 | if (!NoSSAPeephole) |
| 104 | PM.add(createIA64SSAPeepholeOptimizerPass()); |
| 105 | */ |
| 106 | |
| 107 | // Print the instruction selected machine code... |
| 108 | if (PrintMachineCode) |
| 109 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 110 | |
| 111 | // Perform register allocation to convert to a concrete IA64 representation |
| 112 | PM.add(createRegisterAllocator()); |
| 113 | |
| 114 | if (PrintMachineCode) |
| 115 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 116 | |
| 117 | if (PrintMachineCode) |
| 118 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 119 | |
| 120 | // Insert prolog/epilog code. Eliminate abstract frame index references... |
| 121 | PM.add(createPrologEpilogCodeInserter()); |
| 122 | |
| 123 | /* XXX no, not just yet */ |
| 124 | // PM.add(createIA64PeepholeOptimizerPass()); |
| 125 | |
Duraid Madina | badf0d9 | 2006-01-25 02:23:38 +0000 | [diff] [blame] | 126 | // Make sure everything is bundled happily |
| 127 | PM.add(createIA64BundlingPass(*this)); |
| 128 | |
Duraid Madina | 9b9d45f | 2005-03-17 18:17:03 +0000 | [diff] [blame] | 129 | if (PrintMachineCode) // Print the register-allocated code |
| 130 | PM.add(createIA64CodePrinterPass(std::cerr, *this)); |
| 131 | |
| 132 | if (!DisableOutput) |
| 133 | PM.add(createIA64CodePrinterPass(Out, *this)); |
| 134 | |
| 135 | // Delete machine code for this function |
| 136 | PM.add(createMachineCodeDeleter()); |
| 137 | |
| 138 | return false; // success! |
| 139 | } |
| 140 | |