Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "Alpha.h" |
| 14 | #include "AlphaJITInfo.h" |
| 15 | #include "AlphaTargetAsmInfo.h" |
| 16 | #include "AlphaTargetMachine.h" |
| 17 | #include "llvm/Module.h" |
| 18 | #include "llvm/PassManager.h" |
| 19 | #include "llvm/Target/TargetMachineRegistry.h" |
Owen Anderson | 847b99b | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace llvm; |
| 23 | |
Oscar Fuentes | 4f01235 | 2008-11-15 21:36:30 +0000 | [diff] [blame^] | 24 | /// AlphaTargetMachineModule - Note that this is used on hosts that cannot link |
| 25 | /// in a library unless there are references into the library. In particular, |
| 26 | /// it seems that it is not possible to get things to work on Win32 without |
| 27 | /// this. Though it is unused, do not remove it. |
| 28 | extern "C" int AlphaTargetMachineModule; |
| 29 | int AlphaTargetMachineModule = 0; |
| 30 | |
Dan Gohman | 089efff | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 31 | // Register the targets |
Chris Lattner | 3f83d3f | 2008-10-16 06:16:50 +0000 | [diff] [blame] | 32 | static RegisterTarget<AlphaTargetMachine> X("alpha", "Alpha [experimental]"); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 33 | |
| 34 | const TargetAsmInfo *AlphaTargetMachine::createTargetAsmInfo() const { |
| 35 | return new AlphaTargetAsmInfo(*this); |
| 36 | } |
| 37 | |
| 38 | unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) { |
| 39 | // We strongly match "alpha*". |
| 40 | std::string TT = M.getTargetTriple(); |
| 41 | if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' && |
| 42 | TT[3] == 'h' && TT[4] == 'a') |
| 43 | return 20; |
| 44 | // If the target triple is something non-alpha, we don't match. |
| 45 | if (!TT.empty()) return 0; |
| 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 | |
| 54 | return getJITMatchQuality()/2; |
| 55 | } |
| 56 | |
| 57 | unsigned AlphaTargetMachine::getJITMatchQuality() { |
| 58 | #ifdef __alpha |
| 59 | return 10; |
| 60 | #else |
| 61 | return 0; |
| 62 | #endif |
| 63 | } |
| 64 | |
| 65 | AlphaTargetMachine::AlphaTargetMachine(const Module &M, const std::string &FS) |
Dale Johannesen | 4c39f71 | 2007-08-03 20:20:50 +0000 | [diff] [blame] | 66 | : DataLayout("e-f128:128:128"), |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 67 | FrameInfo(TargetFrameInfo::StackGrowsDown, 16, 0), |
| 68 | JITInfo(*this), |
| 69 | Subtarget(M, FS), |
| 70 | TLInfo(*this) { |
| 71 | setRelocationModel(Reloc::PIC_); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | //===----------------------------------------------------------------------===// |
| 76 | // Pass Pipeline Configuration |
| 77 | //===----------------------------------------------------------------------===// |
| 78 | |
Dan Gohman | e34aa77 | 2008-03-11 22:29:46 +0000 | [diff] [blame] | 79 | bool AlphaTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 80 | PM.add(createAlphaISelDag(*this)); |
| 81 | return false; |
| 82 | } |
Dan Gohman | e34aa77 | 2008-03-11 22:29:46 +0000 | [diff] [blame] | 83 | bool AlphaTargetMachine::addPreEmitPass(PassManagerBase &PM, bool Fast) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 84 | // Must run branch selection immediately preceding the asm printer |
| 85 | PM.add(createAlphaBranchSelectionPass()); |
| 86 | return false; |
| 87 | } |
Dan Gohman | e34aa77 | 2008-03-11 22:29:46 +0000 | [diff] [blame] | 88 | bool AlphaTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast, |
Owen Anderson | 847b99b | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 89 | raw_ostream &Out) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 90 | PM.add(createAlphaLLRPPass(*this)); |
| 91 | PM.add(createAlphaCodePrinterPass(Out, *this)); |
| 92 | return false; |
| 93 | } |
Dan Gohman | e34aa77 | 2008-03-11 22:29:46 +0000 | [diff] [blame] | 94 | bool AlphaTargetMachine::addCodeEmitter(PassManagerBase &PM, bool Fast, |
Evan Cheng | 7754721 | 2007-07-20 21:56:13 +0000 | [diff] [blame] | 95 | bool DumpAsm, MachineCodeEmitter &MCE) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 96 | PM.add(createAlphaCodeEmitterPass(*this, MCE)); |
Evan Cheng | 7754721 | 2007-07-20 21:56:13 +0000 | [diff] [blame] | 97 | if (DumpAsm) |
Owen Anderson | 847b99b | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 98 | PM.add(createAlphaCodePrinterPass(errs(), *this)); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 99 | return false; |
| 100 | } |
Dan Gohman | e34aa77 | 2008-03-11 22:29:46 +0000 | [diff] [blame] | 101 | bool AlphaTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM, |
Evan Cheng | 7754721 | 2007-07-20 21:56:13 +0000 | [diff] [blame] | 102 | bool Fast, bool DumpAsm, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 103 | MachineCodeEmitter &MCE) { |
Evan Cheng | 7754721 | 2007-07-20 21:56:13 +0000 | [diff] [blame] | 104 | return addCodeEmitter(PM, Fast, DumpAsm, MCE); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 105 | } |