99#define DEPOTNAME "__local_depot"
102 assert(V.hasName() &&
"Found texture variable with no name");
107 assert(V.hasName() &&
"Found surface variable with no name");
112 assert(V.hasName() &&
"Found sampler variable with no name");
134 if (SP->getUnit()->isDebugDirectivesOnly() || SP->getUnit()->isNoDebug())
151 for (
const auto &O : U->operands())
164 if (Visited.
count(GV))
168 if (!Visiting.
insert(GV).second)
173 for (
const auto &O : GV->
operands())
186 NVPTX_MC::verifyInstructionPredicates(
MI->getOpcode(),
190 lowerToMCInst(
MI, Inst);
196 for (
const auto MO :
MI->operands())
241unsigned NVPTXAsmPrinter::encodeVirtualRegister(
unsigned Reg) {
243 const TargetRegisterClass *RC = MRI->getRegClass(
Reg);
245 DenseMap<unsigned, unsigned> &RegMap = VRegMapping[RC];
246 unsigned RegNum = RegMap[
Reg];
251 if (RC == &NVPTX::B1RegClass) {
253 }
else if (RC == &NVPTX::B16RegClass) {
255 }
else if (RC == &NVPTX::B32RegClass) {
257 }
else if (RC == &NVPTX::B64RegClass) {
259 }
else if (RC == &NVPTX::B128RegClass) {
266 Ret |= (RegNum & 0x0FFFFFFF);
271 return Reg & 0x0FFFFFFF;
283 const NVPTXSubtarget &STI =
TM.getSubtarget<NVPTXSubtarget>(*F);
286 Type *Ty = F->getReturnType();
293 auto PrintScalarRetVal = [&](
unsigned Size) {
297 const unsigned TotalSize =
DL.getTypeAllocSize(Ty);
298 const Align RetAlignment =
300 O <<
".param .align " << RetAlignment.
value() <<
" .b8 func_retval0["
305 PrintScalarRetVal(ITy->getBitWidth());
307 PrintScalarRetVal(TLI->getPointerTy(
DL).getSizeInBits());
316 printReturnValStr(&F, O);
319void NVPTXAsmPrinter::emitCallPrototype(
const CallBase &CB,
320 unsigned UniqueCallSite,
323 const NVPTXSubtarget &STI =
MF->getSubtarget<NVPTXSubtarget>();
325 const auto PtrVT = TLI->getPointerTy(
DL);
328 O <<
"prototype_" << UniqueCallSite <<
" : .callprototype ";
335 const Align RetAlign =
337 O <<
".param .align " << RetAlign.
value() <<
" .b8 _["
338 <<
DL.getTypeAllocSize(RetTy) <<
"]";
342 size = ITy->getBitWidth();
345 "Floating point type expected here");
353 O <<
".param .b" <<
size <<
" _";
355 O <<
".param .b" << PtrVT.getSizeInBits() <<
" _";
363 auto MakeArg = [&](
const unsigned I) {
377 InitialAlign.value_or(TLI->getByValTypeAlignment(ETy,
DL));
378 Align ParamByValAlign =
381 O <<
".param .align " << ParamByValAlign.
value() <<
" .b8 _["
382 <<
DL.getTypeAllocSize(ETy) <<
"]";
389 O <<
".param .align " << ParamAlign.
value() <<
" .b8 _["
390 <<
DL.getTypeAllocSize(Ty) <<
"]";
398 sz = PtrVT.getSizeInBits();
402 O <<
".param .b" << sz <<
" _";
406 const unsigned NumArgs = FTy->getNumParams();
416 if (FTy->isVarArg() && CB.
arg_size() > NumArgs)
417 O << (NonEmptyArgs.empty() ?
"" :
",") <<
" .param .align "
428bool NVPTXAsmPrinter::isLoopHeaderOfNoUnroll(
443 if (
const BasicBlock *PBB = PMBB->getBasicBlock()) {
445 PBB->getTerminator()->getMetadata(LLVMContext::MD_loop)) {
448 if (MDNode *UnrollCountMD =
462 if (isLoopHeaderOfNoUnroll(
MBB))
463 OutStreamer->emitRawText(StringRef(
"\t.pragma \"nounroll\";\n"));
467 SmallString<128> Str;
468 raw_svector_ostream
O(Str);
470 if (!GlobalsEmitted) {
471 emitGlobals(*
MF->getFunction().getParent());
472 GlobalsEmitted =
true;
476 MRI = &
MF->getRegInfo();
477 F = &
MF->getFunction();
478 emitLinkageDirective(F, O);
483 printReturnValStr(*
MF, O);
488 emitFunctionParamList(F, O);
492 emitKernelFunctionDirectives(*F, O);
502 setAndEmitFunctionVirtualRegisters(*
MF);
503 encodeDebugInfoRegisterNumbers(*
MF);
525 for (
const auto &[Id, CB] : MFI->getCallPrototypes())
526 emitCallPrototype(*CB, Id, O);
541void NVPTXAsmPrinter::emitImplicitDef(
const MachineInstr *
MI)
const {
554void NVPTXAsmPrinter::emitKernelFunctionDirectives(
const Function &
F,
561 O <<
formatv(
".reqntid {0:$[, ]}\n",
566 O <<
formatv(
".maxntid {0:$[, ]}\n",
570 O <<
".minnctapersm " << *Mincta <<
"\n";
573 O <<
".maxnreg " << *Maxnreg <<
"\n";
577 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
578 const NVPTXSubtarget *STI = &NTM.
getSubtarget<NVPTXSubtarget>(F);
586 if (!BlocksAreClusters)
587 O <<
".explicitcluster\n";
589 if (ClusterDim[0] != 0) {
591 "cluster_dim_x != 0 implies cluster_dim_y and cluster_dim_z "
592 "should be non-zero as well");
594 O <<
formatv(
".reqnctapercluster {0:$[, ]}\n",
598 "cluster_dim_x == 0 implies cluster_dim_y and cluster_dim_z "
599 "should be 0 as well");
603 if (BlocksAreClusters) {
604 LLVMContext &Ctx = F.getContext();
606 Ctx.
diagnose(DiagnosticInfoUnsupported(
607 F,
"blocksareclusters requires reqntid and cluster_dim attributes",
610 Ctx.
diagnose(DiagnosticInfoUnsupported(
611 F,
"blocksareclusters requires PTX version >= 9.0",
614 O <<
".blocksareclusters\n";
618 O <<
".maxclusterrank " << *Maxclusterrank <<
"\n";
629 assert(
I != VRegMapping.end() &&
"Bad register class");
633 assert(VI != RegMap.
end() &&
"Bad virtual register");
634 unsigned MappedVR = VI->second;
641void NVPTXAsmPrinter::emitVirtualRegister(
unsigned int vr,
646void NVPTXAsmPrinter::emitAliasDeclaration(
const GlobalAlias *GA,
651 "NVPTX aliasee must be a non-kernel function definition");
661 emitDeclarationWithName(F,
getSymbol(F), O);
666 emitLinkageDirective(F, O);
671 printReturnValStr(F, O);
674 emitFunctionParamList(F, O);
686 return GV->getName() !=
"llvm.used";
688 for (
const User *U :
C->users())
698 if (OtherGV->getName() ==
"llvm.used")
702 if (
const Function *CurFunc =
I->getFunction()) {
703 if (OneFunc && (CurFunc != OneFunc))
744 for (
const User *U :
C->users()) {
749 if (
const Function *Caller =
I->getFunction())
758 SmallPtrSet<const Function *, 32> SeenSet;
759 for (
const Function &F : M) {
760 if (F.getAttributes().hasFnAttr(
"nvptx-libcall-callee")) {
761 emitDeclaration(&F, O);
765 if (F.isDeclaration()) {
768 if (F.getIntrinsicID())
772 if (F.isIntrinsic()) {
773 LLVMContext &Ctx = F.getContext();
774 Ctx.
diagnose(DiagnosticInfoUnsupported(
775 F,
"unknown intrinsic '" + F.getName() +
776 "' cannot be lowered by the NVPTX backend"));
779 emitDeclaration(&F, O);
782 for (
const User *U : F.users()) {
788 emitDeclaration(&F, O);
794 emitDeclaration(&F, O);
809 emitDeclaration(&F, O);
815 for (
const GlobalAlias &GA :
M.aliases())
816 emitAliasDeclaration(&GA, O);
819void NVPTXAsmPrinter::emitStartOfAsmFile(
Module &M) {
823 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
844 GlobalsEmitted =
false;
849void NVPTXAsmPrinter::emitGlobals(
const Module &M) {
853 emitDeclarations(M, OS2);
868 assert(GVVisited.
size() == M.global_size() &&
"Missed a global variable");
869 assert(GVVisiting.
size() == 0 &&
"Did not fully process a global variable");
876 printModuleLevelGV(GV, OS2,
false, STI);
896 return static_cast<NVPTXTargetStreamer *
>(
OutStreamer->getTargetStreamer());
901 switch(
CU->getEmissionKind()) {
915 auto *TS = getTargetStreamer();
920 TS->emitVersionDirective(PTXVersion);
922 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
925 TS->emitTargetDirective(STI.
getTargetName(), TexModeIndependent,
927 TS->emitAddressSizeDirective(
M.getDataLayout().getPointerSizeInBits());
933 if (!GlobalsEmitted) {
935 GlobalsEmitted =
true;
947 TS->closeLastSection();
949 OutStreamer->emitRawText(
"\t.section\t.debug_macinfo\t{\t}");
971void NVPTXAsmPrinter::emitLinkageDirective(
const GlobalValue *V,
974 if (V->hasExternalLinkage()) {
976 O << (GVar->hasInitializer() ?
".visible " :
".extern ");
977 else if (V->isDeclaration())
981 }
else if (V->hasAppendingLinkage()) {
983 "' has unsupported appending linkage type");
984 }
else if (!
V->hasInternalLinkage() && !
V->hasPrivateLinkage()) {
990void NVPTXAsmPrinter::printModuleLevelGV(
const GlobalVariable *GVar,
1038 emitPTXGlobalVariable(GVar, O, STI);
1046 const Constant *Initializer =
nullptr;
1049 const ConstantInt *CI =
nullptr;
1060 O <<
"addr_mode_" << i <<
" = ";
1066 O <<
"clamp_to_border";
1069 O <<
"clamp_to_edge";
1080 O <<
"filter_mode = ";
1095 O <<
", force_unnormalized_coords = 1";
1115 const Function *DemotedFunc =
nullptr;
1117 O <<
"// " << GVar->
getName() <<
" has been demoted\n";
1118 localDecls[DemotedFunc].push_back(GVar);
1128 ".attribute(.managed) requires PTX version >= 4.0 and sm_30");
1129 O <<
" .attribute(.managed)";
1133 << GVar->
getAlign().value_or(
DL.getPrefTypeAlign(ETy)).value();
1142 O << getPTXFundamentalTypeStr(ETy,
false);
1155 printScalarConstant(Initializer, O);
1164 "' is not allowed in addrspace(" +
1180 const uint64_t ElementSize =
DL.getTypeStoreSize(ETy);
1188 AggBuffer aggBuffer(ElementSize, *
this);
1189 bufferAggregateConstant(Initializer, &aggBuffer);
1190 if (aggBuffer.numSymbols()) {
1191 const unsigned int ptrSize =
MAI.getCodePointerSize();
1192 if (ElementSize % ptrSize ||
1193 !aggBuffer.allSymbolsAligned(ptrSize)) {
1197 "initialized packed aggregate with pointers '" +
1199 "' requires at least PTX ISA version 7.1");
1202 O <<
"[" << ElementSize <<
"] = {";
1203 aggBuffer.printBytes(O);
1206 O <<
" .u" << ptrSize * 8 <<
" ";
1208 O <<
"[" << ElementSize / ptrSize <<
"] = {";
1209 aggBuffer.printWords(O);
1215 O <<
"[" << ElementSize <<
"] = {";
1216 aggBuffer.printBytes(O);
1223 O <<
"[" << ElementSize <<
"]";
1229 O <<
"[" << ElementSize <<
"]";
1240void NVPTXAsmPrinter::AggBuffer::printSymbol(
unsigned nSym,
raw_ostream &os) {
1241 const Value *
v = Symbols[nSym];
1242 const Value *v0 = SymbolsBeforeStripping[nSym];
1247 bool isGenericPointer = PTy && PTy->getAddressSpace() == 0;
1250 Name->print(os, AP.MAI);
1253 Name->print(os, AP.MAI);
1256 const MCExpr *Expr = AP.lowerConstantForGV(CExpr,
false);
1257 AP.printMCExpr(*Expr, os);
1262void NVPTXAsmPrinter::AggBuffer::printBytes(raw_ostream &os) {
1263 unsigned int ptrSize = AP.MAI.getCodePointerSize();
1268 unsigned int InitializerCount =
Size;
1271 if (numSymbols() == 0)
1272 while (InitializerCount >= 1 && !buffer[InitializerCount - 1])
1275 symbolPosInBuffer.push_back(InitializerCount);
1276 unsigned int nSym = 0;
1277 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
1278 for (
unsigned int pos = 0; pos < InitializerCount;) {
1281 if (pos != nextSymbolPos) {
1282 os << (
unsigned int)buffer[pos];
1289 std::string symText;
1290 llvm::raw_string_ostream oss(symText);
1291 printSymbol(nSym, oss);
1292 for (
unsigned i = 0; i < ptrSize; ++i) {
1296 os <<
"(" << symText <<
")";
1299 nextSymbolPos = symbolPosInBuffer[++nSym];
1300 assert(nextSymbolPos >= pos);
1304void NVPTXAsmPrinter::AggBuffer::printWords(raw_ostream &os) {
1305 unsigned int ptrSize = AP.MAI.getCodePointerSize();
1306 symbolPosInBuffer.push_back(
Size);
1307 unsigned int nSym = 0;
1308 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
1309 assert(nextSymbolPos % ptrSize == 0);
1310 for (
unsigned int pos = 0; pos <
Size; pos += ptrSize) {
1313 if (pos == nextSymbolPos) {
1314 printSymbol(nSym, os);
1315 nextSymbolPos = symbolPosInBuffer[++nSym];
1316 assert(nextSymbolPos % ptrSize == 0);
1317 assert(nextSymbolPos >= pos + ptrSize);
1318 }
else if (ptrSize == 4)
1325void NVPTXAsmPrinter::emitDemotedVars(
const Function *F, raw_ostream &O) {
1326 auto It = localDecls.find(F);
1327 if (It == localDecls.end())
1332 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
1335 for (
const GlobalVariable *GV : GVars) {
1336 O <<
"\t// demoted variable\n\t";
1337 printModuleLevelGV(GV, O,
true, STI);
1341void NVPTXAsmPrinter::emitPTXAddressSpace(
unsigned int AddressSpace,
1342 raw_ostream &O)
const {
1364NVPTXAsmPrinter::getPTXFundamentalTypeStr(
Type *Ty,
bool useB4PTR)
const {
1370 if (NumBits <= 64) {
1371 std::string
name =
"u";
1388 assert((PtrSize == 64 || PtrSize == 32) &&
"Unexpected pointer size");
1406void NVPTXAsmPrinter::emitPTXGlobalVariable(
const GlobalVariable *GVar,
1408 const NVPTXSubtarget &STI) {
1419 ".attribute(.managed) requires PTX version >= 4.0 and sm_30");
1421 O <<
" .attribute(.managed)";
1424 << GVar->
getAlign().value_or(
DL.getPrefTypeAlign(ETy)).value();
1435 O <<
" ." << getPTXFundamentalTypeStr(ETy) <<
" ";
1440 int64_t ElementSize = 0;
1450 ElementSize =
DL.getTypeStoreSize(ETy);
1464void NVPTXAsmPrinter::emitFunctionParamList(
const Function *F, raw_ostream &O) {
1466 const NVPTXSubtarget &STI =
TM.getSubtarget<NVPTXSubtarget>(*F);
1468 const NVPTXMachineFunctionInfo *MFI =
1469 MF ?
MF->getInfo<NVPTXMachineFunctionInfo>() : nullptr;
1471 bool IsFirst =
true;
1478 const auto NonEmptyArgs =
1480 return !Arg.getType()->isEmptyTy();
1483 if (NonEmptyArgs.empty() && !F->isVarArg()) {
1490 for (
const auto &[ParamIndex, Arg] :
enumerate(NonEmptyArgs)) {
1491 Type *Ty = Arg.getType();
1492 const std::string ParamSym = TLI->getParamName(F, ParamIndex);
1508 switch (ArgOpaqueType) {
1510 O <<
".samplerref ";
1526 if (Arg.hasByValAttr()) {
1528 Type *ETy = Arg.getParamByValType();
1529 assert(ETy &&
"Param should have byval type");
1535 const Align OptimalAlign =
1538 F, ETy, Arg.getArgNo() + AttributeList::FirstArgIndex,
DL)
1540 Arg.getParamAlign().valueOrOne(),
DL);
1542 O <<
"\t.param .align " << OptimalAlign.
value() <<
" .b8 " << ParamSym
1543 <<
"[" <<
DL.getTypeAllocSize(ETy) <<
"]";
1553 F, Ty, Arg.getArgNo() + AttributeList::FirstArgIndex,
DL);
1555 O <<
"\t.param .align " << OptimalAlign.
value() <<
" .b8 " << ParamSym
1556 <<
"[" <<
DL.getTypeAllocSize(Ty) <<
"]";
1562 unsigned PTySizeInBits = 0;
1565 TLI->getPointerTy(
DL, PTy->getAddressSpace()).getSizeInBits();
1566 assert(PTySizeInBits &&
"Invalid pointer size");
1571 O <<
"\t.param .u" << PTySizeInBits <<
" .ptr";
1573 switch (PTy->getAddressSpace()) {
1590 O <<
" .align " << Arg.getParamAlign().valueOrOne().value() <<
" "
1601 O << getPTXFundamentalTypeStr(Ty);
1602 O <<
" " << ParamSym;
1611 assert(PTySizeInBits &&
"Invalid pointer size");
1612 Size = PTySizeInBits;
1615 O <<
"\t.param .b" <<
Size <<
" " << ParamSym;
1618 if (F->isVarArg()) {
1622 << TLI->getParamName(F, -1) <<
"[]";
1628void NVPTXAsmPrinter::setAndEmitFunctionVirtualRegisters(
1629 const MachineFunction &
MF) {
1630 SmallString<128> Str;
1631 raw_svector_ostream
O(Str);
1635 const TargetRegisterInfo *
TRI =
MF.getSubtarget().getRegisterInfo();
1638 const MachineFrameInfo &MFI =
MF.getFrameInfo();
1643 if (
static_cast<const NVPTXTargetMachine &
>(
MF.getTarget()).is64Bit()) {
1644 O <<
"\t.reg .b64 \t%SP;\n"
1645 <<
"\t.reg .b64 \t%SPL;\n";
1647 O <<
"\t.reg .b32 \t%SP;\n"
1648 <<
"\t.reg .b32 \t%SPL;\n";
1656 for (
unsigned I :
llvm::seq(MRI->getNumVirtRegs())) {
1658 if (MRI->use_empty(VR) && MRI->def_empty(VR))
1660 auto &RCRegMap = VRegMapping[MRI->getRegClass(VR)];
1661 RCRegMap[VR] = RCRegMap.size() + 1;
1666 for (
const TargetRegisterClass *RC :
TRI->regclasses()) {
1667 const unsigned N = VRegMapping[RC].size();
1673 O <<
"\t.reg " << RCName <<
" \t" << RCStr <<
"<" << (
N + 1) <<
">;\n";
1682void NVPTXAsmPrinter::encodeDebugInfoRegisterNumbers(
1683 const MachineFunction &
MF) {
1684 const NVPTXSubtarget &STI =
MF.getSubtarget<NVPTXSubtarget>();
1692 for (
auto &classMap : VRegMapping) {
1693 for (
auto ®isterMapping : classMap.getSecond()) {
1694 auto reg = registerMapping.getFirst();
1700void NVPTXAsmPrinter::printFPConstant(
const ConstantFP *Fp,
1701 raw_ostream &O)
const {
1704 unsigned int numHex;
1722void NVPTXAsmPrinter::printScalarConstant(
const Constant *CPV, raw_ostream &O) {
1728 printFPConstant(CFP, O);
1737 if (EmitGeneric && !
isa<Function>(CPV) && !IsNonGenericPointer) {
1754void NVPTXAsmPrinter::bufferLEByte(
const Constant *CPV,
int Bytes,
1755 AggBuffer *AggBuffer) {
1757 int AllocSize =
DL.getTypeAllocSize(CPV->
getType());
1761 AggBuffer->addZeros(Bytes ? Bytes : AllocSize);
1766 auto AddIntToBuffer = [AggBuffer, Bytes](
const APInt &Val) {
1767 size_t NumBytes = (Val.getBitWidth() + 7) / 8;
1773 for (
unsigned I = 0;
I < NumBytes - 1; ++
I) {
1774 Buf[
I] = Val.extractBitsAsZExtValue(8,
I * 8);
1776 size_t LastBytePosition = (NumBytes - 1) * 8;
1777 size_t LastByteBits = Val.getBitWidth() - LastBytePosition;
1779 Val.extractBitsAsZExtValue(LastByteBits, LastBytePosition);
1780 AggBuffer->addBytes(Buf.data(), NumBytes, Bytes);
1790 if (
const auto *CI =
1795 if (Cexpr->getOpcode() == Instruction::PtrToInt) {
1796 Value *
V = Cexpr->getOperand(0)->stripPointerCasts();
1797 AggBuffer->addSymbol(V, Cexpr->getOperand(0));
1798 AggBuffer->addZeros(AllocSize);
1805 AggBuffer->addSymbol(Cexpr, Cexpr);
1806 AggBuffer->addZeros(AllocSize);
1821 AggBuffer->addSymbol(GVar, GVar);
1823 const Value *
v = Cexpr->stripPointerCasts();
1824 AggBuffer->addSymbol(v, Cexpr);
1826 AggBuffer->addZeros(AllocSize);
1836 unsigned StartPos = AggBuffer->getCurpos();
1837 bufferAggregateConstant(CPV, AggBuffer);
1838 unsigned Written = AggBuffer->getCurpos() - StartPos;
1839 unsigned SlotSize = std::max<int>(Bytes, AllocSize);
1840 if (SlotSize > Written)
1841 AggBuffer->addZeros(SlotSize - Written);
1843 AggBuffer->addZeros(Bytes);
1854void NVPTXAsmPrinter::bufferAggregateConstant(
const Constant *CPV,
1855 AggBuffer *aggBuffer) {
1858 auto ExtendBuffer = [](APInt Val, AggBuffer *Buffer) {
1861 unsigned NumBits = std::min(8u, Val.
getBitWidth() -
I * 8);
1869 for (
unsigned I :
llvm::seq(VTy->getNumElements()))
1878 ExtendBuffer(CI->
getValue(), aggBuffer);
1884 assert(CFP->getType()->isFloatingPointTy() &&
"Expected fp constant!");
1885 if (CFP->getType()->isFP128Ty()) {
1886 ExtendBuffer(CFP->getValueAPF().bitcastToAPInt(), aggBuffer);
1900 bufferAggregateConstVec(CVec, aggBuffer);
1905 for (
unsigned I :
llvm::seq(CDS->getNumElements()))
1906 bufferLEByte(
cast<Constant>(CDS->getElementAsConstant(
I)), 0, aggBuffer);
1915 ?
DL.getStructLayout(ST)->getElementOffset(0) +
1916 DL.getTypeAllocSize(ST)
1917 :
DL.getStructLayout(ST)->getElementOffset(
I + 1);
1918 int Bytes = EndOffset -
DL.getStructLayout(ST)->getElementOffset(
I);
1927void NVPTXAsmPrinter::bufferAggregateConstVec(
const ConstantVector *CV,
1928 AggBuffer *aggBuffer) {
1930 const unsigned BuffSize = aggBuffer->getBufferSize();
1933 if (BuffSize >= NumElems) {
1946 assert(ElemTySize < 8 &&
"Expected sub-byte data type.");
1947 assert(8 % ElemTySize == 0 &&
"Element type size must evenly divide a byte.");
1949 unsigned NumElemsPerByte = 8 / ElemTySize;
1950 unsigned NumCompleteBytes = NumElems / NumElemsPerByte;
1951 unsigned NumTailElems = NumElems % NumElemsPerByte;
1956 auto ConvertSubCVtoInt8 = [
this, &ElemTy](
const ConstantVector *CV,
1957 unsigned Start,
unsigned End,
1958 unsigned NumPaddingZeros = 0) {
1965 if (NumPaddingZeros)
1972 ConstantInt *MergedElem =
1979 "Cannot lower vector global with unusual element type");
1986 for (
unsigned ByteIdx :
llvm::seq(NumCompleteBytes))
1987 bufferLEByte(ConvertSubCVtoInt8(CV, ByteIdx * NumElemsPerByte,
1988 (ByteIdx + 1) * NumElemsPerByte),
1992 if (NumTailElems > 0)
1993 bufferLEByte(ConvertSubCVtoInt8(CV, NumElems - NumTailElems, NumElems,
1994 NumElemsPerByte - NumTailElems),
2003NVPTXAsmPrinter::lowerConstantForGV(
const Constant *CV,
2004 bool ProcessingGeneric)
const {
2015 if (ProcessingGeneric)
2025 switch (
CE->getOpcode()) {
2029 case Instruction::AddrSpaceCast: {
2032 if (DstTy->getAddressSpace() == 0)
2038 case Instruction::GetElementPtr: {
2042 APInt OffsetAI(
DL.getPointerTypeSizeInBits(
CE->getType()), 0);
2045 const MCExpr *
Base = lowerConstantForGV(
CE->getOperand(0),
2050 int64_t
Offset = OffsetAI.getSExtValue();
2055 case Instruction::Trunc:
2061 case Instruction::BitCast:
2062 return lowerConstantForGV(
CE->getOperand(0), ProcessingGeneric);
2064 case Instruction::IntToPtr: {
2073 return lowerConstantForGV(
Op, ProcessingGeneric);
2078 case Instruction::PtrToInt: {
2084 Type *Ty =
CE->getType();
2086 const MCExpr *OpExpr = lowerConstantForGV(
Op, ProcessingGeneric);
2090 if (
DL.getTypeAllocSize(Ty) ==
DL.getTypeAllocSize(
Op->getType()))
2096 unsigned InBits =
DL.getTypeAllocSizeInBits(
Op->getType());
2103 case Instruction::Add: {
2104 const MCExpr *
LHS = lowerConstantForGV(
CE->getOperand(0), ProcessingGeneric);
2105 const MCExpr *
RHS = lowerConstantForGV(
CE->getOperand(1), ProcessingGeneric);
2106 switch (
CE->getOpcode()) {
2118 return lowerConstantForGV(
C, ProcessingGeneric);
2122 raw_string_ostream OS(S);
2123 OS <<
"Unsupported expression in static initializer: ";
2124 CE->printAsOperand(OS,
false,
2125 !
MF ?
nullptr :
MF->getFunction().getParent());
2129void NVPTXAsmPrinter::printMCExpr(
const MCExpr &Expr, raw_ostream &OS)
const {
2135bool NVPTXAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
2136 const char *ExtraCode, raw_ostream &O) {
2137 if (ExtraCode && ExtraCode[0]) {
2138 if (ExtraCode[1] != 0)
2141 switch (ExtraCode[0]) {
2150 printOperand(
MI, OpNo, O);
2155bool NVPTXAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
2157 const char *ExtraCode,
2159 if (ExtraCode && ExtraCode[0])
2163 printMemOperand(
MI, OpNo, O);
2169void NVPTXAsmPrinter::printOperand(
const MachineInstr *
MI,
unsigned OpNum,
2171 const MachineOperand &MO =
MI->getOperand(OpNum);
2175 if (MO.
getReg() == NVPTX::VRDepot)
2180 emitVirtualRegister(MO.
getReg(), O);
2205void NVPTXAsmPrinter::printMemOperand(
const MachineInstr *
MI,
unsigned OpNum,
2206 raw_ostream &O,
const char *Modifier) {
2207 printOperand(
MI, OpNum, O);
2209 if (Modifier && strcmp(Modifier,
"add") == 0) {
2211 printOperand(
MI, OpNum + 1, O);
2213 if (
MI->getOperand(OpNum + 1).isImm() &&
2214 MI->getOperand(OpNum + 1).getImm() == 0)
2217 printOperand(
MI, OpNum + 1, O);
2225 return !Trimmed.
empty() &&
2226 (std::isalpha(
static_cast<unsigned char>(Trimmed[0])) ||
2233 if (!
MI || !
MI->getDebugLoc())
2235 const DISubprogram *SP =
MI->getMF()->getFunction().getSubprogram();
2239 if (!
DL->getFile() || !
DL->getLine())
2245struct InlineAsmInliningContext {
2247 unsigned FileIA = 0;
2248 unsigned LineIA = 0;
2251 bool hasInlinedAt()
const {
return FuncNameSym !=
nullptr; }
2257static InlineAsmInliningContext
2261 InlineAsmInliningContext Ctx;
2263 if (!InlinedAt || !InlinedAt->getFile() || !NVDD ||
2271 0, InlinedAt->getFile()->getDirectory(),
2272 InlinedAt->getFile()->getFilename(), std::nullopt, std::nullopt, CUID);
2273 Ctx.LineIA = InlinedAt->getLine();
2274 Ctx.ColIA = InlinedAt->getColumn();
2278void NVPTXAsmPrinter::emitInlineAsm(StringRef Str,
const MCSubtargetInfo &STI,
2279 const MCTargetOptions &MCOptions,
2280 const MDNode *LocMDNode,
2282 const MachineInstr *
MI) {
2283 assert(!Str.empty() &&
"Can't emit empty inline asm block");
2284 if (Str.back() == 0)
2285 Str = Str.substr(0, Str.size() - 1);
2287 auto emitAsmStr = [&](StringRef AsmStr) {
2299 const DIFile *
File =
DL->getFile();
2300 unsigned Line =
DL->getLine();
2301 const unsigned Column =
DL->getColumn();
2302 const unsigned CUID =
OutStreamer->getContext().getDwarfCompileUnitID();
2303 const unsigned FileNumber =
OutStreamer->emitDwarfFileDirective(
2304 0,
File->getDirectory(),
File->getFilename(), std::nullopt, std::nullopt,
2307 auto *NVDD =
static_cast<NVPTXDwarfDebug *
>(
getDwarfDebug());
2308 InlineAsmInliningContext InlineCtx =
2311 SmallVector<StringRef, 16>
Lines;
2312 Str.split(Lines,
'\n');
2314 for (
const StringRef &L : Lines) {
2315 StringRef RTrimmed =
L.rtrim(
'\r');
2317 if (InlineCtx.hasInlinedAt()) {
2319 FileNumber, Line, Column, InlineCtx.FileIA, InlineCtx.LineIA,
2321 File->getFilename());
2323 OutStreamer->emitDwarfLocDirective(FileNumber, Line, Column,
2325 File->getFilename());
2341LLVMInitializeNVPTXAsmPrinter() {
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< 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.
#define DWARF2_FLAG_IS_STMT
Register const TargetRegisterInfo * TRI
Promote Memory to Register
static StringRef getTextureName(const Value &V)
static const DILocation * getInlineAsmDebugLoc(const MachineInstr *MI)
Returns the DILocation for an inline asm MachineInstr if debug line info should be emitted,...
static void discoverDependentGlobals(const Value *V, DenseSet< const GlobalVariable * > &Globals)
discoverDependentGlobals - Return a set of GlobalVariables on which V depends.
static bool hasFullDebugInfo(Module &M)
static StringRef getSurfaceName(const Value &V)
static bool canDemoteGlobalVar(const GlobalVariable *GV, Function const *&f)
static StringRef getSamplerName(const Value &V)
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 InlineAsmInliningContext getInlineAsmInliningContext(const DILocation *DL, const MachineFunction &MF, NVPTXDwarfDebug *NVDD, MCStreamer &Streamer, unsigned CUID)
Resolves the enhanced-lineinfo inlining context for an inline asm debug location.
static bool isPTXInstruction(StringRef Line)
Returns true if Line begins with an alphabetic character or underscore, indicating it is a PTX instru...
static bool usedInOneFunc(const User *U, Function const *&OneFunc)
static void emitInitialRawDwarfLocDirective(const MachineFunction &MF, DwarfDebug *DD, MCStreamer &OutStreamer)
Emits initial debug location directive.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Provides some synthesis utilities to produce sequences of values.
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 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)
DwarfDebug * getDwarfDebug()
virtual void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo, const MachineInstr *MI)
Let the target do anything it needs to do after emitting inlineasm.
TargetMachine & TM
Target machine description.
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
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.
const MCAsmInfo & MAI
Target Asm Printer information.
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.
MCSymbol * GetExternalSymbolSymbol(const Twine &Sym) const
Return the MCSymbol for the specified ExternalSymbol.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
virtual void emitInlineAsmStart() const
Let the target do anything it needs to do before emitting inlineasm.
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.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
MaybeAlign getParamStackAlign(unsigned ArgNo) const
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter.
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
unsigned arg_size() const
static LLVM_ABI Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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.
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Subprogram description. Uses SubclassData1.
iterator find(const_arg_type_t< KeyT > Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Implements a dense probed hash-table based set.
Collects and handles dwarf debug information.
const MachineInstr * emitInitialLocDirective(const MachineFunction &MF, unsigned CUID)
Emits inital debug location directive.
unsigned getNumElements() const
Type * getReturnType() const
DISubprogram * getSubprogram() const
Get the attached subprogram.
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.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
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)
Streaming machine code generation interface.
virtual bool hasRawTextSupport() const
Return true if this asm streamer supports emitting unformatted text to the .s file with EmitRawText.
unsigned emitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, std::optional< MD5::MD5Result > Checksum=std::nullopt, std::optional< StringRef > Source=std::nullopt, unsigned CUID=0)
Associate a filename with a specified logical file number.
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.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
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.
DwarfDebug * createDwarfDebug() override
Create NVPTX-specific DwarfDebug handler.
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.
NVPTX-specific DwarfDebug implementation.
bool isEnhancedLineinfo(const MachineFunction &MF) const
Returns true if the enhanced lineinfo mode (with inlined_at) is active for the given MachineFunction.
MCSymbol * getOrCreateFuncNameSymbol(StringRef LinkageName)
Get or create an MCSymbol in .debug_str for a function's linkage name.
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 append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
StringRef ltrim(char Char) const
Return string with consecutive Char characters starting from the the left removed.
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...
LLVM_ABI bool isEmptyTy() const
Return true if this type is empty, that is, it has no elements or all of its elements are empty.
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
@ 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.
bool isVoidTy() const
Return true if this is 'void'.
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.
Type * getElementType() const
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.
constexpr StringLiteral MaxNTID("nvvm.maxntid")
constexpr StringLiteral ReqNTID("nvvm.reqntid")
constexpr StringLiteral ClusterDim("nvvm.cluster_dim")
constexpr StringLiteral BlocksAreClusters("nvvm.blocksareclusters")
@ 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.
constexpr auto not_equal_to(T &&Arg)
Functor variant of std::not_equal_to that can be used as a UnaryPredicate in functional algorithms li...
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.
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)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
An STL-style algorithm similar to std::for_each that applies a second functor between every pair of e...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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)
constexpr auto equal_to(T &&Arg)
Functor variant of std::equal_to that can be used as a UnaryPredicate in functional algorithms like a...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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)
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)
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
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)
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
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
Align getPTXParamAlign(const Function *F, Type *Ty, unsigned AttrIdx, const DataLayout &DL)
Get the alignment for a function parameter or return value.
ArrayRef(const T &OneElt) -> ArrayRef< T >
Align getDeviceByValParamAlign(const Function *F, Type *ArgTy, Align InitialAlign, const DataLayout &DL)
Target & getTheNVPTXTarget64()
bool isKernelFunction(const Function &F)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
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...
PTXOpaqueType getPTXOpaqueType(const GlobalVariable &GV)
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...
LLVM_ABI DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Target & getTheNVPTXTarget32()
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...