blob: 2470972ca496146b4676f0a72b3ed57073666939 [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"
Scott Michelaedc6372008-12-10 00:15:19 +000021#include "llvm/CodeGen/RegAllocRegistry.h"
22#include "llvm/CodeGen/SchedulerRegistry.h"
Scott Michel564427e2007-12-05 01:24:05 +000023
24using namespace llvm;
25
26namespace {
27 // Register the targets
28 RegisterTarget<SPUTargetMachine>
Chris Lattner0d5d05b2008-10-16 06:16:50 +000029 CELLSPU("cellspu", "STI CBEA Cell SPU [experimental]");
Scott Michel564427e2007-12-05 01:24:05 +000030}
31
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000032// No assembler printer by default
33SPUTargetMachine::AsmPrinterCtorFn SPUTargetMachine::AsmPrinterCtor = 0;
34
Bob Wilsona96751f2009-06-23 23:59:40 +000035// Force static initialization.
36extern "C" void LLVMInitializeCellSPUTarget() { }
Douglas Gregor1555a232009-06-16 20:12:29 +000037
Scott Michel564427e2007-12-05 01:24:05 +000038const 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
Bill Wendling98a366d2009-04-29 23:29:43 +000082SPUTargetMachine::addInstSelector(PassManagerBase &PM,
83 CodeGenOpt::Level OptLevel)
Scott Michel564427e2007-12-05 01:24:05 +000084{
85 // Install an instruction selector.
86 PM.add(createSPUISelDag(*this));
87 return false;
88}
89
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000090bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000091 CodeGenOpt::Level OptLevel,
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000092 bool Verbose,
93 raw_ostream &Out) {
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000094 // Output assembly language.
95 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
96 if (AsmPrinterCtor)
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +000097 PM.add(AsmPrinterCtor(Out, *this, Verbose));
Scott Michel564427e2007-12-05 01:24:05 +000098 return false;
99}