blob: 8c74385a7ed93093d6b2f0157c1e445e2cdcdff3 [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
Daniel Dunbar42467902009-07-15 09:22:31 +000026extern Target TheCellSPUTarget;
Scott Michel564427e2007-12-05 01:24:05 +000027namespace {
28 // Register the targets
29 RegisterTarget<SPUTargetMachine>
Daniel Dunbar42467902009-07-15 09:22:31 +000030 CELLSPU(TheCellSPUTarget, "cellspu", "STI CBEA Cell SPU [experimental]");
Scott Michel564427e2007-12-05 01:24:05 +000031}
32
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000033// No assembler printer by default
34SPUTargetMachine::AsmPrinterCtorFn SPUTargetMachine::AsmPrinterCtor = 0;
35
Bob Wilsona96751f2009-06-23 23:59:40 +000036// Force static initialization.
37extern "C" void LLVMInitializeCellSPUTarget() { }
Douglas Gregor1555a232009-06-16 20:12:29 +000038
Scott Michel564427e2007-12-05 01:24:05 +000039const std::pair<unsigned, int> *
40SPUFrameInfo::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
41 NumEntries = 1;
42 return &LR[0];
43}
44
45const TargetAsmInfo *
46SPUTargetMachine::createTargetAsmInfo() const
47{
Scott Micheld03eeaf2008-11-07 04:36:25 +000048 return new SPULinuxTargetAsmInfo(*this);
Scott Michel564427e2007-12-05 01:24:05 +000049}
50
51unsigned
52SPUTargetMachine::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
Scott Michel7f9ba9b2008-01-30 02:55:46 +000062 return 0; // No match at all...
Scott Michel564427e2007-12-05 01:24:05 +000063}
64
Daniel Dunbar03f4bc52009-07-15 12:11:05 +000065SPUTargetMachine::SPUTargetMachine(const Target &T, const Module &M,
66 const std::string &FS)
67 : LLVMTargetMachine(T),
68 Subtarget(*this, M, FS),
Scott Michel564427e2007-12-05 01:24:05 +000069 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
84bool
Bill Wendling98a366d2009-04-29 23:29:43 +000085SPUTargetMachine::addInstSelector(PassManagerBase &PM,
86 CodeGenOpt::Level OptLevel)
Scott Michel564427e2007-12-05 01:24:05 +000087{
88 // Install an instruction selector.
89 PM.add(createSPUISelDag(*this));
90 return false;
91}
92
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000093bool SPUTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +000094 CodeGenOpt::Level OptLevel,
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000095 bool Verbose,
David Greene71847812009-07-14 20:18:05 +000096 formatted_raw_ostream &Out) {
Anton Korobeynikove494b9e2009-06-19 19:36:55 +000097 // Output assembly language.
98 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
99 if (AsmPrinterCtor)
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +0000100 PM.add(AsmPrinterCtor(Out, *this, Verbose));
Scott Michel564427e2007-12-05 01:24:05 +0000101 return false;
102}