Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 1 | //===-- SPUTargetMachine.cpp - Define TargetMachine for Cell SPU ----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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. |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Top-level implementation for the Cell SPU target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SPU.h" |
| 15 | #include "SPURegisterNames.h" |
| 16 | #include "SPUTargetAsmInfo.h" |
| 17 | #include "SPUTargetMachine.h" |
| 18 | #include "llvm/Module.h" |
| 19 | #include "llvm/PassManager.h" |
| 20 | #include "llvm/Target/TargetMachineRegistry.h" |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
| 24 | namespace { |
| 25 | // Register the targets |
| 26 | RegisterTarget<SPUTargetMachine> |
Chris Lattner | 0d5d05b | 2008-10-16 06:16:50 +0000 | [diff] [blame] | 27 | CELLSPU("cellspu", "STI CBEA Cell SPU [experimental]"); |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | const std::pair<unsigned, int> * |
| 31 | SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const { |
| 32 | NumEntries = 1; |
| 33 | return &LR[0]; |
| 34 | } |
| 35 | |
| 36 | const TargetAsmInfo * |
| 37 | SPUTargetMachine::createTargetAsmInfo() const |
| 38 | { |
| 39 | return new SPUTargetAsmInfo(*this); |
| 40 | } |
| 41 | |
| 42 | unsigned |
| 43 | SPUTargetMachine::getModuleMatchQuality(const Module &M) |
| 44 | { |
| 45 | // We strongly match "spu-*" or "cellspu-*". |
| 46 | std::string TT = M.getTargetTriple(); |
| 47 | if ((TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "spu") |
| 48 | || (TT.size() == 7 && std::string(TT.begin(), TT.begin()+7) == "cellspu") |
| 49 | || (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "spu-") |
| 50 | || (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "cellspu-")) |
| 51 | return 20; |
| 52 | |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 53 | return 0; // No match at all... |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | SPUTargetMachine::SPUTargetMachine(const Module &M, const std::string &FS) |
| 57 | : Subtarget(*this, M, FS), |
| 58 | DataLayout(Subtarget.getTargetDataString()), |
| 59 | InstrInfo(*this), |
| 60 | FrameInfo(*this), |
| 61 | TLInfo(*this), |
| 62 | InstrItins(Subtarget.getInstrItineraryData()) |
| 63 | { |
| 64 | // For the time being, use static relocations, since there's really no |
| 65 | // support for PIC yet. |
| 66 | setRelocationModel(Reloc::Static); |
| 67 | } |
| 68 | |
| 69 | //===----------------------------------------------------------------------===// |
| 70 | // Pass Pipeline Configuration |
| 71 | //===----------------------------------------------------------------------===// |
| 72 | |
| 73 | bool |
Dan Gohman | bfae831 | 2008-03-11 22:29:46 +0000 | [diff] [blame] | 74 | SPUTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 75 | { |
| 76 | // Install an instruction selector. |
| 77 | PM.add(createSPUISelDag(*this)); |
| 78 | return false; |
| 79 | } |
| 80 | |
Dan Gohman | bfae831 | 2008-03-11 22:29:46 +0000 | [diff] [blame] | 81 | bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast, |
Owen Anderson | cb37188 | 2008-08-21 00:14:44 +0000 | [diff] [blame] | 82 | raw_ostream &Out) { |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 83 | PM.add(createSPUAsmPrinterPass(Out, *this)); |
| 84 | return false; |
| 85 | } |