1 //===-- SPUTargetMachine.cpp - Define TargetMachine for Cell SPU ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Top-level implementation for the Cell SPU target.
12 //===----------------------------------------------------------------------===//
14 #include "SPUTargetMachine.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/CodeGen/SchedulerRegistry.h"
18 #include "llvm/Support/DynamicLibrary.h"
19 #include "llvm/Support/TargetRegistry.h"
23 extern "C" void LLVMInitializeCellSPUTarget() {
24 // Register the target.
25 RegisterTargetMachine<SPUTargetMachine> X(TheCellSPUTarget);
28 const std::pair<unsigned, int> *
29 SPUFrameLowering::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
34 SPUTargetMachine::SPUTargetMachine(const Target &T, StringRef TT,
35 StringRef CPU, StringRef FS,
36 const TargetOptions &Options,
37 Reloc::Model RM, CodeModel::Model CM,
39 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
40 Subtarget(TT, CPU, FS),
41 DL(Subtarget.getDataLayoutString()),
43 FrameLowering(Subtarget),
46 InstrItins(Subtarget.getInstrItineraryData()),
50 //===----------------------------------------------------------------------===//
51 // Pass Pipeline Configuration
52 //===----------------------------------------------------------------------===//
55 /// SPU Code Generator Pass Configuration Options.
56 class SPUPassConfig : public TargetPassConfig {
58 SPUPassConfig(SPUTargetMachine *TM, PassManagerBase &PM)
59 : TargetPassConfig(TM, PM) {}
61 SPUTargetMachine &getSPUTargetMachine() const {
62 return getTM<SPUTargetMachine>();
65 virtual bool addInstSelector();
66 virtual bool addPreEmitPass();
70 TargetPassConfig *SPUTargetMachine::createPassConfig(PassManagerBase &PM) {
71 return new SPUPassConfig(this, PM);
74 bool SPUPassConfig::addInstSelector() {
75 // Install an instruction selector.
76 addPass(createSPUISelDag(getSPUTargetMachine()));
80 // passes to run just before printing the assembly
81 bool SPUPassConfig::addPreEmitPass() {
82 // load the TCE instruction scheduler, if available via
84 typedef llvm::FunctionPass* (*BuilderFunc)(const char*);
85 BuilderFunc schedulerCreator =
86 (BuilderFunc)(intptr_t)sys::DynamicLibrary::SearchForAddressOfSymbol(
87 "createTCESchedulerPass");
88 if (schedulerCreator != NULL)
89 addPass(schedulerCreator("cellspu"));
91 //align instructions with nops/lnops for dual issue
92 addPass(createSPUNopFillerPass(getSPUTargetMachine()));