86#define DEBUG_TYPE "asmprinter"
88STATISTIC(NumTOCEntries,
"Number of Total TOC Entries Emitted.");
89STATISTIC(NumTOCConstPool,
"Number of Constant Pool TOC Entries.");
91 "Number of Internal Linkage Global TOC Entries.");
93 "Number of External Linkage Global TOC Entries.");
94STATISTIC(NumTOCJumpTable,
"Number of Jump Table TOC Entries.");
95STATISTIC(NumTOCThreadLocal,
"Number of Thread Local TOC Entries.");
96STATISTIC(NumTOCBlockAddress,
"Number of Block Address TOC Entries.");
97STATISTIC(NumTOCEHBlock,
"Number of EH Block TOC Entries.");
110 using TOCKey = std::pair<const MCSymbol *, PPCMCExpr::Specifier>;
129 Tag_GNU_Power_ABI_FP = 4,
130 Tag_GNU_Power_ABI_Vector = 8,
131 Tag_GNU_Power_ABI_Struct_Return = 12,
134 Val_GNU_Power_ABI_NoFloat = 0b00,
135 Val_GNU_Power_ABI_HardFloat_DP = 0b01,
136 Val_GNU_Power_ABI_SoftFloat_DP = 0b10,
137 Val_GNU_Power_ABI_HardFloat_SP = 0b11,
139 Val_GNU_Power_ABI_LDBL_IBM128 = 0b0100,
140 Val_GNU_Power_ABI_LDBL_64 = 0b1000,
141 Val_GNU_Power_ABI_LDBL_IEEE128 = 0b1100,
153 MapVector<std::pair<const MCSymbol *, PPCMCExpr::Specifier>,
MCSymbol *> TOC;
154 const PPCSubtarget *Subtarget =
nullptr;
159 MapVector<const GlobalValue *, uint64_t> TLSVarsToAddressMapping;
162 explicit PPCAsmPrinter(TargetMachine &TM,
163 std::unique_ptr<MCStreamer> Streamer,
char &
ID)
164 : AsmPrinter(
TM, std::
move(Streamer),
ID) {}
166 StringRef getPassName()
const override {
return "PowerPC Assembly Printer"; }
169 TOCType_ConstantPool,
170 TOCType_GlobalExternal,
171 TOCType_GlobalInternal,
174 TOCType_BlockAddress,
178 MCSymbol *lookUpOrCreateTOCEntry(
const MCSymbol *Sym, TOCEntryType
Type,
181 bool doInitialization(
Module &M)
override {
187 const MCExpr *symbolWithSpecifier(
const MCSymbol *S,
194 void printOperand(
const MachineInstr *
MI,
unsigned OpNo, raw_ostream &O);
196 void PrintSymbolOperand(
const MachineOperand &MO, raw_ostream &O)
override;
197 bool PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
198 const char *ExtraCode, raw_ostream &O)
override;
199 bool PrintAsmMemoryOperand(
const MachineInstr *
MI,
unsigned OpNo,
200 const char *ExtraCode, raw_ostream &O)
override;
202 void LowerSTACKMAP(StackMaps &SM,
const MachineInstr &
MI);
203 void LowerPATCHPOINT(StackMaps &SM,
const MachineInstr &
MI);
205 void EmitAIXTlsCallHelper(
const MachineInstr *
MI);
206 const MCExpr *getAdjustedFasterLocalExpr(
const MachineOperand &MO,
208 bool runOnMachineFunction(MachineFunction &MF)
override {
217class PPCLinuxAsmPrinter :
public PPCAsmPrinter {
221 explicit PPCLinuxAsmPrinter(TargetMachine &TM,
222 std::unique_ptr<MCStreamer> Streamer)
223 : PPCAsmPrinter(
TM, std::
move(Streamer), ID) {}
225 StringRef getPassName()
const override {
226 return "Linux PPC Assembly Printer";
229 void emitGNUAttributes(
Module &M);
231 void emitStartOfAsmFile(
Module &M)
override;
232 void emitEndOfAsmFile(
Module &)
override;
234 void emitFunctionEntryLabel()
override;
236 void emitFunctionBodyStart()
override;
237 void emitFunctionBodyEnd()
override;
241class PPCAIXAsmPrinter :
public PPCAsmPrinter {
245 SmallSetVector<MCSymbol *, 8> ExtSymSDNodeSymbols;
249 std::string FormatIndicatorAndUniqueModId;
253 DenseMap<const GlobalObject *, SmallVector<const GlobalAlias *, 1>>
256 uint16_t getNumberOfVRSaved();
257 void emitTracebackTable();
261 void emitGlobalVariableHelper(
const GlobalVariable *);
264 uint64_t getAliasOffset(
const Constant *
C);
269 PPCAIXAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
270 : PPCAsmPrinter(
TM, std::
move(Streamer), ID) {
271 if (MAI->isLittleEndian())
273 "cannot create AIX PPC Assembly Printer for a little-endian target");
276 StringRef getPassName()
const override {
return "AIX PPC Assembly Printer"; }
278 bool doInitialization(
Module &M)
override;
280 void emitXXStructorList(
const DataLayout &
DL,
const Constant *
List,
281 bool IsCtor)
override;
283 void SetupMachineFunction(MachineFunction &MF)
override;
285 void emitGlobalVariable(
const GlobalVariable *GV)
override;
287 void emitFunctionDescriptor()
override;
289 void emitFunctionEntryLabel()
override;
291 void emitFunctionBodyEnd()
override;
293 void emitPGORefs(
Module &M);
297 void emitEndOfAsmFile(
Module &)
override;
299 void emitLinkage(
const GlobalValue *GV, MCSymbol *GVSym)
const override;
303 bool doFinalization(
Module &M)
override;
305 void emitTTypeReference(
const GlobalValue *GV,
unsigned Encoding)
override;
307 void emitModuleCommandLines(
Module &M)
override;
316 getSymbol(GV)->
print(O, MAI);
320void PPCAsmPrinter::printOperand(
const MachineInstr *
MI,
unsigned OpNo,
322 const DataLayout &
DL = getDataLayout();
323 const MachineOperand &MO =
MI->getOperand(OpNo);
343 O <<
DL.getPrivateGlobalPrefix() <<
"CPI" << getFunctionNumber() <<
'_'
350 PrintSymbolOperand(MO, O);
355 O <<
"<unknown operand type: " << (unsigned)MO.
getType() <<
">";
362bool PPCAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
363 const char *ExtraCode, raw_ostream &O) {
365 if (ExtraCode && ExtraCode[0]) {
366 if (ExtraCode[1] != 0)
return true;
368 switch (ExtraCode[0]) {
374 if (!
MI->getOperand(OpNo).isReg() ||
375 OpNo+1 ==
MI->getNumOperands() ||
376 !
MI->getOperand(OpNo+1).isReg())
383 if (
MI->getOperand(OpNo).isImm())
387 if(!
MI->getOperand(OpNo).isReg())
393 Reg = PPC::VSX32 + (
Reg - PPC::V0);
395 Reg = PPC::VSX32 + (
Reg - PPC::VF0);
411bool PPCAsmPrinter::PrintAsmMemoryOperand(
const MachineInstr *
MI,
unsigned OpNo,
412 const char *ExtraCode,
414 if (ExtraCode && ExtraCode[0]) {
415 if (ExtraCode[1] != 0)
return true;
417 switch (ExtraCode[0]) {
418 default:
return true;
420 O << getDataLayout().getPointerSize() <<
"(";
431 if (
MI->getOperand(OpNo).isImm())
442 assert(
MI->getOperand(OpNo).isReg());
447 assert(
MI->getOperand(OpNo).isReg());
457 case PPCAsmPrinter::TOCType_ConstantPool:
460 case PPCAsmPrinter::TOCType_GlobalInternal:
461 ++NumTOCGlobalInternal;
463 case PPCAsmPrinter::TOCType_GlobalExternal:
464 ++NumTOCGlobalExternal;
466 case PPCAsmPrinter::TOCType_JumpTable:
469 case PPCAsmPrinter::TOCType_ThreadLocal:
472 case PPCAsmPrinter::TOCType_BlockAddress:
473 ++NumTOCBlockAddress;
475 case PPCAsmPrinter::TOCType_EHBlock:
492 assert(GV &&
"expected global for MO_GlobalAddress");
513MCSymbol *PPCAsmPrinter::lookUpOrCreateTOCEntry(
const MCSymbol *Sym,
517 auto [It,
Inserted] =
TOC.try_emplace({Sym, Spec});
523 TOCEntry = createTempSymbol(
"C");
527void PPCAsmPrinter::LowerSTACKMAP(StackMaps &SM,
const MachineInstr &
MI) {
528 unsigned NumNOPBytes =
MI.getOperand(1).getImm();
530 auto &Ctx = OutStreamer->getContext();
531 MCSymbol *MILabel = Ctx.createTempSymbol();
532 OutStreamer->emitLabel(MILabel);
535 assert(NumNOPBytes % 4 == 0 &&
"Invalid number of NOP bytes requested!");
538 const MachineBasicBlock &
MBB = *
MI.getParent();
541 while (NumNOPBytes > 0) {
542 if (MII ==
MBB.
end() || MII->isCall() ||
543 MII->getOpcode() == PPC::DBG_VALUE ||
544 MII->getOpcode() == TargetOpcode::PATCHPOINT ||
545 MII->getOpcode() == TargetOpcode::STACKMAP)
552 for (
unsigned i = 0; i < NumNOPBytes; i += 4)
553 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::NOP));
558void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM,
const MachineInstr &
MI) {
559 auto &Ctx = OutStreamer->getContext();
560 MCSymbol *MILabel = Ctx.createTempSymbol();
561 OutStreamer->emitLabel(MILabel);
564 PatchPointOpers Opers(&
MI);
566 unsigned EncodedBytes = 0;
567 const MachineOperand &CalleeMO = Opers.getCallTarget();
569 if (CalleeMO.
isImm()) {
570 int64_t CallTarget = CalleeMO.
getImm();
572 assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
573 "High 16 bits of call target should be zero.");
574 Register ScratchReg =
MI.getOperand(Opers.getNextScratchIdx()).getReg();
577 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LI8)
579 .addImm((CallTarget >> 32) & 0xFFFF));
581 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::RLDIC)
584 .addImm(32).addImm(16));
586 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ORIS8)
589 .addImm((CallTarget >> 16) & 0xFFFF));
591 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ORI8)
594 .addImm(CallTarget & 0xFFFF));
598 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::STD)
600 .addImm(TOCSaveOffset)
610 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
613 .addReg(ScratchReg));
615 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
618 .addReg(ScratchReg));
622 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MTCTR8)
623 .addReg(ScratchReg));
625 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BCTRL8));
629 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
631 .addImm(TOCSaveOffset)
636 const GlobalValue *GValue = CalleeMO.
getGlobal();
637 MCSymbol *MOSymbol = getSymbol(GValue);
640 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BL8_NOP)
649 unsigned NumBytes = Opers.getNumPatchBytes();
650 assert(NumBytes >= EncodedBytes &&
651 "Patchpoint can't request size less than the length of a call.");
652 assert((NumBytes - EncodedBytes) % 4 == 0 &&
653 "Invalid number of NOP bytes requested!");
654 for (
unsigned i = EncodedBytes; i < NumBytes; i += 4)
655 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::NOP));
665 SymName =
".__tls_get_addr";
667 case PPC::GETtlsTpointer32AIX:
668 SymName =
".__get_tpointer";
670 case PPC::GETtlsMOD32AIX:
671 case PPC::GETtlsMOD64AIX:
672 SymName =
".__tls_get_mod";
678 ->getQualNameSymbol();
681void PPCAsmPrinter::EmitAIXTlsCallHelper(
const MachineInstr *
MI) {
683 "Only expecting to emit calls to get the thread pointer on AIX!");
687 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BLA).addExpr(TlsRef));
692void PPCAsmPrinter::emitTlsCall(
const MachineInstr *
MI,
695 unsigned Opcode = PPC::BL8_NOP_TLS;
697 assert(
MI->getNumOperands() >= 3 &&
"Expecting at least 3 operands from MI");
701 Opcode = PPC::BL8_NOTOC_TLS;
703 const Module *
M = MF->getFunction().getParent();
706 ((Subtarget->isPPC64() &&
MI->getOperand(0).getReg() == PPC::X3) ||
707 (!Subtarget->isPPC64() &&
MI->getOperand(0).getReg() == PPC::R3)) &&
708 "GETtls[ld]ADDR[32] must define GPR3");
710 ((Subtarget->isPPC64() &&
MI->getOperand(1).getReg() == PPC::X3) ||
711 (!Subtarget->isPPC64() &&
MI->getOperand(1).getReg() == PPC::R3)) &&
712 "GETtls[ld]ADDR[32] must read GPR3");
719 Register VarOffsetReg = Subtarget->isPPC64() ? PPC::X4 : PPC::R4;
721 assert((
MI->getOpcode() == PPC::GETtlsMOD32AIX ||
722 MI->getOpcode() == PPC::GETtlsMOD64AIX ||
723 (
MI->getOperand(2).isReg() &&
724 MI->getOperand(2).getReg() == VarOffsetReg)) &&
725 "GETtls[ld]ADDR[32] must read GPR4");
726 EmitAIXTlsCallHelper(
MI);
730 MCSymbol *TlsGetAddr = OutContext.getOrCreateSymbol(
"__tls_get_addr");
738 if (Kind ==
PPC::S_PLT && Subtarget->isSecurePlt() &&
742 const MachineOperand &MO =
MI->getOperand(2);
743 const GlobalValue *GValue = MO.
getGlobal();
744 MCSymbol *MOSymbol = getSymbol(GValue);
746 EmitToStreamer(*OutStreamer,
747 MCInstBuilder(Subtarget->isPPC64() ? Opcode
748 : (
unsigned)PPC::BL_TLS)
771static PPCAsmPrinter::TOCEntryType
776 return PPCAsmPrinter::TOCType_ThreadLocal;
785 return PPCAsmPrinter::TOCType_GlobalExternal;
787 return PPCAsmPrinter::TOCType_GlobalInternal;
790 return PPCAsmPrinter::TOCType_ConstantPool;
792 return PPCAsmPrinter::TOCType_JumpTable;
794 return PPCAsmPrinter::TOCType_BlockAddress;
800const MCExpr *PPCAsmPrinter::symbolWithSpecifier(
const MCSymbol *S,
808void PPCAsmPrinter::emitInstruction(
const MachineInstr *
MI) {
809 PPC_MC::verifyInstructionPredicates(
MI->getOpcode(),
810 getSubtargetInfo().getFeatureBits());
813 const bool IsPPC64 = Subtarget->isPPC64();
814 const bool IsAIX = Subtarget->
isAIXABI();
815 const bool HasAIXSmallLocalTLS = Subtarget->hasAIXSmallLocalExecTLS() ||
816 Subtarget->hasAIXSmallLocalDynamicTLS();
817 const Module *
M = MF->getFunction().getParent();
822 if (!
MI->isInlineAsm()) {
823 for (
const MachineOperand &MO:
MI->operands()) {
826 if (Subtarget->hasSPE()) {
844 auto getTOCRelocAdjustedExprForXCOFF = [
this](
const MCExpr *Expr,
845 ptrdiff_t OriginalOffset) {
852 ptrdiff_t Adjustment =
858 auto getTOCEntryLoadingExprForXCOFF =
859 [IsPPC64, getTOCRelocAdjustedExprForXCOFF,
860 this](
const MCSymbol *MOSymbol,
const MCExpr *Expr,
862 const unsigned EntryByteSize = IsPPC64 ? 8 : 4;
863 const auto TOCEntryIter =
TOC.find({MOSymbol, VK});
865 "Could not find the TOC entry for this symbol.");
866 const ptrdiff_t EntryDistanceFromTOCBase =
867 (TOCEntryIter -
TOC.begin()) * EntryByteSize;
868 constexpr int16_t PositiveTOCRange = INT16_MAX;
870 if (EntryDistanceFromTOCBase > PositiveTOCRange)
871 return getTOCRelocAdjustedExprForXCOFF(Expr, EntryDistanceFromTOCBase);
883 assert(MO.
isGlobal() &&
"Only expecting a global MachineOperand here!\n");
891 PPCFunctionInfo *FuncInfo = MF->getInfo<PPCFunctionInfo>();
895 dbgs() <<
"Current function uses IE access for default LD vars.\n");
918 switch (
MI->getOpcode()) {
920 case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
922 "AIX does not support patchable function entry!");
925 (void)
F.getFnAttribute(
"patchable-function-entry")
927 .getAsInteger(10, Num);
933 case TargetOpcode::DBG_VALUE:
935 case TargetOpcode::STACKMAP:
936 return LowerSTACKMAP(SM, *
MI);
937 case TargetOpcode::PATCHPOINT:
938 return LowerPATCHPOINT(SM, *
MI);
940 case PPC::MoveGOTtoLR: {
948 OutContext.getOrCreateSymbol(StringRef(
"_GLOBAL_OFFSET_TABLE_"));
954 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BL).addExpr(OffsExpr));
957 case PPC::MovePCtoLR:
958 case PPC::MovePCtoLR8: {
963 MCSymbol *PICBase = MF->getPICBaseSymbol();
966 EmitToStreamer(*OutStreamer,
967 MCInstBuilder(PPC::BCLalways)
973 OutStreamer->emitLabel(PICBase);
976 case PPC::UpdateGBR: {
985 if (Subtarget->isSecurePlt() && isPositionIndependent() ) {
987 MCSymbol *BaseSymbol = OutContext.getOrCreateSymbol(
996 const MCExpr *DeltaHi =
1000 MCInstBuilder(PPC::ADDIS).addReg(PICR).addReg(PICR).addExpr(DeltaHi));
1002 const MCExpr *DeltaLo =
1006 MCInstBuilder(PPC::ADDI).addReg(PICR).addReg(PICR).addExpr(DeltaLo));
1010 MF->getInfo<PPCFunctionInfo>()->getPICOffsetSymbol(*MF);
1017 const MCOperand PICR = TmpInst.
getOperand(0);
1024 EmitToStreamer(*OutStreamer, TmpInst);
1030 EmitToStreamer(*OutStreamer, TmpInst);
1041 const MachineOperand &MO =
MI->getOperand(1);
1043 "Invalid operand for LWZtoc.");
1051 const MCExpr *
Exp = symbolWithSpecifier(MOSymbol,
PPC::S_GOT);
1053 EmitToStreamer(*OutStreamer, TmpInst);
1072 "This pseudo should only be selected for 32-bit small code model.");
1073 Exp = getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp, VK);
1078 OutStreamer->getCommentOS() << MO <<
'\n';
1079 EmitToStreamer(*OutStreamer, TmpInst);
1086 OutContext.getOrCreateSymbol(Twine(
".LTOC")), OutContext);
1089 EmitToStreamer(*OutStreamer, TmpInst);
1093 case PPC::ADDItoc8: {
1095 "PseudoOp only valid for small code model AIX");
1101 TmpInst.
setOpcode((!IsPPC64) ? (PPC::LA) : (PPC::LA8));
1103 const MachineOperand &MO =
MI->getOperand(2);
1112 EmitToStreamer(*OutStreamer, TmpInst);
1125 const MachineOperand &MO =
MI->getOperand(1);
1127 "Invalid operand!");
1141 const MCExpr *
Exp = symbolWithSpecifier(TOCEntry, VKExpr);
1143 IsAIX ? getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp, VK) : Exp);
1146 if (isVerbose() && IsAIX)
1147 OutStreamer->getCommentOS() << MO <<
'\n';
1148 EmitToStreamer(*OutStreamer, TmpInst);
1151 case PPC::ADDIStocHA: {
1152 const MachineOperand &MO =
MI->getOperand(2);
1155 "Invalid operand for ADDIStocHA.");
1156 assert((IsAIX && !IsPPC64 &&
1158 "This pseudo should only be selected for 32-bit large code model on"
1178 if ( {
1190 const MCExpr *
Exp = symbolWithSpecifier(MOSymbol,
PPC::S_U);
1192 EmitToStreamer(*OutStreamer, TmpInst);
1195 case PPC::LWZtocL: {
1196 const MachineOperand &MO =
MI->getOperand(1);
1199 "Invalid operand for LWZtocL.");
1200 assert(IsAIX && !IsPPC64 &&
1202 "This pseudo should only be selected for 32-bit large code model on"
1222 const MCExpr *
Exp = symbolWithSpecifier(TOCEntry,
PPC::S_L);
1224 EmitToStreamer(*OutStreamer, TmpInst);
1227 case PPC::ADDIStocHA8: {
1237 const MachineOperand &MO =
MI->getOperand(2);
1239 "Invalid operand for ADDIStocHA8!");
1245 const bool GlobalToc =
1257 const MCExpr *
Exp = symbolWithSpecifier(MOSymbol, VK);
1266 EmitToStreamer(*OutStreamer, TmpInst);
1279 const MachineOperand &MO =
MI->getOperand(1);
1282 "Invalid operand for LDtocL!");
1286 "LDtocL used on symbol that could be accessed directly is "
1287 "invalid. Must match ADDIStocHA8."));
1298 const MCExpr *
Exp = symbolWithSpecifier(MOSymbol, VK);
1300 EmitToStreamer(*OutStreamer, TmpInst);
1304 case PPC::ADDItocL8: {
1308 unsigned Op =
MI->getOpcode();
1312 TmpInst.
setOpcode(
Op == PPC::ADDItocL8 ? (IsAIX ? PPC::LA8 : PPC::ADDI8)
1315 const MachineOperand &MO =
MI->getOperand(2);
1318 : MO.
isGlobal() &&
"Invalid operand for ADDItocL8.");
1320 "Interposable definitions must use indirect accesses.");
1329 EmitToStreamer(*OutStreamer, TmpInst);
1332 case PPC::ADDISgotTprelHA: {
1335 assert(IsPPC64 &&
"Not supported for 32-bit PowerPC");
1336 const MachineOperand &MO =
MI->getOperand(2);
1337 const GlobalValue *GValue = MO.
getGlobal();
1338 MCSymbol *MOSymbol = getSymbol(GValue);
1339 const MCExpr *SymGotTprel =
1341 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
1342 .addReg(
MI->getOperand(0).getReg())
1343 .addReg(
MI->getOperand(1).getReg())
1344 .addExpr(SymGotTprel));
1347 case PPC::LDgotTprelL:
1348 case PPC::LDgotTprelL32: {
1353 TmpInst.
setOpcode(IsPPC64 ? PPC::LD : PPC::LWZ);
1354 const MachineOperand &MO =
MI->getOperand(1);
1355 const GlobalValue *GValue = MO.
getGlobal();
1356 MCSymbol *MOSymbol = getSymbol(GValue);
1357 const MCExpr *
Exp = symbolWithSpecifier(
1360 EmitToStreamer(*OutStreamer, TmpInst);
1364 case PPC::PPC32PICGOT: {
1365 MCSymbol *GOTSymbol = OutContext.getOrCreateSymbol(StringRef(
"_GLOBAL_OFFSET_TABLE_"));
1366 MCSymbol *GOTRef = OutContext.createTempSymbol();
1367 MCSymbol *NextInstr = OutContext.createTempSymbol();
1369 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BL)
1373 const MCExpr *OffsExpr =
1377 OutStreamer->emitLabel(GOTRef);
1378 OutStreamer->emitValue(OffsExpr, 4);
1379 OutStreamer->emitLabel(NextInstr);
1380 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MFLR)
1381 .addReg(
MI->getOperand(0).getReg()));
1382 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LWZ)
1383 .addReg(
MI->getOperand(1).getReg())
1385 .addReg(
MI->getOperand(0).getReg()));
1386 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADD4)
1387 .addReg(
MI->getOperand(0).getReg())
1388 .addReg(
MI->getOperand(1).getReg())
1389 .addReg(
MI->getOperand(0).getReg()));
1392 case PPC::PPC32GOT: {
1394 OutContext.getOrCreateSymbol(StringRef(
"_GLOBAL_OFFSET_TABLE_"));
1395 const MCExpr *SymGotTlsL =
1397 const MCExpr *SymGotTlsHA =
1399 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LI)
1400 .addReg(
MI->getOperand(0).getReg())
1401 .addExpr(SymGotTlsL));
1402 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS)
1403 .addReg(
MI->getOperand(0).getReg())
1404 .addReg(
MI->getOperand(0).getReg())
1405 .addExpr(SymGotTlsHA));
1408 case PPC::ADDIStlsgdHA: {
1411 assert(IsPPC64 &&
"Not supported for 32-bit PowerPC");
1412 const MachineOperand &MO =
MI->getOperand(2);
1413 const GlobalValue *GValue = MO.
getGlobal();
1414 MCSymbol *MOSymbol = getSymbol(GValue);
1415 const MCExpr *SymGotTlsGD =
1417 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
1418 .addReg(
MI->getOperand(0).getReg())
1419 .addReg(
MI->getOperand(1).getReg())
1420 .addExpr(SymGotTlsGD));
1423 case PPC::ADDItlsgdL:
1426 case PPC::ADDItlsgdL32: {
1429 const MachineOperand &MO =
MI->getOperand(2);
1430 const GlobalValue *GValue = MO.
getGlobal();
1431 MCSymbol *MOSymbol = getSymbol(GValue);
1432 const MCExpr *SymGotTlsGD = symbolWithSpecifier(
1434 EmitToStreamer(*OutStreamer,
1435 MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
1436 .addReg(
MI->getOperand(0).getReg())
1437 .addReg(
MI->getOperand(1).getReg())
1438 .addExpr(SymGotTlsGD));
1441 case PPC::GETtlsMOD32AIX:
1442 case PPC::GETtlsMOD64AIX:
1446 case PPC::GETtlsADDR:
1449 case PPC::GETtlsADDRPCREL:
1450 case PPC::GETtlsADDR32AIX:
1451 case PPC::GETtlsADDR64AIX:
1455 case PPC::GETtlsADDR32: {
1461 case PPC::GETtlsTpointer32AIX: {
1464 EmitAIXTlsCallHelper(
MI);
1467 case PPC::ADDIStlsldHA: {
1470 assert(IsPPC64 &&
"Not supported for 32-bit PowerPC");
1471 const MachineOperand &MO =
MI->getOperand(2);
1472 const GlobalValue *GValue = MO.
getGlobal();
1473 MCSymbol *MOSymbol = getSymbol(GValue);
1474 const MCExpr *SymGotTlsLD =
1476 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
1477 .addReg(
MI->getOperand(0).getReg())
1478 .addReg(
MI->getOperand(1).getReg())
1479 .addExpr(SymGotTlsLD));
1482 case PPC::ADDItlsldL:
1485 case PPC::ADDItlsldL32: {
1488 const MachineOperand &MO =
MI->getOperand(2);
1489 const GlobalValue *GValue = MO.
getGlobal();
1490 MCSymbol *MOSymbol = getSymbol(GValue);
1491 const MCExpr *SymGotTlsLD = symbolWithSpecifier(
1493 EmitToStreamer(*OutStreamer,
1494 MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
1495 .addReg(
MI->getOperand(0).getReg())
1496 .addReg(
MI->getOperand(1).getReg())
1497 .addExpr(SymGotTlsLD));
1500 case PPC::GETtlsldADDR:
1503 case PPC::GETtlsldADDRPCREL:
1504 case PPC::GETtlsldADDR32: {
1510 case PPC::ADDISdtprelHA:
1513 case PPC::ADDISdtprelHA32: {
1516 const MachineOperand &MO =
MI->getOperand(2);
1517 const GlobalValue *GValue = MO.
getGlobal();
1518 MCSymbol *MOSymbol = getSymbol(GValue);
1522 MCInstBuilder(IsPPC64 ? PPC::ADDIS8 : PPC::ADDIS)
1523 .addReg(
MI->getOperand(0).getReg())
1524 .addReg(
MI->getOperand(1).getReg())
1525 .addExpr(SymDtprel));
1528 case PPC::PADDIdtprel: {
1531 const MachineOperand &MO =
MI->getOperand(2);
1532 const GlobalValue *GValue = MO.
getGlobal();
1533 MCSymbol *MOSymbol = getSymbol(GValue);
1534 const MCExpr *SymDtprel = symbolWithSpecifier(MOSymbol,
PPC::S_DTPREL);
1535 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::PADDI8)
1536 .addReg(
MI->getOperand(0).getReg())
1537 .addReg(
MI->getOperand(1).getReg())
1538 .addExpr(SymDtprel));
1542 case PPC::ADDIdtprelL:
1545 case PPC::ADDIdtprelL32: {
1548 const MachineOperand &MO =
MI->getOperand(2);
1549 const GlobalValue *GValue = MO.
getGlobal();
1550 MCSymbol *MOSymbol = getSymbol(GValue);
1552 EmitToStreamer(*OutStreamer,
1553 MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
1554 .addReg(
MI->getOperand(0).getReg())
1555 .addReg(
MI->getOperand(1).getReg())
1556 .addExpr(SymDtprel));
1561 if (!Subtarget->hasMFOCRF()) {
1564 unsigned NewOpcode =
1565 MI->getOpcode() == PPC::MFOCRF ? PPC::MFCR : PPC::MFCR8;
1566 OutStreamer->AddComment(PPCInstPrinter::
1568 EmitToStreamer(*OutStreamer, MCInstBuilder(NewOpcode)
1569 .addReg(
MI->getOperand(0).getReg()));
1575 if (!Subtarget->hasMFOCRF()) {
1578 unsigned NewOpcode =
1579 MI->getOpcode() == PPC::MTOCRF ? PPC::MTCRF : PPC::MTCRF8;
1580 unsigned Mask = 0x80 >> OutContext.getRegisterInfo()
1581 ->getEncodingValue(
MI->getOperand(0).getReg());
1582 OutStreamer->AddComment(PPCInstPrinter::
1584 EmitToStreamer(*OutStreamer, MCInstBuilder(NewOpcode)
1586 .addReg(
MI->getOperand(1).getReg()));
1596 unsigned OpNum = (
MI->getOpcode() == PPC::STD) ? 2 : 1;
1600 for (
const MachineOperand &TempMO :
MI->operands()) {
1603 TempMO.getOperandNo() == 1)
1606 const MachineOperand &MO =
MI->getOperand(OpNum);
1640 if (!HasAIXSmallLocalTLS)
1642 bool IsMIADDI8 =
MI->getOpcode() == PPC::ADDI8;
1643 unsigned OpNum = IsMIADDI8 ? 2 : 1;
1644 const MachineOperand &MO =
MI->getOperand(OpNum);
1651 const MCExpr *Expr = getAdjustedFasterLocalExpr(MO, MO.
getOffset());
1659 EmitToStreamer(*OutStreamer, TmpInst);
1665 case PPC::PseudoEIEIO: {
1668 MCInstBuilder(PPC::ORI).addReg(PPC::X2).addReg(PPC::X2).addImm(0));
1671 MCInstBuilder(PPC::ORI).addReg(PPC::X2).addReg(PPC::X2).addImm(0));
1672 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::EnforceIEIO));
1678 EmitToStreamer(*OutStreamer, TmpInst);
1688PPCAsmPrinter::getAdjustedFasterLocalExpr(
const MachineOperand &MO,
1695 assert(MO.
isGlobal() &&
"Only expecting a global MachineOperand here!");
1696 const GlobalValue *GValue = MO.
getGlobal();
1699 "Only local-[exec|dynamic] accesses are handled!");
1705 const auto TLSVarsMapEntryIter = TLSVarsToAddressMapping.
find(GValue);
1706 if (TLSVarsMapEntryIter == TLSVarsToAddressMapping.
end())
1707 assert(IsGlobalADeclaration &&
1708 "Only expecting to find extern TLS variables not present in the TLS "
1709 "variable-to-address map!");
1711 unsigned TLSVarAddress =
1712 IsGlobalADeclaration ? 0 : TLSVarsMapEntryIter->second;
1713 ptrdiff_t FinalAddress = (TLSVarAddress +
Offset);
1725 if (FinalAddress >= 32768) {
1732 ptrdiff_t Delta = ((FinalAddress + 32768) & ~0xFFFF);
1734 [[maybe_unused]] ptrdiff_t InstDisp = TLSVarAddress +
Offset - Delta;
1736 ((InstDisp < 32768) && (InstDisp >= -32768)) &&
1737 "Expecting the instruction displacement for local-[exec|dynamic] TLS "
1738 "variables to be between [-32768, 32768)!");
1746void PPCLinuxAsmPrinter::emitGNUAttributes(
Module &M) {
1748 Metadata *MD =
M.getModuleFlag(
"float-abi");
1754 if (flt ==
"doubledouble")
1755 OutStreamer->emitGNUAttribute(Tag_GNU_Power_ABI_FP,
1756 Val_GNU_Power_ABI_HardFloat_DP |
1757 Val_GNU_Power_ABI_LDBL_IBM128);
1758 else if (flt ==
"ieeequad")
1759 OutStreamer->emitGNUAttribute(Tag_GNU_Power_ABI_FP,
1760 Val_GNU_Power_ABI_HardFloat_DP |
1761 Val_GNU_Power_ABI_LDBL_IEEE128);
1762 else if (flt ==
"ieeedouble")
1763 OutStreamer->emitGNUAttribute(Tag_GNU_Power_ABI_FP,
1764 Val_GNU_Power_ABI_HardFloat_DP |
1765 Val_GNU_Power_ABI_LDBL_64);
1768void PPCLinuxAsmPrinter::emitInstruction(
const MachineInstr *
MI) {
1769 if (!Subtarget->isPPC64())
1770 return PPCAsmPrinter::emitInstruction(
MI);
1772 switch (
MI->getOpcode()) {
1775 case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
1790 (void)
F.getFnAttribute(
"patchable-function-entry")
1792 .getAsInteger(10, Num);
1794 if (!MAI->isLittleEndian() || Num)
1796 MCSymbol *BeginOfSled = OutContext.createTempSymbol();
1797 MCSymbol *EndOfSled = OutContext.createTempSymbol();
1798 OutStreamer->emitLabel(BeginOfSled);
1799 EmitToStreamer(*OutStreamer,
1800 MCInstBuilder(PPC::B).addExpr(
1802 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::NOP));
1805 MCInstBuilder(PPC::STD).addReg(PPC::X0).addImm(-8).addReg(PPC::X1));
1806 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MFLR8).addReg(PPC::X0));
1807 EmitToStreamer(*OutStreamer,
1808 MCInstBuilder(PPC::BL8_NOP)
1810 OutContext.getOrCreateSymbol(
"__xray_FunctionEntry"),
1812 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MTLR8).addReg(PPC::X0));
1813 OutStreamer->emitLabel(EndOfSled);
1814 recordSled(BeginOfSled, *
MI, SledKind::FUNCTION_ENTER, 2);
1817 case TargetOpcode::PATCHABLE_RET: {
1818 unsigned RetOpcode =
MI->getOperand(0).getImm();
1828 if (RetOpcode == PPC::BCCLR) {
1829 IsConditional =
true;
1830 }
else if (RetOpcode == PPC::TCRETURNdi8 || RetOpcode == PPC::TCRETURNri8 ||
1831 RetOpcode == PPC::TCRETURNai8) {
1833 }
else if (RetOpcode == PPC::BLR8 || RetOpcode == PPC::TAILB8) {
1834 IsConditional =
false;
1836 EmitToStreamer(*OutStreamer, RetInst);
1841 if (IsConditional) {
1860 FallthroughLabel = OutContext.createTempSymbol();
1863 MCInstBuilder(PPC::BCC)
1866 .addReg(
MI->getOperand(2).getReg())
1883 OutStreamer->emitCodeAlignment(
Align(8), &getSubtargetInfo());
1884 MCSymbol *BeginOfSled = OutContext.createTempSymbol();
1885 OutStreamer->emitLabel(BeginOfSled);
1886 EmitToStreamer(*OutStreamer, RetInst);
1887 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::NOP));
1890 MCInstBuilder(PPC::STD).addReg(PPC::X0).addImm(-8).addReg(PPC::X1));
1891 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MFLR8).addReg(PPC::X0));
1892 EmitToStreamer(*OutStreamer,
1893 MCInstBuilder(PPC::BL8_NOP)
1895 OutContext.getOrCreateSymbol(
"__xray_FunctionExit"),
1897 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MTLR8).addReg(PPC::X0));
1898 EmitToStreamer(*OutStreamer, RetInst);
1900 OutStreamer->emitLabel(FallthroughLabel);
1901 recordSled(BeginOfSled, *
MI, SledKind::FUNCTION_EXIT, 2);
1904 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
1906 case TargetOpcode::PATCHABLE_TAIL_CALL:
1910 "around this assert.");
1912 return PPCAsmPrinter::emitInstruction(
MI);
1915void PPCLinuxAsmPrinter::emitStartOfAsmFile(
Module &M) {
1916 if (
static_cast<const PPCTargetMachine &
>(TM).isELFv2ABI()) {
1917 PPCTargetStreamer *TS =
1918 static_cast<PPCTargetStreamer *
>(OutStreamer->getTargetStreamer());
1922 if (
static_cast<const PPCTargetMachine &
>(TM).isPPC64() ||
1923 !isPositionIndependent())
1929 OutStreamer->switchSection(OutContext.getELFSection(
1932 MCSymbol *TOCSym = OutContext.getOrCreateSymbol(Twine(
".LTOC"));
1933 MCSymbol *CurrentPos = OutContext.createTempSymbol();
1935 OutStreamer->emitLabel(CurrentPos);
1939 const MCExpr *tocExpr =
1944 OutStreamer->emitAssignment(TOCSym, tocExpr);
1946 OutStreamer->switchSection(getObjFileLowering().getTextSection());
1949void PPCLinuxAsmPrinter::emitFunctionEntryLabel() {
1951 if (!Subtarget->isPPC64() &&
1952 (!isPositionIndependent() ||
1956 if (!Subtarget->isPPC64()) {
1957 const PPCFunctionInfo *PPCFI = MF->getInfo<PPCFunctionInfo>();
1958 if (PPCFI->
usesPICBase() && !Subtarget->isSecurePlt()) {
1960 MCSymbol *PICBase = MF->getPICBaseSymbol();
1961 OutStreamer->emitLabel(RelocSymbol);
1963 const MCExpr *OffsExpr =
1969 OutStreamer->emitValue(OffsExpr, 4);
1970 OutStreamer->emitLabel(CurrentFnSym);
1983 && !MF->getRegInfo().use_empty(PPC::X2)) {
1984 const PPCFunctionInfo *PPCFI = MF->getInfo<PPCFunctionInfo>();
1986 MCSymbol *TOCSymbol = OutContext.getOrCreateSymbol(StringRef(
".TOC."));
1988 const MCExpr *TOCDeltaExpr =
1995 OutStreamer->emitValue(TOCDeltaExpr, 8);
2002 MCSectionELF *
Section = OutStreamer->getContext().getELFSection(
2004 OutStreamer->switchSection(Section);
2005 OutStreamer->emitLabel(CurrentFnSym);
2006 OutStreamer->emitValueToAlignment(
Align(8));
2007 MCSymbol *Symbol1 = CurrentFnSymForSize;
2012 MCSymbol *Symbol2 = OutContext.getOrCreateSymbol(StringRef(
".TOC."));
2014 OutStreamer->emitValue(
2017 OutStreamer->emitIntValue(0, 8 );
2018 OutStreamer->switchSection(Current.first, Current.second);
2021void PPCLinuxAsmPrinter::emitEndOfAsmFile(
Module &M) {
2022 const DataLayout &
DL = getDataLayout();
2024 bool isPPC64 =
DL.getPointerSizeInBits() == 64;
2026 PPCTargetStreamer *TS =
2027 static_cast<PPCTargetStreamer *
>(OutStreamer->getTargetStreamer());
2033 if (
static_cast<const PPCTargetMachine &
>(TM).hasGlibcHWCAPAccess())
2034 OutStreamer->emitSymbolValue(
2035 GetExternalSymbolSymbol(
"__parse_hwcap_and_convert_at_platform"),
2036 MAI->getCodePointerSize());
2037 emitGNUAttributes(M);
2040 const char *
Name = isPPC64 ?
".toc" :
".got2";
2041 MCSectionELF *
Section = OutContext.getELFSection(
2043 OutStreamer->switchSection(Section);
2045 OutStreamer->emitValueToAlignment(
Align(4));
2047 for (
const auto &TOCMapPair : TOC) {
2048 const MCSymbol *
const TOCEntryTarget = TOCMapPair.first.first;
2049 MCSymbol *
const TOCEntryLabel = TOCMapPair.second;
2051 OutStreamer->emitLabel(TOCEntryLabel);
2053 TS->
emitTCEntry(*TOCEntryTarget, TOCMapPair.first.second);
2055 OutStreamer->emitSymbolValue(TOCEntryTarget, 4);
2059 PPCAsmPrinter::emitEndOfAsmFile(M);
2063void PPCLinuxAsmPrinter::emitFunctionBodyStart() {
2095 const PPCFunctionInfo *PPCFI = MF->getInfo<PPCFunctionInfo>();
2096 const bool UsesX2OrR2 = !MF->getRegInfo().use_empty(PPC::X2) ||
2097 !MF->getRegInfo().use_empty(PPC::R2);
2106 if (NonPCrelGEPRequired || PCrelGEPRequired) {
2111 OutStreamer->emitLabel(GlobalEntryLabel);
2112 const MCSymbolRefExpr *GlobalEntryLabelExp =
2116 MCSymbol *TOCSymbol = OutContext.getOrCreateSymbol(StringRef(
".TOC."));
2117 const MCExpr *TOCDeltaExpr =
2119 GlobalEntryLabelExp, OutContext);
2121 const MCExpr *TOCDeltaHi =
2123 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS)
2126 .addExpr(TOCDeltaHi));
2128 const MCExpr *TOCDeltaLo =
2130 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDI)
2133 .addExpr(TOCDeltaLo));
2136 const MCExpr *TOCOffsetDeltaExpr =
2138 GlobalEntryLabelExp, OutContext);
2140 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
2142 .addExpr(TOCOffsetDeltaExpr)
2144 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADD8)
2151 OutStreamer->emitLabel(LocalEntryLabel);
2152 const MCSymbolRefExpr *LocalEntryLabelExp =
2154 const MCExpr *LocalOffsetExp =
2156 GlobalEntryLabelExp, OutContext);
2158 PPCTargetStreamer *TS =
2159 static_cast<PPCTargetStreamer *
>(OutStreamer->getTargetStreamer());
2184 if (MF->getFrameInfo().hasCalls() || MF->getFrameInfo().hasTailCall() ||
2185 MF->hasInlineAsm() || (!PPCFI->
usesTOCBasePtr() && UsesX2OrR2)) {
2186 PPCTargetStreamer *TS =
2187 static_cast<PPCTargetStreamer *
>(OutStreamer->getTargetStreamer());
2197void PPCLinuxAsmPrinter::emitFunctionBodyEnd() {
2205 if (Subtarget->isPPC64()) {
2206 OutStreamer->emitIntValue(0, 4);
2207 OutStreamer->emitIntValue(0, 8);
2211char PPCLinuxAsmPrinter::ID = 0;
2214 "Linux PPC Assembly Printer",
false,
false)
2219 switch (GV->getLinkage()) {
2220 case GlobalValue::ExternalLinkage:
2221 LinkageAttr = GV->isDeclaration() ? MCSA_Extern : MCSA_Global;
2223 case GlobalValue::LinkOnceAnyLinkage:
2224 case GlobalValue::LinkOnceODRLinkage:
2225 case GlobalValue::WeakAnyLinkage:
2226 case GlobalValue::WeakODRLinkage:
2227 case GlobalValue::ExternalWeakLinkage:
2228 LinkageAttr = MCSA_Weak;
2230 case GlobalValue::AvailableExternallyLinkage:
2231 LinkageAttr = MCSA_Extern;
2233 case GlobalValue::PrivateLinkage:
2235 case GlobalValue::InternalLinkage:
2236 assert(GV->getVisibility() == GlobalValue::DefaultVisibility &&
2237 "InternalLinkage should not have other visibility setting.");
2238 LinkageAttr = MCSA_LGlobal;
2240 case GlobalValue::AppendingLinkage:
2241 llvm_unreachable(
"Should never emit this");
2242 case GlobalValue::CommonLinkage:
2243 llvm_unreachable(
"CommonLinkage of XCOFF should not come to this path");
2249 if (!TM.getIgnoreXCOFFVisibility()) {
2250 if (GV->hasDLLExportStorageClass() && !GV->hasDefaultVisibility())
2252 "Cannot not be both dllexport and non-default visibility");
2253 switch (GV->getVisibility()) {
2256 case GlobalValue::DefaultVisibility:
2257 if (GV->hasDLLExportStorageClass())
2258 VisibilityAttr = MAI->getExportedVisibilityAttr();
2260 case GlobalValue::HiddenVisibility:
2261 VisibilityAttr = MAI->getHiddenVisibilityAttr();
2263 case GlobalValue::ProtectedVisibility:
2264 VisibilityAttr = MAI->getProtectedVisibilityAttr();
2274 OutStreamer->emitXCOFFSymbolLinkageWithVisibility(GVSym, LinkageAttr,
2278void PPCAIXAsmPrinter::SetupMachineFunction(MachineFunction &MF) {
2280 auto *FnDescSec =
static_cast<MCSectionXCOFF *
>(
2281 getObjFileLowering().getSectionForFunctionDescriptor(&MF.
getFunction(),
2283 FnDescSec->setAlignment(
Align(Subtarget->isPPC64() ? 8 : 4));
2285 CurrentFnDescSym = FnDescSec->getQualNameSymbol();
2290uint16_t PPCAIXAsmPrinter::getNumberOfVRSaved() {
2294 const PPCSubtarget &Subtarget = MF->
getSubtarget<PPCSubtarget>();
2295 if (Subtarget.
isAIXABI() && Subtarget.hasAltivec() &&
2296 TM.getAIXExtendedAltivecABI()) {
2298 for (
unsigned Reg = PPC::V20;
Reg <= PPC::V31; ++
Reg)
2299 if (
MRI.isPhysRegModified(
Reg))
2301 return PPC::V31 -
Reg + 1;
2306void PPCAIXAsmPrinter::emitFunctionBodyEnd() {
2308 if (!
TM.getXCOFFTracebackTable())
2311 emitTracebackTable();
2319 (getNumberOfVRSaved() > 0)) {
2321 OutStreamer->switchSection(getObjFileLowering().getCompactUnwindSection());
2324 OutStreamer->emitLabel(EHInfoLabel);
2327 OutStreamer->emitInt32(0);
2329 const DataLayout &
DL = MMI->getModule()->getDataLayout();
2332 OutStreamer->emitValueToAlignment(
Align(PointerSize));
2334 OutStreamer->emitIntValue(0, PointerSize);
2335 OutStreamer->emitIntValue(0, PointerSize);
2336 OutStreamer->switchSection(MF->
getSection());
2340void PPCAIXAsmPrinter::emitTracebackTable() {
2344 OutStreamer->emitLabel(FuncEnd);
2346 OutStreamer->AddComment(
"Traceback table begin");
2348 OutStreamer->emitIntValueInHexWithPadding(0, 4 );
2350 SmallString<128> CommentString;
2351 raw_svector_ostream CommentOS(CommentString);
2353 auto EmitComment = [&]() {
2354 OutStreamer->AddComment(CommentOS.str());
2355 CommentString.
clear();
2358 auto EmitCommentAndValue = [&](uint64_t
Value,
int Size) {
2360 OutStreamer->emitIntValueInHexWithPadding(
Value,
Size);
2364 CommentOS <<
"Version = " <<
Version;
2365 EmitCommentAndValue(
Version, 1);
2375 CommentOS <<
"Language = "
2377 EmitCommentAndValue(LanguageIdentifier, 1);
2380 uint32_t FirstHalfOfMandatoryField = 0;
2387 const PPCFunctionInfo *FI = MF->
getInfo<PPCFunctionInfo>();
2391 for (
unsigned Reg = PPC::F0;
Reg <= PPC::F31; ++
Reg) {
2392 if (
MRI.isPhysRegUsed(
Reg,
true)) {
2398#define GENBOOLCOMMENT(Prefix, V, Field) \
2399 CommentOS << (Prefix) << ((V) & (TracebackTable::Field##Mask) ? "+" : "-") \
2402#define GENVALUECOMMENT(PrefixAndName, V, Field) \
2403 CommentOS << (PrefixAndName) << " = " \
2404 << static_cast<unsigned>(((V) & (TracebackTable::Field##Mask)) >> \
2405 (TracebackTable::Field##Shift))
2408 GENBOOLCOMMENT(
", ", FirstHalfOfMandatoryField, IsOutOfLineEpilogOrPrologue);
2411 GENBOOLCOMMENT(
"", FirstHalfOfMandatoryField, HasTraceBackTableOffset);
2412 GENBOOLCOMMENT(
", ", FirstHalfOfMandatoryField, IsInternalProcedure);
2415 GENBOOLCOMMENT(
"", FirstHalfOfMandatoryField, HasControlledStorage);
2419 GENBOOLCOMMENT(
"", FirstHalfOfMandatoryField, IsFloatingPointPresent);
2422 IsFloatingPointOperationLogOrAbortEnabled);
2425 OutStreamer->emitIntValueInHexWithPadding(
2426 (FirstHalfOfMandatoryField & 0x0000ff00) >> 8, 1);
2433 if (FrameReg == (Subtarget->isPPC64() ? PPC::X31 : PPC::R31))
2436 const SmallVectorImpl<Register> &MustSaveCRs = FI->
getMustSaveCRs();
2437 if (!MustSaveCRs.
empty())
2443 GENBOOLCOMMENT(
"", FirstHalfOfMandatoryField, IsInterruptHandler);
2444 GENBOOLCOMMENT(
", ", FirstHalfOfMandatoryField, IsFunctionNamePresent);
2448 OnConditionDirective);
2452 OutStreamer->emitIntValueInHexWithPadding((FirstHalfOfMandatoryField & 0xff),
2456 uint32_t SecondHalfOfMandatoryField = 0;
2462 uint32_t FPRSaved = 0;
2463 for (
unsigned Reg = PPC::F14;
Reg <= PPC::F31; ++
Reg) {
2464 if (
MRI.isPhysRegModified(
Reg)) {
2465 FPRSaved = PPC::F31 -
Reg + 1;
2471 GENBOOLCOMMENT(
"", SecondHalfOfMandatoryField, IsBackChainStored);
2473 GENVALUECOMMENT(
", NumOfFPRsSaved", SecondHalfOfMandatoryField, FPRSaved);
2475 OutStreamer->emitIntValueInHexWithPadding(
2476 (SecondHalfOfMandatoryField & 0xff000000) >> 24, 1);
2482 bool HasVectorInst =
false;
2483 for (
unsigned Reg = PPC::V0;
Reg <= PPC::V31; ++
Reg)
2484 if (
MRI.isPhysRegUsed(
Reg,
true)) {
2486 HasVectorInst =
true;
2493 uint16_t NumOfVRSaved = getNumberOfVRSaved();
2494 bool ShouldEmitEHBlock =
2497 if (ShouldEmitEHBlock)
2500 uint32_t GPRSaved = 0;
2503 unsigned GPRBegin = Subtarget->isPPC64() ? PPC::X14 : PPC::R13;
2504 unsigned GPREnd = Subtarget->isPPC64() ? PPC::X31 : PPC::R31;
2506 for (
unsigned Reg = GPRBegin;
Reg <= GPREnd; ++
Reg) {
2507 if (
MRI.isPhysRegModified(
Reg)) {
2508 GPRSaved = GPREnd -
Reg + 1;
2516 GENBOOLCOMMENT(
"", SecondHalfOfMandatoryField, HasExtensionTable);
2518 GENVALUECOMMENT(
", NumOfGPRsSaved", SecondHalfOfMandatoryField, GPRSaved);
2520 OutStreamer->emitIntValueInHexWithPadding(
2521 (SecondHalfOfMandatoryField & 0x00ff0000) >> 16, 1);
2525 SecondHalfOfMandatoryField |=
2529 NumberOfFixedParms);
2531 OutStreamer->emitIntValueInHexWithPadding(
2532 (SecondHalfOfMandatoryField & 0x0000ff00) >> 8, 1);
2540 SecondHalfOfMandatoryField |=
2545 NumberOfFloatingPointParms);
2546 GENBOOLCOMMENT(
", ", SecondHalfOfMandatoryField, HasParmsOnStack);
2548 OutStreamer->emitIntValueInHexWithPadding(SecondHalfOfMandatoryField & 0xff,
2554 if (NumberOfFixedParms || NumberOfFPParms) {
2557 Expected<SmallString<32>> ParmsType =
2560 ParmsTypeValue, NumberOfFixedParms, NumberOfFPParms,
2567 CommentOS <<
"Parameter type = " << ParmsType.
get();
2570 OutStreamer->emitIntValueInHexWithPadding(ParmsTypeValue,
2571 sizeof(ParmsTypeValue));
2574 OutStreamer->AddComment(
"Function size");
2576 MCSymbol *FuncSectSym = getObjFileLowering().getFunctionEntryPointSymbol(
2578 OutStreamer->emitAbsoluteSymbolDiff(FuncEnd, FuncSectSym, 4);
2590 int16_t NameLength =
Name.size();
2591 CommentOS <<
"Function name len = "
2592 <<
static_cast<unsigned int>(NameLength);
2593 EmitCommentAndValue(NameLength, 2);
2594 OutStreamer->AddComment(
"Function Name");
2595 OutStreamer->emitBytes(Name);
2600 OutStreamer->AddComment(
"AllocaUsed");
2601 OutStreamer->emitIntValueInHex(AllocReg,
sizeof(AllocReg));
2605 uint16_t VRData = 0;
2634 OutStreamer->emitIntValueInHexWithPadding((VRData & 0xff00) >> 8, 1);
2639 OutStreamer->emitIntValueInHexWithPadding(VRData & 0x00ff, 1);
2643 Expected<SmallString<32>> VecParmsType =
2647 CommentOS <<
"Vector Parameter type = " << VecParmsType.
get();
2650 OutStreamer->emitIntValueInHexWithPadding(VecParmTypeValue,
2651 sizeof(VecParmTypeValue));
2653 CommentOS <<
"Padding";
2654 EmitCommentAndValue(0, 2);
2657 uint8_t ExtensionTableFlag = 0;
2659 if (ShouldEmitEHBlock)
2660 ExtensionTableFlag |= ExtendedTBTableFlag::TB_EH_INFO;
2663 ExtensionTableFlag |= ExtendedTBTableFlag::TB_SSP_CANARY;
2665 CommentOS <<
"ExtensionTableFlag = "
2667 EmitCommentAndValue(ExtensionTableFlag,
sizeof(ExtensionTableFlag));
2670 if (ExtensionTableFlag & ExtendedTBTableFlag::TB_EH_INFO) {
2671 auto &Ctx = OutStreamer->getContext();
2674 MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(EHInfoSym, TOCType_EHBlock);
2675 const MCSymbol *TOCBaseSym =
static_cast<const MCSectionXCOFF *
>(
2676 getObjFileLowering().getTOCBaseSection())
2677 ->getQualNameSymbol();
2682 const DataLayout &
DL = getDataLayout();
2683 OutStreamer->emitValueToAlignment(
Align(4));
2684 OutStreamer->AddComment(
"EHInfo Table");
2685 OutStreamer->emitValue(Exp,
DL.getPointerSize());
2687#undef GENBOOLCOMMENT
2688#undef GENVALUECOMMENT
2697 .
Case(
"llvm.used",
true)
2699 .
Case(
"llvm.compiler.used",
true)
2705 .
Cases({
"llvm.global_ctors",
"llvm.global_dtors"},
true)
2709uint64_t PPCAIXAsmPrinter::getAliasOffset(
const Constant *
C) {
2711 return getAliasOffset(GA->getAliasee());
2722 return RHS->getValue();
2732 "GlobalVariables with an alignment requirement stricter than TOC entry "
2733 "size not supported by the toc data transformation.");
2736 assert(GVType->
isSized() &&
"A GlobalVariable's size must be known to be "
2737 "supported by the toc data transformation.");
2741 "A GlobalVariable with size larger than a TOC entry is not currently "
2742 "supported by the toc data transformation.");
2745 "currently supported by the toc data transformation.");
2748void PPCAIXAsmPrinter::emitGlobalVariable(
const GlobalVariable *GV) {
2766 emitGlobalVariableHelper(GV);
2769void PPCAIXAsmPrinter::emitGlobalVariableHelper(
const GlobalVariable *GV) {
2771 "Unhandled intrinsic global variable.");
2776 auto *GVSym =
static_cast<MCSymbolXCOFF *
>(getSymbol(GV));
2779 emitLinkage(GV, GVSym);
2783 SectionKind GVKind = getObjFileLowering().getKindForGlobal(GV, TM);
2787 "not supported yet.");
2794 OutStreamer->getCommentOS() <<
'\n';
2798 auto *Csect =
static_cast<MCSectionXCOFF *
>(
2799 getObjFileLowering().SectionForGlobal(GV, GVKind, TM));
2802 OutStreamer->switchSection(Csect);
2811 GVSym->setStorageClass(
2815 OutStreamer->emitZeros(
Size);
2818 "BSS local toc-data already handled and TLS variables "
2819 "incompatible with XMC_TD");
2820 OutStreamer->emitXCOFFLocalCommonSymbol(
2821 OutContext.getOrCreateSymbol(GVSym->getSymbolTableName()),
Size,
2824 OutStreamer->emitCommonSymbol(GVSym,
Size, Alignment);
2832 emitLinkage(GV, EmittedInitSym);
2833 for (
const GlobalAlias *GA : GOAliasMap[GV])
2834 emitLinkage(GA, getSymbol(GA));
2836 emitAlignment(getGVAlignment(GV,
DL), GV);
2840 if (!
TM.getDataSections() || GV->hasSection()) {
2842 OutStreamer->emitLabel(EmittedInitSym);
2846 if (!GOAliasMap[GV].
size()) {
2847 emitGlobalConstant(GV->getDataLayout(), GV->getInitializer());
2853 AliasMapTy AliasList;
2854 for (
const GlobalAlias *GA : GOAliasMap[GV])
2855 AliasList[getAliasOffset(GA->getAliasee())].push_back(GA);
2858 emitGlobalConstant(GV->getDataLayout(), GV->getInitializer(),
2862void PPCAIXAsmPrinter::emitFunctionDescriptor() {
2863 const DataLayout &
DL = getDataLayout();
2864 const unsigned PointerSize =
DL.getPointerSizeInBits() == 64 ? 8 : 4;
2868 OutStreamer->switchSection(
2869 static_cast<MCSymbolXCOFF *
>(CurrentFnDescSym)->getRepresentedCsect());
2872 for (
const GlobalAlias *Alias : GOAliasMap[&MF->
getFunction()])
2873 OutStreamer->emitLabel(getSymbol(Alias));
2879 const MCSymbol *TOCBaseSym =
static_cast<const MCSectionXCOFF *
>(
2880 getObjFileLowering().getTOCBaseSection())
2881 ->getQualNameSymbol();
2885 OutStreamer->emitIntValue(0, PointerSize);
2887 OutStreamer->switchSection(Current.first, Current.second);
2890void PPCAIXAsmPrinter::emitFunctionEntryLabel() {
2894 PPCAsmPrinter::emitFunctionEntryLabel();
2897 for (
const GlobalAlias *Alias : GOAliasMap[&MF->
getFunction()])
2898 OutStreamer->emitLabel(
2899 getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM));
2902void PPCAIXAsmPrinter::emitPGORefs(
Module &M) {
2903 if (!OutContext.hasXCOFFSection(
2914 bool HasNonZeroLengthPrfCntsSection =
false;
2915 const DataLayout &
DL =
M.getDataLayout();
2916 for (GlobalVariable &GV :
M.globals())
2917 if (GV.hasSection() && GV.getSection() ==
"__llvm_prf_cnts" &&
2918 DL.getTypeAllocSize(GV.getValueType()) > 0) {
2919 HasNonZeroLengthPrfCntsSection =
true;
2923 if (HasNonZeroLengthPrfCntsSection) {
2924 MCSection *CntsSection = OutContext.getXCOFFSection(
2929 OutStreamer->switchSection(CntsSection);
2930 if (OutContext.hasXCOFFSection(
2933 MCSymbol *S = OutContext.getOrCreateSymbol(
"__llvm_prf_data[RW]");
2934 OutStreamer->emitXCOFFRefDirective(S);
2936 if (OutContext.hasXCOFFSection(
2939 MCSymbol *S = OutContext.getOrCreateSymbol(
"__llvm_prf_names[RO]");
2940 OutStreamer->emitXCOFFRefDirective(S);
2942 if (OutContext.hasXCOFFSection(
2945 MCSymbol *S = OutContext.getOrCreateSymbol(
"__llvm_prf_vnds[RW]");
2946 OutStreamer->emitXCOFFRefDirective(S);
2951void PPCAIXAsmPrinter::emitGCOVRefs() {
2952 if (!OutContext.hasXCOFFSection(
2953 "__llvm_gcov_ctr_section",
2957 MCSection *CtrSection = OutContext.getXCOFFSection(
2962 OutStreamer->switchSection(CtrSection);
2965 if (OutContext.hasXCOFFSection(
2968 const char *SymbolStr =
TM.Options.XCOFFReadOnlyPointers
2969 ?
"__llvm_covinit[RO]"
2970 :
"__llvm_covinit[RW]";
2971 MCSymbol *S = OutContext.getOrCreateSymbol(SymbolStr);
2972 OutStreamer->emitXCOFFRefDirective(S);
2976void PPCAIXAsmPrinter::emitEndOfAsmFile(
Module &M) {
2979 if (
M.empty() && TOCDataGlobalVars.
empty())
2986 OutStreamer->switchSection(getObjFileLowering().getTOCBaseSection());
2988 PPCTargetStreamer *TS =
2989 static_cast<PPCTargetStreamer *
>(OutStreamer->getTargetStreamer());
2991 for (
auto &
I : TOC) {
2992 MCSectionXCOFF *TCEntry;
2999 (Subtarget->hasAIXShLibTLSModelOpt() &&
3001 SmallString<128>
Name;
3004 Name +=
static_cast<const MCSymbolXCOFF *
>(
I.first.first)
3005 ->getSymbolTableName();
3006 MCSymbol *S = OutContext.getOrCreateSymbol(Name);
3007 TCEntry =
static_cast<MCSectionXCOFF *
>(
3008 getObjFileLowering().getSectionForTOCEntry(S, TM));
3010 TCEntry =
static_cast<MCSectionXCOFF *
>(
3011 getObjFileLowering().getSectionForTOCEntry(
I.first.first, TM));
3013 OutStreamer->switchSection(TCEntry);
3015 OutStreamer->emitLabel(
I.second);
3022 for (
const auto *GV : TOCDataGlobalVars) {
3023 if (!GV->hasCommonLinkage())
3024 emitGlobalVariableHelper(GV);
3026 for (
const auto *GV : TOCDataGlobalVars) {
3027 if (GV->hasCommonLinkage())
3028 emitGlobalVariableHelper(GV);
3032bool PPCAIXAsmPrinter::doInitialization(
Module &M) {
3033 const bool Result = PPCAsmPrinter::doInitialization(M);
3036 const Triple &
Target =
TM.getTargetTriple();
3043 if (FunCpuId > TargetCpuId)
3044 TargetCpuId = FunCpuId;
3050 StringRef TargetCPU =
TM.getTargetCPU();
3055 PPCTargetStreamer *TS =
3056 static_cast<PPCTargetStreamer *
>(OutStreamer->getTargetStreamer());
3059 auto setCsectAlignment = [
this](
const GlobalObject *GO) {
3061 if (GO->isDeclarationForLinker())
3064 SectionKind GOKind = getObjFileLowering().getKindForGlobal(GO, TM);
3065 auto *Csect =
static_cast<MCSectionXCOFF *
>(
3066 getObjFileLowering().SectionForGlobal(GO, GOKind, TM));
3068 Align GOAlign = getGVAlignment(GO, GO->getDataLayout());
3069 Csect->ensureMinAlignment(GOAlign);
3075 uint64_t TLSVarAddress = 0;
3076 auto DL =
M.getDataLayout();
3077 for (
const auto &
G :
M.globals()) {
3078 if (
G.isThreadLocal() && !
G.isDeclaration()) {
3079 TLSVarAddress =
alignTo(TLSVarAddress, getGVAlignment(&
G,
DL));
3080 TLSVarsToAddressMapping[&
G] = TLSVarAddress;
3081 TLSVarAddress +=
DL.getTypeAllocSize(
G.getValueType());
3088 for (
const auto &
G :
M.globals()) {
3095 if (FormatIndicatorAndUniqueModId.empty()) {
3097 if (UniqueModuleId !=
"")
3101 FormatIndicatorAndUniqueModId =
"clang_" + UniqueModuleId.substr(1);
3106 std::chrono::duration_cast<std::chrono::nanoseconds>(
3107 std::chrono::steady_clock::now().time_since_epoch())
3109 FormatIndicatorAndUniqueModId =
3116 emitSpecialLLVMGlobal(&
G);
3120 setCsectAlignment(&
G);
3121 std::optional<CodeModel::Model> OptionalCodeModel =
G.getCodeModel();
3122 if (OptionalCodeModel)
3124 *OptionalCodeModel);
3127 for (
const auto &
F : M)
3128 setCsectAlignment(&
F);
3131 for (
const auto &Alias :
M.aliases()) {
3132 const GlobalObject *Aliasee = Alias.getAliaseeObject();
3135 "alias without a base object is not yet supported on AIX");
3139 "\n\tAlias attribute for " +
3140 Alias.getName() +
" is invalid because " +
3141 Aliasee->
getName() +
" is common.",
3145 const GlobalVariable *GVar =
3148 std::optional<CodeModel::Model> OptionalCodeModel = GVar->
getCodeModel();
3149 if (OptionalCodeModel)
3151 *OptionalCodeModel);
3154 GOAliasMap[Aliasee].push_back(&Alias);
3160void PPCAIXAsmPrinter::emitInstruction(
const MachineInstr *
MI) {
3161 switch (
MI->getOpcode()) {
3168 if (
MI->getNumOperands() < 5)
3170 const MachineOperand &LangMO =
MI->getOperand(3);
3171 const MachineOperand &ReasonMO =
MI->getOperand(4);
3174 MCSymbol *TempSym = OutContext.createNamedTempSymbol();
3175 OutStreamer->emitLabel(TempSym);
3176 OutStreamer->emitXCOFFExceptDirective(
3177 CurrentFnSym, TempSym, LangMO.
getImm(), ReasonMO.
getImm(),
3178 Subtarget->isPPC64() ?
MI->getMF()->getInstructionCount() * 8
3179 :
MI->getMF()->getInstructionCount() * 4,
3183 case PPC::GETtlsMOD32AIX:
3184 case PPC::GETtlsMOD64AIX:
3185 case PPC::GETtlsTpointer32AIX:
3186 case PPC::GETtlsADDR64AIX:
3187 case PPC::GETtlsADDR32AIX: {
3192 ExtSymSDNodeSymbols.
insert(TlsGetAddr);
3199 const MachineOperand &MO =
MI->getOperand(0);
3201 auto *S =
static_cast<MCSymbolXCOFF *
>(
3203 ExtSymSDNodeSymbols.
insert(S);
3209 case PPC::BL8_NOP_TLS:
3216 case PPC::TAILBCTR8:
3217 if (
MI->getOperand(0).isSymbol())
3230 MCInstBuilder(PPC::ORI).addReg(PPC::R0).addReg(PPC::R0).addImm(0));
3233 return PPCAsmPrinter::emitInstruction(
MI);
3236bool PPCAIXAsmPrinter::doFinalization(
Module &M) {
3242 auto *Sec = OutContext.getObjectFileInfo()->getTextSection();
3243 OutStreamer->switchSectionNoPrint(Sec);
3244 MCSymbol *Sym = Sec->getEndSymbol(OutContext);
3245 OutStreamer->emitLabel(Sym);
3248 for (MCSymbol *Sym : ExtSymSDNodeSymbols)
3249 OutStreamer->emitSymbolAttribute(Sym,
MCSA_Extern);
3250 return PPCAsmPrinter::doFinalization(M);
3261 return 20 + (
P - 20) * 16;
3264 return 1004 + (
P - 81);
3267 return 2047 + (
P - 1124) * 33878;
3269 return 2147482625u + (
P - 64512);
3288 std::string PrioritySuffix;
3291 return PrioritySuffix;
3294void PPCAIXAsmPrinter::emitXXStructorList(
const DataLayout &
DL,
3295 const Constant *
List,
bool IsCtor) {
3297 preprocessXXStructorList(
DL,
List, Structors);
3298 if (Structors.
empty())
3302 for (Structor &S : Structors) {
3304 S.Func =
CE->getOperand(0);
3308 (IsCtor ? llvm::Twine(
"__sinit") : llvm::Twine(
"__sterm")) +
3310 llvm::Twine(
"_", FormatIndicatorAndUniqueModId) +
3316void PPCAIXAsmPrinter::emitTTypeReference(
const GlobalValue *GV,
3317 unsigned Encoding) {
3319 TOCEntryType GlobalType = TOCType_GlobalInternal;
3324 GlobalType = TOCType_GlobalExternal;
3326 MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(TypeInfoSym, GlobalType);
3327 const MCSymbol *TOCBaseSym =
static_cast<const MCSectionXCOFF *
>(
3328 getObjFileLowering().getTOCBaseSection())
3329 ->getQualNameSymbol();
3330 auto &Ctx = OutStreamer->getContext();
3334 OutStreamer->emitValue(Exp, GetSizeOfEncodedValue(Encoding));
3336 OutStreamer->emitIntValue(0, GetSizeOfEncodedValue(Encoding));
3343 std::unique_ptr<MCStreamer> &&Streamer) {
3345 return new PPCAIXAsmPrinter(tm, std::move(Streamer));
3347 return new PPCLinuxAsmPrinter(tm, std::move(Streamer));
3350void PPCAIXAsmPrinter::emitModuleCommandLines(
Module &M) {
3351 const NamedMDNode *NMD =
M.getNamedMetadata(
"llvm.commandline");
3356 raw_string_ostream RSOS(S);
3359 assert(
N->getNumOperands() == 1 &&
3360 "llvm.commandline metadata entry can have only one operand");
3364 RSOS <<
"@(#)opt " << MDS->
getString() <<
"\n";
3367 OutStreamer->emitXCOFFCInfoSym(
".GCC.command.line", RSOS.str());
3370char PPCAIXAsmPrinter::ID = 0;
3373 "AIX PPC Assembly Printer",
false,
false)
3377LLVMInitializePowerPCAsmPrinter() {
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static AMDGPUMCExpr::Specifier getSpecifier(unsigned MOFlags)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
static bool hasDebugInfo(const MachineFunction *MF)
Module.h This file contains the declarations for the Module class.
static std::string getRegisterName(const TargetRegisterInfo *TRI, Register Reg)
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
Promote Memory to Register
static void collectTOCStats(PPCAsmPrinter::TOCEntryType Type)
static bool isSpecialLLVMGlobalArrayForStaticInit(const GlobalVariable *GV)
static bool isSpecialLLVMGlobalArrayToSkip(const GlobalVariable *GV)
#define GENBOOLCOMMENT(Prefix, V, Field)
static MCSymbol * getMCSymbolForTOCPseudoMO(const MachineOperand &MO, AsmPrinter &AP)
Map a machine operand for a TOC pseudo-machine instruction to its corresponding MCSymbol.
static void setOptionalCodeModel(MCSymbolXCOFF *XSym, CodeModel::Model CM)
static AsmPrinter * createPPCAsmPrinterPass(TargetMachine &tm, std::unique_ptr< MCStreamer > &&Streamer)
static PPCAsmPrinter::TOCEntryType getTOCEntryTypeForMO(const MachineOperand &MO)
static CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)
static std::string convertToSinitPriority(int Priority)
static MCSymbol * createMCSymbolForTlsGetAddr(MCContext &Ctx, unsigned MIOpc)
This helper function creates the TlsGetAddr/TlsGetMod MCSymbol for AIX.
#define GENVALUECOMMENT(PrefixAndName, V, Field)
static unsigned mapToSinitPriority(int P)
static void tocDataChecks(unsigned PointerSize, const GlobalVariable *GV)
static cl::opt< bool > EnableSSPCanaryBitInTB("aix-ssp-tb-bit", cl::init(false), cl::desc("Enable Passing SSP Canary info in Trackback on AIX"), cl::Hidden)
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Provides a library for accessing information about this process and other processes on the operating ...
static SDValue lowerConstant(SDValue Op, SelectionDAG &DAG, const RISCVSubtarget &Subtarget)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
This file implements a set that has insertion order iteration characteristics.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This class is intended to be used as a driving class for all asm writers.
MCSymbol * getSymbol(const GlobalValue *GV) const
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
virtual void emitStartOfAsmFile(Module &)
This virtual method can be overridden by targets that want to emit something at the start of their fi...
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
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.
LLVM_ABI unsigned getPointerSize(unsigned AS=0) const
The pointer representation size in bytes, rounded up to a whole number of bytes.
TypeSize getTypeSizeInBits(Type *Ty) const
Size examples:
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
static LLVM_ABI GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
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.
LinkageTypes getLinkage() const
bool hasPrivateLinkage() const
ThreadLocalMode getThreadLocalMode() const
bool isDeclarationForLinker() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
bool hasCommonLinkage() const
bool hasAppendingLinkage() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ ExternalLinkage
Externally visible function.
@ AvailableExternallyLinkage
Available for inspection, not emission.
@ ExternalWeakLinkage
ExternalWeak linkage description.
Type * getValueType() const
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists.
bool hasInitializer() const
Definitions have initializers, declarations don't.
std::optional< CodeModel::Model > getCodeModel() const
Get the custom code model of this global if it has one.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Opcode getOpcode() const
Get the kind of this binary expression.
static const MCBinaryExpr * createSub(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)
Context object for machine code objects.
void addOperand(const MCOperand Op)
void setOpcode(unsigned Op)
const MCOperand & getOperand(unsigned i) const
static MCOperand createExpr(const MCExpr *Val)
MCRegister getReg() const
Returns the register number.
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
void setPerSymbolCodeModel(MCSymbolXCOFF::CodeModel Model)
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 StringRef getString() const
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
MCSection * getSection() const
Returns the Section this function belongs to.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineOperand class - Representation of each machine instruction operand.
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isCPI() const
isCPI - Tests if this is a MO_ConstantPoolIndex operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isSymbol() const
isSymbol - Tests if this is a MO_ExternalSymbol operand.
bool isJTI() const
isJTI - Tests if this is a MO_JumpTableIndex operand.
const BlockAddress * getBlockAddress() const
unsigned getTargetFlags() const
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
bool isBlockAddress() const
isBlockAddress - Tests if this is a MO_BlockAddress operand.
Register getReg() const
getReg - Returns the register number.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
int64_t getOffset() const
Return the offset from the symbol in this operand.
iterator find(const KeyT &Key)
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
uint64_t getTOCSaveOffset() const
getTOCSaveOffset - Return the previous frame offset to save the TOC register – 64-bit SVR4 ABI only.
uint32_t getParmsType() const
MCSymbol * getPICOffsetSymbol(MachineFunction &MF) const
const SmallVectorImpl< Register > & getMustSaveCRs() const
unsigned getFloatingPointParmsNum() const
bool isAIXFuncUseTLSIEForLD() const
MCSymbol * getGlobalEPSymbol(MachineFunction &MF) const
MCSymbol * getLocalEPSymbol(MachineFunction &MF) const
unsigned getVectorParmsNum() const
int getVarArgsFrameIndex() const
bool usesTOCBasePtr() const
bool hasVectorParms() const
uint32_t getVecExtParmsType() const
MCSymbol * getTOCOffsetSymbol(MachineFunction &MF) const
unsigned getFixedParmsNum() const
static const char * getRegisterName(MCRegister Reg)
static bool hasTLSFlag(unsigned TF)
Register getFrameRegister(const MachineFunction &MF) const override
bool is32BitELFABI() const
const PPCFrameLowering * getFrameLowering() const override
bool isUsingPCRelativeCalls() const
CodeModel::Model getCodeModel(const TargetMachine &TM, const GlobalValue *GV) const
Calculates the effective code model for argument GV.
const PPCRegisterInfo * getRegisterInfo() const override
bool isGVIndirectSymbol(const GlobalValue *GV) const
True if the GV will be accessed via an indirect symbol.
virtual void emitAbiVersion(int AbiVersion)
virtual void emitLocalEntry(MCSymbolELF *S, const MCExpr *LocalOffset)
virtual void emitTCEntry(const MCSymbol &S, PPCMCExpr::Specifier Kind)
virtual void emitMachine(StringRef CPU)
bool isThreadBSSLocal() const
static SectionKind getText()
static SectionKind getData()
bool isThreadLocal() const
bool isGlobalWriteableData() const
bool insert(const value_type &X)
Insert a new element into the SetVector.
void push_back(const T &Elt)
LLVM_ABI void recordPatchPoint(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a patchpoint instruction.
LLVM_ABI void recordStackMap(const MCSymbol &L, const MachineInstr &MI)
Generate a stackmap record for a stackmap instruction.
StringRef - Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & Cases(std::initializer_list< StringLiteral > CaseStrings, T Value)
static bool ShouldSetSSPCanaryBitInTB(const MachineFunction *MF)
static MCSymbol * getEHInfoTableSymbol(const MachineFunction *MF)
static XCOFF::StorageClass getStorageClassForGlobal(const GlobalValue *GV)
static bool ShouldEmitEHBlock(const MachineFunction *MF)
Primary interface to the complete machine description for the target machine.
const Triple & getTargetTriple() const
bool isOSAIX() const
Tests whether the OS is AIX.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
LLVM_ABI 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.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
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.
static LLVM_ABI Pid getProcessId()
Get the process's identifier.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ MO_TLSLDM_FLAG
MO_TLSLDM_FLAG - on AIX the ML relocation type is only valid for a reference to a TOC symbol from the...
@ MO_TPREL_PCREL_FLAG
MO_TPREL_PCREL_FLAG = MO_PCREL_FLAG | MO_TPREL_FLAG.
@ MO_GOT_TPREL_PCREL_FLAG
MO_GOT_TPREL_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
@ MO_TLSGDM_FLAG
MO_TLSGDM_FLAG - If this bit is set the symbol reference is relative to the region handle of TLS Gene...
@ MO_TLSLD_FLAG
MO_TLSLD_FLAG - If this bit is set the symbol reference is relative to TLS Local Dynamic model.
@ MO_TPREL_FLAG
MO_TPREL_FLAG - If this bit is set, the symbol reference is relative to the thread pointer and the sy...
@ MO_GOT_TLSLD_PCREL_FLAG
MO_GOT_TLSLD_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
@ MO_TLSGD_FLAG
MO_TLSGD_FLAG - If this bit is set the symbol reference is relative to TLS General Dynamic model for ...
@ MO_GOT_TLSGD_PCREL_FLAG
MO_GOT_TLSGD_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
LLVM_ABI StringRef getNormalizedPPCTargetCPU(const Triple &T, StringRef CPUName="")
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
const char * stripRegisterPrefix(const char *RegName)
stripRegisterPrefix - This method strips the character prefix from a register name so that only the n...
static bool isVRRegister(unsigned Reg)
Predicate InvertPredicate(Predicate Opcode)
Invert the specified predicate. != -> ==, < -> >=.
static bool isVFRegister(unsigned Reg)
@ CE
Windows NT (Windows on ARM)
void emitInstruction(MCObjectStreamer &, const MCInst &Inst, const MCSubtargetInfo &STI)
LLVM_ABI SmallString< 32 > getExtendedTBTableFlagString(uint8_t Flag)
LLVM_ABI XCOFF::CFileCpuId getCpuID(StringRef CPU)
LLVM_ABI Expected< SmallString< 32 > > parseParmsTypeWithVecInfo(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum, unsigned VectorParmsNum)
LLVM_ABI Expected< SmallString< 32 > > parseParmsType(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum)
LLVM_ABI Expected< SmallString< 32 > > parseVectorParmsType(uint32_t Value, unsigned ParmsNum)
@ TCPU_INVALID
Invalid id - assumes POWER for old objects.
StorageMappingClass
Storage Mapping Class definitions.
@ XMC_RO
Read Only Constant.
@ XMC_TD
Scalar data item in the TOC.
LLVM_ABI StringRef getTCPUString(XCOFF::CFileCpuId TCPU)
LLVM_ABI StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId)
constexpr uint8_t AllocRegNo
@ XTY_SD
Csect definition for initialized storage.
@ XTY_ER
External reference.
initializer< Ty > init(const Ty &Val)
unsigned combineHashValue(unsigned a, unsigned b)
Simplistic combination of 32-bit hash values into 32-bit hash values.
constexpr uint64_t PointerSize
aarch64 pointer size.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
FunctionAddr VTableAddr Value
Target & getThePPC64LETarget()
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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
bool LowerPPCMachineOperandToMCOperand(const MachineOperand &MO, MCOperand &OutMO, AsmPrinter &AP)
Target & getThePPC32Target()
std::string utostr(uint64_t X, bool isNeg=false)
auto dyn_cast_or_null(const Y &Val)
FunctionAddr VTableAddr uintptr_t uintptr_t Version
LLVM_ABI std::string getUniqueModuleId(Module *M)
Produce a unique identifier for this module by taking the MD5 sum of the names of the module's strong...
void LowerPPCMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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.
Target & getThePPC64Target()
LLVM_ABI uint64_t get_threadid()
Return the current thread id, as used in various OS system calls.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
DWARFExpression::Operation Op
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
constexpr int32_t SignExtend32(uint32_t X)
Sign-extend the number in the bottom B bits of X to a 32-bit integer.
Target & getThePPC32LETarget()
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
std::pair< MCSection *, uint32_t > MCSectionSubPair
std::string itostr(int64_t X)
@ MCSA_Extern
.extern (XCOFF)
@ MCSA_Invalid
Not a valid directive.
Implement std::hash so that hash_code can be used in STL containers.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
static bool isEqual(const TOCKey &A, const TOCKey &B)
std::pair< const MCSymbol *, PPCMCExpr::Specifier > TOCKey
static unsigned getHashValue(const TOCKey &PairVal)
static TOCKey getTombstoneKey()
static TOCKey getEmptyKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn)
RegisterAsmPrinter - Register an AsmPrinter implementation for the given target.
static constexpr uint32_t FPRSavedMask
static constexpr uint16_t NumberOfVRSavedMask
static constexpr uint8_t NumberOfFloatingPointParmsShift
static constexpr uint32_t NumberOfFixedParmsMask
static constexpr uint16_t HasVMXInstructionMask
static constexpr uint32_t IsLRSavedMask
static constexpr uint16_t HasVarArgsMask
static constexpr uint32_t IsAllocaUsedMask
static constexpr uint16_t IsVRSavedOnStackMask
static constexpr uint16_t NumberOfVectorParmsMask
static constexpr uint32_t IsFloatingPointPresentMask
static constexpr uint32_t FPRSavedShift
static constexpr uint32_t NumberOfFloatingPointParmsMask
static constexpr uint32_t HasControlledStorageMask
static constexpr uint32_t HasExtensionTableMask
static constexpr uint32_t HasTraceBackTableOffsetMask
static constexpr uint32_t IsCRSavedMask
static constexpr uint8_t NumberOfFixedParmsShift
static constexpr uint32_t GPRSavedMask
static constexpr uint8_t NumberOfVectorParmsShift
static constexpr uint32_t HasParmsOnStackMask
static constexpr uint32_t IsFunctionNamePresentMask
static constexpr uint32_t IsBackChainStoredMask
static constexpr uint32_t IsInterruptHandlerMask
static constexpr uint32_t HasVectorInfoMask
static constexpr uint8_t NumberOfVRSavedShift
static constexpr uint32_t GPRSavedShift