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" |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/RegAllocRegistry.h" |
| 22 | #include "llvm/CodeGen/SchedulerRegistry.h" |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 23 | |
| 24 | using namespace llvm; |
| 25 | |
Oscar Fuentes | 92adc19 | 2008-11-15 21:36:30 +0000 | [diff] [blame] | 26 | /// CellSPUTargetMachineModule - Note that this is used on hosts that |
| 27 | /// cannot link in a library unless there are references into the |
| 28 | /// library. In particular, it seems that it is not possible to get |
| 29 | /// things to work on Win32 without this. Though it is unused, do not |
| 30 | /// remove it. |
| 31 | extern "C" int CellSPUTargetMachineModule; |
| 32 | int CellSPUTargetMachineModule = 0; |
| 33 | |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 34 | namespace { |
| 35 | // Register the targets |
| 36 | RegisterTarget<SPUTargetMachine> |
Chris Lattner | 0d5d05b | 2008-10-16 06:16:50 +0000 | [diff] [blame] | 37 | CELLSPU("cellspu", "STI CBEA Cell SPU [experimental]"); |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | const std::pair<unsigned, int> * |
| 41 | SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const { |
| 42 | NumEntries = 1; |
| 43 | return &LR[0]; |
| 44 | } |
| 45 | |
| 46 | const TargetAsmInfo * |
| 47 | SPUTargetMachine::createTargetAsmInfo() const |
| 48 | { |
Scott Michel | d03eeaf | 2008-11-07 04:36:25 +0000 | [diff] [blame] | 49 | return new SPULinuxTargetAsmInfo(*this); |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | unsigned |
| 53 | SPUTargetMachine::getModuleMatchQuality(const Module &M) |
| 54 | { |
| 55 | // We strongly match "spu-*" or "cellspu-*". |
| 56 | std::string TT = M.getTargetTriple(); |
| 57 | if ((TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "spu") |
| 58 | || (TT.size() == 7 && std::string(TT.begin(), TT.begin()+7) == "cellspu") |
| 59 | || (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "spu-") |
| 60 | || (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "cellspu-")) |
| 61 | return 20; |
| 62 | |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 63 | return 0; // No match at all... |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | SPUTargetMachine::SPUTargetMachine(const Module &M, const std::string &FS) |
| 67 | : Subtarget(*this, M, FS), |
| 68 | DataLayout(Subtarget.getTargetDataString()), |
| 69 | InstrInfo(*this), |
| 70 | FrameInfo(*this), |
| 71 | TLInfo(*this), |
| 72 | InstrItins(Subtarget.getInstrItineraryData()) |
| 73 | { |
| 74 | // For the time being, use static relocations, since there's really no |
| 75 | // support for PIC yet. |
| 76 | setRelocationModel(Reloc::Static); |
| 77 | } |
| 78 | |
| 79 | //===----------------------------------------------------------------------===// |
| 80 | // Pass Pipeline Configuration |
| 81 | //===----------------------------------------------------------------------===// |
| 82 | |
| 83 | bool |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 84 | SPUTargetMachine::addInstSelector(PassManagerBase &PM, |
| 85 | CodeGenOpt::Level OptLevel) |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 86 | { |
| 87 | // Install an instruction selector. |
| 88 | PM.add(createSPUISelDag(*this)); |
| 89 | return false; |
| 90 | } |
| 91 | |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 92 | bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM, |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 93 | CodeGenOpt::Level OptLevel, |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 94 | bool Verbose, |
| 95 | raw_ostream &Out) { |
| 96 | PM.add(createSPUAsmPrinterPass(Out, *this, OptLevel, Verbose)); |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 97 | return false; |
| 98 | } |