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 | |
| 26 | namespace { |
| 27 | // Register the targets |
| 28 | RegisterTarget<SPUTargetMachine> |
Stuart Hastings | 2286f8d | 2009-07-15 17:27:11 +0000 | [diff] [blame^] | 29 | CELLSPU("cellspu", "STI CBEA Cell SPU [experimental]"); |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Anton Korobeynikov | e494b9e | 2009-06-19 19:36:55 +0000 | [diff] [blame] | 32 | // No assembler printer by default |
| 33 | SPUTargetMachine::AsmPrinterCtorFn SPUTargetMachine::AsmPrinterCtor = 0; |
| 34 | |
Bob Wilson | a96751f | 2009-06-23 23:59:40 +0000 | [diff] [blame] | 35 | // Force static initialization. |
| 36 | extern "C" void LLVMInitializeCellSPUTarget() { } |
Douglas Gregor | 1555a23 | 2009-06-16 20:12:29 +0000 | [diff] [blame] | 37 | |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 38 | const std::pair<unsigned, int> * |
| 39 | SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const { |
| 40 | NumEntries = 1; |
| 41 | return &LR[0]; |
| 42 | } |
| 43 | |
| 44 | const TargetAsmInfo * |
| 45 | SPUTargetMachine::createTargetAsmInfo() const |
| 46 | { |
Scott Michel | d03eeaf | 2008-11-07 04:36:25 +0000 | [diff] [blame] | 47 | return new SPULinuxTargetAsmInfo(*this); |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Stuart Hastings | 2286f8d | 2009-07-15 17:27:11 +0000 | [diff] [blame^] | 50 | unsigned |
| 51 | SPUTargetMachine::getModuleMatchQuality(const Module &M) |
| 52 | { |
| 53 | // We strongly match "spu-*" or "cellspu-*". |
| 54 | std::string TT = M.getTargetTriple(); |
| 55 | if ((TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "spu") |
| 56 | || (TT.size() == 7 && std::string(TT.begin(), TT.begin()+7) == "cellspu") |
| 57 | || (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "spu-") |
| 58 | || (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "cellspu-")) |
| 59 | return 20; |
| 60 | |
| 61 | return 0; // No match at all... |
| 62 | } |
| 63 | |
| 64 | SPUTargetMachine::SPUTargetMachine(const Module &M, const std::string &FS) |
| 65 | : Subtarget(*this, M, FS), |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 66 | DataLayout(Subtarget.getTargetDataString()), |
| 67 | InstrInfo(*this), |
| 68 | FrameInfo(*this), |
| 69 | TLInfo(*this), |
| 70 | InstrItins(Subtarget.getInstrItineraryData()) |
| 71 | { |
| 72 | // For the time being, use static relocations, since there's really no |
| 73 | // support for PIC yet. |
| 74 | setRelocationModel(Reloc::Static); |
| 75 | } |
| 76 | |
| 77 | //===----------------------------------------------------------------------===// |
| 78 | // Pass Pipeline Configuration |
| 79 | //===----------------------------------------------------------------------===// |
| 80 | |
| 81 | bool |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 82 | SPUTargetMachine::addInstSelector(PassManagerBase &PM, |
| 83 | CodeGenOpt::Level OptLevel) |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 84 | { |
| 85 | // Install an instruction selector. |
| 86 | PM.add(createSPUISelDag(*this)); |
| 87 | return false; |
| 88 | } |
| 89 | |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 90 | bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM, |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 91 | CodeGenOpt::Level OptLevel, |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 92 | bool Verbose, |
David Greene | 7184781 | 2009-07-14 20:18:05 +0000 | [diff] [blame] | 93 | formatted_raw_ostream &Out) { |
Anton Korobeynikov | e494b9e | 2009-06-19 19:36:55 +0000 | [diff] [blame] | 94 | // Output assembly language. |
| 95 | assert(AsmPrinterCtor && "AsmPrinter was not linked in"); |
| 96 | if (AsmPrinterCtor) |
Daniel Dunbar | 5bcc8bd | 2009-07-01 01:48:54 +0000 | [diff] [blame] | 97 | PM.add(AsmPrinterCtor(Out, *this, Verbose)); |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 98 | return false; |
| 99 | } |