105#define DEPOTNAME "__local_depot"
108 assert(V.hasName() &&
"Found texture variable with no name");
113 assert(V.hasName() &&
"Found surface variable with no name");
118 assert(V.hasName() &&
"Found sampler variable with no name");
140 if (SP->getUnit()->isDebugDirectivesOnly() || SP->getUnit()->isNoDebug())
150discoverDependentGlobals(
const Value *V,
154 if (Seen.
insert(GV).second)
155 Globals.push_back(GV);
167 discoverDependentGlobals(
GEP->getPointerOperand(), Globals, Seen);
172 for (
const auto &O : U->operands())
173 discoverDependentGlobals(O, Globals, Seen);
176struct GlobalVariableDependencyNode {
177 const GlobalVariable *GV =
nullptr;
178 unsigned ModuleOrder = 0;
182class GlobalVariableDependencyGraph {
185 GlobalVariableDependencyNode SyntheticRoot;
188 std::map<const GlobalVariable *, GlobalVariableDependencyNode> Nodes;
191 explicit GlobalVariableDependencyGraph(
const Module &M) {
192 unsigned ModuleOrder = 0;
193 for (
const GlobalVariable &GV :
M.globals()) {
194 GlobalVariableDependencyNode &
Node = Nodes.try_emplace(&GV).first->second;
196 Node.ModuleOrder = ModuleOrder++;
197 SyntheticRoot.Dependencies.push_back(&Node);
200 for (
auto &[GV, Node] : Nodes) {
202 SmallPtrSet<const GlobalVariable *, 4> Seen;
203 for (
const Use &Operand : GV->operands())
204 discoverDependentGlobals(Operand, Dependencies, Seen);
206 for (
const GlobalVariable *Dependency : Dependencies) {
207 auto It = Nodes.find(Dependency);
208 if (It != Nodes.end())
209 Node.Dependencies.push_back(&It->second);
214 const GlobalVariableDependencyNode *getEntryNode()
const {
215 return &SyntheticRoot;
219struct GlobalVariableDependencyGraphTraits {
220 using NodeRef =
const GlobalVariableDependencyNode *;
221 using ChildIteratorType =
224 static NodeRef getEntryNode(NodeRef Node) {
return Node; }
225 static ChildIteratorType child_begin(NodeRef Node) {
226 return Node->Dependencies.begin();
228 static ChildIteratorType child_end(NodeRef Node) {
229 return Node->Dependencies.end();
233using GlobalVariableSCCIterator =
235 GlobalVariableDependencyGraphTraits>;
237static bool shouldSkipModuleLevelGlobal(
const GlobalVariable &GV) {
243static bool isForwardDeclarableGlobal(
const GlobalVariable *GVar) {
244 if (shouldSkipModuleLevelGlobal(*GVar) || GVar->
isDeclaration() ||
266 using Node = GlobalVariableDependencyNode;
273 std::set<std::pair<unsigned, const Node *>>
Ready;
277 for (
const Node *
N : SCC) {
278 unsigned &
Count = DependencyCount[
N];
279 for (
const Node *Dependency :
N->Dependencies) {
280 if (!SCCSet.
count(Dependency) || ForwardDeclared.
count(Dependency))
283 Dependents[Dependency].push_back(
N);
286 Ready.emplace(
N->ModuleOrder,
N);
290 while (!
Ready.empty()) {
295 auto It = Dependents.
find(
N);
296 if (It == Dependents.
end())
298 for (
const Node *Dependent : It->second) {
299 assert(DependencyCount[Dependent] &&
"Dependency already satisfied");
300 if (--DependencyCount[Dependent] == 0)
301 Ready.emplace(Dependent->ModuleOrder, Dependent);
305 if (Order.
size() !=
SCC.size())
313 NVPTX_MC::verifyInstructionPredicates(
MI->getOpcode(),
317 lowerToMCInst(
MI, Inst);
323 for (
const auto MO :
MI->operands())
373unsigned NVPTXAsmPrinter::encodeVirtualRegister(
unsigned Reg) {
377 DenseMap<unsigned, unsigned> &RegMap = VRegMapping[RC];
378 unsigned RegNum = RegMap[
Reg];
383 if (RC == &NVPTX::B1RegClass) {
385 }
else if (RC == &NVPTX::B16RegClass) {
387 }
else if (RC == &NVPTX::B32RegClass) {
389 }
else if (RC == &NVPTX::B64RegClass) {
391 }
else if (RC == &NVPTX::B128RegClass) {
398 Ret |= (RegNum & 0x0FFFFFFF);
403 return Reg & 0x0FFFFFFF;
415 const NVPTXSubtarget &STI =
TM.getSubtarget<NVPTXSubtarget>(*F);
418 Type *Ty = F->getReturnType();
425 auto PrintScalarRetVal = [&](
unsigned Size) {
429 const unsigned TotalSize =
DL.getTypeAllocSize(Ty);
430 const Align RetAlignment =
432 O <<
".param .align " << RetAlignment.
value() <<
" .b8 func_retval0["
437 PrintScalarRetVal(ITy->getBitWidth());
439 PrintScalarRetVal(TLI->getPointerTy(
DL).getSizeInBits());
448 printReturnValStr(&F, O);
451void NVPTXAsmPrinter::emitCallPrototype(
const CallBase &CB,
452 unsigned UniqueCallSite,
455 const NVPTXSubtarget &STI =
MF->getSubtarget<NVPTXSubtarget>();
457 const auto PtrVT = TLI->getPointerTy(
DL);
460 O <<
"prototype_" << UniqueCallSite <<
" : .callprototype ";
467 const Align RetAlign =
469 O <<
".param .align " << RetAlign.
value() <<
" .b8 _["
470 <<
DL.getTypeAllocSize(RetTy) <<
"]";
474 size = ITy->getBitWidth();
477 "Floating point type expected here");
485 O <<
".param .b" <<
size <<
" _";
487 O <<
".param .b" << PtrVT.getSizeInBits() <<
" _";
495 auto MakeArg = [&](
const unsigned I) {
501 &CB, ETy,
I + AttributeList::FirstArgIndex,
DL);
503 O <<
".param .align " << ParamByValAlign.
value() <<
" .b8 _["
504 <<
DL.getTypeAllocSize(ETy) <<
"]";
511 O <<
".param .align " << ParamAlign.
value() <<
" .b8 _["
512 <<
DL.getTypeAllocSize(Ty) <<
"]";
520 sz = PtrVT.getSizeInBits();
524 O <<
".param .b" << sz <<
" _";
528 const unsigned NumArgs = FTy->getNumParams();
538 if (FTy->isVarArg() && CB.
arg_size() > NumArgs)
539 O << (NonEmptyArgs.empty() ?
"" :
",") <<
" .param .align "
550 O <<
"$L_brx_" << MJTI <<
":\n";
552 if (MJT.
MBBs.empty())
555 O <<
"\t.branchtargets\n\t\t";
558 [&](
const MachineBasicBlock *
MBB) { MBB->getSymbol()->print(O, MAI); },
565bool NVPTXAsmPrinter::isLoopHeaderOfNoUnroll(
580 if (
const BasicBlock *PBB = PMBB->getBasicBlock()) {
582 PBB->getTerminator()->getMetadata(LLVMContext::MD_loop)) {
585 if (MDNode *UnrollCountMD =
599 if (isLoopHeaderOfNoUnroll(
MBB))
600 OutStreamer->emitRawText(StringRef(
"\t.pragma \"nounroll\";\n"));
604 SmallString<128> Str;
605 raw_svector_ostream
O(Str);
607 if (!GlobalsEmitted) {
608 emitGlobals(*
MF->getFunction().getParent());
609 GlobalsEmitted =
true;
613 MRI = &
MF->getRegInfo();
614 F = &
MF->getFunction();
615 emitLinkageDirective(F, O);
620 printReturnValStr(*
MF, O);
625 emitFunctionParamList(F, O);
629 emitKernelFunctionDirectives(*F, O);
639 setAndEmitFunctionVirtualRegisters(*
MF);
640 encodeDebugInfoRegisterNumbers(*
MF);
662 for (
const auto &[Id, CB] : MFI->getCallPrototypes())
663 emitCallPrototype(*CB, Id, O);
666 for (
const auto &[Idx, JT] :
enumerate(MJTI->getJumpTables()))
667 emitJumpTable(JT, Idx, O);
682void NVPTXAsmPrinter::emitImplicitDef(
const MachineInstr *
MI)
const {
695void NVPTXAsmPrinter::emitKernelFunctionDirectives(
const Function &
F,
702 O <<
formatv(
".reqntid {0:$[, ]}\n",
707 O <<
formatv(
".maxntid {0:$[, ]}\n",
711 O <<
".minnctapersm " << *Mincta <<
"\n";
714 O <<
".maxnreg " << *Maxnreg <<
"\n";
718 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
719 const NVPTXSubtarget *STI = &NTM.
getSubtarget<NVPTXSubtarget>(F);
727 if (!BlocksAreClusters)
728 O <<
".explicitcluster\n";
730 if (ClusterDim[0] != 0) {
732 "cluster_dim_x != 0 implies cluster_dim_y and cluster_dim_z "
733 "should be non-zero as well");
735 O <<
formatv(
".reqnctapercluster {0:$[, ]}\n",
739 "cluster_dim_x == 0 implies cluster_dim_y and cluster_dim_z "
740 "should be 0 as well");
744 if (BlocksAreClusters) {
745 LLVMContext &Ctx = F.getContext();
747 Ctx.
diagnose(DiagnosticInfoUnsupported(
748 F,
"blocksareclusters requires reqntid and cluster_dim attributes",
751 Ctx.
diagnose(DiagnosticInfoUnsupported(
752 F,
"blocksareclusters requires PTX version >= 9.0",
755 O <<
".blocksareclusters\n";
759 O <<
".maxclusterrank " << *Maxclusterrank <<
"\n";
770 assert(
I != VRegMapping.end() &&
"Bad register class");
774 assert(VI != RegMap.
end() &&
"Bad virtual register");
775 unsigned MappedVR = VI->second;
782void NVPTXAsmPrinter::emitVirtualRegister(
unsigned int vr,
787void NVPTXAsmPrinter::emitAliasDeclaration(
const GlobalAlias *GA,
792 "NVPTX aliasee must be a non-kernel function definition");
802 emitDeclarationWithName(F,
getSymbol(F), O);
807 emitLinkageDirective(F, O);
812 printReturnValStr(F, O);
815 emitFunctionParamList(F, O);
827 return GV->
getName() !=
"llvm.used";
829 for (
const User *U :
C->users())
839 if (OtherGV->getName() ==
"llvm.used")
843 if (
const Function *CurFunc =
I->getFunction()) {
844 if (OneFunc && (CurFunc != OneFunc))
885 for (
const User *U :
C->users()) {
890 if (
const Function *Caller =
I->getFunction())
899 SmallPtrSet<const Function *, 32> SeenSet;
900 for (
const Function &F : M) {
901 if (F.getAttributes().hasFnAttr(
"nvptx-libcall-callee")) {
902 emitDeclaration(&F, O);
906 if (F.isDeclaration()) {
909 if (F.getIntrinsicID())
913 if (F.isIntrinsic()) {
914 LLVMContext &Ctx = F.getContext();
915 Ctx.
diagnose(DiagnosticInfoUnsupported(
916 F,
"unknown intrinsic '" + F.getName() +
917 "' cannot be lowered by the NVPTX backend"));
920 emitDeclaration(&F, O);
923 for (
const User *U : F.users()) {
929 emitDeclaration(&F, O);
935 emitDeclaration(&F, O);
950 emitDeclaration(&F, O);
956 for (
const GlobalAlias &GA :
M.aliases())
957 emitAliasDeclaration(&GA, O);
960void NVPTXAsmPrinter::emitStartOfAsmFile(
Module &M) {
964 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
985 GlobalsEmitted =
false;
990void NVPTXAsmPrinter::emitGlobals(
const Module &M) {
994 emitDeclarations(M, OS2);
1004 GlobalVariableDependencyGraph DependencyGraph(M);
1005 for (GlobalVariableSCCIterator
I =
1006 GlobalVariableSCCIterator::begin(DependencyGraph.getEntryNode());
1007 !
I.isAtEnd(); ++
I) {
1012 if (!SCC.front()->GV) {
1013 assert(SCC.size() == 1 &&
"Synthetic root must be in its own SCC");
1018 return LHS->ModuleOrder <
RHS->ModuleOrder;
1021 const bool IsCyclic =
I.hasCycle();
1022 DenseSet<const GlobalVariableDependencyNode *> ForwardDeclared;
1024 for (
const auto *Node : SCC)
1025 if (isForwardDeclarableGlobal(
Node->GV))
1026 ForwardDeclared.
insert(Node);
1030 IsCyclic ? orderDefinitionsInSCC(SCC, ForwardDeclared)
1033 for (
const auto *Node : SCC) {
1034 if (!ForwardDeclared.
count(Node))
1037 emitPTXGlobalVariableDefinition(
Node->GV, OS2, STI,
1042 for (
const GlobalVariable *GV : OrderedGlobals)
1043 printModuleLevelGV(GV, OS2,
false, STI);
1052 SmallString<128> Str;
1053 raw_svector_ostream OS(Str);
1064 return static_cast<NVPTXTargetStreamer *
>(
OutStreamer->getTargetStreamer());
1069 switch(
CU->getEmissionKind()) {
1083 auto *TS = getTargetStreamer();
1088 TS->emitVersionDirective(PTXVersion);
1090 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
1093 TS->emitTargetDirective(STI.
getTargetName(), TexModeIndependent,
1095 TS->emitAddressSizeDirective(
M.getDataLayout().getPointerSizeInBits());
1101 if (!GlobalsEmitted) {
1103 GlobalsEmitted =
true;
1115 TS->closeLastSection();
1117 OutStreamer->emitRawText(
"\t.section\t.debug_macinfo\t{\t}");
1139void NVPTXAsmPrinter::emitLinkageDirective(
const GlobalValue *V,
1142 if (V->hasExternalLinkage()) {
1145 else if (V->isDeclaration())
1149 }
else if (V->hasAppendingLinkage()) {
1151 "' has unsupported appending linkage type");
1152 }
else if (!
V->hasInternalLinkage() && !
V->hasPrivateLinkage()) {
1158void NVPTXAsmPrinter::printModuleLevelGV(
const GlobalVariable *GVar,
1162 if (shouldSkipModuleLevelGlobal(*GVar))
1195 emitPTXGlobalVariable(GVar, O, STI);
1203 const Constant *Initializer =
nullptr;
1206 const ConstantInt *CI =
nullptr;
1217 O <<
"addr_mode_" << i <<
" = ";
1223 O <<
"clamp_to_border";
1226 O <<
"clamp_to_edge";
1237 O <<
"filter_mode = ";
1252 O <<
", force_unnormalized_coords = 1";
1272 const Function *DemotedFunc =
nullptr;
1274 O <<
"// " << GVar->
getName() <<
" has been demoted\n";
1275 localDecls[DemotedFunc].push_back(GVar);
1279 emitPTXGlobalVariableDefinition(GVar, O, STI,
true);
1283void NVPTXAsmPrinter::emitPTXGlobalVariableDefinition(
1285 bool EmitInitializer) {
1296 ".attribute(.managed) requires PTX version >= 4.0 and sm_30");
1297 O <<
" .attribute(.managed)";
1301 << GVar->
getAlign().value_or(
DL.getPrefTypeAlign(ETy)).value();
1310 O << getPTXFundamentalTypeStr(ETy,
false);
1323 printScalarConstant(Initializer, O);
1332 "' is not allowed in addrspace(" +
1348 const uint64_t ElementSize =
DL.getTypeStoreSize(ETy);
1356 AggBuffer aggBuffer(ElementSize, *
this);
1357 bufferAggregateConstant(Initializer, &aggBuffer);
1358 if (aggBuffer.numSymbols()) {
1359 const unsigned int ptrSize =
MAI.getCodePointerSize();
1360 if (ElementSize % ptrSize ||
1361 !aggBuffer.allSymbolsAligned(ptrSize)) {
1365 "initialized packed aggregate with pointers '" +
1367 "' requires at least PTX ISA version 7.1");
1370 O <<
"[" << ElementSize <<
"]";
1371 if (EmitInitializer) {
1373 aggBuffer.printBytes(O);
1377 O <<
" .u" << ptrSize * 8 <<
" ";
1379 O <<
"[" << ElementSize / ptrSize <<
"]";
1380 if (EmitInitializer) {
1382 aggBuffer.printWords(O);
1389 O <<
"[" << ElementSize <<
"]";
1390 if (EmitInitializer) {
1392 aggBuffer.printBytes(O);
1400 O <<
"[" << ElementSize <<
"]";
1406 O <<
"[" << ElementSize <<
"]";
1416void NVPTXAsmPrinter::AggBuffer::printSymbol(
unsigned nSym,
raw_ostream &os) {
1417 const Value *
v = Symbols[nSym];
1418 const Value *v0 = SymbolsBeforeStripping[nSym];
1423 bool isGenericPointer = PTy && PTy->getAddressSpace() == 0;
1426 Name->print(os, AP.MAI);
1429 Name->print(os, AP.MAI);
1432 const MCExpr *Expr = AP.lowerConstantForGV(CExpr,
false);
1433 AP.printMCExpr(*Expr, os);
1438void NVPTXAsmPrinter::AggBuffer::printBytes(raw_ostream &os) {
1439 unsigned int ptrSize = AP.MAI.getCodePointerSize();
1444 unsigned int InitializerCount =
Size;
1447 if (numSymbols() == 0)
1448 while (InitializerCount >= 1 && !buffer[InitializerCount - 1])
1451 symbolPosInBuffer.push_back(InitializerCount);
1452 unsigned int nSym = 0;
1453 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
1454 for (
unsigned int pos = 0; pos < InitializerCount;) {
1457 if (pos != nextSymbolPos) {
1458 os << (
unsigned int)buffer[pos];
1465 std::string symText;
1466 llvm::raw_string_ostream oss(symText);
1467 printSymbol(nSym, oss);
1468 for (
unsigned i = 0; i < ptrSize; ++i) {
1472 os <<
"(" << symText <<
")";
1475 nextSymbolPos = symbolPosInBuffer[++nSym];
1476 assert(nextSymbolPos >= pos);
1480void NVPTXAsmPrinter::AggBuffer::printWords(raw_ostream &os) {
1481 unsigned int ptrSize = AP.MAI.getCodePointerSize();
1482 symbolPosInBuffer.push_back(
Size);
1483 unsigned int nSym = 0;
1484 unsigned int nextSymbolPos = symbolPosInBuffer[nSym];
1485 assert(nextSymbolPos % ptrSize == 0);
1486 for (
unsigned int pos = 0; pos <
Size; pos += ptrSize) {
1489 if (pos == nextSymbolPos) {
1490 printSymbol(nSym, os);
1491 nextSymbolPos = symbolPosInBuffer[++nSym];
1492 assert(nextSymbolPos % ptrSize == 0);
1493 assert(nextSymbolPos >= pos + ptrSize);
1494 }
else if (ptrSize == 4)
1501void NVPTXAsmPrinter::emitDemotedVars(
const Function *F, raw_ostream &O) {
1502 auto It = localDecls.find(F);
1503 if (It == localDecls.end())
1508 const NVPTXTargetMachine &NTM =
static_cast<const NVPTXTargetMachine &
>(
TM);
1511 for (
const GlobalVariable *GV : GVars) {
1512 O <<
"\t// demoted variable\n\t";
1513 printModuleLevelGV(GV, O,
true, STI);
1517void NVPTXAsmPrinter::emitPTXAddressSpace(
unsigned int AddressSpace,
1518 raw_ostream &O)
const {
1540NVPTXAsmPrinter::getPTXFundamentalTypeStr(
Type *Ty,
bool useB4PTR)
const {
1546 if (NumBits <= 64) {
1547 std::string
name =
"u";
1564 assert((PtrSize == 64 || PtrSize == 32) &&
"Unexpected pointer size");
1582void NVPTXAsmPrinter::emitPTXGlobalVariable(
const GlobalVariable *GVar,
1584 const NVPTXSubtarget &STI) {
1595 ".attribute(.managed) requires PTX version >= 4.0 and sm_30");
1597 O <<
" .attribute(.managed)";
1600 << GVar->
getAlign().value_or(
DL.getPrefTypeAlign(ETy)).value();
1611 O <<
" ." << getPTXFundamentalTypeStr(ETy) <<
" ";
1616 int64_t ElementSize = 0;
1626 ElementSize =
DL.getTypeStoreSize(ETy);
1640void NVPTXAsmPrinter::emitFunctionParamList(
const Function *F, raw_ostream &O) {
1642 const NVPTXSubtarget &STI =
TM.getSubtarget<NVPTXSubtarget>(*F);
1644 const NVPTXMachineFunctionInfo *MFI =
1645 MF ?
MF->getInfo<NVPTXMachineFunctionInfo>() : nullptr;
1647 bool IsFirst =
true;
1654 const auto NonEmptyArgs =
1656 return !Arg.getType()->isEmptyTy();
1659 if (NonEmptyArgs.empty() && !F->isVarArg()) {
1666 for (
const auto &[ParamIndex, Arg] :
enumerate(NonEmptyArgs)) {
1667 Type *Ty = Arg.getType();
1668 const std::string ParamSym = TLI->getParamName(F, ParamIndex);
1684 switch (ArgOpaqueType) {
1686 O <<
".samplerref ";
1702 if (Arg.hasByValAttr()) {
1704 Type *ETy = Arg.getParamByValType();
1705 assert(ETy &&
"Param should have byval type");
1711 const unsigned ParamIdx = Arg.getArgNo() + AttributeList::FirstArgIndex;
1712 const Align OptimalAlign =
1716 O <<
"\t.param .align " << OptimalAlign.
value() <<
" .b8 " << ParamSym
1717 <<
"[" <<
DL.getTypeAllocSize(ETy) <<
"]";
1727 F, Ty, Arg.getArgNo() + AttributeList::FirstArgIndex,
DL);
1729 O <<
"\t.param .align " << OptimalAlign.
value() <<
" .b8 " << ParamSym
1730 <<
"[" <<
DL.getTypeAllocSize(Ty) <<
"]";
1736 unsigned PTySizeInBits = 0;
1739 TLI->getPointerTy(
DL, PTy->getAddressSpace()).getSizeInBits();
1740 assert(PTySizeInBits &&
"Invalid pointer size");
1745 O <<
"\t.param .u" << PTySizeInBits <<
" .ptr";
1747 switch (PTy->getAddressSpace()) {
1764 O <<
" .align " << Arg.getParamAlign().valueOrOne().value() <<
" "
1775 O << getPTXFundamentalTypeStr(Ty);
1776 O <<
" " << ParamSym;
1785 assert(PTySizeInBits &&
"Invalid pointer size");
1786 Size = PTySizeInBits;
1789 O <<
"\t.param .b" <<
Size <<
" " << ParamSym;
1792 if (F->isVarArg()) {
1796 << TLI->getParamName(F, -1) <<
"[]";
1802void NVPTXAsmPrinter::setAndEmitFunctionVirtualRegisters(
1803 const MachineFunction &
MF) {
1804 SmallString<128> Str;
1805 raw_svector_ostream
O(Str);
1809 const TargetRegisterInfo *
TRI =
MF.getSubtarget().getRegisterInfo();
1812 const MachineFrameInfo &MFI =
MF.getFrameInfo();
1817 const bool Is64Bit =
1818 static_cast<const NVPTXTargetMachine &
>(
MF.getTarget()).is64Bit();
1819 const bool IsLocal64 =
1821 O <<
"\t.reg .b" << (Is64Bit ? 64 : 32) <<
" \t%SP;\n"
1822 <<
"\t.reg .b" << (IsLocal64 ? 64 : 32) <<
" \t%SPL;\n";
1829 for (
unsigned I :
llvm::seq(MRI->getNumVirtRegs())) {
1831 if (MRI->use_empty(VR) && MRI->def_empty(VR))
1833 auto &RCRegMap = VRegMapping[MRI->getRegClass(VR)];
1834 RCRegMap[VR] = RCRegMap.size() + 1;
1840 const unsigned N = VRegMapping[&RC].size();
1846 O <<
"\t.reg " << RCName <<
" \t" << RCStr <<
"<" << (
N + 1) <<
">;\n";
1855void NVPTXAsmPrinter::encodeDebugInfoRegisterNumbers(
1856 const MachineFunction &
MF) {
1857 const NVPTXSubtarget &STI =
MF.getSubtarget<NVPTXSubtarget>();
1865 for (
auto &classMap : VRegMapping) {
1866 for (
auto ®isterMapping : classMap.getSecond()) {
1867 auto reg = registerMapping.getFirst();
1873void NVPTXAsmPrinter::printFPConstant(
const ConstantFP *Fp,
1874 raw_ostream &O)
const {
1877 unsigned int numHex;
1895void NVPTXAsmPrinter::printScalarConstant(
const Constant *CPV, raw_ostream &O) {
1901 printFPConstant(CFP, O);
1910 if (EmitGeneric && !
isa<Function>(CPV) && !IsNonGenericPointer) {
1927void NVPTXAsmPrinter::bufferLEByte(
const Constant *CPV,
int Bytes,
1928 AggBuffer *AggBuffer) {
1930 int AllocSize =
DL.getTypeAllocSize(CPV->
getType());
1934 AggBuffer->addZeros(Bytes ? Bytes : AllocSize);
1939 auto AddIntToBuffer = [AggBuffer, Bytes](
const APInt &Val) {
1940 size_t NumBytes = (Val.getBitWidth() + 7) / 8;
1946 for (
unsigned I = 0;
I < NumBytes - 1; ++
I) {
1947 Buf[
I] = Val.extractBitsAsZExtValue(8,
I * 8);
1949 size_t LastBytePosition = (NumBytes - 1) * 8;
1950 size_t LastByteBits = Val.getBitWidth() - LastBytePosition;
1952 Val.extractBitsAsZExtValue(LastByteBits, LastBytePosition);
1953 AggBuffer->addBytes(Buf.data(), NumBytes, Bytes);
1963 if (
const auto *CI =
1968 if (Cexpr->getOpcode() == Instruction::PtrToInt) {
1969 Value *
V = Cexpr->getOperand(0)->stripPointerCasts();
1970 AggBuffer->addSymbol(V, Cexpr->getOperand(0));
1971 AggBuffer->addZeros(AllocSize);
1978 AggBuffer->addSymbol(Cexpr, Cexpr);
1979 AggBuffer->addZeros(AllocSize);
1994 AggBuffer->addSymbol(GVar, GVar);
1996 const Value *
v = Cexpr->stripPointerCasts();
1997 AggBuffer->addSymbol(v, Cexpr);
1999 AggBuffer->addZeros(AllocSize);
2009 unsigned StartPos = AggBuffer->getCurpos();
2010 bufferAggregateConstant(CPV, AggBuffer);
2011 unsigned Written = AggBuffer->getCurpos() - StartPos;
2012 unsigned SlotSize = std::max<int>(Bytes, AllocSize);
2013 if (SlotSize > Written)
2014 AggBuffer->addZeros(SlotSize - Written);
2016 AggBuffer->addZeros(Bytes);
2027void NVPTXAsmPrinter::bufferAggregateConstant(
const Constant *CPV,
2028 AggBuffer *aggBuffer) {
2031 auto ExtendBuffer = [](APInt Val, AggBuffer *Buffer) {
2034 unsigned NumBits = std::min(8u, Val.
getBitWidth() -
I * 8);
2042 for (
unsigned I :
llvm::seq(VTy->getNumElements()))
2051 ExtendBuffer(CI->
getValue(), aggBuffer);
2057 assert(CFP->getType()->isFloatingPointTy() &&
"Expected fp constant!");
2058 if (CFP->getType()->isFP128Ty()) {
2059 ExtendBuffer(CFP->getValueAPF().bitcastToAPInt(), aggBuffer);
2073 bufferAggregateConstVec(CVec, aggBuffer);
2078 for (
unsigned I :
llvm::seq(CDS->getNumElements()))
2079 bufferLEByte(
cast<Constant>(CDS->getElementAsConstant(
I)), 0, aggBuffer);
2088 ?
DL.getStructLayout(ST)->getElementOffset(0) +
2089 DL.getTypeAllocSize(ST)
2090 :
DL.getStructLayout(ST)->getElementOffset(
I + 1);
2091 int Bytes = EndOffset -
DL.getStructLayout(ST)->getElementOffset(
I);
2100void NVPTXAsmPrinter::bufferAggregateConstVec(
const ConstantVector *CV,
2101 AggBuffer *aggBuffer) {
2103 const unsigned BuffSize = aggBuffer->getBufferSize();
2106 if (BuffSize >= NumElems) {
2119 assert(ElemTySize < 8 &&
"Expected sub-byte data type.");
2120 assert(8 % ElemTySize == 0 &&
"Element type size must evenly divide a byte.");
2122 unsigned NumElemsPerByte = 8 / ElemTySize;
2123 unsigned NumCompleteBytes = NumElems / NumElemsPerByte;
2124 unsigned NumTailElems = NumElems % NumElemsPerByte;
2129 auto ConvertSubCVtoInt8 = [
this, &ElemTy](
const ConstantVector *CV,
2130 unsigned Start,
unsigned End,
2131 unsigned NumPaddingZeros = 0) {
2138 if (NumPaddingZeros)
2145 ConstantInt *MergedElem =
2152 "Cannot lower vector global with unusual element type");
2159 for (
unsigned ByteIdx :
llvm::seq(NumCompleteBytes))
2160 bufferLEByte(ConvertSubCVtoInt8(CV, ByteIdx * NumElemsPerByte,
2161 (ByteIdx + 1) * NumElemsPerByte),
2165 if (NumTailElems > 0)
2166 bufferLEByte(ConvertSubCVtoInt8(CV, NumElems - NumTailElems, NumElems,
2167 NumElemsPerByte - NumTailElems),
2176NVPTXAsmPrinter::lowerConstantForGV(
const Constant *CV,
2177 bool ProcessingGeneric)
const {
2188 if (ProcessingGeneric)
2198 switch (
CE->getOpcode()) {
2202 case Instruction::AddrSpaceCast: {
2205 if (DstTy->getAddressSpace() == 0)
2211 case Instruction::GetElementPtr: {
2215 APInt OffsetAI(
DL.getPointerTypeSizeInBits(
CE->getType()), 0);
2218 const MCExpr *
Base = lowerConstantForGV(
CE->getOperand(0),
2223 int64_t
Offset = OffsetAI.getSExtValue();
2228 case Instruction::Trunc:
2234 case Instruction::BitCast:
2235 return lowerConstantForGV(
CE->getOperand(0), ProcessingGeneric);
2237 case Instruction::IntToPtr: {
2246 return lowerConstantForGV(
Op, ProcessingGeneric);
2251 case Instruction::PtrToInt: {
2257 Type *Ty =
CE->getType();
2259 const MCExpr *OpExpr = lowerConstantForGV(
Op, ProcessingGeneric);
2263 if (
DL.getTypeAllocSize(Ty) ==
DL.getTypeAllocSize(
Op->getType()))
2269 unsigned InBits =
DL.getTypeAllocSizeInBits(
Op->getType());
2276 case Instruction::Add: {
2277 const MCExpr *
LHS = lowerConstantForGV(
CE->getOperand(0), ProcessingGeneric);
2278 const MCExpr *
RHS = lowerConstantForGV(
CE->getOperand(1), ProcessingGeneric);
2279 switch (
CE->getOpcode()) {
2291 return lowerConstantForGV(
C, ProcessingGeneric);
2295 raw_string_ostream OS(S);
2296 OS <<
"Unsupported expression in static initializer: ";
2297 CE->printAsOperand(OS,
false,
2298 !
MF ?
nullptr :
MF->getFunction().getParent());
2302void NVPTXAsmPrinter::printMCExpr(
const MCExpr &Expr, raw_ostream &OS)
const {
2308bool NVPTXAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
2309 const char *ExtraCode, raw_ostream &O) {
2310 if (ExtraCode && ExtraCode[0]) {
2311 if (ExtraCode[1] != 0)
2314 switch (ExtraCode[0]) {
2323 printOperand(
MI, OpNo, O);
2328bool NVPTXAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
2330 const char *ExtraCode,
2332 if (ExtraCode && ExtraCode[0])
2336 printMemOperand(
MI, OpNo, O);
2342void NVPTXAsmPrinter::printOperand(
const MachineInstr *
MI,
unsigned OpNum,
2344 const MachineOperand &MO =
MI->getOperand(OpNum);
2348 if (MO.
getReg() == NVPTX::VRDepot)
2353 emitVirtualRegister(MO.
getReg(), O);
2378void NVPTXAsmPrinter::printMemOperand(
const MachineInstr *
MI,
unsigned OpNum,
2379 raw_ostream &O,
const char *Modifier) {
2380 printOperand(
MI, OpNum, O);
2382 if (Modifier && strcmp(Modifier,
"add") == 0) {
2384 printOperand(
MI, OpNum + 1, O);
2386 if (
MI->getOperand(OpNum + 1).isImm() &&
2387 MI->getOperand(OpNum + 1).getImm() == 0)
2390 printOperand(
MI, OpNum + 1, O);
2398 return !Trimmed.
empty() &&
2399 (std::isalpha(
static_cast<unsigned char>(Trimmed[0])) ||
2406 if (!
MI || !
MI->getDebugLoc())
2408 const DISubprogram *SP =
MI->getMF()->getFunction().getSubprogram();
2412 if (!
DL->getFile() || !
DL->getLine())
2418struct InlineAsmInliningContext {
2420 unsigned FileIA = 0;
2421 unsigned LineIA = 0;
2424 bool hasInlinedAt()
const {
return FuncNameSym !=
nullptr; }
2430static InlineAsmInliningContext
2434 InlineAsmInliningContext Ctx;
2436 if (!InlinedAt || !InlinedAt->getFile() || !NVDD ||
2444 0, InlinedAt->getFile()->getDirectory(),
2445 InlinedAt->getFile()->getFilename(), std::nullopt, std::nullopt, CUID);
2446 Ctx.LineIA = InlinedAt->getLine();
2447 Ctx.ColIA = InlinedAt->getColumn();
2451void NVPTXAsmPrinter::emitInlineAsm(StringRef Str,
const MCSubtargetInfo &STI,
2452 const MCTargetOptions &MCOptions,
2453 const MDNode *LocMDNode,
2455 const MachineInstr *
MI) {
2456 assert(!Str.empty() &&
"Can't emit empty inline asm block");
2457 if (Str.back() == 0)
2458 Str = Str.substr(0, Str.size() - 1);
2460 auto emitAsmStr = [&](StringRef AsmStr) {
2472 const DIFile *
File =
DL->getFile();
2473 unsigned Line =
DL->getLine();
2474 const unsigned Column =
DL->getColumn();
2475 const unsigned CUID =
OutStreamer->getContext().getDwarfCompileUnitID();
2476 const unsigned FileNumber =
OutStreamer->emitDwarfFileDirective(
2477 0,
File->getDirectory(),
File->getFilename(), std::nullopt, std::nullopt,
2480 auto *NVDD =
static_cast<NVPTXDwarfDebug *
>(
getDwarfDebug());
2481 InlineAsmInliningContext InlineCtx =
2484 SmallVector<StringRef, 16>
Lines;
2485 Str.split(Lines,
'\n');
2487 for (
const StringRef &L : Lines) {
2488 StringRef RTrimmed =
L.rtrim(
'\r');
2490 if (InlineCtx.hasInlinedAt()) {
2492 FileNumber, Line, Column, InlineCtx.FileIA, InlineCtx.LineIA,
2494 File->getFilename());
2496 OutStreamer->emitDwarfLocDirective(FileNumber, Line, Column,
2498 File->getFilename());
2514LLVMInitializeNVPTXAsmPrinter() {
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
Machine Check Debug Module
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 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 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)
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
Provides some synthesis utilities to produce sequences of values.
This file defines the SmallPtrSet class.
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.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
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...
LLVM_ABI bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
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...
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
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_JumpTableIndex
Address of indexed Jump Table for switch.
@ 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...
typename SuperClass::const_iterator const_iterator
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)
void insert_range(Range &&R)
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.
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
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.
@ Ready
Emitted to memory, but waiting on transitive dependencies.
NodeAddr< NodeBase * > Node
uint64_t read64le(const void *P)
uint32_t read32le(const void *P)
This is an optimization pass for GlobalISel generic memory operations.
bool isManaged(const Value &)
SmallVector< unsigned, 3 > getReqNTID(const Function &)
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 shouldEmitPTXNoReturn(const Value *V, const TargetMachine &TM)
Align getDeviceByValParamAlign(const Function *F, Type *ArgTy, unsigned AttrIdx, const DataLayout &DL)
The .param-space alignment for a byval parameter or call argument: the (possibly promoted) parameter ...
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.
bool hasBlocksAreClusters(const Function &)
SmallVector< unsigned, 3 > getClusterDim(const Function &)
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.
std::optional< unsigned > getMaxNReg(const Function &)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
PTXOpaqueType getPTXOpaqueType(const GlobalVariable &)
std::string utostr(uint64_t X, bool isNeg=false)
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
std::optional< unsigned > getMinCTASm(const Function &)
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)
void sort(IteratorTy Start, IteratorTy End)
unsigned promoteScalarArgumentSize(unsigned size)
SmallVector< unsigned, 3 > getMaxNTID(const Function &)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
bool shouldPassAsArray(Type *Ty)
StringRef getNVPTXRegClassStr(const TargetRegisterClass *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...
std::optional< unsigned > getMaxClusterRank(const Function &)
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...
constexpr T divideCeil(U Numerator, V Denominator)
Returns the integer ceil(Numerator / Denominator).
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
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)
Alignment for a function parameter or return value at AttributeList index AttrIdx (FirstArgIndex + ar...
ArrayRef(const T &OneElt) -> ArrayRef< T >
Target & getTheNVPTXTarget64()
bool isKernelFunction(const Function &F)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
constexpr auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
StringRef getNVPTXRegClassName(const TargetRegisterClass *RC)
void clearAnnotationCache(const Module *)
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...
LLVM_ABI DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Target & getTheNVPTXTarget32()
MCRegisterClass TargetRegisterClass
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
MachineJumpTableEntry - One jump table in the jump table info.
std::vector< MachineBasicBlock * > MBBs
MBBs - The vector of basic blocks from which to create the jump table.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...