[NVPTX] .attribute(.managed) is only supported for sm_30 and PTX 4.0

PTX ISA spec, s5.4.8. Variable Attribute Directive: .attribute

PTX ISA Notes
Introduced in PTX ISA version 4.0.

Target ISA Notes
.managed attribute requires sm_30 or higher.

Differential Revision: https://reviews.llvm.org/D123040
This commit is contained in:
Andrew Savonichev 2022-03-31 23:50:34 +03:00
parent 230f326964
commit 4cef5c397d
3 changed files with 31 additions and 10 deletions

View File

@ -817,9 +817,13 @@ void NVPTXAsmPrinter::emitGlobals(const Module &M) {
"Missed a global variable"); "Missed a global variable");
assert(GVVisiting.size() == 0 && "Did not fully process a global variable"); assert(GVVisiting.size() == 0 && "Did not fully process a global variable");
const NVPTXTargetMachine &NTM = static_cast<const NVPTXTargetMachine &>(TM);
const NVPTXSubtarget &STI =
*static_cast<const NVPTXSubtarget *>(NTM.getSubtargetImpl());
// Print out module-level global variables in proper order // Print out module-level global variables in proper order
for (unsigned i = 0, e = Globals.size(); i != e; ++i) for (unsigned i = 0, e = Globals.size(); i != e; ++i)
printModuleLevelGV(Globals[i], OS2); printModuleLevelGV(Globals[i], OS2, /*processDemoted=*/false, STI);
OS2 << '\n'; OS2 << '\n';
@ -957,8 +961,8 @@ void NVPTXAsmPrinter::emitLinkageDirective(const GlobalValue *V,
} }
void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar, void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
raw_ostream &O, raw_ostream &O, bool processDemoted,
bool processDemoted) { const NVPTXSubtarget &STI) {
// Skip meta data // Skip meta data
if (GVar->hasSection()) { if (GVar->hasSection()) {
if (GVar->getSection() == "llvm.metadata") if (GVar->getSection() == "llvm.metadata")
@ -1001,7 +1005,7 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
// (extern) declarations, no definition or initializer // (extern) declarations, no definition or initializer
// Currently the only known declaration is for an automatic __local // Currently the only known declaration is for an automatic __local
// (.shared) promoted to global. // (.shared) promoted to global.
emitPTXGlobalVariable(GVar, O); emitPTXGlobalVariable(GVar, O, STI);
O << ";\n"; O << ";\n";
return; return;
} }
@ -1095,6 +1099,10 @@ void NVPTXAsmPrinter::printModuleLevelGV(const GlobalVariable *GVar,
emitPTXAddressSpace(PTy->getAddressSpace(), O); emitPTXAddressSpace(PTy->getAddressSpace(), O);
if (isManaged(*GVar)) { if (isManaged(*GVar)) {
if (STI.getPTXVersion() < 40 || STI.getSmVersion() < 30) {
report_fatal_error(
".attribute(.managed) requires PTX version >= 4.0 and sm_30");
}
O << " .attribute(.managed)"; O << " .attribute(.managed)";
} }
@ -1214,9 +1222,13 @@ void NVPTXAsmPrinter::emitDemotedVars(const Function *f, raw_ostream &O) {
std::vector<const GlobalVariable *> &gvars = localDecls[f]; std::vector<const GlobalVariable *> &gvars = localDecls[f];
const NVPTXTargetMachine &NTM = static_cast<const NVPTXTargetMachine &>(TM);
const NVPTXSubtarget &STI =
*static_cast<const NVPTXSubtarget *>(NTM.getSubtargetImpl());
for (const GlobalVariable *GV : gvars) { for (const GlobalVariable *GV : gvars) {
O << "\t// demoted variable\n\t"; O << "\t// demoted variable\n\t";
printModuleLevelGV(GV, O, true); printModuleLevelGV(GV, O, /*processDemoted=*/true, STI);
} }
} }
@ -1282,7 +1294,8 @@ NVPTXAsmPrinter::getPTXFundamentalTypeStr(Type *Ty, bool useB4PTR) const {
} }
void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar, void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar,
raw_ostream &O) { raw_ostream &O,
const NVPTXSubtarget &STI) {
const DataLayout &DL = getDataLayout(); const DataLayout &DL = getDataLayout();
// GlobalVariables are always constant pointers themselves. // GlobalVariables are always constant pointers themselves.
@ -1290,8 +1303,13 @@ void NVPTXAsmPrinter::emitPTXGlobalVariable(const GlobalVariable *GVar,
O << "."; O << ".";
emitPTXAddressSpace(GVar->getType()->getAddressSpace(), O); emitPTXAddressSpace(GVar->getType()->getAddressSpace(), O);
if (isManaged(*GVar)) if (isManaged(*GVar)) {
if (STI.getPTXVersion() < 40 || STI.getSmVersion() < 30) {
report_fatal_error(
".attribute(.managed) requires PTX version >= 4.0 and sm_30");
}
O << " .attribute(.managed)"; O << " .attribute(.managed)";
}
if (MaybeAlign A = GVar->getAlign()) if (MaybeAlign A = GVar->getAlign())
O << " .align " << A->value(); O << " .align " << A->value();
else else

View File

@ -218,7 +218,7 @@ private:
void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O, void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
const char *Modifier = nullptr); const char *Modifier = nullptr);
void printModuleLevelGV(const GlobalVariable *GVar, raw_ostream &O, void printModuleLevelGV(const GlobalVariable *GVar, raw_ostream &O,
bool = false); bool processDemoted, const NVPTXSubtarget &STI);
void printParamName(Function::const_arg_iterator I, int paramIndex, void printParamName(Function::const_arg_iterator I, int paramIndex,
raw_ostream &O); raw_ostream &O);
void emitGlobals(const Module &M); void emitGlobals(const Module &M);
@ -258,7 +258,8 @@ private:
// List of variables demoted to a function scope. // List of variables demoted to a function scope.
std::map<const Function *, std::vector<const GlobalVariable *>> localDecls; std::map<const Function *, std::vector<const GlobalVariable *>> localDecls;
void emitPTXGlobalVariable(const GlobalVariable *GVar, raw_ostream &O); void emitPTXGlobalVariable(const GlobalVariable *GVar, raw_ostream &O,
const NVPTXSubtarget &STI);
void emitPTXAddressSpace(unsigned int AddressSpace, raw_ostream &O) const; void emitPTXAddressSpace(unsigned int AddressSpace, raw_ostream &O) const;
std::string getPTXFundamentalTypeStr(Type *Ty, bool = true) const; std::string getPTXFundamentalTypeStr(Type *Ty, bool = true) const;
void printScalarConstant(const Constant *CPV, raw_ostream &O); void printScalarConstant(const Constant *CPV, raw_ostream &O);

View File

@ -1,5 +1,7 @@
; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s ; RUN: llc < %s -march=nvptx -mcpu=sm_30 -mattr=+ptx40 | FileCheck %s
; RUN: not --crash llc < %s -march=nvptx -mcpu=sm_20 2>&1 | FileCheck %s --check-prefix ERROR
; ERROR: LLVM ERROR: .attribute(.managed) requires PTX version >= 4.0 and sm_30
; CHECK: .visible .global .align 4 .u32 device_g; ; CHECK: .visible .global .align 4 .u32 device_g;
@device_g = addrspace(1) global i32 zeroinitializer @device_g = addrspace(1) global i32 zeroinitializer