blob: 1e922a4efd1d72d8c0854d6f848ff9d2090b71be [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,
Nick Lewycky8a8d4792011-12-02 22:16:29 +000037 const TargetOptions &Options,
Evan Chengb95fc312011-11-16 08:38:26 +000038 Reloc::Model RM, CodeModel::Model CM,
39 CodeGenOpt::Level OL)
Nick Lewycky8a8d4792011-12-02 22:16:29 +000040 : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
Evan Cheng276365d2011-06-30 01:53:36 +000041 Subtarget(TT, CPU, FS),
Scott Michel564427e2007-12-05 01:24:05 +000042 DataLayout(Subtarget.getTargetDataString()),
43 InstrInfo(*this),
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000044 FrameLowering(Subtarget),
Scott Michel564427e2007-12-05 01:24:05 +000045 TLInfo(*this),
Dan Gohmanff7a5622010-05-11 17:31:57 +000046 TSInfo(*this),
Chris Lattner09e820b2009-08-02 04:44:33 +000047 InstrItins(Subtarget.getInstrItineraryData()) {
Scott Michel564427e2007-12-05 01:24:05 +000048}
49
50//===----------------------------------------------------------------------===//
51// Pass Pipeline Configuration
52//===----------------------------------------------------------------------===//
53
Evan Chengb95fc312011-11-16 08:38:26 +000054bool SPUTargetMachine::addInstSelector(PassManagerBase &PM) {
Scott Michel564427e2007-12-05 01:24:05 +000055 // Install an instruction selector.
56 PM.add(createSPUISelDag(*this));
57 return false;
58}
Kalle Raiskila76020ed2011-01-11 09:07:54 +000059
60// passes to run just before printing the assembly
61bool SPUTargetMachine::
Evan Chengb95fc312011-11-16 08:38:26 +000062addPreEmitPass(PassManagerBase &PM) {
Kalle Raiskila67a9b1f2011-08-19 10:50:24 +000063 // load the TCE instruction scheduler, if available via
64 // loaded plugins
65 typedef llvm::FunctionPass* (*BuilderFunc)(const char*);
Benjamin Kramer0dac82d2011-08-20 02:22:42 +000066 BuilderFunc schedulerCreator =
67 (BuilderFunc)(intptr_t)sys::DynamicLibrary::SearchForAddressOfSymbol(
Kalle Raiskila67a9b1f2011-08-19 10:50:24 +000068 "createTCESchedulerPass");
69 if (schedulerCreator != NULL)
70 PM.add(schedulerCreator("cellspu"));
71
Kalle Raiskila76020ed2011-01-11 09:07:54 +000072 //align instructions with nops/lnops for dual issue
73 PM.add(createSPUNopFillerPass(*this));
74 return true;
75}