diff options
Diffstat (limited to 'lib/Target/NVPTX')
31 files changed, 263 insertions, 301 deletions
diff --git a/lib/Target/NVPTX/CMakeLists.txt b/lib/Target/NVPTX/CMakeLists.txt index 4f1324c..029118a 100644 --- a/lib/Target/NVPTX/CMakeLists.txt +++ b/lib/Target/NVPTX/CMakeLists.txt @@ -16,7 +16,6 @@ set(NVPTXCodeGen_sources NVPTXRegisterInfo.cpp NVPTXSubtarget.cpp NVPTXTargetMachine.cpp - NVPTXSplitBBatBar.cpp NVPTXLowerAggrCopies.cpp NVPTXutil.cpp NVPTXAllocaHoisting.cpp @@ -24,14 +23,13 @@ set(NVPTXCodeGen_sources NVPTXUtilities.cpp NVVMReflect.cpp NVPTXGenericToNVVM.cpp + NVPTXAssignValidGlobalNames.cpp NVPTXPrologEpilogPass.cpp NVPTXMCExpr.cpp ) add_llvm_target(NVPTXCodeGen ${NVPTXCodeGen_sources}) -add_dependencies(LLVMNVPTXCodeGen NVPTXCommonTableGen intrinsics_gen) - add_subdirectory(TargetInfo) add_subdirectory(InstPrinter) add_subdirectory(MCTargetDesc) diff --git a/lib/Target/NVPTX/InstPrinter/CMakeLists.txt b/lib/Target/NVPTX/InstPrinter/CMakeLists.txt index ae4c751..bb6c8ab 100644 --- a/lib/Target/NVPTX/InstPrinter/CMakeLists.txt +++ b/lib/Target/NVPTX/InstPrinter/CMakeLists.txt @@ -1,7 +1,3 @@ -include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. ) - add_llvm_library(LLVMNVPTXAsmPrinter NVPTXInstPrinter.cpp ) - -add_dependencies(LLVMNVPTXAsmPrinter NVPTXCommonTableGen) diff --git a/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp b/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp index d5be0e4..cf165be 100644 --- a/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp +++ b/lib/Target/NVPTX/InstPrinter/NVPTXInstPrinter.cpp @@ -13,13 +13,13 @@ #define DEBUG_TYPE "asm-printer" #include "InstPrinter/NVPTXInstPrinter.h" -#include "NVPTX.h" #include "MCTargetDesc/NVPTXBaseInfo.h" +#include "NVPTX.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCInstrInfo.h" -#include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/MC/MCSymbol.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" #include <cctype> diff --git a/lib/Target/NVPTX/LLVMBuild.txt b/lib/Target/NVPTX/LLVMBuild.txt index e2d6ed2..e805aba 100644 --- a/lib/Target/NVPTX/LLVMBuild.txt +++ b/lib/Target/NVPTX/LLVMBuild.txt @@ -28,5 +28,5 @@ has_asmprinter = 1 type = Library name = NVPTXCodeGen parent = NVPTX -required_libraries = Analysis AsmPrinter CodeGen Core MC NVPTXDesc NVPTXInfo SelectionDAG Support Target TransformUtils +required_libraries = Analysis AsmPrinter CodeGen Core MC NVPTXAsmPrinter NVPTXDesc NVPTXInfo SelectionDAG Support Target add_to_library_groups = NVPTX diff --git a/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt b/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt index a030d9f..dbbf235 100644 --- a/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt +++ b/lib/Target/NVPTX/MCTargetDesc/CMakeLists.txt @@ -2,8 +2,3 @@ add_llvm_library(LLVMNVPTXDesc NVPTXMCAsmInfo.cpp NVPTXMCTargetDesc.cpp ) - -add_dependencies(LLVMNVPTXDesc NVPTXCommonTableGen) - -# Hack: we need to include 'main' target directory to grab private headers -#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/..) diff --git a/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp b/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp index f2784b8..366341a 100644 --- a/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp +++ b/lib/Target/NVPTX/MCTargetDesc/NVPTXMCAsmInfo.cpp @@ -33,8 +33,6 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(const StringRef &TT) { CommentString = "//"; - PrivateGlobalPrefix = "$L__"; - HasSetDirective = false; HasSingleParameterDotFile = false; @@ -49,7 +47,6 @@ NVPTXMCAsmInfo::NVPTXMCAsmInfo(const StringRef &TT) { Data16bitsDirective = " .b16 "; Data32bitsDirective = " .b32 "; Data64bitsDirective = " .b64 "; - PrivateGlobalPrefix = ""; ZeroDirective = " .b8"; AsciiDirective = " .b8"; AscizDirective = " .b8"; diff --git a/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp b/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp index 871bac9..3cf6e4b 100644 --- a/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp +++ b/lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.cpp @@ -12,8 +12,8 @@ //===----------------------------------------------------------------------===// #include "NVPTXMCTargetDesc.h" -#include "NVPTXMCAsmInfo.h" #include "InstPrinter/NVPTXInstPrinter.h" +#include "NVPTXMCAsmInfo.h" #include "llvm/MC/MCCodeGenInfo.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCRegisterInfo.h" diff --git a/lib/Target/NVPTX/NVPTX.h b/lib/Target/NVPTX/NVPTX.h index 490b49d..8cbdd47 100644 --- a/lib/Target/NVPTX/NVPTX.h +++ b/lib/Target/NVPTX/NVPTX.h @@ -61,6 +61,7 @@ inline static const char *NVPTXCondCodeToString(NVPTXCC::CondCodes CC) { FunctionPass * createNVPTXISelDag(NVPTXTargetMachine &TM, llvm::CodeGenOpt::Level OptLevel); +ModulePass *createNVPTXAssignValidGlobalNamesPass(); ModulePass *createGenericToNVVMPass(); ModulePass *createNVVMReflectPass(); ModulePass *createNVVMReflectPass(const StringMap<int>& Mapping); diff --git a/lib/Target/NVPTX/NVPTX.td b/lib/Target/NVPTX/NVPTX.td index 6183a75..d78b4e8 100644 --- a/lib/Target/NVPTX/NVPTX.td +++ b/lib/Target/NVPTX/NVPTX.td @@ -57,12 +57,6 @@ def : Proc<"sm_35", [SM35]>; def NVPTXInstrInfo : InstrInfo { } -def NVPTXAsmWriter : AsmWriter { - bit isMCAsmWriter = 1; - string AsmWriterClassName = "InstPrinter"; -} - def NVPTX : Target { let InstructionSet = NVPTXInstrInfo; - let AssemblyWriters = [NVPTXAsmWriter]; } diff --git a/lib/Target/NVPTX/NVPTXAllocaHoisting.h b/lib/Target/NVPTX/NVPTXAllocaHoisting.h index 19d73c5..22404b7 100644 --- a/lib/Target/NVPTX/NVPTXAllocaHoisting.h +++ b/lib/Target/NVPTX/NVPTXAllocaHoisting.h @@ -31,7 +31,8 @@ public: NVPTXAllocaHoisting() : FunctionPass(ID) {} void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired<DataLayout>(); + AU.addRequired<DataLayoutPass>(); + AU.addPreserved("stack-protector"); AU.addPreserved<MachineFunctionAnalysis>(); } diff --git a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp index 7552fe7..97e2cc6 100644 --- a/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "NVPTXAsmPrinter.h" +#include "InstPrinter/NVPTXInstPrinter.h" #include "MCTargetDesc/NVPTXMCAsmInfo.h" #include "NVPTX.h" #include "NVPTXInstrInfo.h" @@ -20,19 +21,18 @@ #include "NVPTXRegisterInfo.h" #include "NVPTXTargetMachine.h" #include "NVPTXUtilities.h" -#include "InstPrinter/NVPTXInstPrinter.h" #include "cl_common_defines.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Analysis/ConstantFolding.h" -#include "llvm/Assembly/Writer.h" #include "llvm/CodeGen/Analysis.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineModuleInfo.h" #include "llvm/CodeGen/MachineRegisterInfo.h" -#include "llvm/DebugInfo.h" +#include "llvm/IR/DebugInfo.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/Mangler.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" #include "llvm/MC/MCStreamer.h" @@ -43,7 +43,6 @@ #include "llvm/Support/Path.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TimeValue.h" -#include "llvm/Target/Mangler.h" #include "llvm/Target/TargetLoweringObjectFile.h" #include <sstream> using namespace llvm; @@ -149,7 +148,7 @@ const MCExpr *nvptx::LowerConstant(const Constant *CV, AsmPrinter &AP) { std::string S; raw_string_ostream OS(S); OS << "Unsupported expression in static initializer: "; - WriteAsOperand(OS, CE, /*PrintType=*/ false, + CE->printAsOperand(OS, /*PrintType=*/ false, !AP.MF ? 0 : AP.MF->getFunction()->getParent()); report_fatal_error(OS.str()); } @@ -308,7 +307,7 @@ void NVPTXAsmPrinter::EmitInstruction(const MachineInstr *MI) { MCInst Inst; lowerToMCInst(MI, Inst); - OutStreamer.EmitInstruction(Inst); + EmitToStreamer(OutStreamer, Inst); } void NVPTXAsmPrinter::lowerToMCInst(const MachineInstr *MI, MCInst &OutMI) { @@ -430,7 +429,7 @@ void NVPTXAsmPrinter::printReturnValStr(const Function *F, raw_ostream &O) { O << " ("; if (isABI) { - if (Ty->isPrimitiveType() || Ty->isIntegerTy()) { + if (Ty->isFloatingPointTy() || Ty->isIntegerTy()) { unsigned size = 0; if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty)) { size = ITy->getBitWidth(); @@ -700,12 +699,11 @@ static bool usedInGlobalVarDef(const Constant *C) { return true; } - for (Value::const_use_iterator ui = C->use_begin(), ue = C->use_end(); - ui != ue; ++ui) { - const Constant *C = dyn_cast<Constant>(*ui); - if (usedInGlobalVarDef(C)) - return true; - } + for (const User *U : C->users()) + if (const Constant *C = dyn_cast<Constant>(U)) + if (usedInGlobalVarDef(C)) + return true; + return false; } @@ -731,11 +729,10 @@ static bool usedInOneFunc(const User *U, Function const *&oneFunc) { (md->getName().str() == "llvm.dbg.sp"))) return true; - for (User::const_use_iterator ui = U->use_begin(), ue = U->use_end(); - ui != ue; ++ui) { - if (usedInOneFunc(*ui, oneFunc) == false) + for (const User *UU : U->users()) + if (usedInOneFunc(UU, oneFunc) == false) return false; - } + return true; } @@ -766,12 +763,11 @@ static bool canDemoteGlobalVar(const GlobalVariable *gv, Function const *&f) { static bool useFuncSeen(const Constant *C, llvm::DenseMap<const Function *, bool> &seenMap) { - for (Value::const_use_iterator ui = C->use_begin(), ue = C->use_end(); - ui != ue; ++ui) { - if (const Constant *cu = dyn_cast<Constant>(*ui)) { + for (const User *U : C->users()) { + if (const Constant *cu = dyn_cast<Constant>(U)) { if (useFuncSeen(cu, seenMap)) return true; - } else if (const Instruction *I = dyn_cast<Instruction>(*ui)) { + } else if (const Instruction *I = dyn_cast<Instruction>(U)) { const BasicBlock *bb = I->getParent(); if (!bb) continue; @@ -798,10 +794,8 @@ void NVPTXAsmPrinter::emitDeclarations(const Module &M, raw_ostream &O) { emitDeclaration(F, O); continue; } - for (Value::const_use_iterator iter = F->use_begin(), - iterEnd = F->use_end(); - iter != iterEnd; ++iter) { - if (const Constant *C = dyn_cast<Constant>(*iter)) { + for (const User *U : F->users()) { + if (const Constant *C = dyn_cast<Constant>(U)) { if (usedInGlobalVarDef(C)) { // The use is in the initialization of a global variable // that is a function pointer, so print a declaration @@ -817,9 +811,9 @@ void NVPTXAsmPrinter::emitDeclarations(const Module &M, raw_ostream &O) { } } - if (!isa<Instruction>(*iter)) + if (!isa<Instruction>(U)) continue; - const Instruction *instr = cast<Instruction>(*iter); + const Instruction *instr = cast<Instruction>(U); const BasicBlock *bb = instr->getParent(); if (!bb) continue; @@ -844,10 +838,7 @@ void NVPTXAsmPrinter::recordAndEmitFilenames(Module &M) { DbgFinder.processModule(M); unsigned i = 1; - for (DebugInfoFinder::iterator I = DbgFinder.compile_unit_begin(), - E = DbgFinder.compile_unit_end(); - I != E; ++I) { - DICompileUnit DIUnit(*I); + for (DICompileUnit DIUnit : DbgFinder.compile_units()) { StringRef Filename(DIUnit.getFilename()); StringRef Dirname(DIUnit.getDirectory()); SmallString<128> FullPathName = Dirname; @@ -862,10 +853,7 @@ void NVPTXAsmPrinter::recordAndEmitFilenames(Module &M) { ++i; } - for (DebugInfoFinder::iterator I = DbgFinder.subprogram_begin(), - E = DbgFinder.subprogram_end(); - I != E; ++I) { - DISubprogram SP(*I); + for (DISubprogram SP : DbgFinder.subprograms()) { StringRef Filename(SP.getFilename()); StringRef Dirname(SP.getDirectory()); SmallString<128> FullPathName = Dirname; @@ -895,7 +883,7 @@ bool NVPTXAsmPrinter::doInitialization(Module &M) { const_cast<TargetLoweringObjectFile &>(getObjFileLowering()) .Initialize(OutContext, TM); - Mang = new Mangler(&TM); + Mang = new Mangler(TM.getDataLayout()); // Emit header before any dwarf directives are emitted below. emitHeader(M, OS1); @@ -1207,7 +1195,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar, else O << " .align " << GVar->getAlignment(); - if (ETy->isPrimitiveType() || ETy->isIntegerTy() || isa<PointerType>(ETy)) { + if (ETy->isSingleValueType()) { O << " ."; // Special case: ABI requires that we use .u8 for predicates if (ETy->isIntegerTy(1)) @@ -1378,7 +1366,7 @@ void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar, else O << " .align " << GVar->getAlignment(); - if (ETy->isPrimitiveType() || ETy->isIntegerTy() || isa<PointerType>(ETy)) { + if (ETy->isSingleValueType()) { O << " ."; O << getPTXFundamentalTypeStr(ETy); O << " "; @@ -1410,7 +1398,7 @@ void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar, } static unsigned int getOpenCLAlignment(const DataLayout *TD, Type *Ty) { - if (Ty->isPrimitiveType() || Ty->isIntegerTy() || isa<PointerType>(Ty)) + if (Ty->isSingleValueType()) return TD->getPrefTypeAlignment(Ty); const ArrayType *ATy = dyn_cast<ArrayType>(Ty); @@ -1523,8 +1511,8 @@ void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) { } if (PAL.hasAttribute(paramIndex + 1, Attribute::ByVal) == false) { - if (Ty->isVectorTy()) { - // Just print .param .b8 .align <a> .param[size]; + if (Ty->isAggregateType() || Ty->isVectorTy()) { + // Just print .param .align <a> .b8 .param[size]; // <a> = PAL.getparamalignment // size = typeallocsize of element type unsigned align = PAL.getParamAlignment(paramIndex + 1); @@ -1580,7 +1568,7 @@ void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) { continue; } // Non-kernel function, just print .param .b<size> for ABI - // and .reg .b<size> for non ABY + // and .reg .b<size> for non-ABI unsigned sz = 0; if (isa<IntegerType>(Ty)) { sz = cast<IntegerType>(Ty)->getBitWidth(); @@ -1604,7 +1592,7 @@ void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) { Type *ETy = PTy->getElementType(); if (isABI || isKernelFunc) { - // Just print .param .b8 .align <a> .param[size]; + // Just print .param .align <a> .b8 .param[size]; // <a> = PAL.getparamalignment // size = typeallocsize of element type unsigned align = PAL.getParamAlignment(paramIndex + 1); @@ -2087,21 +2075,6 @@ void NVPTXAsmPrinter::printOperand(const MachineInstr *MI, int opNum, O << *getSymbol(MO.getGlobal()); break; - case MachineOperand::MO_ExternalSymbol: { - const char *symbname = MO.getSymbolName(); - if (strstr(symbname, ".PARAM") == symbname) { - unsigned index; - sscanf(symbname + 6, "%u[];", &index); - printParamName(index, O); - } else if (strstr(symbname, ".HLPPARAM") == symbname) { - unsigned index; - sscanf(symbname + 9, "%u[];", &index); - O << *CurrentFnSym << "_param_" << index << "_offset"; - } else - O << symbname; - break; - } - case MachineOperand::MO_MachineBasicBlock: O << *MO.getMBB()->getSymbol(); return; diff --git a/lib/Target/NVPTX/NVPTXAsmPrinter.h b/lib/Target/NVPTX/NVPTXAsmPrinter.h index 3abe5d1..7162420 100644 --- a/lib/Target/NVPTX/NVPTXAsmPrinter.h +++ b/lib/Target/NVPTX/NVPTXAsmPrinter.h @@ -27,7 +27,6 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FormattedStream.h" -#include "llvm/Target/Mangler.h" #include "llvm/Target/TargetMachine.h" #include <fstream> @@ -198,14 +197,11 @@ private: void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0) const {} - void printGlobalVariable(const GlobalVariable *GVar); void printVecModifiedImmediate(const MachineOperand &MO, const char *Modifier, raw_ostream &O); void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O, const char *Modifier = 0); void printImplicitDef(const MachineInstr *MI, raw_ostream &O) const; - // definition autogenerated. - void printInstruction(const MachineInstr *MI, raw_ostream &O); void printModuleLevelGV(const GlobalVariable *GVar, raw_ostream &O, bool = false); void printParamName(int paramIndex, raw_ostream &O); diff --git a/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp b/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp new file mode 100644 index 0000000..158c482 --- /dev/null +++ b/lib/Target/NVPTX/NVPTXAssignValidGlobalNames.cpp @@ -0,0 +1,84 @@ +//===-- NVPTXAssignValidGlobalNames.cpp - Assign valid names to globals ---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Clean up the names of global variables in the module to not contain symbols +// that are invalid in PTX. +// +// Currently NVPTX, like other backends, relies on generic symbol name +// sanitizing done by MC. However, the ptxas assembler is more stringent and +// disallows some additional characters in symbol names. This pass makes sure +// such names do not reach MC at all. +// +//===----------------------------------------------------------------------===// + +#include "NVPTX.h" +#include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/Module.h" +#include "llvm/PassManager.h" +#include "llvm/Support/raw_ostream.h" +#include <string> + +using namespace llvm; + +namespace { +/// \brief NVPTXAssignValidGlobalNames +class NVPTXAssignValidGlobalNames : public ModulePass { +public: + static char ID; + NVPTXAssignValidGlobalNames() : ModulePass(ID) {} + + virtual bool runOnModule(Module &M); + + /// \brief Clean up the name to remove symbols invalid in PTX. + std::string cleanUpName(StringRef Name); +}; +} + +char NVPTXAssignValidGlobalNames::ID = 0; + +namespace llvm { +void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry &); +} + +INITIALIZE_PASS(NVPTXAssignValidGlobalNames, "nvptx-assign-valid-global-names", + "Assign valid PTX names to globals", false, false) + +bool NVPTXAssignValidGlobalNames::runOnModule(Module &M) { + for (GlobalVariable &GV : M.globals()) { + // We are only allowed to rename local symbols. + if (GV.hasLocalLinkage()) { + // setName doesn't do extra work if the name does not change. + // Note: this does not create collisions - if setName is asked to set the + // name to something that already exists, it adds a proper postfix to + // avoid collisions. + GV.setName(cleanUpName(GV.getName())); + } + } + + return true; +} + +std::string NVPTXAssignValidGlobalNames::cleanUpName(StringRef Name) { + std::string ValidName; + raw_string_ostream ValidNameStream(ValidName); + for (unsigned I = 0, E = Name.size(); I != E; ++I) { + char C = Name[I]; + if (C == '.' || C == '@') { + ValidNameStream << "_$_"; + } else { + ValidNameStream << C; + } + } + + return ValidNameStream.str(); +} + +ModulePass *llvm::createNVPTXAssignValidGlobalNamesPass() { + return new NVPTXAssignValidGlobalNames(); +} diff --git a/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp index 9fb0dd8..45f0734 100644 --- a/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp +++ b/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp @@ -13,20 +13,19 @@ //===----------------------------------------------------------------------===// #include "NVPTX.h" -#include "NVPTXUtilities.h" #include "MCTargetDesc/NVPTXBaseInfo.h" - -#include "llvm/PassManager.h" +#include "NVPTXUtilities.h" +#include "llvm/CodeGen/MachineFunctionAnalysis.h" +#include "llvm/CodeGen/ValueTypes.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/IRBuilder.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" -#include "llvm/ADT/ValueMap.h" -#include "llvm/CodeGen/MachineFunctionAnalysis.h" -#include "llvm/CodeGen/ValueTypes.h" -#include "llvm/IR/IRBuilder.h" +#include "llvm/IR/ValueMap.h" +#include "llvm/PassManager.h" using namespace llvm; @@ -64,7 +63,7 @@ private: GVMapTy GVMap; ConstantToValueMapTy ConstantToValueMap; }; -} +} // end namespace char GenericToNVVM::ID = 0; @@ -147,10 +146,8 @@ bool GenericToNVVM::runOnModule(Module &M) { // variable initializers, as other uses have been already been removed // while walking through the instructions in function definitions. for (Value::use_iterator UI = GV->use_begin(), UE = GV->use_end(); - UI != UE;) { - Use &U = (UI++).getUse(); - U.set(BitCastNewGV); - } + UI != UE;) + (UI++)->set(BitCastNewGV); std::string Name = GV->getName(); GV->removeDeadConstantUsers(); GV->eraseFromParent(); diff --git a/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp b/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp index 4b8b306..bd08d2d 100644 --- a/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp +++ b/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp @@ -162,6 +162,9 @@ SDNode *NVPTXDAGToDAGISel::Select(SDNode *N) { case NVPTXISD::StoreParamU32: ResNode = SelectStoreParam(N); break; + case ISD::ADDRSPACECAST: + ResNode = SelectAddrSpaceCast(N); + break; default: break; } @@ -191,6 +194,66 @@ static unsigned int getCodeAddrSpace(MemSDNode *N, return NVPTX::PTXLdStInstCode::GENERIC; } +SDNode *NVPTXDAGToDAGISel::SelectAddrSpaceCast(SDNode *N) { + SDValue Src = N->getOperand(0); + AddrSpaceCastSDNode *CastN = cast<AddrSpaceCastSDNode>(N); + unsigned SrcAddrSpace = CastN->getSrcAddressSpace(); + unsigned DstAddrSpace = CastN->getDestAddressSpace(); + + assert(SrcAddrSpace != DstAddrSpace && + "addrspacecast must be between different address spaces"); + + if (DstAddrSpace == ADDRESS_SPACE_GENERIC) { + // Specific to generic + unsigned Opc; + switch (SrcAddrSpace) { + default: report_fatal_error("Bad address space in addrspacecast"); + case ADDRESS_SPACE_GLOBAL: + Opc = Subtarget.is64Bit() ? NVPTX::cvta_global_yes_64 + : NVPTX::cvta_global_yes; + break; + case ADDRESS_SPACE_SHARED: + Opc = Subtarget.is64Bit() ? NVPTX::cvta_shared_yes_64 + : NVPTX::cvta_shared_yes; + break; + case ADDRESS_SPACE_CONST: + Opc = Subtarget.is64Bit() ? NVPTX::cvta_const_yes_64 + : NVPTX::cvta_const_yes; + break; + case ADDRESS_SPACE_LOCAL: + Opc = Subtarget.is64Bit() ? NVPTX::cvta_local_yes_64 + : NVPTX::cvta_local_yes; + break; + } + return CurDAG->getMachineNode(Opc, SDLoc(N), N->getValueType(0), Src); + } else { + // Generic to specific + if (SrcAddrSpace != 0) + report_fatal_error("Cannot cast between two non-generic address spaces"); + unsigned Opc; + switch (DstAddrSpace) { + default: report_fatal_error("Bad address space in addrspacecast"); + case ADDRESS_SPACE_GLOBAL: + Opc = Subtarget.is64Bit() ? NVPTX::cvta_to_global_yes_64 + : NVPTX::cvta_to_global_yes; + break; + case ADDRESS_SPACE_SHARED: + Opc = Subtarget.is64Bit() ? NVPTX::cvta_to_shared_yes_64 + : NVPTX::cvta_to_shared_yes; + break; + case ADDRESS_SPACE_CONST: + Opc = Subtarget.is64Bit() ? NVPTX::cvta_to_const_yes_64 + : NVPTX::cvta_to_const_yes; + break; + case ADDRESS_SPACE_LOCAL: + Opc = Subtarget.is64Bit() ? NVPTX::cvta_to_local_yes_64 + : NVPTX::cvta_to_local_yes; + break; + } + return CurDAG->getMachineNode(Opc, SDLoc(N), N->getValueType(0), Src); + } +} + SDNode *NVPTXDAGToDAGISel::SelectLoad(SDNode *N) { SDLoc dl(N); LoadSDNode *LD = cast<LoadSDNode>(N); @@ -2014,7 +2077,7 @@ SDNode *NVPTXDAGToDAGISel::SelectLoadParam(SDNode *Node) { VTs = CurDAG->getVTList(EltVT, EltVT, MVT::Other, MVT::Glue); } else { EVT EVTs[] = { EltVT, EltVT, EltVT, EltVT, MVT::Other, MVT::Glue }; - VTs = CurDAG->getVTList(&EVTs[0], 5); + VTs = CurDAG->getVTList(&EVTs[0], array_lengthof(EVTs)); } unsigned OffsetVal = cast<ConstantSDNode>(Offset)->getZExtValue(); @@ -2440,24 +2503,3 @@ bool NVPTXDAGToDAGISel::SelectInlineAsmMemoryOperand( } return true; } - -// Return true if N is a undef or a constant. -// If N was undef, return a (i8imm 0) in Retval -// If N was imm, convert it to i8imm and return in Retval -// Note: The convert to i8imm is required, otherwise the -// pattern matcher inserts a bunch of IMOVi8rr to convert -// the imm to i8imm, and this causes instruction selection -// to fail. -bool NVPTXDAGToDAGISel::UndefOrImm(SDValue Op, SDValue N, SDValue &Retval) { - if (!(N.getOpcode() == ISD::UNDEF) && !(N.getOpcode() == ISD::Constant)) - return false; - - if (N.getOpcode() == ISD::UNDEF) - Retval = CurDAG->getTargetConstant(0, MVT::i8); - else { - ConstantSDNode *cn = cast<ConstantSDNode>(N.getNode()); - unsigned retval = cn->getZExtValue(); - Retval = CurDAG->getTargetConstant(retval, MVT::i8); - } - return true; -} diff --git a/lib/Target/NVPTX/NVPTXISelDAGToDAG.h b/lib/Target/NVPTX/NVPTXISelDAGToDAG.h index d961e50..93ad169 100644 --- a/lib/Target/NVPTX/NVPTXISelDAGToDAG.h +++ b/lib/Target/NVPTX/NVPTXISelDAGToDAG.h @@ -67,6 +67,7 @@ private: SDNode *SelectLoadParam(SDNode *N); SDNode *SelectStoreRetval(SDNode *N); SDNode *SelectStoreParam(SDNode *N); + SDNode *SelectAddrSpaceCast(SDNode *N); inline SDValue getI32Imm(unsigned Imm) { return CurDAG->getTargetConstant(Imm, MVT::i32); @@ -91,7 +92,5 @@ private: bool ChkMemSDNodeAddressSpace(SDNode *N, unsigned int spN) const; - bool UndefOrImm(SDValue Op, SDValue N, SDValue &Retval); - }; } diff --git a/lib/Target/NVPTX/NVPTXISelLowering.cpp b/lib/Target/NVPTX/NVPTXISelLowering.cpp index 6a8be75..8e25a65 100644 --- a/lib/Target/NVPTX/NVPTXISelLowering.cpp +++ b/lib/Target/NVPTX/NVPTXISelLowering.cpp @@ -22,6 +22,7 @@ #include "llvm/CodeGen/MachineInstrBuilder.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" +#include "llvm/IR/CallSite.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -29,7 +30,6 @@ #include "llvm/IR/Intrinsics.h" #include "llvm/IR/Module.h" #include "llvm/MC/MCSectionELF.h" -#include "llvm/Support/CallSite.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" @@ -331,8 +331,8 @@ const char *NVPTXTargetLowering::getTargetNodeName(unsigned Opcode) const { } } -bool NVPTXTargetLowering::shouldSplitVectorElementType(EVT VT) const { - return VT == MVT::i1; +bool NVPTXTargetLowering::shouldSplitVectorType(EVT VT) const { + return VT.getScalarType() == MVT::i1; } SDValue @@ -361,7 +361,7 @@ NVPTXTargetLowering::getPrototype(Type *retTy, const ArgListTy &Args, O << "()"; } else { O << "("; - if (retTy->isPrimitiveType() || retTy->isIntegerTy()) { + if (retTy->isFloatingPointTy() || retTy->isIntegerTy()) { unsigned size = 0; if (const IntegerType *ITy = dyn_cast<IntegerType>(retTy)) { size = ITy->getBitWidth(); @@ -856,8 +856,7 @@ SDValue NVPTXTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, // .param .align 16 .b8 retval0[<size-in-bytes>], or // .param .b<size-in-bits> retval0 unsigned resultsz = TD->getTypeAllocSizeInBits(retTy); - if (retTy->isPrimitiveType() || retTy->isIntegerTy() || - retTy->isPointerTy()) { + if (retTy->isSingleValueType()) { // Scalar needs to be at least 32bit wide if (resultsz < 32) resultsz = 32; @@ -1259,7 +1258,7 @@ NVPTXTargetLowering::LowerSTOREVector(SDValue Op, SelectionDAG &DAG) const { // Since StoreV2 is a target node, we cannot rely on DAG type legalization. // Therefore, we must ensure the type is legal. For i1 and i8, we set the - // stored type to i16 and propogate the "real" type as the memory type. + // stored type to i16 and propagate the "real" type as the memory type. bool NeedExt = false; if (EltVT.getSizeInBits() < 16) NeedExt = true; @@ -2075,7 +2074,7 @@ static void ReplaceLoadVector(SDNode *N, SelectionDAG &DAG, // Since LoadV2 is a target node, we cannot rely on DAG type legalization. // Therefore, we must ensure the type is legal. For i1 and i8, we set the - // loaded type to i16 and propogate the "real" type as the memory type. + // loaded type to i16 and propagate the "real" type as the memory type. bool NeedTrunc = false; if (EltVT.getSizeInBits() < 16) { EltVT = MVT::i16; @@ -2162,7 +2161,7 @@ static void ReplaceINTRINSIC_W_CHAIN(SDNode *N, SelectionDAG &DAG, // Since LDU/LDG are target nodes, we cannot rely on DAG type // legalization. // Therefore, we must ensure the type is legal. For i1 and i8, we set the - // loaded type to i16 and propogate the "real" type as the memory type. + // loaded type to i16 and propagate the "real" type as the memory type. bool NeedTrunc = false; if (EltVT.getSizeInBits() < 16) { EltVT = MVT::i16; diff --git a/lib/Target/NVPTX/NVPTXISelLowering.h b/lib/Target/NVPTX/NVPTXISelLowering.h index 66e708f..c1e8c21 100644 --- a/lib/Target/NVPTX/NVPTXISelLowering.h +++ b/lib/Target/NVPTX/NVPTXISelLowering.h @@ -141,7 +141,7 @@ public: // PTX always uses 32-bit shift amounts virtual MVT getScalarShiftAmountTy(EVT LHSTy) const { return MVT::i32; } - virtual bool shouldSplitVectorElementType(EVT VT) const; + virtual bool shouldSplitVectorType(EVT VT) const override; private: const NVPTXSubtarget &nvptxSubtarget; // cache the subtarget here diff --git a/lib/Target/NVPTX/NVPTXInstrInfo.td b/lib/Target/NVPTX/NVPTXInstrInfo.td index b23f1e4..fbcd0e4 100644 --- a/lib/Target/NVPTX/NVPTXInstrInfo.td +++ b/lib/Target/NVPTX/NVPTXInstrInfo.td @@ -689,12 +689,24 @@ def FDIV32approxrr_ftz : NVPTXInst<(outs Float32Regs:$dst), [(set Float32Regs:$dst, (fdiv Float32Regs:$a, Float32Regs:$b))]>, Requires<[do_DIVF32_APPROX, doF32FTZ]>; +def FDIV32approxri_ftz : NVPTXInst<(outs Float32Regs:$dst), + (ins Float32Regs:$a, f32imm:$b), + "div.approx.ftz.f32 \t$dst, $a, $b;", + [(set Float32Regs:$dst, + (fdiv Float32Regs:$a, fpimm:$b))]>, + Requires<[do_DIVF32_APPROX, doF32FTZ]>; def FDIV32approxrr : NVPTXInst<(outs Float32Regs:$dst), (ins Float32Regs:$a, Float32Regs:$b), "div.approx.f32 \t$dst, $a, $b;", [(set Float32Regs:$dst, (fdiv Float32Regs:$a, Float32Regs:$b))]>, Requires<[do_DIVF32_APPROX]>; +def FDIV32approxri : NVPTXInst<(outs Float32Regs:$dst), + (ins Float32Regs:$a, f32imm:$b), + "div.approx.f32 \t$dst, $a, $b;", + [(set Float32Regs:$dst, + (fdiv Float32Regs:$a, fpimm:$b))]>, + Requires<[do_DIVF32_APPROX]>; // // F32 Semi-accurate reciprocal // diff --git a/lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp b/lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp index 7c257b4..f0c3663 100644 --- a/lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp +++ b/lib/Target/NVPTX/NVPTXLowerAggrCopies.cpp @@ -16,12 +16,12 @@ #include "llvm/IR/DataLayout.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InstIterator.h" #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" -#include "llvm/Support/InstIterator.h" using namespace llvm; @@ -104,7 +104,7 @@ bool NVPTXLowerAggrCopies::runOnFunction(Function &F) { SmallVector<MemTransferInst *, 4> aggrMemcpys; SmallVector<MemSetInst *, 4> aggrMemsets; - DataLayout *TD = &getAnalysis<DataLayout>(); + const DataLayout *DL = &getAnalysis<DataLayoutPass>().getDataLayout(); LLVMContext &Context = F.getParent()->getContext(); // @@ -120,10 +120,10 @@ bool NVPTXLowerAggrCopies::runOnFunction(Function &F) { if (load->hasOneUse() == false) continue; - if (TD->getTypeStoreSize(load->getType()) < MaxAggrCopySize) + if (DL->getTypeStoreSize(load->getType()) < MaxAggrCopySize) continue; - User *use = *(load->use_begin()); + User *use = load->user_back(); if (StoreInst *store = dyn_cast<StoreInst>(use)) { if (store->getOperand(0) != load) //getValueOperand continue; @@ -163,10 +163,10 @@ bool NVPTXLowerAggrCopies::runOnFunction(Function &F) { // for (unsigned i = 0, e = aggrLoads.size(); i != e; ++i) { LoadInst *load = aggrLoads[i]; - StoreInst *store = dyn_cast<StoreInst>(*load->use_begin()); + StoreInst *store = dyn_cast<StoreInst>(*load->user_begin()); Value *srcAddr = load->getOperand(0); Value *dstAddr = store->getOperand(1); - unsigned numLoads = TD->getTypeStoreSize(load->getType()); + unsigned numLoads = DL->getTypeStoreSize(load->getType()); Value *len = ConstantInt::get(Type::getInt32Ty(Context), numLoads); convertTransferToLoop(store, srcAddr, dstAddr, len, load->isVolatile(), diff --git a/lib/Target/NVPTX/NVPTXLowerAggrCopies.h b/lib/Target/NVPTX/NVPTXLowerAggrCopies.h index 286e753..c9aa87d 100644 --- a/lib/Target/NVPTX/NVPTXLowerAggrCopies.h +++ b/lib/Target/NVPTX/NVPTXLowerAggrCopies.h @@ -28,7 +28,8 @@ struct NVPTXLowerAggrCopies : public FunctionPass { NVPTXLowerAggrCopies() : FunctionPass(ID) {} void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addRequired<DataLayout>(); + AU.addRequired<DataLayoutPass>(); + AU.addPreserved("stack-protector"); AU.addPreserved<MachineFunctionAnalysis>(); } diff --git a/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp b/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp index 843ebed..d5b042a 100644 --- a/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp +++ b/lib/Target/NVPTX/NVPTXPrologEpilogPass.cpp @@ -14,14 +14,14 @@ //===----------------------------------------------------------------------===// #include "NVPTX.h" -#include "llvm/Pass.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" -#include "llvm/Target/TargetFrameLowering.h" -#include "llvm/Target/TargetRegisterInfo.h" +#include "llvm/Pass.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetFrameLowering.h" +#include "llvm/Target/TargetRegisterInfo.h" using namespace llvm; diff --git a/lib/Target/NVPTX/NVPTXSplitBBatBar.cpp b/lib/Target/NVPTX/NVPTXSplitBBatBar.cpp deleted file mode 100644 index b64c308..0000000 --- a/lib/Target/NVPTX/NVPTXSplitBBatBar.cpp +++ /dev/null @@ -1,73 +0,0 @@ -//===- NVPTXSplitBBatBar.cpp - Split BB at Barrier --*- C++ -*--===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// Split basic blocks so that a basic block that contains a barrier instruction -// only contains the barrier instruction. -// -//===----------------------------------------------------------------------===// - -#include "NVPTXSplitBBatBar.h" -#include "NVPTXUtilities.h" -#include "llvm/IR/Function.h" -#include "llvm/IR/Instructions.h" -#include "llvm/IR/IntrinsicInst.h" -#include "llvm/IR/Intrinsics.h" -#include "llvm/Support/InstIterator.h" - -using namespace llvm; - -namespace llvm { FunctionPass *createSplitBBatBarPass(); } - -char NVPTXSplitBBatBar::ID = 0; - -bool NVPTXSplitBBatBar::runOnFunction(Function &F) { - - SmallVector<Instruction *, 4> SplitPoints; - bool changed = false; - - // Collect all the split points in SplitPoints - for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) { - BasicBlock::iterator IB = BI->begin(); - BasicBlock::iterator II = IB; - BasicBlock::iterator IE = BI->end(); - - // Skit the first instruction. No splitting is needed at this - // point even if this is a bar. - while (II != IE) { - if (IntrinsicInst *inst = dyn_cast<IntrinsicInst>(II)) { - Intrinsic::ID id = inst->getIntrinsicID(); - // If this is a barrier, split at this instruction - // and the next instruction. - if (llvm::isBarrierIntrinsic(id)) { - if (II != IB) - SplitPoints.push_back(II); - II++; - if ((II != IE) && (!II->isTerminator())) { - SplitPoints.push_back(II); - II++; - } - continue; - } - } - II++; - } - } - - for (unsigned i = 0; i != SplitPoints.size(); i++) { - changed = true; - Instruction *inst = SplitPoints[i]; - inst->getParent()->splitBasicBlock(inst, "bar_split"); - } - - return changed; -} - -// This interface will most likely not be necessary, because this pass will -// not be invoked by the driver, but will be used as a prerequisite to -// another pass. -FunctionPass *llvm::createSplitBBatBarPass() { return new NVPTXSplitBBatBar(); } diff --git a/lib/Target/NVPTX/NVPTXSplitBBatBar.h b/lib/Target/NVPTX/NVPTXSplitBBatBar.h deleted file mode 100644 index bdafba9..0000000 --- a/lib/Target/NVPTX/NVPTXSplitBBatBar.h +++ /dev/null @@ -1,41 +0,0 @@ -//===-- llvm/lib/Target/NVPTX/NVPTXSplitBBatBar.h ---------------*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file contains the declaration of the NVIDIA specific declarations -// for splitting basic blocks at barrier instructions. -// -//===----------------------------------------------------------------------===// - -#ifndef NVPTX_SPLIT_BB_AT_BAR_H -#define NVPTX_SPLIT_BB_AT_BAR_H - -#include "llvm/CodeGen/MachineFunctionAnalysis.h" -#include "llvm/Pass.h" - -namespace llvm { - -// actual analysis class, which is a functionpass -struct NVPTXSplitBBatBar : public FunctionPass { - static char ID; - - NVPTXSplitBBatBar() : FunctionPass(ID) {} - void getAnalysisUsage(AnalysisUsage &AU) const { - AU.addPreserved<MachineFunctionAnalysis>(); - } - virtual bool runOnFunction(Function &F); - - virtual const char *getPassName() const { - return "Split basic blocks at barrier"; - } -}; - -extern FunctionPass *createSplitBBatBarPass(); -} - -#endif //NVPTX_SPLIT_BB_AT_BAR_H diff --git a/lib/Target/NVPTX/NVPTXSubtarget.h b/lib/Target/NVPTX/NVPTXSubtarget.h index 004be11..f99bebd 100644 --- a/lib/Target/NVPTX/NVPTXSubtarget.h +++ b/lib/Target/NVPTX/NVPTXSubtarget.h @@ -74,21 +74,6 @@ public: unsigned getPTXVersion() const { return PTXVersion; } void ParseSubtargetFeatures(StringRef CPU, StringRef FS); - - std::string getDataLayout() const { - const char *p; - if (is64Bit()) - p = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" - "f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-" - "n16:32:64"; - else - p = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-" - "f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-" - "n16:32:64"; - - return std::string(p); - } - }; } // End llvm namespace diff --git a/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/lib/Target/NVPTX/NVPTXTargetMachine.cpp index 46edd6d..7d7d793 100644 --- a/lib/Target/NVPTX/NVPTXTargetMachine.cpp +++ b/lib/Target/NVPTX/NVPTXTargetMachine.cpp @@ -16,16 +16,15 @@ #include "NVPTX.h" #include "NVPTXAllocaHoisting.h" #include "NVPTXLowerAggrCopies.h" -#include "NVPTXSplitBBatBar.h" #include "llvm/ADT/OwningPtr.h" #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" #include "llvm/IR/DataLayout.h" +#include "llvm/IR/IRPrintingPasses.h" +#include "llvm/IR/Verifier.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCStreamer.h" @@ -50,6 +49,7 @@ using namespace llvm; namespace llvm { void initializeNVVMReflectPass(PassRegistry&); void initializeGenericToNVVMPass(PassRegistry&); +void initializeNVPTXAssignValidGlobalNamesPass(PassRegistry&); } extern "C" void LLVMInitializeNVPTXTarget() { @@ -61,6 +61,18 @@ extern "C" void LLVMInitializeNVPTXTarget() { // but it's very NVPTX-specific. initializeNVVMReflectPass(*PassRegistry::getPassRegistry()); initializeGenericToNVVMPass(*PassRegistry::getPassRegistry()); + initializeNVPTXAssignValidGlobalNamesPass(*PassRegistry::getPassRegistry()); +} + +static std::string computeDataLayout(const NVPTXSubtarget &ST) { + std::string Ret = "e"; + + if (!ST.is64Bit()) + Ret += "-p:32:32"; + + Ret += "-i64:64-v16:16-v32:32-n16:32:64"; + + return Ret; } NVPTXTargetMachine::NVPTXTargetMachine( @@ -68,7 +80,7 @@ NVPTXTargetMachine::NVPTXTargetMachine( 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()), + Subtarget(TT, CPU, FS, is64bit), DL(computeDataLayout(Subtarget)), InstrInfo(*this), TLInfo(*this), TSInfo(*this), FrameLowering( *this, is64bit) /*FrameInfo(TargetFrameInfo::StackGrowsUp, 8, 0)*/ { @@ -106,7 +118,7 @@ public: virtual bool addPreRegAlloc(); virtual bool addPostRegAlloc(); - virtual FunctionPass *createTargetRegisterAllocator(bool) LLVM_OVERRIDE; + virtual FunctionPass *createTargetRegisterAllocator(bool) override; virtual void addFastRegAlloc(FunctionPass *RegAllocPass); virtual void addOptimizedRegAlloc(FunctionPass *RegAllocPass); }; @@ -129,12 +141,12 @@ void NVPTXPassConfig::addIRPasses() { disablePass(&TailDuplicateID); TargetPassConfig::addIRPasses(); + addPass(createNVPTXAssignValidGlobalNamesPass()); addPass(createGenericToNVVMPass()); } bool NVPTXPassConfig::addInstSelector() { addPass(createLowerAggrCopies()); - addPass(createSplitBBatBarPass()); addPass(createAllocaHoisting()); addPass(createNVPTXISelDag(getNVPTXTargetMachine(), getOptLevel())); return false; diff --git a/lib/Target/NVPTX/NVPTXTargetObjectFile.h b/lib/Target/NVPTX/NVPTXTargetObjectFile.h index 2a7394b..2a7281e 100644 --- a/lib/Target/NVPTX/NVPTXTargetObjectFile.h +++ b/lib/Target/NVPTX/NVPTXTargetObjectFile.h @@ -46,7 +46,7 @@ public: virtual ~NVPTXTargetObjectFile(); - virtual void Initialize(MCContext &ctx, const TargetMachine &TM) { + void Initialize(MCContext &ctx, const TargetMachine &TM) override { TargetLoweringObjectFile::Initialize(ctx, TM); TextSection = new NVPTXSection(MCSection::SV_ELF, SectionKind::getText()); DataSection = @@ -87,13 +87,13 @@ public: new NVPTXSection(MCSection::SV_ELF, SectionKind::getMetadata()); } - virtual const MCSection *getSectionForConstant(SectionKind Kind) const { + const MCSection *getSectionForConstant(SectionKind Kind) const override { return ReadOnlySection; } - virtual const MCSection * - getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, - Mangler *Mang, const TargetMachine &TM) const { + const MCSection *getExplicitSectionGlobal(const GlobalValue *GV, + SectionKind Kind, Mangler &Mang, + const TargetMachine &TM) const override { return DataSection; } diff --git a/lib/Target/NVPTX/NVPTXUtilities.cpp b/lib/Target/NVPTX/NVPTXUtilities.cpp index 6786eb0..60a5173 100644 --- a/lib/Target/NVPTX/NVPTXUtilities.cpp +++ b/lib/Target/NVPTX/NVPTXUtilities.cpp @@ -24,7 +24,7 @@ #include <vector> //#include <iostream> #include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/InstIterator.h" +#include "llvm/IR/InstIterator.h" using namespace llvm; diff --git a/lib/Target/NVPTX/NVVMReflect.cpp b/lib/Target/NVPTX/NVVMReflect.cpp index 7406207..8b5444a 100644 --- a/lib/Target/NVPTX/NVVMReflect.cpp +++ b/lib/Target/NVPTX/NVVMReflect.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This pass replaces occurences of __nvvm_reflect("string") with an +// This pass replaces occurrences of __nvvm_reflect("string") with an // integer based on -nvvm-reflect-list string=<int> option given to this pass. // If an undefined string value is seen in a call to __nvvm_reflect("string"), // a default value of 0 will be used. @@ -18,13 +18,13 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" -#include "llvm/Pass.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" +#include "llvm/IR/Instructions.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" -#include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/Instructions.h" -#include "llvm/IR/Constants.h" +#include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_os_ostream.h" @@ -84,7 +84,7 @@ NVVMReflectEnabled("nvvm-reflect-enable", cl::init(true), cl::Hidden, char NVVMReflect::ID = 0; INITIALIZE_PASS(NVVMReflect, "nvvm-reflect", - "Replace occurences of __nvvm_reflect() calls with 0/1", false, + "Replace occurrences of __nvvm_reflect() calls with 0/1", false, false) static cl::list<std::string> @@ -143,11 +143,9 @@ bool NVVMReflect::runOnModule(Module &M) { // ConstantArray can be found successfully, see if it can be // found in VarMap. If so, replace the uses of CallInst with the // value found in VarMap. If not, replace the use with value 0. - for (Value::use_iterator I = ReflectFunction->use_begin(), - E = ReflectFunction->use_end(); - I != E; ++I) { - assert(isa<CallInst>(*I) && "Only a call instruction can use _reflect"); - CallInst *Reflect = cast<CallInst>(*I); + for (User *U : ReflectFunction->users()) { + assert(isa<CallInst>(U) && "Only a call instruction can use _reflect"); + CallInst *Reflect = cast<CallInst>(U); assert((Reflect->getNumOperands() == 2) && "Only one operand expect for _reflect function"); diff --git a/lib/Target/NVPTX/TargetInfo/CMakeLists.txt b/lib/Target/NVPTX/TargetInfo/CMakeLists.txt index 0bf1334..1beb40e 100644 --- a/lib/Target/NVPTX/TargetInfo/CMakeLists.txt +++ b/lib/Target/NVPTX/TargetInfo/CMakeLists.txt @@ -1,7 +1,3 @@ -#include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/.. ) - add_llvm_library(LLVMNVPTXInfo NVPTXTargetInfo.cpp ) - -add_dependencies(LLVMNVPTXInfo NVPTXCommonTableGen) diff --git a/lib/Target/NVPTX/TargetInfo/LLVMBuild.txt b/lib/Target/NVPTX/TargetInfo/LLVMBuild.txt index ef12b0e..af7ec27 100644 --- a/lib/Target/NVPTX/TargetInfo/LLVMBuild.txt +++ b/lib/Target/NVPTX/TargetInfo/LLVMBuild.txt @@ -19,5 +19,5 @@ type = Library name = NVPTXInfo parent = NVPTX -required_libraries = MC Support Target +required_libraries = Support add_to_library_groups = NVPTX |