Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 1 | //===-- NVPTXTargetMachine.cpp - Define TargetMachine for NVPTX -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Top-level implementation for the NVPTX target. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "NVPTXTargetMachine.h" |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 15 | #include "MCTargetDesc/NVPTXMCAsmInfo.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "NVPTX.h" |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 17 | #include "NVPTXAllocaHoisting.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "NVPTXLowerAggrCopies.h" |
| 19 | #include "NVPTXSplitBBatBar.h" |
| 20 | #include "llvm/ADT/OwningPtr.h" |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 21 | #include "llvm/Analysis/Passes.h" |
| 22 | #include "llvm/Analysis/Verifier.h" |
| 23 | #include "llvm/Assembly/PrintModulePass.h" |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/AsmPrinter.h" |
| 25 | #include "llvm/CodeGen/MachineFunctionAnalysis.h" |
| 26 | #include "llvm/CodeGen/MachineModuleInfo.h" |
| 27 | #include "llvm/CodeGen/Passes.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 28 | #include "llvm/IR/DataLayout.h" |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 29 | #include "llvm/MC/MCAsmInfo.h" |
| 30 | #include "llvm/MC/MCInstrInfo.h" |
| 31 | #include "llvm/MC/MCStreamer.h" |
| 32 | #include "llvm/MC/MCSubtargetInfo.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 33 | #include "llvm/PassManager.h" |
| 34 | #include "llvm/Support/CommandLine.h" |
| 35 | #include "llvm/Support/Debug.h" |
| 36 | #include "llvm/Support/FormattedStream.h" |
| 37 | #include "llvm/Support/TargetRegistry.h" |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 38 | #include "llvm/Support/raw_ostream.h" |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 39 | #include "llvm/Target/TargetInstrInfo.h" |
| 40 | #include "llvm/Target/TargetLowering.h" |
| 41 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 42 | #include "llvm/Target/TargetMachine.h" |
| 43 | #include "llvm/Target/TargetOptions.h" |
| 44 | #include "llvm/Target/TargetRegisterInfo.h" |
| 45 | #include "llvm/Target/TargetSubtargetInfo.h" |
| 46 | #include "llvm/Transforms/Scalar.h" |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 47 | |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 48 | using namespace llvm; |
| 49 | |
Justin Holewinski | 21fdcb0 | 2013-03-30 14:29:25 +0000 | [diff] [blame] | 50 | namespace llvm { |
| 51 | void initializeNVVMReflectPass(PassRegistry&); |
| 52 | } |
| 53 | |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 54 | extern "C" void LLVMInitializeNVPTXTarget() { |
| 55 | // Register the target. |
| 56 | RegisterTargetMachine<NVPTXTargetMachine32> X(TheNVPTXTarget32); |
| 57 | RegisterTargetMachine<NVPTXTargetMachine64> Y(TheNVPTXTarget64); |
| 58 | |
| 59 | RegisterMCAsmInfo<NVPTXMCAsmInfo> A(TheNVPTXTarget32); |
| 60 | RegisterMCAsmInfo<NVPTXMCAsmInfo> B(TheNVPTXTarget64); |
| 61 | |
Justin Holewinski | 21fdcb0 | 2013-03-30 14:29:25 +0000 | [diff] [blame] | 62 | // FIXME: This pass is really intended to be invoked during IR optimization, |
| 63 | // but it's very NVPTX-specific. |
| 64 | initializeNVVMReflectPass(*PassRegistry::getPassRegistry()); |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 67 | NVPTXTargetMachine::NVPTXTargetMachine( |
| 68 | const Target &T, StringRef TT, StringRef CPU, StringRef FS, |
| 69 | const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, |
| 70 | CodeGenOpt::Level OL, bool is64bit) |
| 71 | : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL), |
| 72 | Subtarget(TT, CPU, FS, is64bit), DL(Subtarget.getDataLayout()), |
| 73 | InstrInfo(*this), TLInfo(*this), TSInfo(*this), |
| 74 | FrameLowering( |
| 75 | *this, is64bit) /*FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0)*/ {} |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 76 | |
| 77 | void NVPTXTargetMachine32::anchor() {} |
| 78 | |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 79 | NVPTXTargetMachine32::NVPTXTargetMachine32( |
| 80 | const Target &T, StringRef TT, StringRef CPU, StringRef FS, |
| 81 | const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, |
| 82 | CodeGenOpt::Level OL) |
| 83 | : NVPTXTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {} |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 84 | |
| 85 | void NVPTXTargetMachine64::anchor() {} |
| 86 | |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 87 | NVPTXTargetMachine64::NVPTXTargetMachine64( |
| 88 | const Target &T, StringRef TT, StringRef CPU, StringRef FS, |
| 89 | const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, |
| 90 | CodeGenOpt::Level OL) |
| 91 | : NVPTXTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {} |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 92 | |
| 93 | namespace llvm { |
| 94 | class NVPTXPassConfig : public TargetPassConfig { |
| 95 | public: |
| 96 | NVPTXPassConfig(NVPTXTargetMachine *TM, PassManagerBase &PM) |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 97 | : TargetPassConfig(TM, PM) {} |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 98 | |
| 99 | NVPTXTargetMachine &getNVPTXTargetMachine() const { |
| 100 | return getTM<NVPTXTargetMachine>(); |
| 101 | } |
| 102 | |
| 103 | virtual bool addInstSelector(); |
| 104 | virtual bool addPreRegAlloc(); |
| 105 | }; |
| 106 | } |
| 107 | |
| 108 | TargetPassConfig *NVPTXTargetMachine::createPassConfig(PassManagerBase &PM) { |
| 109 | NVPTXPassConfig *PassConfig = new NVPTXPassConfig(this, PM); |
| 110 | return PassConfig; |
| 111 | } |
| 112 | |
| 113 | bool NVPTXPassConfig::addInstSelector() { |
Bob Wilson | 564fbf6 | 2012-07-02 19:48:31 +0000 | [diff] [blame] | 114 | addPass(createLowerAggrCopies()); |
| 115 | addPass(createSplitBBatBarPass()); |
| 116 | addPass(createAllocaHoisting()); |
| 117 | addPass(createNVPTXISelDag(getNVPTXTargetMachine(), getOptLevel())); |
Justin Holewinski | 49683f3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 118 | return false; |
| 119 | } |
| 120 | |
Justin Holewinski | 3639ce2 | 2013-03-30 14:29:21 +0000 | [diff] [blame] | 121 | bool NVPTXPassConfig::addPreRegAlloc() { return false; } |