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