2012-05-04 20:18:50 +00:00
|
|
|
//===-- NVPTXTargetMachine.cpp - Define TargetMachine for NVPTX -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Top-level implementation for the NVPTX target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "NVPTXTargetMachine.h"
|
|
|
|
#include "MCTargetDesc/NVPTXMCAsmInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "NVPTX.h"
|
2012-05-04 20:18:50 +00:00
|
|
|
#include "NVPTXAllocaHoisting.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "NVPTXLowerAggrCopies.h"
|
|
|
|
#include "NVPTXSplitBBatBar.h"
|
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
2012-05-04 20:18:50 +00:00
|
|
|
#include "llvm/Analysis/Passes.h"
|
|
|
|
#include "llvm/Analysis/Verifier.h"
|
|
|
|
#include "llvm/Assembly/PrintModulePass.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2012-05-04 20:18:50 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/PassManager.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2012-05-04 20:18:50 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/Target/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/Target/TargetSubtargetInfo.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2013-03-30 14:29:25 +00:00
|
|
|
namespace llvm {
|
|
|
|
void initializeNVVMReflectPass(PassRegistry&);
|
2013-05-20 12:13:32 +00:00
|
|
|
void initializeGenericToNVVMPass(PassRegistry&);
|
2013-03-30 14:29:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 20:18:50 +00:00
|
|
|
extern "C" void LLVMInitializeNVPTXTarget() {
|
|
|
|
// Register the target.
|
|
|
|
RegisterTargetMachine<NVPTXTargetMachine32> X(TheNVPTXTarget32);
|
|
|
|
RegisterTargetMachine<NVPTXTargetMachine64> Y(TheNVPTXTarget64);
|
|
|
|
|
|
|
|
RegisterMCAsmInfo<NVPTXMCAsmInfo> A(TheNVPTXTarget32);
|
|
|
|
RegisterMCAsmInfo<NVPTXMCAsmInfo> B(TheNVPTXTarget64);
|
|
|
|
|
2013-03-30 14:29:25 +00:00
|
|
|
// FIXME: This pass is really intended to be invoked during IR optimization,
|
|
|
|
// but it's very NVPTX-specific.
|
|
|
|
initializeNVVMReflectPass(*PassRegistry::getPassRegistry());
|
2013-05-20 12:13:32 +00:00
|
|
|
initializeGenericToNVVMPass(*PassRegistry::getPassRegistry());
|
2012-05-04 20:18:50 +00:00
|
|
|
}
|
|
|
|
|
2013-03-30 14:29:21 +00:00
|
|
|
NVPTXTargetMachine::NVPTXTargetMachine(
|
|
|
|
const Target &T, StringRef TT, StringRef CPU, StringRef FS,
|
|
|
|
const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL, bool is64bit)
|
|
|
|
: LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
|
|
|
|
Subtarget(TT, CPU, FS, is64bit), DL(Subtarget.getDataLayout()),
|
|
|
|
InstrInfo(*this), TLInfo(*this), TSInfo(*this),
|
|
|
|
FrameLowering(
|
2013-05-13 01:16:13 +00:00
|
|
|
*this, is64bit) /*FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0)*/ {
|
|
|
|
initAsmInfo();
|
|
|
|
}
|
2012-05-04 20:18:50 +00:00
|
|
|
|
|
|
|
void NVPTXTargetMachine32::anchor() {}
|
|
|
|
|
2013-03-30 14:29:21 +00:00
|
|
|
NVPTXTargetMachine32::NVPTXTargetMachine32(
|
|
|
|
const Target &T, StringRef TT, StringRef CPU, StringRef FS,
|
|
|
|
const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
|
|
|
: NVPTXTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {}
|
2012-05-04 20:18:50 +00:00
|
|
|
|
|
|
|
void NVPTXTargetMachine64::anchor() {}
|
|
|
|
|
2013-03-30 14:29:21 +00:00
|
|
|
NVPTXTargetMachine64::NVPTXTargetMachine64(
|
|
|
|
const Target &T, StringRef TT, StringRef CPU, StringRef FS,
|
|
|
|
const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL)
|
|
|
|
: NVPTXTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {}
|
2012-05-04 20:18:50 +00:00
|
|
|
|
2013-05-23 17:10:37 +00:00
|
|
|
namespace {
|
2012-05-04 20:18:50 +00:00
|
|
|
class NVPTXPassConfig : public TargetPassConfig {
|
|
|
|
public:
|
|
|
|
NVPTXPassConfig(NVPTXTargetMachine *TM, PassManagerBase &PM)
|
2013-03-30 14:29:21 +00:00
|
|
|
: TargetPassConfig(TM, PM) {}
|
2012-05-04 20:18:50 +00:00
|
|
|
|
|
|
|
NVPTXTargetMachine &getNVPTXTargetMachine() const {
|
|
|
|
return getTM<NVPTXTargetMachine>();
|
|
|
|
}
|
|
|
|
|
2013-05-20 12:13:32 +00:00
|
|
|
virtual void addIRPasses();
|
2012-05-04 20:18:50 +00:00
|
|
|
virtual bool addInstSelector();
|
|
|
|
virtual bool addPreRegAlloc();
|
2013-05-31 12:14:49 +00:00
|
|
|
virtual bool addPostRegAlloc();
|
|
|
|
|
2013-05-31 19:21:58 +00:00
|
|
|
virtual FunctionPass *createTargetRegisterAllocator(bool) LLVM_OVERRIDE;
|
2013-05-31 12:14:49 +00:00
|
|
|
virtual void addFastRegAlloc(FunctionPass *RegAllocPass);
|
|
|
|
virtual void addOptimizedRegAlloc(FunctionPass *RegAllocPass);
|
2012-05-04 20:18:50 +00:00
|
|
|
};
|
2013-05-23 17:10:37 +00:00
|
|
|
} // end anonymous namespace
|
2012-05-04 20:18:50 +00:00
|
|
|
|
|
|
|
TargetPassConfig *NVPTXTargetMachine::createPassConfig(PassManagerBase &PM) {
|
|
|
|
NVPTXPassConfig *PassConfig = new NVPTXPassConfig(this, PM);
|
|
|
|
return PassConfig;
|
|
|
|
}
|
|
|
|
|
2013-05-20 12:13:32 +00:00
|
|
|
void NVPTXPassConfig::addIRPasses() {
|
2013-05-31 12:14:49 +00:00
|
|
|
// The following passes are known to not play well with virtual regs hanging
|
|
|
|
// around after register allocation (which in our case, is *all* registers).
|
|
|
|
// We explicitly disable them here. We do, however, need some functionality
|
|
|
|
// of the PrologEpilogCodeInserter pass, so we emulate that behavior in the
|
|
|
|
// NVPTXPrologEpilog pass (see NVPTXPrologEpilogPass.cpp).
|
|
|
|
disablePass(&PrologEpilogCodeInserterID);
|
|
|
|
disablePass(&MachineCopyPropagationID);
|
|
|
|
disablePass(&BranchFolderPassID);
|
|
|
|
|
2013-05-20 12:13:32 +00:00
|
|
|
TargetPassConfig::addIRPasses();
|
|
|
|
addPass(createGenericToNVVMPass());
|
|
|
|
}
|
|
|
|
|
2012-05-04 20:18:50 +00:00
|
|
|
bool NVPTXPassConfig::addInstSelector() {
|
2012-07-02 19:48:31 +00:00
|
|
|
addPass(createLowerAggrCopies());
|
|
|
|
addPass(createSplitBBatBarPass());
|
|
|
|
addPass(createAllocaHoisting());
|
|
|
|
addPass(createNVPTXISelDag(getNVPTXTargetMachine(), getOptLevel()));
|
2012-05-04 20:18:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-30 14:29:21 +00:00
|
|
|
bool NVPTXPassConfig::addPreRegAlloc() { return false; }
|
2013-05-31 12:14:49 +00:00
|
|
|
bool NVPTXPassConfig::addPostRegAlloc() {
|
|
|
|
addPass(createNVPTXPrologEpilogPass());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-31 19:21:58 +00:00
|
|
|
FunctionPass *NVPTXPassConfig::createTargetRegisterAllocator(bool) {
|
|
|
|
return 0; // No reg alloc
|
|
|
|
}
|
|
|
|
|
2013-05-31 12:14:49 +00:00
|
|
|
void NVPTXPassConfig::addFastRegAlloc(FunctionPass *RegAllocPass) {
|
2013-05-31 19:21:58 +00:00
|
|
|
assert(!RegAllocPass && "NVPTX uses no regalloc!");
|
2013-05-31 12:14:49 +00:00
|
|
|
addPass(&StrongPHIEliminationID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NVPTXPassConfig::addOptimizedRegAlloc(FunctionPass *RegAllocPass) {
|
2013-05-31 19:21:58 +00:00
|
|
|
assert(!RegAllocPass && "NVPTX uses no regalloc!");
|
2013-05-31 12:14:49 +00:00
|
|
|
addPass(&StrongPHIEliminationID);
|
|
|
|
}
|