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