94 #define DEPOTNAME "__local_depot" 104 if (
const User *U = dyn_cast<User>(V)) {
105 for (
unsigned i = 0,
e = U->getNumOperands(); i !=
e; ++i) {
121 if (Visited.
count(GV))
125 if (!Visiting.
insert(GV).second)
146 lowerToMCInst(MI, Inst);
151 bool NVPTXAsmPrinter::lowerImageHandleOperand(
const MachineInstr *MI,
159 if (OpNo == 4 && MO.
isImm()) {
160 lowerImageHandleSymbol(MO.
getImm(), MCOp);
164 lowerImageHandleSymbol(MO.
getImm(), MCOp);
174 if (OpNo == VecSize && MO.
isImm()) {
175 lowerImageHandleSymbol(MO.
getImm(), MCOp);
182 if (OpNo == 0 && MO.
isImm()) {
183 lowerImageHandleSymbol(MO.
getImm(), MCOp);
190 if (OpNo == 1 && MO.
isImm()) {
191 lowerImageHandleSymbol(MO.
getImm(), MCOp);
201 void NVPTXAsmPrinter::lowerImageHandleSymbol(
unsigned Index,
MCOperand &MCOp) {
207 std::string *SymNamePtr =
215 if (MI->
getOpcode() == NVPTX::CALL_PROTOTYPE) {
228 if (lowerImageHandleOperand(MI, i, MCOp)) {
234 if (lowerOperand(MO, MCOp))
284 unsigned NVPTXAsmPrinter::encodeVirtualRegister(
unsigned Reg) {
289 unsigned RegNum = RegMap[
Reg];
294 if (RC == &NVPTX::Int1RegsRegClass) {
296 }
else if (RC == &NVPTX::Int16RegsRegClass) {
298 }
else if (RC == &NVPTX::Int32RegsRegClass) {
300 }
else if (RC == &NVPTX::Int64RegsRegClass) {
302 }
else if (RC == &NVPTX::Float32RegsRegClass) {
304 }
else if (RC == &NVPTX::Float64RegsRegClass) {
306 }
else if (RC == &NVPTX::Float16RegsRegClass) {
308 }
else if (RC == &NVPTX::Float16x2RegsRegClass) {
315 Ret |= (RegNum & 0x0FFFFFFF);
320 return Reg & 0x0FFFFFFF;
336 Type *Ty = F->getReturnType();
348 if (
auto *ITy = dyn_cast<IntegerType>(Ty)) {
349 size = ITy->getBitWidth();
360 O <<
".param .b" << size <<
" func_retval0";
361 }
else if (isa<PointerType>(Ty)) {
366 unsigned retAlignment = 0;
369 O <<
".param .align " << retAlignment <<
" .b8 func_retval0[" << totalsz
377 for (
unsigned i = 0,
e = vtparts.
size(); i !=
e; ++i) {
379 EVT elemtype = vtparts[i];
381 elems = vtparts[i].getVectorNumElements();
382 elemtype = vtparts[i].getVectorElementType();
385 for (
unsigned j = 0, je = elems; j != je; ++j) {
389 O <<
".reg .b" << sz <<
" func_retval" << idx;
404 printReturnValStr(&F, O);
410 bool NVPTXAsmPrinter::isLoopHeaderOfNoUnroll(
428 PBB->getTerminator()->getMetadata(LLVMContext::MD_loop)) {
439 if (isLoopHeaderOfNoUnroll(MBB))
443 void NVPTXAsmPrinter::EmitFunctionEntryLabel() {
447 if (!GlobalsEmitted) {
449 GlobalsEmitted =
true;
455 emitLinkageDirective(F, O);
460 printReturnValStr(*MF, O);
465 emitFunctionParamList(*MF, O);
468 emitKernelFunctionDirectives(*F, O);
475 setAndEmitFunctionVirtualRegisters(*MF);
492 void NVPTXAsmPrinter::EmitFunctionBodyStart() {
499 void NVPTXAsmPrinter::EmitFunctionBodyEnd() {
509 void NVPTXAsmPrinter::emitImplicitDef(
const MachineInstr *MI)
const {
522 void NVPTXAsmPrinter::emitKernelFunctionDirectives(
const Function &F,
527 unsigned reqntidx, reqntidy, reqntidz;
528 bool specified =
false;
543 O <<
".reqntid " << reqntidx <<
", " << reqntidy <<
", " << reqntidz
549 unsigned maxntidx, maxntidy, maxntidz;
565 O <<
".maxntid " << maxntidx <<
", " << maxntidy <<
", " << maxntidz
570 O <<
".minnctapersm " << mincta <<
"\n";
574 O <<
".maxnreg " << maxnreg <<
"\n";
585 assert(I != VRegMapping.
end() &&
"Bad register class");
589 assert(VI != RegMap.end() &&
"Bad virtual register");
590 unsigned MappedVR = VI->second;
598 void NVPTXAsmPrinter::emitVirtualRegister(
unsigned int vr,
604 emitLinkageDirective(F, O);
609 printReturnValStr(F, O);
612 emitFunctionParamList(F, O);
621 return GV->getName() !=
"llvm.used";
625 if (
const Constant *C = dyn_cast<Constant>(U))
633 if (
const GlobalVariable *othergv = dyn_cast<GlobalVariable>(U)) {
634 if (othergv->getName() ==
"llvm.used")
638 if (
const Instruction *instr = dyn_cast<Instruction>(U)) {
639 if (instr->getParent() && instr->getParent()->getParent()) {
641 if (oneFunc && (curFunc != oneFunc))
684 if (
const Constant *cu = dyn_cast<Constant>(U)) {
687 }
else if (
const Instruction *
I = dyn_cast<Instruction>(U)) {
694 if (seenMap.
find(caller) != seenMap.
end())
707 emitDeclaration(F, O);
716 emitDeclaration(F, O);
720 if (
const Constant *
C = dyn_cast<Constant>(U)) {
725 emitDeclaration(F, O);
731 emitDeclaration(F, O);
736 if (!isa<Instruction>(U))
749 if (seenMap.
find(caller) != seenMap.
end()) {
750 emitDeclaration(F, O);
759 if (!GV)
return true;
761 if (!InitList)
return true;
778 "Module has a nontrivial global ctor, which NVPTX does not support.");
783 "Module has a nontrivial global dtor, which NVPTX does not support.");
794 emitHeader(M, OS1, *STI);
799 OutStreamer->AddComment(
"Start of file scope inline assembly");
803 OutStreamer->AddComment(
"End of file scope inline assembly");
807 GlobalsEmitted =
false;
812 void NVPTXAsmPrinter::emitGlobals(
const Module &M) {
816 emitDeclarations(M, OS2);
832 "Missed a global variable");
833 assert(GVVisiting.
size() == 0 &&
"Did not fully process a global variable");
836 for (
unsigned i = 0,
e = Globals.
size(); i !=
e; ++i)
837 printModuleLevelGV(Globals[i], OS2);
847 O <<
"// Generated by LLVM NVPTX Back-End\n";
852 O <<
".version " << (PTXVersion / 10) <<
"." << (PTXVersion % 10) <<
"\n";
859 O <<
", texmode_independent";
861 bool HasFullDebugInfo =
false;
863 switch(
CU->getEmissionKind()) {
869 HasFullDebugInfo =
true;
872 if (HasFullDebugInfo)
880 O <<
".address_size ";
895 if (!GlobalsEmitted) {
897 GlobalsEmitted =
true;
904 int i, n = global_list.size();
914 while (!global_list.empty())
915 global_list.
remove(global_list.begin());
921 for (i = 0; i < n; i++)
922 global_list.
insert(global_list.end(), gv_array[i]);
930 ->closeLastSection();
932 OutStreamer->EmitRawText(
"\t.section\t.debug_loc\t{\t}");
937 ->outputDwarfFileDirectives();
964 void NVPTXAsmPrinter::emitLinkageDirective(
const GlobalValue *V,
966 if (static_cast<NVPTXTargetMachine &>(
TM).getDrvInterface() ==
NVPTX::CUDA) {
968 if (isa<GlobalVariable>(V)) {
982 msg.append(
"Error: ");
983 msg.append(
"Symbol ");
986 msg.append(
"has unsupported appending linkage type");
995 void NVPTXAsmPrinter::printModuleLevelGV(
const GlobalVariable *GVar,
997 bool processDemoted) {
1040 emitPTXGlobalVariable(GVar, O);
1048 const Constant *Initializer =
nullptr;
1062 O <<
"addr_mode_" << i <<
" = ";
1068 O <<
"clamp_to_border";
1071 O <<
"clamp_to_edge";
1082 O <<
"filter_mode = ";
1097 O <<
", force_unnormalized_coords = 1";
1107 if (strncmp(GVar->
getName().
data(),
"unrollpragma", 12) == 0)
1111 if (strncmp(GVar->
getName().
data(),
"filename", 8) == 0)
1117 const Function *demotedFunc =
nullptr;
1119 O <<
"// " << GVar->
getName() <<
" has been demoted\n";
1120 if (localDecls.find(demotedFunc) != localDecls.end())
1121 localDecls[demotedFunc].push_back(GVar);
1123 std::vector<const GlobalVariable *> temp;
1124 temp.push_back(GVar);
1125 localDecls[demotedFunc] = temp;
1134 O <<
" .attribute(.managed)";
1149 O << getPTXFundamentalTypeStr(ETy,
false);
1160 if (!Initializer->
isNullValue() && !isa<UndefValue>(Initializer)) {
1162 printScalarConstant(Initializer, O);
1171 "' is not allowed in addrspace(" +
1177 unsigned int ElementSize = 0;
1195 if (!isa<UndefValue>(Initializer) && !Initializer->
isNullValue()) {
1196 AggBuffer aggBuffer(ElementSize, O, *
this);
1197 bufferAggregateConstant(Initializer, &aggBuffer);
1198 if (aggBuffer.numSymbols) {
1199 if (static_cast<const NVPTXTargetMachine &>(
TM).
is64Bit()) {
1203 O << ElementSize / 8;
1208 O << ElementSize / 4;
1248 if (localDecls.find(f) == localDecls.end())
1251 std::vector<const GlobalVariable *> &gvars = localDecls[f];
1253 for (
unsigned i = 0,
e = gvars.size(); i !=
e; ++i) {
1254 O <<
"\t// demoted variable\n\t";
1255 printModuleLevelGV(gvars[i], O,
true);
1259 void NVPTXAsmPrinter::emitPTXAddressSpace(
unsigned int AddressSpace,
1282 NVPTXAsmPrinter::getPTXFundamentalTypeStr(
Type *Ty,
bool useB4PTR)
const {
1288 unsigned NumBits = cast<IntegerType>(Ty)->
getBitWidth();
1291 else if (NumBits <= 64) {
1292 std::string
name =
"u";
1293 return name +
utostr(NumBits);
1308 if (static_cast<const NVPTXTargetMachine &>(
TM).
is64Bit())
1322 void NVPTXAsmPrinter::emitPTXGlobalVariable(
const GlobalVariable *GVar,
1346 O << getPTXFundamentalTypeStr(ETy);
1352 int64_t ElementSize = 0;
1386 unsigned int alignStruct = 1;
1389 for (
unsigned i = 0,
e = STy->getNumElements(); i !=
e; i++) {
1390 Type *ETy = STy->getElementType(i);
1392 if (align > alignStruct)
1393 alignStruct = align;
1407 O <<
"_param_" << paramIndex;
1416 unsigned paramIndex = 0;
1423 if (F->arg_empty()) {
1430 for (I = F->arg_begin(), E = F->arg_end(); I !=
E; ++
I, paramIndex++) {
1442 std::string sname = I->
getName();
1444 if (hasImageHandles)
1445 O <<
"\t.param .u64 .ptr .surfref ";
1447 O <<
"\t.param .surfref ";
1449 O <<
"_param_" << paramIndex;
1452 if (hasImageHandles)
1453 O <<
"\t.param .u64 .ptr .texref ";
1455 O <<
"\t.param .texref ";
1457 O <<
"_param_" << paramIndex;
1460 if (hasImageHandles)
1461 O <<
"\t.param .u64 .ptr .samplerref ";
1463 O <<
"\t.param .samplerref ";
1465 O <<
"_param_" << paramIndex;
1480 O <<
"\t.param .align " << align.
value() <<
" .b8 ";
1481 printParamName(I, paramIndex, O);
1482 O <<
"[" << sz <<
"]";
1493 if (static_cast<NVPTXTargetMachine &>(
TM).getDrvInterface() !=
1495 Type *ETy = PTy->getElementType();
1496 int addrSpace = PTy->getAddressSpace();
1497 switch (addrSpace) {
1502 O <<
".ptr .const ";
1505 O <<
".ptr .shared ";
1508 O <<
".ptr .global ";
1513 printParamName(I, paramIndex, O);
1523 O << getPTXFundamentalTypeStr(Ty);
1525 printParamName(I, paramIndex, O);
1531 if (isa<IntegerType>(Ty)) {
1535 }
else if (isa<PointerType>(Ty))
1545 O <<
"\t.param .b" << sz <<
" ";
1547 O <<
"\t.reg .b" << sz <<
" ";
1548 printParamName(I, paramIndex, O);
1554 assert(PTy &&
"Param with byval attribute should be a pointer type");
1555 Type *ETy = PTy->getElementType();
1557 if (isABI || isKernelFunc) {
1574 if (!isKernelFunc && align <
Align(4))
1577 O <<
"\t.param .align " << align.
value() <<
" .b8 ";
1578 printParamName(I, paramIndex, O);
1579 O <<
"[" << sz <<
"]";
1588 for (
unsigned i = 0,
e = vtparts.
size(); i !=
e; ++i) {
1590 EVT elemtype = vtparts[i];
1592 elems = vtparts[i].getVectorNumElements();
1593 elemtype = vtparts[i].getVectorElementType();
1596 for (
unsigned j = 0, je = elems; j != je; ++j) {
1600 O <<
"\t.reg .b" << sz <<
" ";
1601 printParamName(I, paramIndex, O);
1617 void NVPTXAsmPrinter::emitFunctionParamList(
const MachineFunction &MF,
1620 emitFunctionParamList(&F, O);
1623 void NVPTXAsmPrinter::setAndEmitFunctionVirtualRegisters(
1640 O <<
"\t.reg .b64 \t%SP;\n";
1641 O <<
"\t.reg .b64 \t%SPL;\n";
1643 O <<
"\t.reg .b32 \t%SP;\n";
1644 O <<
"\t.reg .b32 \t%SPL;\n";
1652 unsigned int numVRs =
MRI->getNumVirtRegs();
1653 for (
unsigned i = 0; i < numVRs; i++) {
1657 int n = regmap.
size();
1658 regmap.
insert(std::make_pair(vr, n + 1));
1678 int n = regmap.
size();
1682 O <<
"\t.reg " << rcname <<
" \t" << rcStr <<
"<" << (n+1)
1693 unsigned int numHex;
1712 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
1713 O << CI->getValue();
1716 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(CPV)) {
1717 printFPConstant(CFP, O);
1720 if (isa<ConstantPointerNull>(CPV)) {
1724 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(CPV)) {
1725 bool IsNonGenericPointer =
false;
1727 IsNonGenericPointer =
true;
1729 if (EmitGeneric && !isa<Function>(CPV) && !IsNonGenericPointer) {
1738 if (
const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1741 bool IsNonGenericPointer =
false;
1743 IsNonGenericPointer =
true;
1745 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(v)) {
1746 if (EmitGeneric && !isa<Function>(v) && !IsNonGenericPointer) {
1765 int64_t vp = (int64_t)val;
1766 for (
unsigned i = 0; i <
sizeof(
T); ++i) {
1767 p[i] = (
unsigned char)vp;
1772 int32_t *vp = (int32_t *)&val;
1773 for (
unsigned i = 0; i <
sizeof(int32_t); ++i) {
1774 p[i] = (
unsigned char)*vp;
1779 int64_t *vp = (int64_t *)&val;
1780 for (
unsigned i = 0; i <
sizeof(int64_t); ++i) {
1781 p[i] = (
unsigned char)*vp;
1786 void NVPTXAsmPrinter::bufferLEByte(
const Constant *CPV,
int Bytes,
1794 aggBuffer->addZeros(s);
1798 unsigned char ptr[8];
1804 unsigned char c = (
unsigned char)cast<ConstantInt>(CPV)->getZExtValue();
1805 ConvertIntToBytes<>(ptr, c);
1806 aggBuffer->addBytes(ptr, 1, Bytes);
1808 short int16 = (short)cast<ConstantInt>(CPV)->getZExtValue();
1809 ConvertIntToBytes<>(ptr, int16);
1810 aggBuffer->addBytes(ptr, 2, Bytes);
1812 if (
const ConstantInt *constInt = dyn_cast<ConstantInt>(CPV)) {
1813 int int32 = (int)(constInt->getZExtValue());
1814 ConvertIntToBytes<>(ptr, int32);
1815 aggBuffer->addBytes(ptr, 4, Bytes);
1817 }
else if (
const auto *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1818 if (
const auto *constInt = dyn_cast_or_null<ConstantInt>(
1820 int int32 = (int)(constInt->getZExtValue());
1821 ConvertIntToBytes<>(ptr, int32);
1822 aggBuffer->addBytes(ptr, 4, Bytes);
1825 if (Cexpr->getOpcode() == Instruction::PtrToInt) {
1827 aggBuffer->addSymbol(v, Cexpr->getOperand(0));
1828 aggBuffer->addZeros(4);
1834 if (
const ConstantInt *constInt = dyn_cast<ConstantInt>(CPV)) {
1835 long long int64 = (
long long)(constInt->getZExtValue());
1836 ConvertIntToBytes<>(ptr, int64);
1837 aggBuffer->addBytes(ptr, 8, Bytes);
1839 }
else if (
const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1840 if (
const auto *constInt = dyn_cast_or_null<ConstantInt>(
1842 long long int64 = (
long long)(constInt->getZExtValue());
1843 ConvertIntToBytes<>(ptr, int64);
1844 aggBuffer->addBytes(ptr, 8, Bytes);
1847 if (Cexpr->getOpcode() == Instruction::PtrToInt) {
1849 aggBuffer->addSymbol(v, Cexpr->getOperand(0));
1850 aggBuffer->addZeros(8);
1862 const auto *CFP = cast<ConstantFP>(CPV);
1863 Type *Ty = CFP->getType();
1865 APInt API = CFP->getValueAPF().bitcastToAPInt();
1867 ConvertIntToBytes<>(ptr, float16);
1868 aggBuffer->addBytes(ptr, 2, Bytes);
1870 float float32 = (float) CFP->getValueAPF().convertToFloat();
1872 aggBuffer->addBytes(ptr, 4, Bytes);
1874 double float64 = CFP->getValueAPF().convertToDouble();
1876 aggBuffer->addBytes(ptr, 8, Bytes);
1883 if (
const GlobalValue *GVar = dyn_cast<GlobalValue>(CPV)) {
1884 aggBuffer->addSymbol(GVar, GVar);
1885 }
else if (
const ConstantExpr *Cexpr = dyn_cast<ConstantExpr>(CPV)) {
1887 aggBuffer->addSymbol(v, Cexpr);
1890 aggBuffer->addZeros(s);
1897 if (isa<ConstantAggregate>(CPV) || isa<ConstantDataSequential>(CPV)) {
1899 bufferAggregateConstant(CPV, aggBuffer);
1900 if (Bytes > ElementSize)
1901 aggBuffer->addZeros(Bytes - ElementSize);
1902 }
else if (isa<ConstantAggregateZero>(CPV))
1903 aggBuffer->addZeros(Bytes);
1914 void NVPTXAsmPrinter::bufferAggregateConstant(
const Constant *CPV,
1920 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CPV)) {
1921 APInt Val = CI->getValue();
1924 aggBuffer->addBytes(&Byte, 1, 1);
1931 if (isa<ConstantArray>(CPV) || isa<ConstantVector>(CPV)) {
1934 bufferLEByte(cast<Constant>(CPV->
getOperand(i)), 0, aggBuffer);
1939 dyn_cast<ConstantDataSequential>(CPV)) {
1940 if (CDS->getNumElements())
1941 for (
unsigned i = 0; i < CDS->getNumElements(); ++i)
1942 bufferLEByte(cast<Constant>(CDS->getElementAsConstant(i)), 0,
1947 if (isa<ConstantStruct>(CPV)) {
1958 bufferLEByte(cast<Constant>(CPV->
getOperand(i)), Bytes, aggBuffer);
1971 NVPTXAsmPrinter::lowerConstantForGV(
const Constant *CV,
bool ProcessingGeneric) {
1977 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(CV))
1980 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
1983 if (ProcessingGeneric) {
2002 return lowerConstantForGV(
C, ProcessingGeneric);
2008 OS <<
"Unsupported expression in static initializer: ";
2014 case Instruction::AddrSpaceCast: {
2018 return lowerConstantForGV(cast<const Constant>(CE->
getOperand(0)),
true);
2022 OS <<
"Unsupported expression in static initializer: ";
2028 case Instruction::GetElementPtr: {
2033 cast<GEPOperator>(CE)->accumulateConstantOffset(DL, OffsetAI);
2045 case Instruction::Trunc:
2051 case Instruction::BitCast:
2052 return lowerConstantForGV(CE->
getOperand(0), ProcessingGeneric);
2054 case Instruction::IntToPtr: {
2062 return lowerConstantForGV(Op, ProcessingGeneric);
2065 case Instruction::PtrToInt: {
2073 const MCExpr *OpExpr = lowerConstantForGV(Op, ProcessingGeneric);
2091 const MCExpr *LHS = lowerConstantForGV(CE->
getOperand(0), ProcessingGeneric);
2092 const MCExpr *RHS = lowerConstantForGV(CE->
getOperand(1), ProcessingGeneric);
2105 return cast<MCTargetExpr>(&Expr)->printImpl(OS,
MAI);
2107 OS << cast<MCConstantExpr>(Expr).getValue();
2133 if (isa<MCConstantExpr>(BE.
getLHS()) || isa<MCSymbolRefExpr>(BE.
getLHS()) ||
2134 isa<NVPTXGenericMCSymbolRefExpr>(BE.
getLHS())) {
2146 if (RHSC->getValue() < 0) {
2147 OS << RHSC->getValue();
2158 if (isa<MCConstantExpr>(BE.
getRHS()) || isa<MCSymbolRefExpr>(BE.
getRHS())) {
2174 bool NVPTXAsmPrinter::PrintAsmOperand(
const MachineInstr *MI,
unsigned OpNo,
2176 if (ExtraCode && ExtraCode[0]) {
2177 if (ExtraCode[1] != 0)
2180 switch (ExtraCode[0]) {
2194 bool NVPTXAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *MI,
2196 const char *ExtraCode,
2198 if (ExtraCode && ExtraCode[0])
2214 if (MO.
getReg() == NVPTX::VRDepot)
2219 emitVirtualRegister(MO.
getReg(),
O);
2248 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
unsigned getPTXVersion() const
A parsed version of the target data layout string in and methods for querying it. ...
MaybeAlign getParamAlignment(unsigned ArgNo) const
Return the alignment for the specified function parameter.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
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 MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
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.
This class represents lattice values for constants.
bool getMaxNReg(const Function &F, unsigned &x)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
A Module instance is used to store all the information related to an LLVM module. ...
2: 32-bit floating point type
bool doFinalization(Module &M) override
Shut down the asmprinter.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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)
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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...
void push_back(const T &Elt)
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
Describe properties that are true of each instruction in the target description file.
bool isTexture(const Value &val)
bool hasAvailableExternallyLinkage() const
Opcode getOpcode() const
Get the kind of this unary expression.
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)
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
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.
LegalityPredicate isVector(unsigned TypeIdx)
True iff the specified type index is a vector.
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.
Align getPointerPrefAlignment(unsigned AS=0) const
Return target's alignment for stack-based pointers FIXME: The defaults need to be removed once all of...
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
Retuns the total number of operands.
Class to represent struct types.
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)
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.
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.
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)
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
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.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeNVPTXAsmPrinter()
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
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
bool hasLinkOnceLinkage() const
Align getValueOrABITypeAlignment(MaybeAlign Alignment, Type *Ty) const
Helper function to return Alignment if it's set or the result of getABITypeAlignment(Ty), in any case the result is a valid alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
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...
const NVPTXSubtarget * getSubtargetImpl(const Function &) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
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.
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false)
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)
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.
LLVM Basic Block Representation.
const MCAsmInfo * MAI
Target Asm Printer information.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
The instances of the Type class are immutable: once they are created, they are never changed...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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.
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
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
std::pair< iterator, bool > insert(const ValueT &V)
ConstantFP - Floating Point Values [float, double].
size_t alias_size() 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)
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
NVPTX::DrvInterface getDrvInterface() const
virtual 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...
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Binary assembler expressions.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
bool getMaxNTIDy(const Function &F, unsigned &y)
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
static void printMCExpr(const MCExpr *E, raw_ostream &OS)
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.
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.
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...
StringRef str()
Return a StringRef for the vector contents.
#define LLVM_EXTERNAL_VISIBILITY
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...
Representation of each machine instruction.
pointer remove(iterator &IT)
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
void emitInitialRawDwarfLocDirective(const MachineFunction &MF)
Emits inital debug location directive.
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.
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)
iterator_range< debug_compile_units_iterator > debug_compile_units() const
Return an iterator for all DICompileUnits listed in this Module's llvm.dbg.cu named metadata node and...
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)
virtual void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &OS)
Print the MachineOperand as a symbol.
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.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
TypeSize getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
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
Implments NVPTX-specific streamer.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool hasFnAttribute(Attribute::AttrKind Kind) const
Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but may be faster. ...
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.
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.
bool hasInitializer() const
Definitions have initializers, declarations don't.
MachineLoop * getLoopFor(const MachineBasicBlock *BB) const
Return the innermost loop that BB lives in.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
unsigned int getSmVersion() const
This class implements an extremely fast bulk output stream that can only output to a stream...
const DataLayout & getDataLayout() const
Return information about data layout.
static void ConvertDoubleToBytes(unsigned char *p, double val)
iterator_range< global_iterator > globals()
void addOperand(const MCOperand &Op)
StringRef - Represent a constant reference to a string, i.e.
virtual void EmitBasicBlockStart(const MachineBasicBlock &MBB)
Targets can override this to emit stuff at the start of a basic block.
APInt bitcastToAPInt() const
bool getMinCTASm(const Function &F, unsigned &x)
Target specific expression.
Register getReg() const
getReg - Returns the register number.
static void ConvertIntToBytes(unsigned char *p, T val)
const STC & getSubtarget(const Function &F) const
This method returns a pointer to the specified type of TargetSubtargetInfo.
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 bool is64Bit(const char *name)
bool isImageWriteOnly(const Value &val)
PointerType * getType() const
Global values are always pointers.
Wrapper class representing virtual and physical registers.
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.