blob: 69403160ac0a79b876c31cf4d5a00bd16dd6ed90 [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"
Scott Michel564427e2007-12-05 01:24:05 +000015#include "SPUTargetMachine.h"
Scott Michel564427e2007-12-05 01:24:05 +000016#include "llvm/PassManager.h"
Scott Michelaedc6372008-12-10 00:15:19 +000017#include "llvm/CodeGen/RegAllocRegistry.h"
18#include "llvm/CodeGen/SchedulerRegistry.h"
Kalle Raiskila67a9b1f2011-08-19 10:50:24 +000019#include "llvm/Support/DynamicLibrary.h"
Evan Cheng3e74d6f2011-08-24 18:08:43 +000020#include "llvm/Support/TargetRegistry.h"
Scott Michel564427e2007-12-05 01:24:05 +000021
22using namespace llvm;
23
Daniel Dunbar0c795d62009-07-25 06:49:55 +000024extern "C" void LLVMInitializeCellSPUTarget() {
25 // Register the target.
26 RegisterTargetMachine<SPUTargetMachine> X(TheCellSPUTarget);
Scott Michel564427e2007-12-05 01:24:05 +000027}
28
29const std::pair<unsigned, int> *
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000030SPUFrameLowering::getCalleeSaveSpillSlots(unsigned &NumEntries) const {
Scott Michel564427e2007-12-05 01:24:05 +000031 NumEntries = 1;
32 return &LR[0];
33}
34
Evan Cheng43966132011-07-19 06:37:02 +000035SPUTargetMachine::SPUTargetMachine(const Target &T, StringRef TT,
Evan Cheng34ad6db2011-07-20 07:51:56 +000036 StringRef CPU, StringRef FS,
Evan Chengb95fc312011-11-16 08:38:26 +000037 Reloc::Model RM, CodeModel::Model CM,
38 CodeGenOpt::Level OL)
39 : LLVMTargetMachine(T, TT, CPU, FS, RM, CM, OL),
Evan Cheng276365d2011-06-30 01:53:36 +000040 Subtarget(TT, CPU, FS),
Scott Michel564427e2007-12-05 01:24:05 +000041 DataLayout(Subtarget.getTargetDataString()),
42 InstrInfo(*this),
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000043 FrameLowering(Subtarget),
Scott Michel564427e2007-12-05 01:24:05 +000044 TLInfo(*this),
Dan Gohmanff7a5622010-05-11 17:31:57 +000045 TSInfo(*this),
Chris Lattner09e820b2009-08-02 04:44:33 +000046 InstrItins(Subtarget.getInstrItineraryData()) {
Scott Michel564427e2007-12-05 01:24:05 +000047}
48
49//===----------------------------------------------------------------------===//
50// Pass Pipeline Configuration
51//===----------------------------------------------------------------------===//
52
Evan Chengb95fc312011-11-16 08:38:26 +000053bool SPUTargetMachine::addInstSelector(PassManagerBase &PM) {
Scott Michel564427e2007-12-05 01:24:05 +000054 // Install an instruction selector.
55 PM.add(createSPUISelDag(*this));
56 return false;
57}
Kalle Raiskila76020ed2011-01-11 09:07:54 +000058
59// passes to run just before printing the assembly
60bool SPUTargetMachine::
Evan Chengb95fc312011-11-16 08:38:26 +000061addPreEmitPass(PassManagerBase &PM) {
Kalle Raiskila67a9b1f2011-08-19 10:50:24 +000062 // load the TCE instruction scheduler, if available via
63 // loaded plugins
64 typedef llvm::FunctionPass* (*BuilderFunc)(const char*);
Benjamin Kramer0dac82d2011-08-20 02:22:42 +000065 BuilderFunc schedulerCreator =
66 (BuilderFunc)(intptr_t)sys::DynamicLibrary::SearchForAddressOfSymbol(
Kalle Raiskila67a9b1f2011-08-19 10:50:24 +000067 "createTCESchedulerPass");
68 if (schedulerCreator != NULL)
69 PM.add(schedulerCreator("cellspu"));
70
Kalle Raiskila76020ed2011-01-11 09:07:54 +000071 //align instructions with nops/lnops for dual issue
72 PM.add(createSPUNopFillerPass(*this));
73 return true;
74}