Provide TargetMachine implementations with reference to Target they were created
[oota-llvm.git] / lib / Target / CellSPU / SPUTargetMachine.cpp
1 //===-- SPUTargetMachine.cpp - Define TargetMachine for Cell SPU ----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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 #include "llvm/CodeGen/RegAllocRegistry.h"
22 #include "llvm/CodeGen/SchedulerRegistry.h"
23
24 using namespace llvm;
25
26 extern Target TheCellSPUTarget;
27 namespace {
28   // Register the targets
29   RegisterTarget<SPUTargetMachine>
30   CELLSPU(TheCellSPUTarget, "cellspu", "STI CBEA Cell SPU [experimental]");
31 }
32
33 // No assembler printer by default
34 SPUTargetMachine::AsmPrinterCtorFn SPUTargetMachine::AsmPrinterCtor = 0;
35
36 // Force static initialization.
37 extern "C" void LLVMInitializeCellSPUTarget() { }
38
39 const std::pair<unsigned, int> *
40 SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
41   NumEntries = 1;
42   return &LR[0];
43 }
44
45 const TargetAsmInfo *
46 SPUTargetMachine::createTargetAsmInfo() const
47 {
48   return new SPULinuxTargetAsmInfo(*this);
49 }
50
51 unsigned
52 SPUTargetMachine::getModuleMatchQuality(const Module &M)
53 {
54   // We strongly match "spu-*" or "cellspu-*".
55   std::string TT = M.getTargetTriple();
56   if ((TT.size() == 3 && std::string(TT.begin(), TT.begin()+3) == "spu")
57       || (TT.size() == 7 && std::string(TT.begin(), TT.begin()+7) == "cellspu")
58       || (TT.size() >= 4 && std::string(TT.begin(), TT.begin()+4) == "spu-")
59       || (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "cellspu-"))
60     return 20;
61   
62   return 0;                     // No match at all...
63 }
64
65 SPUTargetMachine::SPUTargetMachine(const Target &T, const Module &M, 
66                                    const std::string &FS)
67   : LLVMTargetMachine(T),
68     Subtarget(*this, M, FS),
69     DataLayout(Subtarget.getTargetDataString()),
70     InstrInfo(*this),
71     FrameInfo(*this),
72     TLInfo(*this),
73     InstrItins(Subtarget.getInstrItineraryData())
74 {
75   // For the time being, use static relocations, since there's really no
76   // support for PIC yet.
77   setRelocationModel(Reloc::Static);
78 }
79
80 //===----------------------------------------------------------------------===//
81 // Pass Pipeline Configuration
82 //===----------------------------------------------------------------------===//
83
84 bool
85 SPUTargetMachine::addInstSelector(PassManagerBase &PM,
86                                   CodeGenOpt::Level OptLevel)
87 {
88   // Install an instruction selector.
89   PM.add(createSPUISelDag(*this));
90   return false;
91 }
92
93 bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
94                                           CodeGenOpt::Level OptLevel,
95                                           bool Verbose,
96                                           formatted_raw_ostream &Out) {
97   // Output assembly language.
98   assert(AsmPrinterCtor && "AsmPrinter was not linked in");
99   if (AsmPrinterCtor)
100     PM.add(AsmPrinterCtor(Out, *this, Verbose));
101   return false;
102 }