93 #define DEPOTNAME "__local_depot" 103 if (
const User *U = dyn_cast<User>(V)) {
104 for (
unsigned i = 0, e = U->getNumOperands(); i != e; ++i) {
120 if (Visited.
count(GV))
124 if (!Visiting.
insert(GV).second)
145 lowerToMCInst(MI, Inst);
150 bool NVPTXAsmPrinter::lowerImageHandleOperand(
const MachineInstr *MI,
158 if (OpNo == 4 && MO.
isImm()) {
159 lowerImageHandleSymbol(MO.
getImm(), MCOp);
163 lowerImageHandleSymbol(MO.
getImm(), MCOp);
173 if (OpNo == VecSize && MO.
isImm()) {
174 lowerImageHandleSymbol(MO.
getImm(), MCOp);
181 if (OpNo == 0 && MO.
isImm()) {
182 lowerImageHandleSymbol(MO.
getImm(), MCOp);
189 if (OpNo == 1 && MO.
isImm()) {
190 lowerImageHandleSymbol(MO.
getImm(), MCOp);
200 void NVPTXAsmPrinter::lowerImageHandleSymbol(
unsigned Index,
MCOperand &MCOp) {
206 std::string *SymNamePtr =
214 if (MI->
getOpcode() == NVPTX::CALL_PROTOTYPE) {
226 if (lowerImageHandleOperand(MI, i, MCOp)) {
232 if (lowerOperand(MO, MCOp))
282 unsigned NVPTXAsmPrinter::encodeVirtualRegister(
unsigned Reg) {
287 unsigned RegNum = RegMap[
Reg];
292 if (RC == &NVPTX::Int1RegsRegClass) {
294 }
else if (RC == &NVPTX::Int16RegsRegClass) {
296 }
else if (RC == &NVPTX::Int32RegsRegClass) {
298 }
else if (RC == &NVPTX::Int64RegsRegClass) {
300 }
else if (RC == &NVPTX::Float32RegsRegClass) {
302 }
else if (RC == &NVPTX::Float64RegsRegClass) {
304 }
else if (RC == &NVPTX::Float16RegsRegClass) {
306 }
else if (RC == &NVPTX::Float16x2RegsRegClass) {
313 Ret |= (RegNum & 0x0FFFFFFF);
318 return Reg & 0x0FFFFFFF;
345 if (
auto *ITy = dyn_cast<IntegerType>(Ty)) {
346 size = ITy->getBitWidth();
357 O <<
".param .b" << size <<
" func_retval0";
358 }
else if (isa<PointerType>(Ty)) {
363 unsigned retAlignment = 0;
366 O <<
".param .align " << retAlignment <<
" .b8 func_retval0[" << totalsz
374 for (
unsigned i = 0, e = vtparts.
size(); i != e; ++i) {
376 EVT elemtype = vtparts[i];
378 elems = vtparts[i].getVectorNumElements();
379 elemtype = vtparts[i].getVectorElementType();
382 for (
unsigned j = 0, je = elems; j != je; ++j) {
386 O <<
".reg .b" << sz <<
" func_retval" << idx;
401 printReturnValStr(&F, O);
407 bool NVPTXAsmPrinter::isLoopHeaderOfNoUnroll(
436 if (isLoopHeaderOfNoUnroll(MBB))
440 void NVPTXAsmPrinter::EmitFunctionEntryLabel() {
444 if (!GlobalsEmitted) {
446 GlobalsEmitted =
true;
452 emitLinkageDirective(F, O);
457 printReturnValStr(*MF, O);
462 emitFunctionParamList(*MF, O);
465 emitKernelFunctionDirectives(*F, O);
472 setAndEmitFunctionVirtualRegisters(*MF);
487 void NVPTXAsmPrinter::EmitFunctionBodyStart() {
494 void NVPTXAsmPrinter::EmitFunctionBodyEnd() {
504 void NVPTXAsmPrinter::emitImplicitDef(
const MachineInstr *MI)
const {
516 void NVPTXAsmPrinter::emitKernelFunctionDirectives(
const Function &F,
521 unsigned reqntidx, reqntidy, reqntidz;
522 bool specified =
false;
537 O <<
".reqntid " << reqntidx <<
", " << reqntidy <<
", " << reqntidz
543 unsigned maxntidx, maxntidy, maxntidz;
559 O <<
".maxntid " << maxntidx <<
", " << maxntidy <<
", " << maxntidz
564 O <<
".minnctapersm " << mincta <<
"\n";
568 O <<
".maxnreg " << maxnreg <<
"\n";
579 assert(I != VRegMapping.
end() &&
"Bad register class");
583 assert(VI != RegMap.end() &&
"Bad virtual register");
584 unsigned MappedVR = VI->second;
592 void NVPTXAsmPrinter::emitVirtualRegister(
unsigned int vr,
597 void NVPTXAsmPrinter::printVecModifiedImmediate(
599 static const char vecelem[] = {
'0',
'1',
'2',
'3',
'0',
'1',
'2',
'3' };
600 int Imm = (int) MO.
getImm();
601 if (0 == strcmp(Modifier,
"vecelem"))
602 O <<
"_" << vecelem[Imm];
603 else if (0 == strcmp(Modifier,
"vecv4comm1")) {
604 if ((Imm < 0) || (Imm > 3))
606 }
else if (0 == strcmp(Modifier,
"vecv4comm2")) {
607 if ((Imm < 4) || (Imm > 7))
609 }
else if (0 == strcmp(Modifier,
"vecv4pos")) {
612 O <<
"_" << vecelem[Imm % 4];
613 }
else if (0 == strcmp(Modifier,
"vecv2comm1")) {
614 if ((Imm < 0) || (Imm > 1))
616 }
else if (0 == strcmp(Modifier,
"vecv2comm2")) {
617 if ((Imm < 2) || (Imm > 3))
619 }
else if (0 == strcmp(Modifier,
"vecv2pos")) {
622 O <<
"_" << vecelem[Imm % 2];
628 emitLinkageDirective(F, O);
633 printReturnValStr(F, O);
636 emitFunctionParamList(F, O);
645 return GV->getName() !=
"llvm.used";
649 if (
const Constant *C = dyn_cast<Constant>(U))
657 if (
const GlobalVariable *othergv = dyn_cast<GlobalVariable>(U)) {
658 if (othergv->getName() ==
"llvm.used")
662 if (
const Instruction *instr = dyn_cast<Instruction>(U)) {
663 if (instr->getParent() && instr->getParent()->getParent()) {
665 if (oneFunc && (curFunc != oneFunc))
708 if (
const Constant *cu = dyn_cast<Constant>(U)) {
711 }
else if (
const Instruction *
I = dyn_cast<Instruction>(U)) {
718 if (seenMap.
find(caller) != seenMap.
end())
735 emitDeclaration(F, O);
739 if (
const Constant *
C = dyn_cast<Constant>(U)) {
744 emitDeclaration(F, O);
750 emitDeclaration(F, O);
755 if (!isa<Instruction>(U))
768 if (seenMap.
find(caller) != seenMap.
end()) {
769 emitDeclaration(F, O);
778 if (!GV)
return true;
780 if (!InitList)
return true;
800 "Module has a nontrivial global ctor, which NVPTX does not support.");
805 "Module has a nontrivial global dtor, which NVPTX does not support.");
816 emitHeader(M, OS1, STI);
821 OutStreamer->AddComment(
"Start of file scope inline assembly");
825 OutStreamer->AddComment(
"End of file scope inline assembly");
829 GlobalsEmitted =
false;
834 void NVPTXAsmPrinter::emitGlobals(
const Module &M) {
838 emitDeclarations(M, OS2);
854 "Missed a global variable");
855 assert(GVVisiting.
size() == 0 &&
"Did not fully process a global variable");
858 for (
unsigned i = 0, e = Globals.
size(); i != e; ++i)
859 printModuleLevelGV(Globals[i], OS2);
869 O <<
"// Generated by LLVM NVPTX Back-End\n";
874 O <<
".version " << (PTXVersion / 10) <<
"." << (PTXVersion % 10) <<
"\n";
881 O <<
", texmode_independent";
889 O <<
".address_size ";
904 if (!GlobalsEmitted) {
906 GlobalsEmitted =
true;
913 int i, n = global_list.size();
923 while (!global_list.empty())
924 global_list.
remove(global_list.begin());
930 for (i = 0; i < n; i++)
931 global_list.
insert(global_list.end(), gv_array[i]);
966 void NVPTXAsmPrinter::emitLinkageDirective(
const GlobalValue *V,
968 if (static_cast<NVPTXTargetMachine &>(
TM).getDrvInterface() ==
NVPTX::CUDA) {
970 if (isa<GlobalVariable>(V)) {
984 msg.append(
"Error: ");
985 msg.append(
"Symbol ");
988 msg.append(
"has unsupported appending linkage type");
997 void NVPTXAsmPrinter::printModuleLevelGV(
const GlobalVariable *GVar,
999 bool processDemoted) {
1042 emitPTXGlobalVariable(GVar, O);
1050 const Constant *Initializer =
nullptr;
1064 O <<
"addr_mode_" << i <<
" = ";
1070 O <<
"clamp_to_border";
1073 O <<
"clamp_to_edge";
1084 O <<
"filter_mode = ";
1099 O <<
", force_unnormalized_coords = 1";
1109 if (strncmp(GVar->
getName().
data(),
"unrollpragma", 12) == 0)
1113 if (strncmp(GVar->
getName().
data(),
"filename", 8) == 0)
1119 const Function *demotedFunc =
nullptr;
1121 O <<
"// " << GVar->
getName() <<
" has been demoted\n";
1122 if (localDecls.find(demotedFunc) != localDecls.end())
1123 localDecls[demotedFunc].push_back(GVar);
1125 std::vector<const GlobalVariable *> temp;
1126 temp.push_back(GVar);
1127 localDecls[demotedFunc] = temp;
1136 O <<
" .attribute(.managed)";
1151 O << getPTXFundamentalTypeStr(ETy,
false);
1162 if (!Initializer->
isNullValue() && !isa<UndefValue>(Initializer)) {
1164 printScalarConstant(Initializer, O);
1173 "' is not allowed in addrspace(" +
1179 unsigned int ElementSize = 0;
1197 if (!isa<UndefValue>(Initializer) && !Initializer->
isNullValue()) {
1198 AggBuffer aggBuffer(ElementSize, O, *
this);
1199 bufferAggregateConstant(Initializer, &aggBuffer);
1200 if (aggBuffer.numSymbols) {
1201 if (static_cast<const NVPTXTargetMachine &>(
TM).
is64Bit()) {
1205 O << ElementSize / 8;
1210 O << ElementSize / 4;
1250 if (localDecls.find(f) == localDecls.end())
1253 std::vector<const GlobalVariable *> &gvars = localDecls[f];
1255 for (
unsigned i = 0, e = gvars.size(); i != e; ++i) {
1256 O <<
"\t// demoted variable\n\t";
1257 printModuleLevelGV(gvars[i], O,
true);
1261 void NVPTXAsmPrinter::emitPTXAddressSpace(
unsigned int AddressSpace,
1284 NVPTXAsmPrinter::getPTXFundamentalTypeStr(
Type *Ty,
bool useB4PTR)
const {
1290 unsigned NumBits = cast<IntegerType>(Ty)->
getBitWidth();
1293 else if (NumBits <= 64) {
1294 std::string
name =
"u";
1295 return name +
utostr(NumBits);
1310 if (static_cast<const NVPTXTargetMachine &>(
TM).
is64Bit())
1324 void NVPTXAsmPrinter::emitPTXGlobalVariable(
const GlobalVariable *GVar,
1348 O << getPTXFundamentalTypeStr(ETy);
1354 int64_t ElementSize = 0;
1388 unsigned int alignStruct = 1;
1391 for (
unsigned i = 0, e = STy->getNumElements(); i != e; i++) {
1392 Type *ETy = STy->getElementType(i);
1394 if (align > alignStruct)
1395 alignStruct = align;
1409 O <<
"_param_" << paramIndex;
1417 unsigned paramIndex = 0;
1442 std::string sname = I->
getName();
1445 O <<
"\t.param .u64 .ptr .surfref ";
1447 O <<
"\t.param .surfref ";
1449 O <<
"_param_" << paramIndex;
1453 O <<
"\t.param .u64 .ptr .texref ";
1455 O <<
"\t.param .texref ";
1457 O <<
"_param_" << paramIndex;
1461 O <<
"\t.param .u64 .ptr .samplerref ";
1463 O <<
"\t.param .samplerref ";
1465 O <<
"_param_" << paramIndex;
1481 O <<
"\t.param .align " << align <<
" .b8 ";
1482 printParamName(I, paramIndex, O);
1483 O <<
"[" << sz <<
"]";
1494 if (static_cast<NVPTXTargetMachine &>(
TM).getDrvInterface() !=
1496 Type *ETy = PTy->getElementType();
1497 int addrSpace = PTy->getAddressSpace();
1498 switch (addrSpace) {
1503 O <<
".ptr .const ";
1506 O <<
".ptr .shared ";
1509 O <<
".ptr .global ";
1514 printParamName(I, paramIndex, O);
1524 O << getPTXFundamentalTypeStr(Ty);
1526 printParamName(I, paramIndex, O);
1532 if (isa<IntegerType>(Ty)) {
1536 }
else if (isa<PointerType>(Ty))
1546 O <<
"\t.param .b" << sz <<
" ";
1548 O <<
"\t.reg .b" << sz <<
" ";
1549 printParamName(I, paramIndex, O);
1555 assert(PTy &&
"Param with byval attribute should be a pointer type");
1556 Type *ETy = PTy->getElementType();
1558 if (isABI || isKernelFunc) {
1576 if (!isKernelFunc && align < 4)
1579 O <<
"\t.param .align " << align <<
" .b8 ";
1580 printParamName(I, paramIndex, O);
1581 O <<
"[" << sz <<
"]";
1590 for (
unsigned i = 0, e = vtparts.
size(); i != e; ++i) {
1592 EVT elemtype = vtparts[i];
1594 elems = vtparts[i].getVectorNumElements();
1595 elemtype = vtparts[i].getVectorElementType();
1598 for (
unsigned j = 0, je = elems; j != je; ++j) {
1602 O <<
"\t.reg .b" << sz <<
" ";
1603 printParamName(I, paramIndex, O);
1619 void NVPTXAsmPrinter::emitFunctionParamList(
const MachineFunction &MF,
1622 emitFunctionParamList(&F, O);
1625 void NVPTXAsmPrinter::setAndEmitFunctionVirtualRegisters(
1642 O <<
"\t.reg .b64 \t%SP;\n";
1643 O <<
"\t.reg .b64 \t%SPL;\n";
1645 O <<
"\t.reg .b32 \t%SP;\n";
1646 O <<
"\t.reg .b32 \t%SPL;\n";
1654 unsigned int numVRs =
MRI->getNumVirtRegs();
1655 for (
unsigned i = 0; i < numVRs; i++) {
1659 int n = regmap.
size();
1660 regmap.
insert(std::make_pair(vr, n + 1));
1680 int n = regmap.
size();
1684 O <<
"\t.reg " << rcname <<
" \t" << rcStr <<
"<" << (n+1)
1695 unsigned int numHex;
1714 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
1715 O << CI->getValue();
1718 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CPV)) {
1719 printFPConstant(CFP, O);
1722 if (isa<ConstantPointerNull>(CPV)) {
1726 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(CPV)) {
1727 bool IsNonGenericPointer =
false;
1729 IsNonGenericPointer =
true;
1731 if (EmitGeneric && !isa<Function>(CPV) && !IsNonGenericPointer) {
1740 if (
const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1743 bool IsNonGenericPointer =
false;
1745 IsNonGenericPointer =
true;
1747 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
1748 if (EmitGeneric && !isa<Function>(v) && !IsNonGenericPointer) {
1767 int64_t vp = (int64_t)val;
1768 for (
unsigned i = 0; i <
sizeof(
T); ++i) {
1769 p[i] = (
unsigned char)vp;
1774 int32_t *vp = (int32_t *)&val;
1775 for (
unsigned i = 0; i <
sizeof(int32_t); ++i) {
1776 p[i] = (
unsigned char)*vp;
1781 int64_t *vp = (int64_t *)&val;
1782 for (
unsigned i = 0; i <
sizeof(int64_t); ++i) {
1783 p[i] = (
unsigned char)*vp;
1788 void NVPTXAsmPrinter::bufferLEByte(
const Constant *CPV,
int Bytes,
1796 aggBuffer->addZeros(s);
1800 unsigned char ptr[8];
1806 unsigned char c = (
unsigned char)cast<ConstantInt>(CPV)->getZExtValue();
1807 ConvertIntToBytes<>(ptr, c);
1808 aggBuffer->addBytes(ptr, 1, Bytes);
1810 short int16 = (short)cast<ConstantInt>(CPV)->getZExtValue();
1811 ConvertIntToBytes<>(ptr, int16);
1812 aggBuffer->addBytes(ptr, 2, Bytes);
1814 if (
const ConstantInt *constInt = dyn_cast<ConstantInt>(CPV)) {
1815 int int32 = (int)(constInt->getZExtValue());
1816 ConvertIntToBytes<>(ptr, int32);
1817 aggBuffer->addBytes(ptr, 4, Bytes);
1819 }
else if (
const auto *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1820 if (
const auto *constInt = dyn_cast_or_null<ConstantInt>(
1822 int int32 = (int)(constInt->getZExtValue());
1823 ConvertIntToBytes<>(ptr, int32);
1824 aggBuffer->addBytes(ptr, 4, Bytes);
1827 if (Cexpr->getOpcode() == Instruction::PtrToInt) {
1829 aggBuffer->addSymbol(v, Cexpr->getOperand(0));
1830 aggBuffer->addZeros(4);
1836 if (
const ConstantInt *constInt = dyn_cast<ConstantInt>(CPV)) {
1837 long long int64 = (
long long)(constInt->getZExtValue());
1838 ConvertIntToBytes<>(ptr, int64);
1839 aggBuffer->addBytes(ptr, 8, Bytes);
1841 }
else if (
const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1842 if (
const auto *constInt = dyn_cast_or_null<ConstantInt>(
1844 long long int64 = (
long long)(constInt->getZExtValue());
1845 ConvertIntToBytes<>(ptr, int64);
1846 aggBuffer->addBytes(ptr, 8, Bytes);
1849 if (Cexpr->getOpcode() == Instruction::PtrToInt) {
1851 aggBuffer->addSymbol(v, Cexpr->getOperand(0));
1852 aggBuffer->addZeros(8);
1869 ConvertIntToBytes<>(ptr, float16);
1870 aggBuffer->addBytes(ptr, 2, Bytes);
1874 aggBuffer->addBytes(ptr, 4, Bytes);
1878 aggBuffer->addBytes(ptr, 8, Bytes);
1885 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(CPV)) {
1886 aggBuffer->addSymbol(GVar, GVar);
1887 }
else if (
const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1889 aggBuffer->addSymbol(v, Cexpr);
1892 aggBuffer->addZeros(s);
1899 if (isa<ConstantAggregate>(CPV) || isa<ConstantDataSequential>(CPV)) {
1901 bufferAggregateConstant(CPV, aggBuffer);
1902 if (Bytes > ElementSize)
1903 aggBuffer->addZeros(Bytes - ElementSize);
1904 }
else if (isa<ConstantAggregateZero>(CPV))
1905 aggBuffer->addZeros(Bytes);
1916 void NVPTXAsmPrinter::bufferAggregateConstant(
const Constant *CPV,
1922 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
1923 APInt Val = CI->getValue();
1926 aggBuffer->addBytes(&Byte, 1, 1);
1933 if (isa<ConstantArray>(CPV) || isa<ConstantVector>(CPV)) {
1936 bufferLEByte(cast<Constant>(CPV->
getOperand(i)), 0, aggBuffer);
1941 dyn_cast<ConstantDataSequential>(CPV)) {
1942 if (CDS->getNumElements())
1943 for (
unsigned i = 0; i < CDS->getNumElements(); ++i)
1944 bufferLEByte(cast<Constant>(CDS->getElementAsConstant(i)), 0,
1949 if (isa<ConstantStruct>(CPV)) {
1960 bufferLEByte(cast<Constant>(CPV->
getOperand(i)), Bytes, aggBuffer);
1973 NVPTXAsmPrinter::lowerConstantForGV(
const Constant *CV,
bool ProcessingGeneric) {
1979 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV))
1982 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
1985 if (ProcessingGeneric) {
2004 return lowerConstantForGV(
C, ProcessingGeneric);
2010 OS <<
"Unsupported expression in static initializer: ";
2016 case Instruction::AddrSpaceCast: {
2020 return lowerConstantForGV(cast<const Constant>(CE->
getOperand(0)),
true);
2024 OS <<
"Unsupported expression in static initializer: ";
2030 case Instruction::GetElementPtr: {
2035 cast<GEPOperator>(CE)->accumulateConstantOffset(DL, OffsetAI);
2047 case Instruction::Trunc:
2053 case Instruction::BitCast:
2054 return lowerConstantForGV(CE->
getOperand(0), ProcessingGeneric);
2056 case Instruction::IntToPtr: {
2064 return lowerConstantForGV(Op, ProcessingGeneric);
2067 case Instruction::PtrToInt: {
2075 const MCExpr *OpExpr = lowerConstantForGV(Op, ProcessingGeneric);
2093 const MCExpr *LHS = lowerConstantForGV(CE->
getOperand(0), ProcessingGeneric);
2094 const MCExpr *RHS = lowerConstantForGV(CE->
getOperand(1), ProcessingGeneric);
2107 return cast<MCTargetExpr>(&Expr)->printImpl(OS,
MAI);
2109 OS << cast<MCConstantExpr>(Expr).getValue();
2135 if (isa<MCConstantExpr>(BE.
getLHS()) || isa<MCSymbolRefExpr>(BE.
getLHS()) ||
2136 isa<NVPTXGenericMCSymbolRefExpr>(BE.
getLHS())) {
2137 printMCExpr(*BE.
getLHS(), OS);
2140 printMCExpr(*BE.
getLHS(), OS);
2148 if (RHSC->getValue() < 0) {
2149 OS << RHSC->getValue();
2160 if (isa<MCConstantExpr>(BE.
getRHS()) || isa<MCSymbolRefExpr>(BE.
getRHS())) {
2161 printMCExpr(*BE.
getRHS(), OS);
2164 printMCExpr(*BE.
getRHS(), OS);
2176 bool NVPTXAsmPrinter::PrintAsmOperand(
const MachineInstr *MI,
unsigned OpNo,
2177 unsigned AsmVariant,
2179 if (ExtraCode && ExtraCode[0]) {
2180 if (ExtraCode[1] != 0)
2183 switch (ExtraCode[0]) {
2197 bool NVPTXAsmPrinter::PrintAsmMemoryOperand(
2198 const MachineInstr *MI,
unsigned OpNo,
unsigned AsmVariant,
2200 if (ExtraCode && ExtraCode[0])
2216 if (MO.
getReg() == NVPTX::VRDepot)
2221 emitVirtualRegister(MO.
getReg(),
O);
2228 else if (strstr(Modifier,
"vec") == Modifier)
2229 printVecModifiedImmediate(MO, Modifier, O);
2232 "Don't know how to handle modifier on immediate operand");
2256 if (Modifier && strcmp(Modifier,
"add") == 0) {
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
StringRef getSection() const
Get the custom section of this global if it has one.
unsigned getAlignment() const
void push_back(const T &Elt)
unsigned getPTXVersion() const
A parsed version of the target data layout string in and methods for querying it. ...
StringRef getTargetFeatureString() const
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static Type * getDoubleTy(LLVMContext &C)
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
uint64_t getZExtValue() const
Get zero extended value.
This class represents an incoming formal argument to a Function.
MachineBasicBlock * getMBB() const
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
bool hasDebugInfo() const
Returns true if valid debug info is present.
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
bool getAlign(const Function &F, unsigned index, unsigned &align)
bool hasPrivateLinkage() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
bool getMaxNReg(const Function &F, unsigned &x)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
A Module instance is used to store all the information related to an LLVM module. ...
unsigned getPointerPrefAlignment(unsigned AS=0) const
Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of...
2: 32-bit floating point type
bool doFinalization(Module &M) override
Shut down the asmprinter.
MCContext & OutContext
This is the context for the output file that we are streaming.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
static MCOperand createExpr(const MCExpr *Val)
Implements a dense probed hash-table based set.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
Describe properties that are true of each instruction in the target description file.
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
bool isTexture(const Value &val)
bool hasAvailableExternallyLinkage() const
Opcode getOpcode() const
Get the kind of this unary expression.
float convertToFloat() const
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
LLVMContext & getContext() const
All values hold a context through their type.
bool erase(const ValueT &V)
A raw_ostream that writes to an SmallVector or SmallString.
MachineBasicBlock reference.
unsigned const TargetRegisterInfo * TRI
static const MCBinaryExpr * createAnd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
bool isInteger() const
Return true if this is an integer or a vector integer type.
MachineFunction * MF
The current machine function.
1: 16-bit floating point type
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
static IntegerType * getInt64Ty(LLVMContext &C)
bool isVectorTy() const
True if this is an instance of VectorType.
static IntegerType * getInt16Ty(LLVMContext &C)
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
static const NVPTXFloatMCExpr * createConstantFPSingle(const APFloat &Flt, MCContext &Ctx)
bool hasImageHandles() const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
static void DiscoverDependentGlobals(const Value *V, DenseSet< const GlobalVariable *> &Globals)
DiscoverDependentGlobals - Return a set of GlobalVariables on which V depends.
const MCSymbol * getFunctionFrameSymbol() const override
Return symbol for the function pseudo stack if the stack frame is not a register based.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
APInt getLoBits(unsigned numBits) const
Compute an APInt containing numBits lowbits from this APInt.
static MCOperand createReg(unsigned Reg)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Type * getFloatTy(LLVMContext &C)
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
TypeID getTypeID() const
Return the type id for the type.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
static bool usedInOneFunc(const User *U, Function const *&oneFunc)
const ConstantFP * getFPImm() const
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Class to represent struct types.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
void clearAnnotationCache(const Module *Mod)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for the full range of assembler expressions which are needed for parsing.
bool isIntegerTy() const
True if this is an instance of IntegerType.
Name of external global symbol.
This file contains the simple types necessary to represent the attributes associated with functions a...
Represent a reference to a symbol from inside an expression.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
static const NVPTXFloatMCExpr * createConstantFPDouble(const APFloat &Flt, MCContext &Ctx)
const char * getSymbolName() const
void lshrInPlace(unsigned ShiftAmt)
Logical right-shift this APInt by ShiftAmt in place.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This file implements a class to represent arbitrary precision integral constant values and operations...
bool hasCommonLinkage() const
Target & getTheNVPTXTarget64()
unsigned getNumRegClasses() const
bool getMaxNTIDz(const Function &F, unsigned &z)
unsigned getSizeInBits() const
Context object for machine code objects.
bool hasExternalLinkage() const
Constant * ConstantFoldConstant(const Constant *C, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldConstant - Attempt to fold the constant using the specified DataLayout.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
A constant value that is initialized with an expression using other constant values.
Class to represent function types.
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
int64_t getSExtValue() const
Get sign extended value.
bool isKernelFunction(const Function &F)
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Type * getType() const
All values are typed, get the type of this value.
bool isSurface(const Value &val)
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Unary assembler expressions.
Class to represent array types.
bool getMaxNTIDx(const Function &F, unsigned &x)
std::string getTextureName(const Value &val)
ManagedStringPool * getManagedStrPool() const
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
bool runOnMachineFunction(MachineFunction &F) override
Emit the specified function out to the OutStreamer.
AttributeList getAttributes() const
Return the attribute list for this Function.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer, for use in the target machine initialization function.
static const fltSemantics & IEEEdouble() LLVM_READNONE
StringRef getTargetCPU() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
bool hasLinkOnceLinkage() const
bool isSampler(const Value &val)
void ComputeValueVTs(const TargetLowering &TLI, const DataLayout &DL, Type *Ty, SmallVectorImpl< EVT > &ValueVTs, SmallVectorImpl< uint64_t > *Offsets=nullptr, uint64_t StartingOffset=0)
ComputeValueVTs - Given an LLVM IR type, compute a sequence of EVTs that represent all the individual...
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Value * getOperand(unsigned i) const
Instances of this class represent a single low-level machine instruction.
static const NVPTXGenericMCSymbolRefExpr * create(const MCSymbolRefExpr *SymExpr, MCContext &Ctx)
Class to represent pointers.
bool hasAppendingLinkage() const
iterator find(const_arg_type_t< KeyT > Val)
11: Arbitrary bit width integers
Target & getTheNVPTXTarget32()
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
Address of a global value.
static bool isEmptyXXStructor(GlobalVariable *GV)
Type * getReturnType() const
Returns the type of the ret val.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
unsigned const MachineRegisterInfo * MRI
MCSymbol * CurrentFnSym
The symbol for the current function.
MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
LLVM Basic Block Representation.
const MCAsmInfo * MAI
Target Asm Printer information.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
The instances of the Type class are immutable: once they are created, they are never changed...
const char * getImageHandleSymbol(unsigned Idx) const
Returns the symbol name at the given index.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
static bool is64Bit(const char *name)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol, HexagonAsmPrinter &Printer, bool MustExtend)
const GlobalValue * getGlobal() const
const NVPTXTargetLowering * getTargetLowering() const override
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, unsigned AsmVariant, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant...
std::pair< iterator, bool > insert(const ValueT &V)
ConstantFP - Floating Point Values [float, double].
size_t alias_size() const
double convertToDouble() const
TargetMachine & TM
Target machine description.
std::string getTargetName() const
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
unsigned getMaxAlignment() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
bool hasInternalLinkage() const
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
static const char * getRegisterName(unsigned RegNo)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const Triple & getTargetTriple() const
unsigned getAddressSpace() const
Return the address space of the Pointer type.
NVPTX::DrvInterface getDrvInterface() const
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Binary assembler expressions.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
pred_iterator pred_begin()
std::string getVirtualRegisterName(unsigned) const
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool getMaxNTIDy(const Function &F, unsigned &y)
Triple - Helper class for working with autoconf configuration names.
bool getReqNTIDx(const Function &F, unsigned &x)
bool hasWeakLinkage() const
const APFloat & getValueAPF() const
bool isImage(const Value &val)
bool getReqNTIDz(const Function &F, unsigned &z)
unsigned getFunctionNumber() const
Return a unique ID for the current function.
static Type * getHalfTy(LLVMContext &C)
static const fltSemantics & IEEEsingle() LLVM_READNONE
static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, const MachineFunction *MF, const Module *M, const MachineFrameInfo *MFI, const TargetInstrInfo *TII, LLVMContext &Ctx)
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const
Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
void setOpcode(unsigned Op)
This is the shared class of boolean and integer constants.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
static void ConvertFloatToBytes(unsigned char *p, float val)
std::string * getManagedString(const char *S)
16: SIMD 'packed' format, or other vector type
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
MCSymbol * getSymbol(const GlobalValue *GV) const
const MCSymbol & getSymbol() const
virtual const MCExpr * lowerConstant(const Constant *CV)
Lower the specified LLVM Constant to an MCExpr.
MachineOperand class - Representation of each machine instruction operand.
bool hasSection() const
Check if this global has a custom object file section.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
bool isVector(MCInstrInfo const &MCII, MCInst const &MCI)
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
bool isImageReadWrite(const Value &val)
bool isAggregateType() const
Return true if the type is an aggregate type.
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
StringRef str()
Return a StringRef for the vector contents.
std::string getSurfaceName(const Value &val)
const char * getName(unsigned RegNo) const
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...
std::string utostr(uint64_t X, bool isNeg=false)
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
std::string getSamplerName(const Value &val)
Class for arbitrary precision integers.
ConstantArray - Constant Array Declarations.
bool isManaged(const Value &val)
bool getReqNTIDy(const Function &F, unsigned &y)
iterator_range< user_iterator > users()
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...
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Representation of each machine instruction.
pointer remove(iterator &IT)
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
unsigned getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
iterator insert(iterator where, pointer New)
const Function * getParent() const
std::string getNVPTXRegClassStr(TargetRegisterClass const *RC)
uint64_t getElementOffset(unsigned Idx) const
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static IntegerType * getInt32Ty(LLVMContext &C)
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB) const
Targets can override this to emit stuff at the start of a basic block.
static bool usedInGlobalVarDef(const Constant *C)
StringRef getName() const
Return a constant reference to the value's name.
const Function * getParent() const
Return the enclosing method, or null if none.
FormattedNumber format_hex_no_prefix(uint64_t N, unsigned Width, bool Upper=false)
format_hex_no_prefix - Output N as a fixed width hexadecimal.
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
std::string getNVPTXRegClassName(TargetRegisterClass const *RC)
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
References to labels and assigned expressions.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
static const NVPTXFloatMCExpr * createConstantFPHalf(const APFloat &Flt, MCContext &Ctx)
static bool canDemoteGlobalVar(const GlobalVariable *gv, Function const *&f)
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
Opcode getOpcode() const
Get the kind of this binary expression.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
3: 64-bit floating point type
static unsigned int getOpenCLAlignment(const DataLayout &DL, Type *Ty)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool useFuncSeen(const Constant *C, DenseMap< const Function *, bool > &seenMap)
A raw_ostream that writes to an std::string.
const MCExpr * getSubExpr() const
Get the child of this unary expression.
bool isSingleValueType() const
Return true if the type is a valid type for a register in codegen.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool isLoopHeader(const MachineBasicBlock *BB) const
True if the block is a loop header node.
Floating-point immediate operand.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
bool hasInitializer() const
Definitions have initializers, declarations don't.
MachineLoop * getLoopFor(const MachineBasicBlock *BB) const
Return the innermost loop that BB lives in.
unsigned int getSmVersion() const
This class implements an extremely fast bulk output stream that can only output to a stream...
Primary interface to the complete machine description for the target machine.
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
const DataLayout & getDataLayout() const
Return information about data layout.
static void ConvertDoubleToBytes(unsigned char *p, double val)
iterator_range< global_iterator > globals()
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
APInt bitcastToAPInt() const
bool getMinCTASm(const Function &F, unsigned &x)
Target specific expression.
static void ConvertIntToBytes(unsigned char *p, T val)
const MachineOperand & getOperand(unsigned i) const
Instances of this class represent operands of the MCInst class.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects...
static MCOperand createImm(int64_t Val)
static IntegerType * getInt8Ty(LLVMContext &C)
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
bool isImageWriteOnly(const Value &val)
PointerType * getType() const
Global values are always pointers.
void LLVMInitializeNVPTXAsmPrinter()
bool doFinalization(Module &M) override
Shut down the asmprinter.
This file describes how to lower LLVM code to machine code.
const BasicBlock * getParent() const
const NVPTXRegisterInfo * getRegisterInfo() const override
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.