Move target independent td files from lib/Target/ to include/llvm/Target so they...
[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
22 using namespace llvm;
23
24 /// CellSPUTargetMachineModule - Note that this is used on hosts that
25 /// cannot link in a library unless there are references into the
26 /// library.  In particular, it seems that it is not possible to get
27 /// things to work on Win32 without this.  Though it is unused, do not
28 /// remove it.
29 extern "C" int CellSPUTargetMachineModule;
30 int CellSPUTargetMachineModule = 0;
31
32 namespace {
33   // Register the targets
34   RegisterTarget<SPUTargetMachine>
35   CELLSPU("cellspu", "STI CBEA Cell SPU [experimental]");
36 }
37
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 {
47   return new SPULinuxTargetAsmInfo(*this);
48 }
49
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),
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
82 SPUTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast)
83 {
84   // Install an instruction selector.
85   PM.add(createSPUISelDag(*this));
86   return false;
87 }
88
89 bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast, 
90                                           raw_ostream &Out) {
91   PM.add(createSPUAsmPrinterPass(Out, *this));
92   return false;
93 }