blob: 48b85832e5824d4ff4c7bb1bf2e4ad8664681430 [file] [log] [blame]
Scott Michel564427e2007-12-05 01:24:05 +00001//===-- SPUTargetMachine.cpp - Define TargetMachine for Cell SPU ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Scott Michel564427e2007-12-05 01:24:05 +00007//
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
22using namespace llvm;
23
Oscar Fuentes92adc192008-11-15 21:36:30 +000024/// 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.
29extern "C" int CellSPUTargetMachineModule;
30int CellSPUTargetMachineModule = 0;
31
Scott Michel564427e2007-12-05 01:24:05 +000032namespace {
33 // Register the targets
34 RegisterTarget<SPUTargetMachine>
Chris Lattner0d5d05b2008-10-16 06:16:50 +000035 CELLSPU("cellspu", "STI CBEA Cell SPU [experimental]");
Scott Michel564427e2007-12-05 01:24:05 +000036}
37
38const std::pair<unsigned, int> *
39SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
40 NumEntries = 1;
41 return &LR[0];
42}
43
44const TargetAsmInfo *
45SPUTargetMachine::createTargetAsmInfo() const
46{
Scott Micheld03eeaf2008-11-07 04:36:25 +000047 return new SPULinuxTargetAsmInfo(*this);
Scott Michel564427e2007-12-05 01:24:05 +000048}
49
50unsigned
51SPUTargetMachine::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
Scott Michel7f9ba9b2008-01-30 02:55:46 +000061 return 0; // No match at all...
Scott Michel564427e2007-12-05 01:24:05 +000062}
63
64SPUTargetMachine::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
81bool
Dan Gohmanbfae8312008-03-11 22:29:46 +000082SPUTargetMachine::addInstSelector(PassManagerBase &PM, bool Fast)
Scott Michel564427e2007-12-05 01:24:05 +000083{
84 // Install an instruction selector.
85 PM.add(createSPUISelDag(*this));
86 return false;
87}
88
Dan Gohmanbfae8312008-03-11 22:29:46 +000089bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM, bool Fast,
Owen Andersoncb371882008-08-21 00:14:44 +000090 raw_ostream &Out) {
Scott Michel564427e2007-12-05 01:24:05 +000091 PM.add(createSPUAsmPrinterPass(Out, *this));
92 return false;
93}