Andrew Lenharth | 886470e | 2005-01-24 18:45:41 +0000 | [diff] [blame] | 1 | //===-- AlphaTargetMachine.cpp - Define TargetMachine for Alpha -----------===// |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 2 | // |
| 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. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "Alpha.h" |
| 14 | #include "AlphaTargetMachine.h" |
Andrew Lenharth | 2f40163 | 2005-02-01 20:35:11 +0000 | [diff] [blame] | 15 | #include "llvm/Module.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/Passes.h" |
| 17 | #include "llvm/Target/TargetOptions.h" |
| 18 | #include "llvm/Target/TargetMachineRegistry.h" |
| 19 | #include "llvm/Transforms/Scalar.h" |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 20 | #include <iostream> |
Andrew Lenharth | 2f40163 | 2005-02-01 20:35:11 +0000 | [diff] [blame] | 21 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
| 24 | namespace { |
| 25 | // Register the targets |
| 26 | RegisterTarget<AlphaTargetMachine> X("alpha", " Alpha (incomplete)"); |
| 27 | } |
| 28 | |
Andrew Lenharth | 2f40163 | 2005-02-01 20:35:11 +0000 | [diff] [blame] | 29 | unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) { |
| 30 | // We strongly match "alpha*". |
| 31 | std::string TT = M.getTargetTriple(); |
| 32 | if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' && |
| 33 | TT[3] == 'h' && TT[4] == 'a') |
| 34 | return 20; |
| 35 | |
| 36 | if (M.getEndianness() == Module::LittleEndian && |
| 37 | M.getPointerSize() == Module::Pointer64) |
| 38 | return 10; // Weak match |
| 39 | else if (M.getEndianness() != Module::AnyEndianness || |
| 40 | M.getPointerSize() != Module::AnyPointerSize) |
| 41 | return 0; // Match for some other target |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 46 | AlphaTargetMachine::AlphaTargetMachine( const Module &M, IntrinsicLowering *IL) |
| 47 | : TargetMachine("alpha", IL, true), |
| 48 | FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) //TODO: check these |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 49 | {} |
| 50 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 51 | /// addPassesToEmitAssembly - Add passes to the specified pass manager |
| 52 | /// to implement a static compiler for this target. |
| 53 | /// |
| 54 | bool AlphaTargetMachine::addPassesToEmitAssembly(PassManager &PM, |
| 55 | std::ostream &Out) { |
| 56 | |
| 57 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 58 | PM.add(createLowerGCPass()); |
| 59 | |
| 60 | // FIXME: Implement the invoke/unwind instructions! |
| 61 | PM.add(createLowerInvokePass()); |
| 62 | |
| 63 | // FIXME: Implement the switch instruction in the instruction selector! |
| 64 | PM.add(createLowerSwitchPass()); |
| 65 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 66 | // Make sure that no unreachable blocks are instruction selected. |
| 67 | PM.add(createUnreachableBlockEliminationPass()); |
| 68 | |
| 69 | PM.add(createAlphaPatternInstructionSelector(*this)); |
| 70 | |
| 71 | if (PrintMachineCode) |
| 72 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 73 | |
| 74 | PM.add(createRegisterAllocator()); |
| 75 | |
| 76 | if (PrintMachineCode) |
| 77 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 78 | |
| 79 | PM.add(createPrologEpilogCodeInserter()); |
| 80 | |
| 81 | // Must run branch selection immediately preceding the asm printer |
| 82 | //PM.add(createAlphaBranchSelectionPass()); |
| 83 | |
| 84 | PM.add(createAlphaCodePrinterPass(Out, *this)); |
| 85 | |
| 86 | PM.add(createMachineCodeDeleter()); |
| 87 | return false; |
| 88 | } |