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