Andrew Lenharth | 886470e | 2005-01-24 18:45:41 +0000 | [diff] [blame] | 1 | //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===// |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 2 | // |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 7 | // |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 9 | // |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "Alpha.h" |
Andrew Lenharth | 0934ae0 | 2005-07-22 20:52:16 +0000 | [diff] [blame] | 14 | #include "AlphaJITInfo.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 15 | #include "AlphaTargetMachine.h" |
Andrew Lenharth | 2f40163 | 2005-02-01 20:35:11 +0000 | [diff] [blame] | 16 | #include "llvm/Module.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/Passes.h" |
| 18 | #include "llvm/Target/TargetOptions.h" |
| 19 | #include "llvm/Target/TargetMachineRegistry.h" |
| 20 | #include "llvm/Transforms/Scalar.h" |
Andrew Lenharth | 120ab48 | 2005-09-29 22:54:56 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Debug.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 22 | #include <iostream> |
Andrew Lenharth | 2f40163 | 2005-02-01 20:35:11 +0000 | [diff] [blame] | 23 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
| 26 | namespace { |
| 27 | // Register the targets |
| 28 | RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)"); |
| 29 | } |
| 30 | |
Andrew Lenharth | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 31 | namespace llvm { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 32 | cl::opt<bool> EnableAlphaLSR("enable-lsr-for-alpha", |
| 33 | cl::desc("Enable LSR for Alpha (beta option!)"), |
Andrew Lenharth | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 34 | cl::Hidden); |
Andrew Lenharth | 4907d22 | 2005-10-20 00:28:31 +0000 | [diff] [blame] | 35 | cl::opt<bool> EnableAlphaDAG("enable-dag-isel-for-alpha", |
| 36 | cl::desc("Enable DAG ISEL for Alpha (beta option!)"), |
| 37 | cl::Hidden); |
Andrew Lenharth | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Andrew Lenharth | 2f40163 | 2005-02-01 20:35:11 +0000 | [diff] [blame] | 40 | unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) { |
| 41 | // We strongly match "alpha*". |
| 42 | std::string TT = M.getTargetTriple(); |
| 43 | if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' && |
| 44 | TT[3] == 'h' && TT[4] == 'a') |
| 45 | return 20; |
| 46 | |
| 47 | if (M.getEndianness() == Module::LittleEndian && |
| 48 | M.getPointerSize() == Module::Pointer64) |
| 49 | return 10; // Weak match |
| 50 | else if (M.getEndianness() != Module::AnyEndianness || |
| 51 | M.getPointerSize() != Module::AnyPointerSize) |
| 52 | return 0; // Match for some other target |
| 53 | |
Chris Lattner | c1d6f67 | 2005-10-30 16:44:01 +0000 | [diff] [blame^] | 54 | return getJITMatchQuality()/2; |
Andrew Lenharth | 2f40163 | 2005-02-01 20:35:11 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Andrew Lenharth | 0934ae0 | 2005-07-22 20:52:16 +0000 | [diff] [blame] | 57 | unsigned AlphaTargetMachine::getJITMatchQuality() { |
Andrew Lenharth | 38396f8 | 2005-07-22 21:00:30 +0000 | [diff] [blame] | 58 | #ifdef __alpha |
Andrew Lenharth | 0934ae0 | 2005-07-22 20:52:16 +0000 | [diff] [blame] | 59 | return 10; |
| 60 | #else |
| 61 | return 0; |
| 62 | #endif |
| 63 | } |
| 64 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 65 | AlphaTargetMachine::AlphaTargetMachine(const Module &M, IntrinsicLowering *IL, |
| 66 | const std::string &FS) |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 67 | : TargetMachine("alpha", IL, true), |
Andrew Lenharth | dc7c0b8 | 2005-08-03 22:33:21 +0000 | [diff] [blame] | 68 | FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), |
Andrew Lenharth | 120ab48 | 2005-09-29 22:54:56 +0000 | [diff] [blame] | 69 | JITInfo(*this), |
| 70 | Subtarget(M, FS) |
| 71 | { |
| 72 | DEBUG(std::cerr << "FS is " << FS << "\n"); |
| 73 | } |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 74 | |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 75 | /// addPassesToEmitFile - Add passes to the specified pass manager to implement |
| 76 | /// a static compiler for this target. |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 77 | /// |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame] | 78 | bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM, |
| 79 | std::ostream &Out, |
| 80 | CodeGenFileType FileType) { |
| 81 | if (FileType != TargetMachine::AssemblyFile) return true; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 82 | |
Andrew Lenharth | f3f475e | 2005-03-03 19:03:21 +0000 | [diff] [blame] | 83 | if (EnableAlphaLSR) { |
Andrew Lenharth | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 84 | PM.add(createLoopStrengthReducePass()); |
Andrew Lenharth | f3f475e | 2005-03-03 19:03:21 +0000 | [diff] [blame] | 85 | PM.add(createCFGSimplificationPass()); |
| 86 | } |
Andrew Lenharth | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 87 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 88 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 89 | PM.add(createLowerGCPass()); |
| 90 | |
| 91 | // FIXME: Implement the invoke/unwind instructions! |
| 92 | PM.add(createLowerInvokePass()); |
| 93 | |
| 94 | // FIXME: Implement the switch instruction in the instruction selector! |
| 95 | PM.add(createLowerSwitchPass()); |
| 96 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 97 | // Make sure that no unreachable blocks are instruction selected. |
| 98 | PM.add(createUnreachableBlockEliminationPass()); |
| 99 | |
Andrew Lenharth | 4907d22 | 2005-10-20 00:28:31 +0000 | [diff] [blame] | 100 | if (EnableAlphaDAG) |
| 101 | PM.add(createAlphaISelDag(*this)); |
| 102 | else |
| 103 | PM.add(createAlphaPatternInstructionSelector(*this)); |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 104 | |
| 105 | if (PrintMachineCode) |
| 106 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 107 | |
| 108 | PM.add(createRegisterAllocator()); |
| 109 | |
| 110 | if (PrintMachineCode) |
| 111 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 112 | |
| 113 | PM.add(createPrologEpilogCodeInserter()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 114 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 115 | // Must run branch selection immediately preceding the asm printer |
| 116 | //PM.add(createAlphaBranchSelectionPass()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 117 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 118 | PM.add(createAlphaCodePrinterPass(Out, *this)); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 119 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 120 | PM.add(createMachineCodeDeleter()); |
| 121 | return false; |
| 122 | } |
Andrew Lenharth | 0934ae0 | 2005-07-22 20:52:16 +0000 | [diff] [blame] | 123 | |
| 124 | void AlphaJITInfo::addPassesToJITCompile(FunctionPassManager &PM) { |
| 125 | |
| 126 | if (EnableAlphaLSR) { |
| 127 | PM.add(createLoopStrengthReducePass()); |
| 128 | PM.add(createCFGSimplificationPass()); |
| 129 | } |
| 130 | |
| 131 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 132 | PM.add(createLowerGCPass()); |
| 133 | |
| 134 | // FIXME: Implement the invoke/unwind instructions! |
| 135 | PM.add(createLowerInvokePass()); |
| 136 | |
| 137 | // FIXME: Implement the switch instruction in the instruction selector! |
| 138 | PM.add(createLowerSwitchPass()); |
| 139 | |
| 140 | // Make sure that no unreachable blocks are instruction selected. |
| 141 | PM.add(createUnreachableBlockEliminationPass()); |
| 142 | |
| 143 | PM.add(createAlphaPatternInstructionSelector(TM)); |
| 144 | |
| 145 | if (PrintMachineCode) |
| 146 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 147 | |
| 148 | PM.add(createRegisterAllocator()); |
| 149 | |
| 150 | if (PrintMachineCode) |
| 151 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 152 | |
| 153 | PM.add(createPrologEpilogCodeInserter()); |
| 154 | |
| 155 | // Must run branch selection immediately preceding the asm printer |
| 156 | //PM.add(createAlphaBranchSelectionPass()); |
| 157 | |
| 158 | } |
| 159 | |
| 160 | bool AlphaTargetMachine::addPassesToEmitMachineCode(FunctionPassManager &PM, |
| 161 | MachineCodeEmitter &MCE) { |
| 162 | PM.add(createAlphaCodeEmitterPass(MCE)); |
| 163 | // Delete machine code for this function |
| 164 | PM.add(createMachineCodeDeleter()); |
| 165 | return false; |
| 166 | } |