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" |
| 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 | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 29 | namespace llvm { |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 30 | cl::opt<bool> EnableAlphaLSR("enable-lsr-for-alpha", |
| 31 | cl::desc("Enable LSR for Alpha (beta option!)"), |
Andrew Lenharth | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 32 | cl::Hidden); |
| 33 | } |
| 34 | |
Andrew Lenharth | 2f40163 | 2005-02-01 20:35:11 +0000 | [diff] [blame] | 35 | unsigned AlphaTargetMachine::getModuleMatchQuality(const Module &M) { |
| 36 | // We strongly match "alpha*". |
| 37 | std::string TT = M.getTargetTriple(); |
| 38 | if (TT.size() >= 5 && TT[0] == 'a' && TT[1] == 'l' && TT[2] == 'p' && |
| 39 | TT[3] == 'h' && TT[4] == 'a') |
| 40 | return 20; |
| 41 | |
| 42 | if (M.getEndianness() == Module::LittleEndian && |
| 43 | M.getPointerSize() == Module::Pointer64) |
| 44 | return 10; // Weak match |
| 45 | else if (M.getEndianness() != Module::AnyEndianness || |
| 46 | M.getPointerSize() != Module::AnyPointerSize) |
| 47 | return 0; // Match for some other target |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 52 | AlphaTargetMachine::AlphaTargetMachine( const Module &M, IntrinsicLowering *IL) |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 53 | : TargetMachine("alpha", IL, true), |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 54 | FrameInfo(TargetFrameInfo::StackGrowsDown, 8, 0) //TODO: check these |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 55 | {} |
| 56 | |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame^] | 57 | /// addPassesToEmitFile - Add passes to the specified pass manager to implement |
| 58 | /// a static compiler for this target. |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 59 | /// |
Chris Lattner | 0431c96 | 2005-06-25 02:48:37 +0000 | [diff] [blame^] | 60 | bool AlphaTargetMachine::addPassesToEmitFile(PassManager &PM, |
| 61 | std::ostream &Out, |
| 62 | CodeGenFileType FileType) { |
| 63 | if (FileType != TargetMachine::AssemblyFile) return true; |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 64 | |
Andrew Lenharth | f3f475e | 2005-03-03 19:03:21 +0000 | [diff] [blame] | 65 | if (EnableAlphaLSR) { |
Andrew Lenharth | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 66 | PM.add(createLoopStrengthReducePass()); |
Andrew Lenharth | f3f475e | 2005-03-03 19:03:21 +0000 | [diff] [blame] | 67 | PM.add(createCFGSimplificationPass()); |
| 68 | } |
Andrew Lenharth | e4f161c | 2005-03-02 17:21:38 +0000 | [diff] [blame] | 69 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 70 | // FIXME: Implement efficient support for garbage collection intrinsics. |
| 71 | PM.add(createLowerGCPass()); |
| 72 | |
| 73 | // FIXME: Implement the invoke/unwind instructions! |
| 74 | PM.add(createLowerInvokePass()); |
| 75 | |
| 76 | // FIXME: Implement the switch instruction in the instruction selector! |
| 77 | PM.add(createLowerSwitchPass()); |
| 78 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 79 | // Make sure that no unreachable blocks are instruction selected. |
| 80 | PM.add(createUnreachableBlockEliminationPass()); |
| 81 | |
| 82 | PM.add(createAlphaPatternInstructionSelector(*this)); |
| 83 | |
| 84 | if (PrintMachineCode) |
| 85 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 86 | |
| 87 | PM.add(createRegisterAllocator()); |
| 88 | |
| 89 | if (PrintMachineCode) |
| 90 | PM.add(createMachineFunctionPrinterPass(&std::cerr)); |
| 91 | |
| 92 | PM.add(createPrologEpilogCodeInserter()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 93 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 94 | // Must run branch selection immediately preceding the asm printer |
| 95 | //PM.add(createAlphaBranchSelectionPass()); |
Misha Brukman | 4633f1c | 2005-04-21 23:13:11 +0000 | [diff] [blame] | 96 | |
Andrew Lenharth | 304d0f3 | 2005-01-22 23:41:55 +0000 | [diff] [blame] | 97 | PM.add(createAlphaCodePrinterPass(Out, *this)); |
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 | PM.add(createMachineCodeDeleter()); |
| 100 | return false; |
| 101 | } |