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" |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 15 | #include "SPUTargetMachine.h" |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 16 | #include "llvm/PassManager.h" |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/RegAllocRegistry.h" |
| 18 | #include "llvm/CodeGen/SchedulerRegistry.h" |
Daniel Dunbar | 0c795d6 | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetRegistry.h" |
Kalle Raiskila | 67a9b1f | 2011-08-19 10:50:24 +0000 | [diff] [blame] | 20 | #include "llvm/Support/DynamicLibrary.h" |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace llvm; |
| 23 | |
Daniel Dunbar | 0c795d6 | 2009-07-25 06:49:55 +0000 | [diff] [blame] | 24 | extern "C" void LLVMInitializeCellSPUTarget() { |
| 25 | // Register the target. |
| 26 | RegisterTargetMachine<SPUTargetMachine> X(TheCellSPUTarget); |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | const std::pair<unsigned, int> * |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 30 | SPUFrameLowering::getCalleeSaveSpillSlots(unsigned &NumEntries) const { |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 31 | NumEntries = 1; |
| 32 | return &LR[0]; |
| 33 | } |
| 34 | |
Evan Cheng | 4396613 | 2011-07-19 06:37:02 +0000 | [diff] [blame] | 35 | SPUTargetMachine::SPUTargetMachine(const Target &T, StringRef TT, |
Evan Cheng | 34ad6db | 2011-07-20 07:51:56 +0000 | [diff] [blame] | 36 | StringRef CPU, StringRef FS, |
| 37 | Reloc::Model RM, CodeModel::Model CM) |
| 38 | : LLVMTargetMachine(T, TT, CPU, FS, RM, CM), |
Evan Cheng | 276365d | 2011-06-30 01:53:36 +0000 | [diff] [blame] | 39 | Subtarget(TT, CPU, FS), |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 40 | DataLayout(Subtarget.getTargetDataString()), |
| 41 | InstrInfo(*this), |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 42 | FrameLowering(Subtarget), |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 43 | TLInfo(*this), |
Dan Gohman | ff7a562 | 2010-05-11 17:31:57 +0000 | [diff] [blame] | 44 | TSInfo(*this), |
Chris Lattner | 09e820b | 2009-08-02 04:44:33 +0000 | [diff] [blame] | 45 | InstrItins(Subtarget.getInstrItineraryData()) { |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | //===----------------------------------------------------------------------===// |
| 49 | // Pass Pipeline Configuration |
| 50 | //===----------------------------------------------------------------------===// |
| 51 | |
Chris Lattner | 09e820b | 2009-08-02 04:44:33 +0000 | [diff] [blame] | 52 | bool SPUTargetMachine::addInstSelector(PassManagerBase &PM, |
| 53 | CodeGenOpt::Level OptLevel) { |
Scott Michel | 564427e | 2007-12-05 01:24:05 +0000 | [diff] [blame] | 54 | // Install an instruction selector. |
| 55 | PM.add(createSPUISelDag(*this)); |
| 56 | return false; |
| 57 | } |
Kalle Raiskila | 76020ed | 2011-01-11 09:07:54 +0000 | [diff] [blame] | 58 | |
| 59 | // passes to run just before printing the assembly |
| 60 | bool SPUTargetMachine:: |
Benjamin Kramer | 0dac82d | 2011-08-20 02:22:42 +0000 | [diff] [blame] | 61 | addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel) { |
Kalle Raiskila | 67a9b1f | 2011-08-19 10:50:24 +0000 | [diff] [blame] | 62 | // load the TCE instruction scheduler, if available via |
| 63 | // loaded plugins |
| 64 | typedef llvm::FunctionPass* (*BuilderFunc)(const char*); |
Benjamin Kramer | 0dac82d | 2011-08-20 02:22:42 +0000 | [diff] [blame] | 65 | BuilderFunc schedulerCreator = |
| 66 | (BuilderFunc)(intptr_t)sys::DynamicLibrary::SearchForAddressOfSymbol( |
Kalle Raiskila | 67a9b1f | 2011-08-19 10:50:24 +0000 | [diff] [blame] | 67 | "createTCESchedulerPass"); |
| 68 | if (schedulerCreator != NULL) |
| 69 | PM.add(schedulerCreator("cellspu")); |
| 70 | |
Kalle Raiskila | 76020ed | 2011-01-11 09:07:54 +0000 | [diff] [blame] | 71 | //align instructions with nops/lnops for dual issue |
| 72 | PM.add(createSPUNopFillerPass(*this)); |
| 73 | return true; |
| 74 | } |