95#define DEPOTNAME "__local_depot"
108 for (
const auto &O : U->operands())
121 if (Visited.
count(GV))
125 if (!Visiting.
insert(GV).second)
130 for (
const auto &O : GV->
operands())
143 NVPTX_MC::verifyInstructionPredicates(
MI->getOpcode(),
147 lowerToMCInst(
MI, Inst);
154 if (
MI->getOpcode() == NVPTX::CALL_PROTOTYPE) {
155 const MachineOperand &MO =
MI->getOperand(0);
161 for (
const auto MO :
MI->operands())
206unsigned NVPTXAsmPrinter::encodeVirtualRegister(
unsigned Reg) {
208 const TargetRegisterClass *RC = MRI->getRegClass(
Reg);
210 DenseMap<unsigned, unsigned> &RegMap = VRegMapping[RC];
211 unsigned RegNum = RegMap[
Reg];
216 if (RC == &NVPTX::B1RegClass) {
218 }
else if (RC == &NVPTX::B16RegClass) {
220 }
else if (RC == &NVPTX::B32RegClass) {
222 }
else if (RC == &NVPTX::B64RegClass) {
224 }
else if (RC == &NVPTX::B128RegClass) {
231 Ret |= (RegNum & 0x0FFFFFFF);
236 return Reg & 0x0FFFFFFF;
248 const NVPTXSubtarget &STI =
TM.getSubtarget<NVPTXSubtarget>(*F);
251 Type *Ty = F->getReturnType();
256 auto PrintScalarRetVal = [&](
unsigned Size) {
260 const unsigned TotalSize =
DL.getTypeAllocSize(Ty);
261 const Align RetAlignment = TLI->getFunctionArgumentAlignment(
262 F, Ty, AttributeList::ReturnIndex,
DL);
263 O <<
".param .align " << RetAlignment.
value() <<
" .b8 func_retval0["
268 PrintScalarRetVal(ITy->getBitWidth());
270 PrintScalarRetVal(TLI->getPointerTy(
DL).getSizeInBits());
279 printReturnValStr(&F, O);
284bool NVPTXAsmPrinter::isLoopHeaderOfNoUnroll(
299 if (
const BasicBlock *PBB = PMBB->getBasicBlock()) {
301 PBB->getTerminator()->getMetadata(LLVMContext::MD_loop)) {
304 if (MDNode *UnrollCountMD =
318 if (isLoopHeaderOfNoUnroll(
MBB))
319 OutStreamer->emitRawText(StringRef(
"\t.pragma \"nounroll\";\n"));
323 SmallString<128> Str;
324 raw_svector_ostream
O(Str);
326 if (!GlobalsEmitted) {
327 emitGlobals(*
MF->getFunction().getParent());
328 GlobalsEmitted =
true;
332 MRI = &
MF->getRegInfo();
333 F = &
MF->getFunction();
334 emitLinkageDirective(F, O);
339 printReturnValStr(*
MF, O);
344 emitFunctionParamList(F, O);
348 emitKernelFunctionDirectives(*F, O);
358 setAndEmitFunctionVirtualRegisters(*
MF);
359 encodeDebugInfoRegisterNumbers(*
MF);
361 if (
const DISubprogram *SP =
MF->getFunction().getSubprogram()) {
363 if (!
SP->getUnit()->isDebugDirectivesOnly())
396void NVPTXAsmPrinter::emitImplicitDef(
const MachineInstr *
MI)
const {
409void NVPTXAsmPrinter::emitKernelFunctionDirectives(
const Function &
F,
415 if (!ReqNTID.empty())
416 O <<
formatv(
".reqntid {0:$[, ]}\n",
420 if (!MaxNTID.empty())
421 O <<
formatv(
".maxntid {0:$[, ]}\n",
425 O <<
".minnctapersm " << *Mincta <<
"\n";
428 O <<
".maxnreg " << *Maxnreg <<
"\n";
432 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
433 const NVPTXSubtarget *STI = &NTM.
getSubtarget<NVPTXSubtarget>(F);
439 if (!ClusterDim.empty()) {
441 if (!BlocksAreClusters)
442 O <<
".explicitcluster\n";
444 if (ClusterDim[0] != 0) {
446 "cluster_dim_x != 0 implies cluster_dim_y and cluster_dim_z "
447 "should be non-zero as well");
449 O <<
formatv(
".reqnctapercluster {0:$[, ]}\n",
450 make_range(ClusterDim.begin(), ClusterDim.end()));
453 "cluster_dim_x == 0 implies cluster_dim_y and cluster_dim_z "
454 "should be 0 as well");
458 if (BlocksAreClusters) {
459 LLVMContext &Ctx = F.getContext();
460 if (ReqNTID.empty() || ClusterDim.empty())
461 Ctx.
diagnose(DiagnosticInfoUnsupported(
462 F,
"blocksareclusters requires reqntid and cluster_dim attributes",
465 Ctx.
diagnose(DiagnosticInfoUnsupported(
466 F,
"blocksareclusters requires PTX version >= 9.0",
469 O <<
".blocksareclusters\n";
473 O <<
".maxclusterrank " << *Maxclusterrank <<
"\n";
484 assert(
I != VRegMapping.end() &&
"Bad register class");
488 assert(VI != RegMap.
end() &&
"Bad virtual register");
489 unsigned MappedVR = VI->second;
496void NVPTXAsmPrinter::emitVirtualRegister(
unsigned int vr,
501void NVPTXAsmPrinter::emitAliasDeclaration(
const GlobalAlias *GA,
506 "NVPTX aliasee must be a non-kernel function definition");
516 emitDeclarationWithName(F,
getSymbol(F), O);
521 emitLinkageDirective(F, O);
526 printReturnValStr(F, O);
529 emitFunctionParamList(F, O);
541 return GV->getName() !=
"llvm.used";
543 for (
const User *U :
C->users())
553 if (OtherGV->getName() ==
"llvm.used")
557 if (
const Function *CurFunc =
I->getFunction()) {
558 if (OneFunc && (CurFunc != OneFunc))
599 for (
const User *U :
C->users()) {
604 if (
const Function *Caller =
I->getFunction())
613 SmallPtrSet<const Function *, 32> SeenSet;
614 for (
const Function &F : M) {
615 if (F.getAttributes().hasFnAttr(
"nvptx-libcall-callee")) {
616 emitDeclaration(&F, O);
620 if (F.isDeclaration()) {
623 if (F.getIntrinsicID())
625 emitDeclaration(&F, O);
628 for (
const User *U : F.users()) {
634 emitDeclaration(&F, O);
640 emitDeclaration(&F, O);
655 emitDeclaration(&F, O);
661 for (
const GlobalAlias &GA :
M.aliases())
662 emitAliasDeclaration(&GA, O);
665void NVPTXAsmPrinter::emitStartOfAsmFile(
Module &M) {
669 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
671 SmallString<128> Str1;
672 raw_svector_ostream OS1(Str1);
675 emitHeader(M, OS1, *STI);
688 GlobalsEmitted =
false;
693void NVPTXAsmPrinter::emitGlobals(
const Module &M) {
697 emitDeclarations(M, OS2);
712 assert(GVVisited.
size() == M.global_size() &&
"Missed a global variable");
713 assert(GVVisiting.
size() == 0 &&
"Did not fully process a global variable");
720 printModuleLevelGV(GV, OS2,
false, STI);
744 "// Generated by LLVM NVPTX Back-End\n"
747 <<
".version " << (PTXVersion / 10) <<
"." << (PTXVersion % 10) <<
"\n"
750 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
752 O <<
", texmode_independent";
754 bool HasFullDebugInfo =
false;
755 for (DICompileUnit *CU :
M.debug_compile_units()) {
756 switch(CU->getEmissionKind()) {
762 HasFullDebugInfo =
true;
765 if (HasFullDebugInfo)
768 if (HasFullDebugInfo)
772 <<
".address_size " << (NTM.
is64Bit() ?
"64" :
"32") <<
"\n"
779 if (!GlobalsEmitted) {
781 GlobalsEmitted =
true;
793 TS->closeLastSection();
795 OutStreamer->emitRawText(
"\t.section\t.debug_macinfo\t{\t}");
817void NVPTXAsmPrinter::emitLinkageDirective(
const GlobalValue *V,
820 if (V->hasExternalLinkage()) {
822 O << (GVar->hasInitializer() ?
".visible " :
".extern ");
823 else if (V->isDeclaration())
827 }
else if (V->hasAppendingLinkage()) {
829 "' has unsupported appending linkage type");
830 }
else if (!
V->hasInternalLinkage() && !
V->hasPrivateLinkage()) {
836void NVPTXAsmPrinter::printModuleLevelGV(
const GlobalVariable *GVar,
882 emitPTXGlobalVariable(GVar, O, STI);
890 const Constant *Initializer =
nullptr;
893 const ConstantInt *CI =
nullptr;
904 O <<
"addr_mode_" << i <<
" = ";
910 O <<
"clamp_to_border";
913 O <<
"clamp_to_edge";
924 O <<
"filter_mode = ";
939 O <<
", force_unnormalized_coords = 1";
959 const Function *DemotedFunc =
nullptr;
961 O <<
"// " << GVar->
getName() <<
" has been demoted\n";
962 localDecls[DemotedFunc].push_back(GVar);
972 ".attribute(.managed) requires PTX version >= 4.0 and sm_30");
973 O <<
" .attribute(.managed)";
977 << GVar->
getAlign().value_or(
DL.getPrefTypeAlign(ETy)).value();
986 O << getPTXFundamentalTypeStr(ETy,
false);
999 printScalarConstant(Initializer, O);
1008 "' is not allowed in addrspace(" +
1024 const uint64_t ElementSize =
DL.getTypeStoreSize(ETy);
1032 AggBuffer aggBuffer(ElementSize, *
this);
1033 bufferAggregateConstant(Initializer, &aggBuffer);
1034 if (aggBuffer.numSymbols()) {
1035 const unsigned int ptrSize =
MAI->getCodePointerSize();
1036 if (ElementSize % ptrSize ||
1037 !aggBuffer.allSymbolsAligned(ptrSize)) {
1041 "initialized packed aggregate with pointers '" +
1043 "' requires at least PTX ISA version 7.1");
1046 O <<
"[" << ElementSize <<
"] = {";
1047 aggBuffer.printBytes(O);
1050 O <<
" .u" << ptrSize * 8 <<
" ";
1052 O <<
"[" << ElementSize / ptrSize <<
"] = {";
1053 aggBuffer.printWords(O);
1059 O <<
"[" << ElementSize <<
"] = {";
1060 aggBuffer.printBytes(O);
1067 O <<
"[" << ElementSize <<
"]";
1073 O <<
"[" << ElementSize <<
"]";
1084void NVPTXAsmPrinter::AggBuffer::printSymbol(
unsigned nSym,
raw_ostream &os) {
1085 const Value *
v = Symbols[nSym];
1086 const Value *v0 = SymbolsBeforeStripping[nSym];
1091 bool isGenericPointer = PTy && PTy->getAddressSpace() == 0;
1094 Name->print(os, AP.MAI);
1097 Name->print(os, AP.MAI);
1100 const MCExpr *Expr = AP.lowerConstantForGV(CExpr,
false);
1101 AP.printMCExpr(*Expr, os);
1106void NVPTXAsmPrinter::AggBuffer::printBytes(raw_ostream &os) {
1107 unsigned int ptrSize = AP.MAI->getCodePointerSize();
1112 unsigned int InitializerCount =
size;
1115 if (numSymbols() == 0)
1116 while (InitializerCount >= 1 && !buffer[InitializerCount - 1])
1119 symbolPosInBuffer.push_back(InitializerCount);
1120 unsigned int nSym = 0;
1121 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
1122 for (
unsigned int pos = 0; pos < InitializerCount;) {
1125 if (pos != nextSymbolPos) {
1126 os << (
unsigned int)buffer[pos];
1133 std::string symText;
1134 llvm::raw_string_ostream oss(symText);
1135 printSymbol(nSym, oss);
1136 for (
unsigned i = 0; i < ptrSize; ++i) {
1140 os <<
"(" << symText <<
")";
1143 nextSymbolPos = symbolPosInBuffer[++nSym];
1144 assert(nextSymbolPos >= pos);
1148void NVPTXAsmPrinter::AggBuffer::printWords(raw_ostream &os) {
1149 unsigned int ptrSize = AP.MAI->getCodePointerSize();
1150 symbolPosInBuffer.push_back(
size);
1151 unsigned int nSym = 0;
1152 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
1153 assert(nextSymbolPos % ptrSize == 0);
1154 for (
unsigned int pos = 0; pos <
size; pos += ptrSize) {
1157 if (pos == nextSymbolPos) {
1158 printSymbol(nSym, os);
1159 nextSymbolPos = symbolPosInBuffer[++nSym];
1160 assert(nextSymbolPos % ptrSize == 0);
1161 assert(nextSymbolPos >= pos + ptrSize);
1162 }
else if (ptrSize == 4)
1169void NVPTXAsmPrinter::emitDemotedVars(
const Function *F, raw_ostream &O) {
1170 auto It = localDecls.find(F);
1171 if (It == localDecls.end())
1176 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
1179 for (
const GlobalVariable *GV : GVars) {
1180 O <<
"\t// demoted variable\n\t";
1181 printModuleLevelGV(GV, O,
true, STI);
1185void NVPTXAsmPrinter::emitPTXAddressSpace(
unsigned int AddressSpace,
1186 raw_ostream &O)
const {
1208NVPTXAsmPrinter::getPTXFundamentalTypeStr(
Type *Ty,
bool useB4PTR)
const {
1214 if (NumBits <= 64) {
1215 std::string
name =
"u";
1232 assert((PtrSize == 64 || PtrSize == 32) &&
"Unexpected pointer size");
1250void NVPTXAsmPrinter::emitPTXGlobalVariable(
const GlobalVariable *GVar,
1252 const NVPTXSubtarget &STI) {
1263 ".attribute(.managed) requires PTX version >= 4.0 and sm_30");
1265 O <<
" .attribute(.managed)";
1268 << GVar->
getAlign().value_or(
DL.getPrefTypeAlign(ETy)).value();
1279 O <<
" ." << getPTXFundamentalTypeStr(ETy) <<
" ";
1284 int64_t ElementSize = 0;
1294 ElementSize =
DL.getTypeStoreSize(ETy);
1308void NVPTXAsmPrinter::emitFunctionParamList(
const Function *F, raw_ostream &O) {
1310 const NVPTXSubtarget &STI =
TM.getSubtarget<NVPTXSubtarget>(*F);
1312 const NVPTXMachineFunctionInfo *MFI =
1313 MF ?
MF->getInfo<NVPTXMachineFunctionInfo>() : nullptr;
1315 bool IsFirst =
true;
1318 if (F->arg_empty() && !F->isVarArg()) {
1325 for (
const Argument &Arg : F->args()) {
1326 Type *Ty = Arg.getType();
1327 const std::string ParamSym = TLI->getParamName(F, Arg.getArgNo());
1338 const bool IsSurface = !IsSampler && !IsTexture &&
1340 if (IsSampler || IsTexture || IsSurface) {
1347 O <<
".samplerref ";
1357 auto GetOptimalAlignForParam = [TLI, &
DL, F, &Arg](
Type *Ty) -> Align {
1358 if (MaybeAlign StackAlign =
1359 getAlign(*F, Arg.getArgNo() + AttributeList::FirstArgIndex))
1360 return StackAlign.value();
1362 Align TypeAlign = TLI->getFunctionParamOptimizedAlign(F, Ty,
DL);
1363 MaybeAlign ParamAlign =
1364 Arg.hasByValAttr() ? Arg.getParamAlign() : MaybeAlign();
1365 return std::max(TypeAlign, ParamAlign.
valueOrOne());
1368 if (Arg.hasByValAttr()) {
1370 Type *ETy = Arg.getParamByValType();
1371 assert(ETy &&
"Param should have byval type");
1377 const Align OptimalAlign =
1378 IsKernelFunc ? GetOptimalAlignForParam(ETy)
1379 : TLI->getFunctionByValParamAlign(
1380 F, ETy, Arg.getParamAlign().valueOrOne(),
DL);
1382 O <<
"\t.param .align " << OptimalAlign.
value() <<
" .b8 " << ParamSym
1383 <<
"[" <<
DL.getTypeAllocSize(ETy) <<
"]";
1392 Align OptimalAlign = GetOptimalAlignForParam(Ty);
1394 O <<
"\t.param .align " << OptimalAlign.
value() <<
" .b8 " << ParamSym
1395 <<
"[" <<
DL.getTypeAllocSize(Ty) <<
"]";
1401 unsigned PTySizeInBits = 0;
1404 TLI->getPointerTy(
DL, PTy->getAddressSpace()).getSizeInBits();
1405 assert(PTySizeInBits &&
"Invalid pointer size");
1410 O <<
"\t.param .u" << PTySizeInBits <<
" .ptr";
1412 switch (PTy->getAddressSpace()) {
1429 O <<
" .align " << Arg.getParamAlign().valueOrOne().value() <<
" "
1440 O << getPTXFundamentalTypeStr(Ty);
1441 O <<
" " << ParamSym;
1450 assert(PTySizeInBits &&
"Invalid pointer size");
1451 Size = PTySizeInBits;
1454 O <<
"\t.param .b" <<
Size <<
" " << ParamSym;
1457 if (F->isVarArg()) {
1461 << TLI->getParamName(F, -1) <<
"[]";
1467void NVPTXAsmPrinter::setAndEmitFunctionVirtualRegisters(
1468 const MachineFunction &
MF) {
1469 SmallString<128> Str;
1470 raw_svector_ostream
O(Str);
1474 const TargetRegisterInfo *
TRI =
MF.getSubtarget().getRegisterInfo();
1477 const MachineFrameInfo &MFI =
MF.getFrameInfo();
1482 if (
static_cast<const NVPTXTargetMachine &
>(
MF.getTarget()).is64Bit()) {
1483 O <<
"\t.reg .b64 \t%SP;\n"
1484 <<
"\t.reg .b64 \t%SPL;\n";
1486 O <<
"\t.reg .b32 \t%SP;\n"
1487 <<
"\t.reg .b32 \t%SPL;\n";
1495 for (
unsigned I :
llvm::seq(MRI->getNumVirtRegs())) {
1497 if (MRI->use_empty(VR) && MRI->def_empty(VR))
1499 auto &RCRegMap = VRegMapping[MRI->getRegClass(VR)];
1500 RCRegMap[VR] = RCRegMap.size() + 1;
1505 for (
const TargetRegisterClass *RC :
TRI->regclasses()) {
1506 const unsigned N = VRegMapping[RC].size();
1512 O <<
"\t.reg " << RCName <<
" \t" << RCStr <<
"<" << (
N + 1) <<
">;\n";
1521void NVPTXAsmPrinter::encodeDebugInfoRegisterNumbers(
1522 const MachineFunction &
MF) {
1523 const NVPTXSubtarget &STI =
MF.getSubtarget<NVPTXSubtarget>();
1531 for (
auto &classMap : VRegMapping) {
1532 for (
auto ®isterMapping : classMap.getSecond()) {
1533 auto reg = registerMapping.getFirst();
1539void NVPTXAsmPrinter::printFPConstant(
const ConstantFP *Fp,
1540 raw_ostream &O)
const {
1543 unsigned int numHex;
1561void NVPTXAsmPrinter::printScalarConstant(
const Constant *CPV, raw_ostream &O) {
1567 printFPConstant(CFP, O);
1576 if (EmitGeneric && !
isa<Function>(CPV) && !IsNonGenericPointer) {
1593void NVPTXAsmPrinter::bufferLEByte(
const Constant *CPV,
int Bytes,
1594 AggBuffer *AggBuffer) {
1596 int AllocSize =
DL.getTypeAllocSize(CPV->
getType());
1600 AggBuffer->addZeros(Bytes ? Bytes : AllocSize);
1605 auto AddIntToBuffer = [AggBuffer, Bytes](
const APInt &Val) {
1606 size_t NumBytes = (Val.getBitWidth() + 7) / 8;
1612 for (
unsigned I = 0;
I < NumBytes - 1; ++
I) {
1613 Buf[
I] = Val.extractBitsAsZExtValue(8,
I * 8);
1615 size_t LastBytePosition = (NumBytes - 1) * 8;
1616 size_t LastByteBits = Val.getBitWidth() - LastBytePosition;
1618 Val.extractBitsAsZExtValue(LastByteBits, LastBytePosition);
1619 AggBuffer->addBytes(Buf.data(), NumBytes, Bytes);
1629 if (
const auto *CI =
1634 if (Cexpr->getOpcode() == Instruction::PtrToInt) {
1635 Value *
V = Cexpr->getOperand(0)->stripPointerCasts();
1636 AggBuffer->addSymbol(V, Cexpr->getOperand(0));
1637 AggBuffer->addZeros(AllocSize);
1653 AggBuffer->addSymbol(GVar, GVar);
1655 const Value *
v = Cexpr->stripPointerCasts();
1656 AggBuffer->addSymbol(v, Cexpr);
1658 AggBuffer->addZeros(AllocSize);
1666 bufferAggregateConstant(CPV, AggBuffer);
1667 if (Bytes > AllocSize)
1668 AggBuffer->addZeros(Bytes - AllocSize);
1670 AggBuffer->addZeros(Bytes);
1681void NVPTXAsmPrinter::bufferAggregateConstant(
const Constant *CPV,
1682 AggBuffer *aggBuffer) {
1685 auto ExtendBuffer = [](APInt Val, AggBuffer *Buffer) {
1692 ExtendBuffer(CI->
getValue(), aggBuffer);
1698 if (CFP->getType()->isFP128Ty()) {
1699 ExtendBuffer(CFP->getValueAPF().bitcastToAPInt(), aggBuffer);
1712 for (
unsigned I :
llvm::seq(CDS->getNumElements()))
1713 bufferLEByte(
cast<Constant>(CDS->getElementAsConstant(
I)), 0, aggBuffer);
1722 ?
DL.getStructLayout(ST)->getElementOffset(0) +
1723 DL.getTypeAllocSize(ST)
1724 :
DL.getStructLayout(ST)->getElementOffset(
I + 1);
1725 int Bytes = EndOffset -
DL.getStructLayout(ST)->getElementOffset(
I);
1739NVPTXAsmPrinter::lowerConstantForGV(
const Constant *CV,
1740 bool ProcessingGeneric)
const {
1751 if (ProcessingGeneric)
1761 switch (
CE->getOpcode()) {
1765 case Instruction::AddrSpaceCast: {
1768 if (DstTy->getAddressSpace() == 0)
1774 case Instruction::GetElementPtr: {
1778 APInt OffsetAI(
DL.getPointerTypeSizeInBits(
CE->getType()), 0);
1781 const MCExpr *
Base = lowerConstantForGV(
CE->getOperand(0),
1786 int64_t
Offset = OffsetAI.getSExtValue();
1791 case Instruction::Trunc:
1797 case Instruction::BitCast:
1798 return lowerConstantForGV(
CE->getOperand(0), ProcessingGeneric);
1800 case Instruction::IntToPtr: {
1809 return lowerConstantForGV(
Op, ProcessingGeneric);
1814 case Instruction::PtrToInt: {
1820 Type *Ty =
CE->getType();
1822 const MCExpr *OpExpr = lowerConstantForGV(
Op, ProcessingGeneric);
1826 if (
DL.getTypeAllocSize(Ty) ==
DL.getTypeAllocSize(
Op->getType()))
1832 unsigned InBits =
DL.getTypeAllocSizeInBits(
Op->getType());
1839 case Instruction::Add: {
1840 const MCExpr *
LHS = lowerConstantForGV(
CE->getOperand(0), ProcessingGeneric);
1841 const MCExpr *
RHS = lowerConstantForGV(
CE->getOperand(1), ProcessingGeneric);
1842 switch (
CE->getOpcode()) {
1854 return lowerConstantForGV(
C, ProcessingGeneric);
1858 raw_string_ostream OS(S);
1859 OS <<
"Unsupported expression in static initializer: ";
1860 CE->printAsOperand(OS,
false,
1861 !
MF ?
nullptr :
MF->getFunction().getParent());
1865void NVPTXAsmPrinter::printMCExpr(
const MCExpr &Expr, raw_ostream &OS)
const {
1866 OutContext.getAsmInfo()->printExpr(OS, Expr);
1871bool NVPTXAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
1872 const char *ExtraCode, raw_ostream &O) {
1873 if (ExtraCode && ExtraCode[0]) {
1874 if (ExtraCode[1] != 0)
1877 switch (ExtraCode[0]) {
1886 printOperand(
MI, OpNo, O);
1891bool NVPTXAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
1893 const char *ExtraCode,
1895 if (ExtraCode && ExtraCode[0])
1899 printMemOperand(
MI, OpNo, O);
1905void NVPTXAsmPrinter::printOperand(
const MachineInstr *
MI,
unsigned OpNum,
1907 const MachineOperand &MO =
MI->getOperand(OpNum);
1911 if (MO.
getReg() == NVPTX::VRDepot)
1916 emitVirtualRegister(MO.
getReg(), O);
1941void NVPTXAsmPrinter::printMemOperand(
const MachineInstr *
MI,
unsigned OpNum,
1942 raw_ostream &O,
const char *Modifier) {
1943 printOperand(
MI, OpNum, O);
1945 if (Modifier && strcmp(Modifier,
"add") == 0) {
1947 printOperand(
MI, OpNum + 1, O);
1949 if (
MI->getOperand(OpNum + 1).isImm() &&
1950 MI->getOperand(OpNum + 1).getImm() == 0)
1953 printOperand(
MI, OpNum + 1, O);
1964LLVMInitializeNVPTXAsmPrinter() {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
Module.h This file contains the declarations for the Module class.
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static void discoverDependentGlobals(const Value *V, DenseSet< const GlobalVariable * > &Globals)
discoverDependentGlobals - Return a set of GlobalVariables on which V depends.
static bool canDemoteGlobalVar(const GlobalVariable *GV, Function const *&f)
static bool useFuncSeen(const Constant *C, const SmallPtrSetImpl< const Function * > &SeenSet)
static void VisitGlobalVariableForEmission(const GlobalVariable *GV, SmallVectorImpl< const GlobalVariable * > &Order, DenseSet< const GlobalVariable * > &Visited, DenseSet< const GlobalVariable * > &Visiting)
VisitGlobalVariableForEmission - Add GV to the list of GlobalVariable instances to be emitted,...
static bool usedInGlobalVarDef(const Constant *C)
static bool usedInOneFunc(const User *U, Function const *&OneFunc)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file defines the SmallString class.
This file defines the SmallVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
static const fltSemantics & IEEEsingle()
static const fltSemantics & IEEEdouble()
static constexpr roundingMode rmNearestTiesToEven
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
APInt bitcastToAPInt() const
uint64_t getZExtValue() const
Get zero extended value.
LLVM_ABI uint64_t extractBitsAsZExtValue(unsigned numBits, unsigned bitPosition) const
unsigned getBitWidth() const
Return the number of bits in the APInt.
MCSymbol * getSymbol(const GlobalValue *GV) const
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
TargetMachine & TM
Target machine description.
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
const MCAsmInfo * MAI
Target Asm Printer information.
MachineFunction * MF
The current machine function.
bool hasDebugInfo() const
Returns true if valid debug info is present.
virtual void emitFunctionBodyStart()
Targets can override this to emit stuff before the first basic block in the function.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
unsigned getFunctionNumber() const
Return a unique ID for the current function.
MCSymbol * CurrentFnSym
The symbol for the current function.
MCContext & OutContext
This is the context for the output file that we are streaming.
bool doFinalization(Module &M) override
Shut down the asmprinter.
virtual void emitBasicBlockStart(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the start of a basic block.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
virtual void emitFunctionBodyEnd()
Targets can override this to emit stuff after the last basic block in the function.
const DataLayout & getDataLayout() const
Return information about data layout.
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
void emitInitialRawDwarfLocDirective(const MachineFunction &MF)
Emits inital debug location directive.
MCSymbol * GetExternalSymbolSymbol(const Twine &Sym) const
Return the MCSymbol for the specified ExternalSymbol.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
const APFloat & getValueAPF() const
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
This is an important base class in LLVM.
LLVM_ABI bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
iterator find(const_arg_type_t< KeyT > Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Implements a dense probed hash-table based set.
LLVM_ABI const GlobalObject * getAliaseeObject() const
StringRef getSection() const
Get the custom section of this global if it has one.
bool hasSection() const
Check if this global has a custom object file section.
bool hasLinkOnceLinkage() const
bool hasExternalLinkage() const
LLVM_ABI bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
bool hasLocalLinkage() const
bool hasPrivateLinkage() const
unsigned getAddressSpace() const
PointerType * getType() const
Global values are always pointers.
bool hasWeakLinkage() const
bool hasCommonLinkage() const
bool hasAvailableExternallyLinkage() const
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
LLVM_ABI void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
bool isLoopHeader(const BlockT *BB) const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Instances of this class represent a single low-level machine instruction.
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
Instances of this class represent operands of the MCInst class.
static MCOperand createExpr(const MCExpr *Val)
static MCOperand createReg(MCRegister Reg)
static MCOperand createImm(int64_t Val)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
iterator_range< pred_iterator > predecessors()
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
MachineBasicBlock * getMBB() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
const ConstantFP * getFPImm() const
@ MO_Immediate
Immediate operand.
@ MO_GlobalAddress
Address of a global value.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_FPImmediate
Floating-point immediate operand.
A Module instance is used to store all the information related to an LLVM module.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
bool runOnMachineFunction(MachineFunction &F) override
Emit the specified function out to the OutStreamer.
std::string getVirtualRegisterName(unsigned) const
bool doFinalization(Module &M) override
Shut down the asmprinter.
const MCSymbol * getFunctionFrameSymbol() const override
Return symbol for the function pseudo stack if the stack frame is not a register based.
static const NVPTXFloatMCExpr * createConstantBFPHalf(const APFloat &Flt, MCContext &Ctx)
static const NVPTXFloatMCExpr * createConstantFPHalf(const APFloat &Flt, MCContext &Ctx)
static const NVPTXFloatMCExpr * createConstantFPSingle(const APFloat &Flt, MCContext &Ctx)
static const NVPTXFloatMCExpr * createConstantFPDouble(const APFloat &Flt, MCContext &Ctx)
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
static const char * getRegisterName(MCRegister Reg)
bool checkImageHandleSymbol(StringRef Symbol) const
Check if the symbol has a mapping.
void clearDebugRegisterMap() const
const char * getName(unsigned RegNo) const
std::string getTargetName() const
unsigned getMaxRequiredAlignment() const
bool hasMaskOperator() const
const NVPTXTargetLowering * getTargetLowering() const override
unsigned getPTXVersion() const
const NVPTXRegisterInfo * getRegisterInfo() const override
unsigned int getSmVersion() const
NVPTX::DrvInterface getDrvInterface() const
const NVPTXSubtarget * getSubtargetImpl(const Function &) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
Implments NVPTX-specific streamer.
void outputDwarfFileDirectives()
Outputs the list of the DWARF '.file' directives to the streamer.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
static constexpr bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool isPointerTy() const
True if this is an instance of PointerType.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ HalfTyID
16-bit floating point type
@ VoidTyID
type with no size
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ FP128TyID
128-bit floating point type (112-bit significand)
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
iterator_range< user_iterator > users()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
bool erase(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
A raw_ostream that writes to an SmallVector or SmallString.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ C
The default llvm calling convention, compatible with C.
@ CE
Windows NT (Windows on ARM)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)
Extract a Value from Metadata.
uint64_t read64le(const void *P)
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
bool isManaged(const Value &V)
StringRef getNVPTXRegClassStr(TargetRegisterClass const *RC)
bool shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
MaybeAlign getAlign(const CallInst &I, unsigned Index)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
std::optional< unsigned > getMaxNReg(const Function &F)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
StringRef getSamplerName(const Value &V)
bool isImageReadWrite(const Value &V)
bool isImageReadOnly(const Value &V)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::string utostr(uint64_t X, bool isNeg=false)
std::optional< unsigned > getMinCTASm(const Function &F)
SmallVector< unsigned, 3 > getReqNTID(const Function &F)
LLVM_ABI Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Fold the constant using the specified DataLayout.
auto dyn_cast_or_null(const Y &Val)
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
bool isSampler(const Value &V)
unsigned promoteScalarArgumentSize(unsigned size)
void clearAnnotationCache(const Module *Mod)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
bool shouldPassAsArray(Type *Ty)
StringRef getNVPTXRegClassName(TargetRegisterClass const *RC)
bool isSurface(const Value &V)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
std::optional< unsigned > getMaxClusterRank(const Function &F)
StringRef getTextureName(const Value &V)
SmallVector< unsigned, 3 > getMaxNTID(const Function &F)
LLVM_ABI void write_hex(raw_ostream &S, uint64_t N, HexPrintStyle Style, std::optional< size_t > Width=std::nullopt)
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
StringRef getSurfaceName(const Value &V)
Target & getTheNVPTXTarget64()
bool isKernelFunction(const Function &F)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool isTexture(const Value &V)
bool isImageWriteOnly(const Value &V)
auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
bool hasBlocksAreClusters(const Function &F)
SmallVector< unsigned, 3 > getClusterDim(const Function &F)
LLVM_ABI Constant * ConstantFoldIntegerCast(Constant *C, Type *DestTy, bool IsSigned, const DataLayout &DL)
Constant fold a zext, sext or trunc, depending on IsSigned and whether the DestTy is wider or narrowe...
LLVM_ABI MDNode * GetUnrollMetadata(MDNode *LoopID, StringRef Name)
Given an llvm.loop loop id metadata node, returns the loop hint metadata node with the given name (fo...
Target & getTheNVPTXTarget32()
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...