LLVM 24.0.0git
PPCAsmPrinter.cpp
Go to the documentation of this file.
1//===-- PPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly ------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a printer that converts from our internal representation
10// of machine-dependent LLVM code to PowerPC assembly language. This printer is
11// the output mechanism used by `llc'.
12//
13// Documentation at http://developer.apple.com/documentation/DeveloperTools/
14// Reference/Assembler/ASMIntroduction/chapter_1_section_1.html
15//
16//===----------------------------------------------------------------------===//
17
23#include "PPC.h"
24#include "PPCInstrInfo.h"
26#include "PPCSubtarget.h"
27#include "PPCTargetMachine.h"
29#include "llvm/ADT/MapVector.h"
30#include "llvm/ADT/SetVector.h"
31#include "llvm/ADT/Statistic.h"
33#include "llvm/ADT/StringRef.h"
34#include "llvm/ADT/Twine.h"
46#include "llvm/IR/DataLayout.h"
47#include "llvm/IR/GlobalValue.h"
49#include "llvm/IR/Module.h"
51#include "llvm/MC/MCAsmInfo.h"
52#include "llvm/MC/MCContext.h"
54#include "llvm/MC/MCExpr.h"
55#include "llvm/MC/MCInst.h"
59#include "llvm/MC/MCStreamer.h"
60#include "llvm/MC/MCSymbol.h"
61#include "llvm/MC/MCSymbolELF.h"
63#include "llvm/MC/SectionKind.h"
68#include "llvm/Support/Debug.h"
69#include "llvm/Support/Error.h"
79#include <cassert>
80#include <cstdint>
81#include <memory>
82#include <new>
83
84using namespace llvm;
85using namespace llvm::XCOFF;
86using namespace PatternMatch;
87
88#define DEBUG_TYPE "asmprinter"
89
90STATISTIC(NumTOCEntries, "Number of Total TOC Entries Emitted.");
91STATISTIC(NumTOCConstPool, "Number of Constant Pool TOC Entries.");
92STATISTIC(NumTOCGlobalInternal,
93 "Number of Internal Linkage Global TOC Entries.");
94STATISTIC(NumTOCGlobalExternal,
95 "Number of External Linkage Global TOC Entries.");
96STATISTIC(NumTOCJumpTable, "Number of Jump Table TOC Entries.");
97STATISTIC(NumTOCThreadLocal, "Number of Thread Local TOC Entries.");
98STATISTIC(NumTOCBlockAddress, "Number of Block Address TOC Entries.");
99STATISTIC(NumTOCEHBlock, "Number of EH Block TOC Entries.");
100
101// Specialize DenseMapInfo to allow
102// std::pair<const MCSymbol *, PPCMCExpr::Specifier> in DenseMap.
103// This specialization is needed here because that type is used as keys in the
104// map representing TOC entries.
105namespace llvm {
106template <>
107struct DenseMapInfo<std::pair<const MCSymbol *, PPCMCExpr::Specifier>> {
108 using TOCKey = std::pair<const MCSymbol *, PPCMCExpr::Specifier>;
109
110 static unsigned getHashValue(const TOCKey &PairVal) {
113 DenseMapInfo<int>::getHashValue(PairVal.second));
114 }
115 static bool isEqual(const TOCKey &A, const TOCKey &B) { return A == B; }
116};
117} // end namespace llvm
118
119namespace {
120
121enum {
122 // GNU attribute tags for PowerPC ABI
123 Tag_GNU_Power_ABI_FP = 4,
124 Tag_GNU_Power_ABI_Vector = 8,
125 Tag_GNU_Power_ABI_Struct_Return = 12,
126
127 // GNU attribute values for PowerPC float ABI, as combination of two parts
128 Val_GNU_Power_ABI_NoFloat = 0b00,
129 Val_GNU_Power_ABI_HardFloat_DP = 0b01,
130 Val_GNU_Power_ABI_SoftFloat_DP = 0b10,
131 Val_GNU_Power_ABI_HardFloat_SP = 0b11,
132
133 Val_GNU_Power_ABI_LDBL_IBM128 = 0b0100,
134 Val_GNU_Power_ABI_LDBL_64 = 0b1000,
135 Val_GNU_Power_ABI_LDBL_IEEE128 = 0b1100,
136};
137
138class PPCAsmPrinter : public AsmPrinter {
139protected:
140 // For TLS on AIX, we need to be able to identify TOC entries of specific
141 // specifier so we can add the right relocations when we generate the
142 // entries. So each entry is represented by a pair of MCSymbol and
143 // VariantKind. For example, we need to be able to identify the following
144 // entry as a TLSGD entry so we can add the @m relocation:
145 // .tc .i[TC],i[TL]@m
146 // By default, 0 is used for the specifier.
147 MapVector<std::pair<const MCSymbol *, PPCMCExpr::Specifier>, MCSymbol *> TOC;
148 const PPCSubtarget *Subtarget = nullptr;
149
150 // Keep track of the number of TLS variables and their corresponding
151 // addresses, which is then used for the assembly printing of
152 // non-TOC-based local-exec variables.
153 MapVector<const GlobalValue *, uint64_t> TLSVarsToAddressMapping;
154
155public:
156 explicit PPCAsmPrinter(TargetMachine &TM,
157 std::unique_ptr<MCStreamer> Streamer, char &ID)
158 : AsmPrinter(TM, std::move(Streamer), ID) {}
159
160 StringRef getPassName() const override { return "PowerPC Assembly Printer"; }
161
162 enum TOCEntryType {
163 TOCType_ConstantPool,
164 TOCType_GlobalExternal,
165 TOCType_GlobalInternal,
166 TOCType_JumpTable,
167 TOCType_ThreadLocal,
168 TOCType_BlockAddress,
169 TOCType_EHBlock
170 };
171
172 MCSymbol *lookUpOrCreateTOCEntry(const MCSymbol *Sym, TOCEntryType Type,
174
175 bool doInitialization(Module &M) override {
176 if (!TOC.empty())
177 TOC.clear();
179 }
180
181 const MCExpr *symbolWithSpecifier(const MCSymbol *S,
183 void emitInstruction(const MachineInstr *MI) override;
184
185 /// This function is for PrintAsmOperand and PrintAsmMemoryOperand,
186 /// invoked by EmitMSInlineAsmStr and EmitGCCInlineAsmStr only.
187 /// The \p MI would be INLINEASM ONLY.
188 void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
189
190 void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override;
191 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
192 const char *ExtraCode, raw_ostream &O) override;
193 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
194 const char *ExtraCode, raw_ostream &O) override;
195
196 void LowerSTACKMAP(StackMaps &SM, const MachineInstr &MI);
197 void LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI);
198 void emitTlsCall(const MachineInstr *MI, PPCMCExpr::Specifier VK);
199 void EmitAIXTlsCallHelper(const MachineInstr *MI);
200 const MCExpr *getAdjustedFasterLocalExpr(const MachineOperand &MO,
201 int64_t Offset);
202 bool runOnMachineFunction(MachineFunction &MF) override {
203 Subtarget = &MF.getSubtarget<PPCSubtarget>();
205 emitXRayTable();
206 return Changed;
207 }
208};
209
210/// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
211class PPCLinuxAsmPrinter : public PPCAsmPrinter {
212public:
213 static char ID;
214
215 explicit PPCLinuxAsmPrinter(TargetMachine &TM,
216 std::unique_ptr<MCStreamer> Streamer)
217 : PPCAsmPrinter(TM, std::move(Streamer), ID) {}
218
219 StringRef getPassName() const override {
220 return "Linux PPC Assembly Printer";
221 }
222
223 void emitGNUAttributes(Module &M);
224
225 void emitStartOfAsmFile(Module &M) override;
226 void emitEndOfAsmFile(Module &) override;
227
228 void emitFunctionEntryLabel() override;
229
230 void emitFunctionBodyStart() override;
231 void emitFunctionBodyEnd() override;
232 void emitInstruction(const MachineInstr *MI) override;
233};
234
235class PPCAIXAsmPrinter : public PPCAsmPrinter {
236private:
237 /// Symbols lowered from ExternalSymbolSDNodes, we will need to emit extern
238 /// linkage for them in AIX.
239 SmallSetVector<MCSymbol *, 8> ExtSymSDNodeSymbols;
240
241 /// A format indicator and unique trailing identifier to form part of the
242 /// sinit/sterm function names.
243 std::string FormatIndicatorAndUniqueModId;
244
245 // Record a list of GlobalAlias associated with a GlobalObject.
246 // This is used for AIX's extra-label-at-definition aliasing strategy.
247 DenseMap<const GlobalObject *, SmallVector<const GlobalAlias *, 1>>
248 GOAliasMap;
249
250 uint16_t getNumberOfVRSaved();
251 void emitTracebackTable();
252
254
255 void emitGlobalVariableHelper(const GlobalVariable *);
256
257 // Get the offset of an alias based on its AliaseeObject.
258 uint64_t getAliasOffset(const Constant *C);
259
260public:
261 static char ID;
262
263 PPCAIXAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer)
264 : PPCAsmPrinter(TM, std::move(Streamer), ID) {
265 if (MAI.isLittleEndian())
267 "cannot create AIX PPC Assembly Printer for a little-endian target");
268 }
269
270 StringRef getPassName() const override { return "AIX PPC Assembly Printer"; }
271
272 bool doInitialization(Module &M) override;
273
274 void emitXXStructorList(const DataLayout &DL, const Constant *List,
275 bool IsCtor) override;
276
277 void SetupMachineFunction(MachineFunction &MF) override;
278
279 void emitGlobalVariable(const GlobalVariable *GV) override;
280
281 void emitFunctionDescriptor() override;
282
283 void emitFunctionEntryLabel() override;
284
285 void emitFunctionBodyEnd() override;
286
287 void emitPGORefs(Module &M);
288
289 void emitGCOVRefs();
290
291 void emitEndOfAsmFile(Module &) override;
292
293 void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const override;
294
295 void emitInstruction(const MachineInstr *MI) override;
296
297 bool doFinalization(Module &M) override;
298
299 void emitTTypeReference(const GlobalValue *GV, unsigned Encoding) override;
300
301 void emitModuleCommandLines(Module &M) override;
302
303 void emitRefMetadata(const GlobalObject *);
304
305 void emitGlobalIFunc(Module &M, const GlobalIFunc &GI) override;
306};
307
308} // end anonymous namespace
309
310void PPCAsmPrinter::PrintSymbolOperand(const MachineOperand &MO,
311 raw_ostream &O) {
312 // Computing the address of a global symbol, not calling it.
313 const GlobalValue *GV = MO.getGlobal();
314 getSymbol(GV)->print(O, MAI);
315 printOffset(MO.getOffset(), O);
316}
317
318void PPCAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
319 raw_ostream &O) {
320 const DataLayout &DL = getDataLayout();
321 const MachineOperand &MO = MI->getOperand(OpNo);
322
323 switch (MO.getType()) {
325 // The MI is INLINEASM ONLY and UseVSXReg is always false.
327
328 // Linux assembler (Others?) does not take register mnemonics.
329 // FIXME - What about special registers used in mfspr/mtspr?
331 return;
332 }
334 O << MO.getImm();
335 return;
336
338 MO.getMBB()->getSymbol()->print(O, MAI);
339 return;
341 O << DL.getInternalSymbolPrefix() << "CPI" << getFunctionNumber() << '_'
342 << MO.getIndex();
343 return;
345 GetBlockAddressSymbol(MO.getBlockAddress())->print(O, MAI);
346 return;
348 PrintSymbolOperand(MO, O);
349 return;
350 }
351
352 default:
353 O << "<unknown operand type: " << (unsigned)MO.getType() << ">";
354 return;
355 }
356}
357
358/// PrintAsmOperand - Print out an operand for an inline asm expression.
359///
360bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
361 const char *ExtraCode, raw_ostream &O) {
362 // Does this asm operand have a single letter operand modifier?
363 if (ExtraCode && ExtraCode[0]) {
364 if (ExtraCode[1] != 0) return true; // Unknown modifier.
365
366 switch (ExtraCode[0]) {
367 default:
368 // See if this is a generic print operand
369 return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, O);
370 case 'L': // Write second word of DImode reference.
371 // Verify that this operand has two consecutive registers.
372 if (!MI->getOperand(OpNo).isReg() ||
373 OpNo+1 == MI->getNumOperands() ||
374 !MI->getOperand(OpNo+1).isReg())
375 return true;
376 ++OpNo; // Return the high-part.
377 break;
378 case 'I':
379 // Write 'i' if an integer constant, otherwise nothing. Used to print
380 // addi vs add, etc.
381 if (MI->getOperand(OpNo).isImm())
382 O << "i";
383 return false;
384 case 'x':
385 if(!MI->getOperand(OpNo).isReg())
386 return true;
387 // This operand uses VSX numbering.
388 // If the operand is a VMX register, convert it to a VSX register.
389 Register Reg = MI->getOperand(OpNo).getReg();
391 Reg = PPC::VSX32 + (Reg - PPC::V0);
392 else if (PPC::isVFRegister(Reg))
393 Reg = PPC::VSX32 + (Reg - PPC::VF0);
394 const char *RegName;
397 O << RegName;
398 return false;
399 }
400 }
401
402 printOperand(MI, OpNo, O);
403 return false;
404}
405
406// At the moment, all inline asm memory operands are a single register.
407// In any case, the output of this routine should always be just one
408// assembler operand.
409bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
410 const char *ExtraCode,
411 raw_ostream &O) {
412 if (ExtraCode && ExtraCode[0]) {
413 if (ExtraCode[1] != 0) return true; // Unknown modifier.
414
415 switch (ExtraCode[0]) {
416 default: return true; // Unknown modifier.
417 case 'L': // A memory reference to the upper word of a double word op.
418 O << getDataLayout().getPointerSize() << "(";
419 printOperand(MI, OpNo, O);
420 O << ")";
421 return false;
422 case 'y': // A memory reference for an X-form instruction
423 O << "0, ";
424 printOperand(MI, OpNo, O);
425 return false;
426 case 'I':
427 // Write 'i' if an integer constant, otherwise nothing. Used to print
428 // addi vs add, etc.
429 if (MI->getOperand(OpNo).isImm())
430 O << "i";
431 return false;
432 case 'U': // Print 'u' for update form.
433 case 'X': // Print 'x' for indexed form.
434 // FIXME: Currently for PowerPC memory operands are always loaded
435 // into a register, so we never get an update or indexed form.
436 // This is bad even for offset forms, since even if we know we
437 // have a value in -16(r1), we will generate a load into r<n>
438 // and then load from 0(r<n>). Until that issue is fixed,
439 // tolerate 'U' and 'X' but don't output anything.
440 assert(MI->getOperand(OpNo).isReg());
441 return false;
442 }
443 }
444
445 assert(MI->getOperand(OpNo).isReg());
446 O << "0(";
447 printOperand(MI, OpNo, O);
448 O << ")";
449 return false;
450}
451
452static void collectTOCStats(PPCAsmPrinter::TOCEntryType Type) {
453 ++NumTOCEntries;
454 switch (Type) {
455 case PPCAsmPrinter::TOCType_ConstantPool:
456 ++NumTOCConstPool;
457 break;
458 case PPCAsmPrinter::TOCType_GlobalInternal:
459 ++NumTOCGlobalInternal;
460 break;
461 case PPCAsmPrinter::TOCType_GlobalExternal:
462 ++NumTOCGlobalExternal;
463 break;
464 case PPCAsmPrinter::TOCType_JumpTable:
465 ++NumTOCJumpTable;
466 break;
467 case PPCAsmPrinter::TOCType_ThreadLocal:
468 ++NumTOCThreadLocal;
469 break;
470 case PPCAsmPrinter::TOCType_BlockAddress:
471 ++NumTOCBlockAddress;
472 break;
473 case PPCAsmPrinter::TOCType_EHBlock:
474 ++NumTOCEHBlock;
475 break;
476 }
477}
478
480 const TargetMachine &TM,
481 const MachineOperand &MO) {
482 CodeModel::Model ModuleModel = TM.getCodeModel();
483
484 // If the operand is not a global address then there is no
485 // global variable to carry an attribute.
487 return ModuleModel;
488
489 const GlobalValue *GV = MO.getGlobal();
490 assert(GV && "expected global for MO_GlobalAddress");
491
492 return S.getCodeModel(TM, GV);
493}
494
496 switch (CM) {
497 case CodeModel::Large:
499 return;
500 case CodeModel::Small:
502 return;
503 default:
504 report_fatal_error("Invalid code model for AIX");
505 }
506}
507
508/// lookUpOrCreateTOCEntry -- Given a symbol, look up whether a TOC entry
509/// exists for it. If not, create one. Then return a symbol that references
510/// the TOC entry.
511MCSymbol *PPCAsmPrinter::lookUpOrCreateTOCEntry(const MCSymbol *Sym,
512 TOCEntryType Type,
514 // If this is a new TOC entry add statistics about it.
515 auto [It, Inserted] = TOC.try_emplace({Sym, Spec});
516 if (Inserted)
518
519 MCSymbol *&TOCEntry = It->second;
520 if (!TOCEntry)
521 TOCEntry = createTempSymbol("C");
522 return TOCEntry;
523}
524
525void PPCAsmPrinter::LowerSTACKMAP(StackMaps &SM, const MachineInstr &MI) {
526 unsigned NumNOPBytes = MI.getOperand(1).getImm();
527
528 auto &Ctx = OutStreamer->getContext();
529 MCSymbol *MILabel = Ctx.createTempSymbol();
530 OutStreamer->emitLabel(MILabel);
531
532 SM.recordStackMap(*MILabel, MI);
533 assert(NumNOPBytes % 4 == 0 && "Invalid number of NOP bytes requested!");
534
535 // Scan ahead to trim the shadow.
536 const MachineBasicBlock &MBB = *MI.getParent();
538 ++MII;
539 while (NumNOPBytes > 0) {
540 if (MII != MBB.end() && MII->isDebugInstr()) {
541 ++MII;
542 continue;
543 }
544 if (MII == MBB.end() || MII->isCall() ||
545 MII->getOpcode() == TargetOpcode::PATCHPOINT ||
546 MII->getOpcode() == TargetOpcode::STACKMAP)
547 break;
548 ++MII;
549 NumNOPBytes -= 4;
550 }
551
552 // Emit nops.
553 for (unsigned i = 0; i < NumNOPBytes; i += 4)
554 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::NOP));
555}
556
557// Lower a patchpoint of the form:
558// [<def>], <id>, <numBytes>, <target>, <numArgs>
559void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
560 auto &Ctx = OutStreamer->getContext();
561 MCSymbol *MILabel = Ctx.createTempSymbol();
562 OutStreamer->emitLabel(MILabel);
563
564 SM.recordPatchPoint(*MILabel, MI);
565 PatchPointOpers Opers(&MI);
566
567 unsigned EncodedBytes = 0;
568 const MachineOperand &CalleeMO = Opers.getCallTarget();
569
570 if (CalleeMO.isImm()) {
571 int64_t CallTarget = CalleeMO.getImm();
572 if (CallTarget) {
573 assert((CallTarget & 0xFFFFFFFFFFFF) == CallTarget &&
574 "High 16 bits of call target should be zero.");
575 Register ScratchReg = MI.getOperand(Opers.getNextScratchIdx()).getReg();
576 EncodedBytes = 0;
577 // Materialize the jump address:
578 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LI8)
579 .addReg(ScratchReg)
580 .addImm((CallTarget >> 32) & 0xFFFF));
581 ++EncodedBytes;
582
583 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::RLDIC)
584 .addReg(ScratchReg)
585 .addReg(ScratchReg)
586 .addImm(32).addImm(16));
587 ++EncodedBytes;
588
589 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ORIS8)
590 .addReg(ScratchReg)
591 .addReg(ScratchReg)
592 .addImm((CallTarget >> 16) & 0xFFFF));
593 ++EncodedBytes;
594
595 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ORI8)
596 .addReg(ScratchReg)
597 .addReg(ScratchReg)
598 .addImm(CallTarget & 0xFFFF));
599 ++EncodedBytes;
600
601 // Save the current TOC pointer before the remote call.
602 int TOCSaveOffset = Subtarget->getFrameLowering()->getTOCSaveOffset();
603 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::STD)
604 .addReg(PPC::X2)
605 .addImm(TOCSaveOffset)
606 .addReg(PPC::X1));
607 ++EncodedBytes;
608
609 // If we're on ELFv1, then we need to load the actual function pointer
610 // from the function descriptor.
611 if (!Subtarget->isELFv2ABI()) {
612 // Load the new TOC pointer and the function address, but not r11
613 // (needing this is rare, and loading it here would prevent passing it
614 // via a 'nest' parameter.
615 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
616 .addReg(PPC::X2)
617 .addImm(8)
618 .addReg(ScratchReg));
619 ++EncodedBytes;
620
621 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
622 .addReg(ScratchReg)
623 .addImm(0)
624 .addReg(ScratchReg));
625 ++EncodedBytes;
626 }
627
628 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MTCTR8)
629 .addReg(ScratchReg));
630 ++EncodedBytes;
631
632 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BCTRL8));
633 ++EncodedBytes;
634
635 // Restore the TOC pointer after the call.
636 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
637 .addReg(PPC::X2)
638 .addImm(TOCSaveOffset)
639 .addReg(PPC::X1));
640 ++EncodedBytes;
641 }
642 } else if (CalleeMO.isGlobal()) {
643 const GlobalValue *GValue = CalleeMO.getGlobal();
644 MCSymbol *MOSymbol = getSymbol(GValue);
645 const MCExpr *SymVar = MCSymbolRefExpr::create(MOSymbol, OutContext);
646
647 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BL8_NOP)
648 .addExpr(SymVar));
649 EncodedBytes += 2;
650 }
651
652 // Each instruction is 4 bytes.
653 EncodedBytes *= 4;
654
655 // Emit padding.
656 unsigned NumBytes = Opers.getNumPatchBytes();
657 if (NumBytes < EncodedBytes)
659 "Patchpoint can't request size less than the length of a call.");
660
661 assert((NumBytes - EncodedBytes) % 4 == 0 &&
662 "Invalid number of NOP bytes requested!");
663 for (unsigned i = EncodedBytes; i < NumBytes; i += 4)
664 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::NOP));
665}
666
667/// This helper function creates the TlsGetAddr/TlsGetMod MCSymbol for AIX. We
668/// will create the csect and use the qual-name symbol instead of creating just
669/// the external symbol.
670static MCSymbol *createMCSymbolForTlsGetAddr(MCContext &Ctx, unsigned MIOpc) {
671 StringRef SymName;
672 switch (MIOpc) {
673 default:
674 SymName = ".__tls_get_addr";
675 break;
676 case PPC::GETtlsTpointer32AIX:
677 SymName = ".__get_tpointer";
678 break;
679 case PPC::GETtlsMOD32AIX:
680 case PPC::GETtlsMOD64AIX:
681 SymName = ".__tls_get_mod";
682 break;
683 }
684 return Ctx
685 .getXCOFFSection(SymName, SectionKind::getText(),
687 ->getQualNameSymbol();
688}
689
690void PPCAsmPrinter::EmitAIXTlsCallHelper(const MachineInstr *MI) {
691 assert(Subtarget->isAIXABI() &&
692 "Only expecting to emit calls to get the thread pointer on AIX!");
693
694 MCSymbol *TlsCall = createMCSymbolForTlsGetAddr(OutContext, MI->getOpcode());
695 const MCExpr *TlsRef = MCSymbolRefExpr::create(TlsCall, OutContext);
696 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BLA).addExpr(TlsRef));
697}
698
699/// Given a GETtls[ld]ADDR[32] instruction, print a call to __tls_get_addr to
700/// the current output stream.
701void PPCAsmPrinter::emitTlsCall(const MachineInstr *MI,
704 unsigned Opcode = PPC::BL8_NOP_TLS;
705
706 assert(MI->getNumOperands() >= 3 && "Expecting at least 3 operands from MI");
707 if (MI->getOperand(2).getTargetFlags() == PPCII::MO_GOT_TLSGD_PCREL_FLAG ||
708 MI->getOperand(2).getTargetFlags() == PPCII::MO_GOT_TLSLD_PCREL_FLAG) {
710 Opcode = PPC::BL8_NOTOC_TLS;
711 }
712 const Module *M = MF->getFunction().getParent();
713
714 assert(MI->getOperand(0).isReg() &&
715 ((Subtarget->isPPC64() && MI->getOperand(0).getReg() == PPC::X3) ||
716 (!Subtarget->isPPC64() && MI->getOperand(0).getReg() == PPC::R3)) &&
717 "GETtls[ld]ADDR[32] must define GPR3");
718 assert(MI->getOperand(1).isReg() &&
719 ((Subtarget->isPPC64() && MI->getOperand(1).getReg() == PPC::X3) ||
720 (!Subtarget->isPPC64() && MI->getOperand(1).getReg() == PPC::R3)) &&
721 "GETtls[ld]ADDR[32] must read GPR3");
722
723 if (Subtarget->isAIXABI()) {
724 // For TLSGD, the variable offset should already be in R4 and the region
725 // handle should already be in R3. We generate an absolute branch to
726 // .__tls_get_addr. For TLSLD, the module handle should already be in R3.
727 // We generate an absolute branch to .__tls_get_mod.
728 Register VarOffsetReg = Subtarget->isPPC64() ? PPC::X4 : PPC::R4;
729 (void)VarOffsetReg;
730 assert((MI->getOpcode() == PPC::GETtlsMOD32AIX ||
731 MI->getOpcode() == PPC::GETtlsMOD64AIX ||
732 (MI->getOperand(2).isReg() &&
733 MI->getOperand(2).getReg() == VarOffsetReg)) &&
734 "GETtls[ld]ADDR[32] must read GPR4");
735 EmitAIXTlsCallHelper(MI);
736 return;
737 }
738
739 MCSymbol *TlsGetAddr = OutContext.getOrCreateSymbol("__tls_get_addr");
740
741 if (Subtarget->is32BitELFABI() && isPositionIndependent())
743
744 const MCExpr *TlsRef = MCSymbolRefExpr::create(TlsGetAddr, Kind, OutContext);
745
746 // Add 32768 offset to the symbol so we follow up the latest GOT/PLT ABI.
747 if (Kind == PPC::S_PLT && Subtarget->isSecurePlt() &&
748 M->getPICLevel() == PICLevel::BigPIC)
750 TlsRef, MCConstantExpr::create(32768, OutContext), OutContext);
751 const MachineOperand &MO = MI->getOperand(2);
752 const GlobalValue *GValue = MO.getGlobal();
753 MCSymbol *MOSymbol = getSymbol(GValue);
754 const MCExpr *SymVar = MCSymbolRefExpr::create(MOSymbol, VK, OutContext);
755 EmitToStreamer(*OutStreamer,
756 MCInstBuilder(Subtarget->isPPC64() ? Opcode
757 : (unsigned)PPC::BL_TLS)
758 .addExpr(TlsRef)
759 .addExpr(SymVar));
760}
761
762/// Map a machine operand for a TOC pseudo-machine instruction to its
763/// corresponding MCSymbol.
765 AsmPrinter &AP) {
766 switch (MO.getType()) {
768 return AP.getSymbol(MO.getGlobal());
770 return AP.GetCPISymbol(MO.getIndex());
772 return AP.GetJTISymbol(MO.getIndex());
775 default:
776 llvm_unreachable("Unexpected operand type to get symbol.");
777 }
778}
779
780static PPCAsmPrinter::TOCEntryType
785 return PPCAsmPrinter::TOCType_GlobalExternal;
786
787 return PPCAsmPrinter::TOCType_GlobalInternal;
788}
789
790static PPCAsmPrinter::TOCEntryType
792 // Use the target flags to determine if this MO is Thread Local.
793 // If we don't do this it comes out as Global.
795 return PPCAsmPrinter::TOCType_ThreadLocal;
796
797 switch (MO.getType()) {
799 const GlobalValue *GlobalV = MO.getGlobal();
800 return getTOCEntryTypeForLinkage(GlobalV->getLinkage());
801 }
803 return PPCAsmPrinter::TOCType_ConstantPool;
805 return PPCAsmPrinter::TOCType_JumpTable;
807 return PPCAsmPrinter::TOCType_BlockAddress;
808 default:
809 llvm_unreachable("Unexpected operand type to get TOC type.");
810 }
811}
812
813const MCExpr *PPCAsmPrinter::symbolWithSpecifier(const MCSymbol *S,
815 return MCSymbolRefExpr::create(S, Spec, OutContext);
816}
817
818/// EmitInstruction -- Print out a single PowerPC MI in Darwin syntax to
819/// the current output stream.
820///
821void PPCAsmPrinter::emitInstruction(const MachineInstr *MI) {
822 PPC_MC::verifyInstructionPredicates(MI->getOpcode(),
823 getSubtargetInfo().getFeatureBits());
824
825 MCInst TmpInst;
826 const bool IsPPC64 = Subtarget->isPPC64();
827 const bool IsAIX = Subtarget->isAIXABI();
828 const bool HasAIXSmallLocalTLS = Subtarget->hasAIXSmallLocalExecTLS() ||
829 Subtarget->hasAIXSmallLocalDynamicTLS();
830 const Module *M = MF->getFunction().getParent();
831 PICLevel::Level PL = M->getPICLevel();
832
833#ifndef NDEBUG
834 // Validate that SPE and FPU are mutually exclusive in codegen
835 if (!MI->isInlineAsm()) {
836 for (const MachineOperand &MO: MI->operands()) {
837 if (MO.isReg()) {
838 Register Reg = MO.getReg();
839 if (Subtarget->hasSPE()) {
840 if (PPC::F4RCRegClass.contains(Reg) ||
841 PPC::F8RCRegClass.contains(Reg) ||
842 PPC::VFRCRegClass.contains(Reg) ||
843 PPC::VRRCRegClass.contains(Reg) ||
844 PPC::VSFRCRegClass.contains(Reg) ||
845 PPC::VSSRCRegClass.contains(Reg)
846 )
847 llvm_unreachable("SPE targets cannot have FPRegs!");
848 } else {
849 if (PPC::SPERCRegClass.contains(Reg))
850 llvm_unreachable("SPE register found in FPU-targeted code!");
851 }
852 }
853 }
854 }
855#endif
856
857 auto getTOCRelocAdjustedExprForXCOFF = [this](const MCExpr *Expr,
858 ptrdiff_t OriginalOffset) {
859 // Apply an offset to the TOC-based expression such that the adjusted
860 // notional offset from the TOC base (to be encoded into the instruction's D
861 // or DS field) is the signed 16-bit truncation of the original notional
862 // offset from the TOC base.
863 // This is consistent with the treatment used both by XL C/C++ and
864 // by AIX ld -r.
865 ptrdiff_t Adjustment =
866 OriginalOffset - llvm::SignExtend32<16>(OriginalOffset);
868 Expr, MCConstantExpr::create(-Adjustment, OutContext), OutContext);
869 };
870
871 auto getTOCEntryLoadingExprForXCOFF =
872 [IsPPC64, getTOCRelocAdjustedExprForXCOFF,
873 this](const MCSymbol *MOSymbol, const MCExpr *Expr,
874 PPCMCExpr::Specifier VK = PPC::S_None) -> const MCExpr * {
875 const unsigned EntryByteSize = IsPPC64 ? 8 : 4;
876 const auto TOCEntryIter = TOC.find({MOSymbol, VK});
877 assert(TOCEntryIter != TOC.end() &&
878 "Could not find the TOC entry for this symbol.");
879 const ptrdiff_t EntryDistanceFromTOCBase =
880 (TOCEntryIter - TOC.begin()) * EntryByteSize;
881 constexpr int16_t PositiveTOCRange = INT16_MAX;
882
883 if (EntryDistanceFromTOCBase > PositiveTOCRange)
884 return getTOCRelocAdjustedExprForXCOFF(Expr, EntryDistanceFromTOCBase);
885
886 return Expr;
887 };
888 auto getSpecifier = [&](const MachineOperand &MO) {
889 // For TLS initial-exec and local-exec accesses on AIX, we have one TOC
890 // entry for the symbol (with the variable offset), which is differentiated
891 // by MO_TPREL_FLAG.
892 unsigned Flag = MO.getTargetFlags();
893 if (Flag == PPCII::MO_TPREL_FLAG ||
896 assert(MO.isGlobal() && "Only expecting a global MachineOperand here!\n");
897 TLSModel::Model Model = TM.getTLSModel(MO.getGlobal());
898 if (Model == TLSModel::LocalExec)
899 return PPC::S_AIX_TLSLE;
900 if (Model == TLSModel::InitialExec)
901 return PPC::S_AIX_TLSIE;
902 // On AIX, TLS model opt may have turned local-dynamic accesses into
903 // initial-exec accesses.
904 PPCFunctionInfo *FuncInfo = MF->getInfo<PPCFunctionInfo>();
905 if (Model == TLSModel::LocalDynamic &&
906 FuncInfo->isAIXFuncUseTLSIEForLD()) {
908 dbgs() << "Current function uses IE access for default LD vars.\n");
909 return PPC::S_AIX_TLSIE;
910 }
911 llvm_unreachable("Only expecting local-exec or initial-exec accesses!");
912 }
913 // For GD TLS access on AIX, we have two TOC entries for the symbol (one for
914 // the variable offset and the other for the region handle). They are
915 // differentiated by MO_TLSGD_FLAG and MO_TLSGDM_FLAG.
916 if (Flag == PPCII::MO_TLSGDM_FLAG)
917 return PPC::S_AIX_TLSGDM;
919 return PPC::S_AIX_TLSGD;
920 // For local-dynamic TLS access on AIX, we have one TOC entry for the symbol
921 // (the variable offset) and one shared TOC entry for the module handle.
922 // They are differentiated by MO_TLSLD_FLAG and MO_TLSLDM_FLAG.
923 if (Flag == PPCII::MO_TLSLD_FLAG && IsAIX)
924 return PPC::S_AIX_TLSLD;
925 if (Flag == PPCII::MO_TLSLDM_FLAG && IsAIX)
926 return PPC::S_AIX_TLSML;
927 return PPC::S_None;
928 };
929
930 // Lower multi-instruction pseudo operations.
931 switch (MI->getOpcode()) {
932 default: break;
933 case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
934 assert(!Subtarget->isAIXABI() &&
935 "AIX does not support patchable function entry!");
936 const Function &F = MF->getFunction();
937 unsigned Num = F.getFnAttributeAsParsedInteger("patchable-function-entry");
938 if (!Num)
939 return;
940 emitNops(Num);
941 return;
942 }
943 case TargetOpcode::DBG_VALUE:
944 llvm_unreachable("Should be handled target independently");
945 case TargetOpcode::STACKMAP:
946 return LowerSTACKMAP(SM, *MI);
947 case TargetOpcode::PATCHPOINT:
948 return LowerPATCHPOINT(SM, *MI);
949
950 case PPC::MoveGOTtoLR: {
951 // Transform %lr = MoveGOTtoLR
952 // Into this: bl _GLOBAL_OFFSET_TABLE_@local-4
953 // _GLOBAL_OFFSET_TABLE_@local-4 (instruction preceding
954 // _GLOBAL_OFFSET_TABLE_) has exactly one instruction:
955 // blrl
956 // This will return the pointer to _GLOBAL_OFFSET_TABLE_@local
957 MCSymbol *GOTSymbol =
958 OutContext.getOrCreateSymbol(StringRef("_GLOBAL_OFFSET_TABLE_"));
959 const MCExpr *OffsExpr = MCBinaryExpr::createSub(
960 MCSymbolRefExpr::create(GOTSymbol, PPC::S_LOCAL, OutContext),
961 MCConstantExpr::create(4, OutContext), OutContext);
962
963 // Emit the 'bl'.
964 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BL).addExpr(OffsExpr));
965 return;
966 }
967 case PPC::MovePCtoLR:
968 case PPC::MovePCtoLR8: {
969 // Transform %lr = MovePCtoLR
970 // Into this, where the label is the PIC base:
971 // bl L1$pb
972 // L1$pb:
973 MCSymbol *PICBase = MF->getPICBaseSymbol();
974
975 // Emit 'bcl 20,31,.+4' so the link stack is not corrupted.
976 EmitToStreamer(*OutStreamer,
977 MCInstBuilder(PPC::BCLalways)
978 // FIXME: We would like an efficient form for this, so we
979 // don't have to do a lot of extra uniquing.
980 .addExpr(MCSymbolRefExpr::create(PICBase, OutContext)));
981
982 // Emit the label.
983 OutStreamer->emitLabel(PICBase);
984 return;
985 }
986 case PPC::UpdateGBR: {
987 // Transform %rd = UpdateGBR(%rt, %ri)
988 // Into: lwz %rt, .L0$poff - .L0$pb(%ri)
989 // add %rd, %rt, %ri
990 // or into (if secure plt mode is on):
991 // addis r30, r30, {.LTOC,_GLOBAL_OFFSET_TABLE} - .L0$pb@ha
992 // addi r30, r30, {.LTOC,_GLOBAL_OFFSET_TABLE} - .L0$pb@l
993 // Get the offset from the GOT Base Register to the GOT
994 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
995 if (Subtarget->isSecurePlt() && isPositionIndependent() ) {
996 MCRegister PICR = TmpInst.getOperand(0).getReg();
997 MCSymbol *BaseSymbol = OutContext.getOrCreateSymbol(
998 M->getPICLevel() == PICLevel::SmallPIC ? "_GLOBAL_OFFSET_TABLE_"
999 : ".LTOC");
1000 const MCExpr *PB =
1001 MCSymbolRefExpr::create(MF->getPICBaseSymbol(), OutContext);
1002
1003 const MCExpr *DeltaExpr = MCBinaryExpr::createSub(
1004 MCSymbolRefExpr::create(BaseSymbol, OutContext), PB, OutContext);
1005
1006 const MCExpr *DeltaHi =
1007 MCSpecifierExpr::create(DeltaExpr, PPC::S_HA, OutContext);
1008 EmitToStreamer(
1009 *OutStreamer,
1010 MCInstBuilder(PPC::ADDIS).addReg(PICR).addReg(PICR).addExpr(DeltaHi));
1011
1012 const MCExpr *DeltaLo =
1013 MCSpecifierExpr::create(DeltaExpr, PPC::S_LO, OutContext);
1014 EmitToStreamer(
1015 *OutStreamer,
1016 MCInstBuilder(PPC::ADDI).addReg(PICR).addReg(PICR).addExpr(DeltaLo));
1017 return;
1018 } else {
1019 MCSymbol *PICOffset =
1020 MF->getInfo<PPCFunctionInfo>()->getPICOffsetSymbol(*MF);
1021 TmpInst.setOpcode(PPC::LWZ);
1022 const MCExpr *Exp = MCSymbolRefExpr::create(PICOffset, OutContext);
1023 const MCExpr *PB =
1024 MCSymbolRefExpr::create(MF->getPICBaseSymbol(),
1025 OutContext);
1026 const MCOperand TR = TmpInst.getOperand(1);
1027 const MCOperand PICR = TmpInst.getOperand(0);
1028
1029 // Step 1: lwz %rt, .L$poff - .L$pb(%ri)
1030 TmpInst.getOperand(1) =
1032 TmpInst.getOperand(0) = TR;
1033 TmpInst.getOperand(2) = PICR;
1034 EmitToStreamer(*OutStreamer, TmpInst);
1035
1036 TmpInst.setOpcode(PPC::ADD4);
1037 TmpInst.getOperand(0) = PICR;
1038 TmpInst.getOperand(1) = TR;
1039 TmpInst.getOperand(2) = PICR;
1040 EmitToStreamer(*OutStreamer, TmpInst);
1041 return;
1042 }
1043 }
1044 case PPC::LWZtoc: {
1045 // Transform %rN = LWZtoc @op1, %r2
1046 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1047
1048 // Change the opcode to LWZ.
1049 TmpInst.setOpcode(PPC::LWZ);
1050
1051 const MachineOperand &MO = MI->getOperand(1);
1052 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isBlockAddress()) &&
1053 "Invalid operand for LWZtoc.");
1054
1055 // Map the operand to its corresponding MCSymbol.
1056 const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
1057
1058 // Create a reference to the GOT entry for the symbol. The GOT entry will be
1059 // synthesized later.
1060 if (PL == PICLevel::SmallPIC && !IsAIX) {
1061 const MCExpr *Exp = symbolWithSpecifier(MOSymbol, PPC::S_GOT);
1062 TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
1063 EmitToStreamer(*OutStreamer, TmpInst);
1064 return;
1065 }
1066
1068
1069 // Otherwise, use the TOC. 'TOCEntry' is a label used to reference the
1070 // storage allocated in the TOC which contains the address of
1071 // 'MOSymbol'. Said TOC entry will be synthesized later.
1072 MCSymbol *TOCEntry =
1073 lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
1074 const MCExpr *Exp = MCSymbolRefExpr::create(TOCEntry, OutContext);
1075
1076 // AIX uses the label directly as the lwz displacement operand for
1077 // references into the toc section. The displacement value will be generated
1078 // relative to the toc-base.
1079 if (IsAIX) {
1080 assert(
1082 "This pseudo should only be selected for 32-bit small code model.");
1083 Exp = getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp, VK);
1084 TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
1085
1086 // Print MO for better readability
1087 if (isVerbose())
1088 OutStreamer->getCommentOS() << MO << '\n';
1089 EmitToStreamer(*OutStreamer, TmpInst);
1090 return;
1091 }
1092
1093 // Create an explicit subtract expression between the local symbol and
1094 // '.LTOC' to manifest the toc-relative offset.
1095 const MCExpr *PB = MCSymbolRefExpr::create(
1096 OutContext.getOrCreateSymbol(Twine(".LTOC")), OutContext);
1097 Exp = MCBinaryExpr::createSub(Exp, PB, OutContext);
1098 TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
1099 EmitToStreamer(*OutStreamer, TmpInst);
1100 return;
1101 }
1102 case PPC::ADDItoc:
1103 case PPC::ADDItoc8: {
1104 assert(IsAIX && TM.getCodeModel() == CodeModel::Small &&
1105 "PseudoOp only valid for small code model AIX");
1106
1107 // Transform %rN = ADDItoc/8 %r2, @op1.
1108 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1109
1110 // Change the opcode to load address.
1111 TmpInst.setOpcode((!IsPPC64) ? (PPC::LA) : (PPC::LA8));
1112
1113 const MachineOperand &MO = MI->getOperand(2);
1114 assert(MO.isGlobal() && "Invalid operand for ADDItoc[8].");
1115
1116 // Map the operand to its corresponding MCSymbol.
1117 const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
1118
1119 const MCExpr *Exp = MCSymbolRefExpr::create(MOSymbol, OutContext);
1120
1121 TmpInst.getOperand(2) = MCOperand::createExpr(Exp);
1122 EmitToStreamer(*OutStreamer, TmpInst);
1123 return;
1124 }
1125 case PPC::LDtocJTI:
1126 case PPC::LDtocCPT:
1127 case PPC::LDtocBA:
1128 case PPC::LDtoc: {
1129 // Transform %x3 = LDtoc @min1, %x2
1130 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1131
1132 // Change the opcode to LD.
1133 TmpInst.setOpcode(PPC::LD);
1134
1135 const MachineOperand &MO = MI->getOperand(1);
1136 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isBlockAddress()) &&
1137 "Invalid operand!");
1138
1139 // Map the operand to its corresponding MCSymbol.
1140 const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
1141
1143
1144 // Map the machine operand to its corresponding MCSymbol, then map the
1145 // global address operand to be a reference to the TOC entry we will
1146 // synthesize later.
1147 MCSymbol *TOCEntry =
1148 lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
1149
1150 PPCMCExpr::Specifier VKExpr = IsAIX ? PPC::S_None : PPC::S_TOC;
1151 const MCExpr *Exp = symbolWithSpecifier(TOCEntry, VKExpr);
1152 TmpInst.getOperand(1) = MCOperand::createExpr(
1153 IsAIX ? getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp, VK) : Exp);
1154
1155 // Print MO for better readability
1156 if (isVerbose() && IsAIX)
1157 OutStreamer->getCommentOS() << MO << '\n';
1158 EmitToStreamer(*OutStreamer, TmpInst);
1159 return;
1160 }
1161 case PPC::ADDIStocHA: {
1162 const MachineOperand &MO = MI->getOperand(2);
1163
1164 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isBlockAddress()) &&
1165 "Invalid operand for ADDIStocHA.");
1166 assert((IsAIX && !IsPPC64 &&
1167 getCodeModel(*Subtarget, TM, MO) == CodeModel::Large) &&
1168 "This pseudo should only be selected for 32-bit large code model on"
1169 " AIX.");
1170
1171 // Transform %rd = ADDIStocHA %rA, @sym(%r2)
1172 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1173
1174 // Change the opcode to ADDIS.
1175 TmpInst.setOpcode(PPC::ADDIS);
1176
1177 // Map the machine operand to its corresponding MCSymbol.
1178 MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
1179
1181
1182 // Map the global address operand to be a reference to the TOC entry we
1183 // will synthesize later. 'TOCEntry' is a label used to reference the
1184 // storage allocated in the TOC which contains the address of 'MOSymbol'.
1185 // If the symbol does not have the toc-data attribute, then we create the
1186 // TOC entry on AIX. If the toc-data attribute is used, the TOC entry
1187 // contains the data rather than the address of the MOSymbol.
1188 if (![](const MachineOperand &MO) {
1189 if (!MO.isGlobal())
1190 return false;
1191
1192 const GlobalVariable *GV = dyn_cast<GlobalVariable>(MO.getGlobal());
1193 if (!GV)
1194 return false;
1195 return GV->hasAttribute("toc-data");
1196 }(MO)) {
1197 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
1198 }
1199
1200 const MCExpr *Exp = symbolWithSpecifier(MOSymbol, PPC::S_U);
1201 TmpInst.getOperand(2) = MCOperand::createExpr(Exp);
1202 EmitToStreamer(*OutStreamer, TmpInst);
1203 return;
1204 }
1205 case PPC::LWZtocL: {
1206 const MachineOperand &MO = MI->getOperand(1);
1207
1208 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isBlockAddress()) &&
1209 "Invalid operand for LWZtocL.");
1210 assert(IsAIX && !IsPPC64 &&
1212 "This pseudo should only be selected for 32-bit large code model on"
1213 " AIX.");
1214
1215 // Transform %rd = LWZtocL @sym, %rs.
1216 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1217
1218 // Change the opcode to lwz.
1219 TmpInst.setOpcode(PPC::LWZ);
1220
1221 // Map the machine operand to its corresponding MCSymbol.
1222 MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
1223
1225
1226 // Always use TOC on AIX. Map the global address operand to be a reference
1227 // to the TOC entry we will synthesize later. 'TOCEntry' is a label used to
1228 // reference the storage allocated in the TOC which contains the address of
1229 // 'MOSymbol'.
1230 MCSymbol *TOCEntry =
1231 lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
1232 const MCExpr *Exp = symbolWithSpecifier(TOCEntry, PPC::S_L);
1233 TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
1234 EmitToStreamer(*OutStreamer, TmpInst);
1235 return;
1236 }
1237 case PPC::ADDIStocHA8: {
1238 // Transform %xd = ADDIStocHA8 %x2, @sym
1239 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1240
1241 // Change the opcode to ADDIS8. If the global address is the address of
1242 // an external symbol, is a jump table address, is a block address, or is a
1243 // constant pool index with large code model enabled, then generate a TOC
1244 // entry and reference that. Otherwise, reference the symbol directly.
1245 TmpInst.setOpcode(PPC::ADDIS8);
1246
1247 const MachineOperand &MO = MI->getOperand(2);
1248 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isBlockAddress()) &&
1249 "Invalid operand for ADDIStocHA8!");
1250
1251 const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
1252
1254
1255 const bool GlobalToc =
1256 MO.isGlobal() && Subtarget->isGVIndirectSymbol(MO.getGlobal());
1257
1258 const CodeModel::Model CM =
1259 IsAIX ? getCodeModel(*Subtarget, TM, MO) : TM.getCodeModel();
1260
1261 if (GlobalToc || MO.isJTI() || MO.isBlockAddress() ||
1262 (MO.isCPI() && CM == CodeModel::Large))
1263 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
1264
1265 VK = IsAIX ? PPC::S_U : PPC::S_TOC_HA;
1266
1267 const MCExpr *Exp = symbolWithSpecifier(MOSymbol, VK);
1268
1269 if (!MO.isJTI() && MO.getOffset())
1272 OutContext),
1273 OutContext);
1274
1275 TmpInst.getOperand(2) = MCOperand::createExpr(Exp);
1276 EmitToStreamer(*OutStreamer, TmpInst);
1277 return;
1278 }
1279 case PPC::LDtocL: {
1280 // Transform %xd = LDtocL @sym, %xs
1281 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1282
1283 // Change the opcode to LD. If the global address is the address of
1284 // an external symbol, is a jump table address, is a block address, or is
1285 // a constant pool index with large code model enabled, then generate a
1286 // TOC entry and reference that. Otherwise, reference the symbol directly.
1287 TmpInst.setOpcode(PPC::LD);
1288
1289 const MachineOperand &MO = MI->getOperand(1);
1290 assert((MO.isGlobal() || MO.isCPI() || MO.isJTI() ||
1291 MO.isBlockAddress()) &&
1292 "Invalid operand for LDtocL!");
1293
1295 (!MO.isGlobal() || Subtarget->isGVIndirectSymbol(MO.getGlobal())) &&
1296 "LDtocL used on symbol that could be accessed directly is "
1297 "invalid. Must match ADDIStocHA8."));
1298
1299 const MCSymbol *MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
1300
1302 CodeModel::Model CM =
1303 IsAIX ? getCodeModel(*Subtarget, TM, MO) : TM.getCodeModel();
1304 if (!MO.isCPI() || CM == CodeModel::Large)
1305 MOSymbol = lookUpOrCreateTOCEntry(MOSymbol, getTOCEntryTypeForMO(MO), VK);
1306
1307 VK = IsAIX ? PPC::S_L : PPC::S_TOC_LO;
1308 const MCExpr *Exp = symbolWithSpecifier(MOSymbol, VK);
1309 TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
1310 EmitToStreamer(*OutStreamer, TmpInst);
1311 return;
1312 }
1313 case PPC::ADDItocL:
1314 case PPC::ADDItocL8: {
1315 // Transform %xd = ADDItocL %xs, @sym
1316 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1317
1318 unsigned Op = MI->getOpcode();
1319
1320 // Change the opcode to load address for toc-data.
1321 // ADDItocL is only used for 32-bit toc-data on AIX and will always use LA.
1322 TmpInst.setOpcode(Op == PPC::ADDItocL8 ? (IsAIX ? PPC::LA8 : PPC::ADDI8)
1323 : PPC::LA);
1324
1325 const MachineOperand &MO = MI->getOperand(2);
1326 assert((Op == PPC::ADDItocL8)
1327 ? (MO.isGlobal() || MO.isCPI())
1328 : MO.isGlobal() && "Invalid operand for ADDItocL8.");
1329 assert(!(MO.isGlobal() && Subtarget->isGVIndirectSymbol(MO.getGlobal())) &&
1330 "Interposable definitions must use indirect accesses.");
1331
1332 // Map the operand to its corresponding MCSymbol.
1333 const MCSymbol *const MOSymbol = getMCSymbolForTOCPseudoMO(MO, *this);
1334
1335 const MCExpr *Exp = MCSymbolRefExpr::create(
1336 MOSymbol, IsAIX ? PPC::S_L : PPC::S_TOC_LO, OutContext);
1337
1338 TmpInst.getOperand(2) = MCOperand::createExpr(Exp);
1339 EmitToStreamer(*OutStreamer, TmpInst);
1340 return;
1341 }
1342 case PPC::ADDISgotTprelHA: {
1343 // Transform: %xd = ADDISgotTprelHA %x2, @sym
1344 // Into: %xd = ADDIS8 %x2, sym@got@tlsgd@ha
1345 assert(IsPPC64 && "Not supported for 32-bit PowerPC");
1346 const MachineOperand &MO = MI->getOperand(2);
1347 const GlobalValue *GValue = MO.getGlobal();
1348 MCSymbol *MOSymbol = getSymbol(GValue);
1349 const MCExpr *SymGotTprel =
1350 symbolWithSpecifier(MOSymbol, PPC::S_GOT_TPREL_HA);
1351 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
1352 .addReg(MI->getOperand(0).getReg())
1353 .addReg(MI->getOperand(1).getReg())
1354 .addExpr(SymGotTprel));
1355 return;
1356 }
1357 case PPC::LDgotTprelL:
1358 case PPC::LDgotTprelL32: {
1359 // Transform %xd = LDgotTprelL @sym, %xs
1360 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1361
1362 // Change the opcode to LD.
1363 TmpInst.setOpcode(IsPPC64 ? PPC::LD : PPC::LWZ);
1364 const MachineOperand &MO = MI->getOperand(1);
1365 const GlobalValue *GValue = MO.getGlobal();
1366 MCSymbol *MOSymbol = getSymbol(GValue);
1367 const MCExpr *Exp = symbolWithSpecifier(
1368 MOSymbol, IsPPC64 ? PPC::S_GOT_TPREL_LO : PPC::S_GOT_TPREL);
1369 TmpInst.getOperand(1) = MCOperand::createExpr(Exp);
1370 EmitToStreamer(*OutStreamer, TmpInst);
1371 return;
1372 }
1373
1374 case PPC::PPC32PICGOT: {
1375 MCSymbol *GOTSymbol = OutContext.getOrCreateSymbol(StringRef("_GLOBAL_OFFSET_TABLE_"));
1376 MCSymbol *GOTRef = OutContext.createTempSymbol();
1377 MCSymbol *NextInstr = OutContext.createTempSymbol();
1378
1379 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::BL)
1380 // FIXME: We would like an efficient form for this, so we don't have to do
1381 // a lot of extra uniquing.
1382 .addExpr(MCSymbolRefExpr::create(NextInstr, OutContext)));
1383 const MCExpr *OffsExpr =
1384 MCBinaryExpr::createSub(MCSymbolRefExpr::create(GOTSymbol, OutContext),
1385 MCSymbolRefExpr::create(GOTRef, OutContext),
1386 OutContext);
1387 OutStreamer->emitLabel(GOTRef);
1388 OutStreamer->emitValue(OffsExpr, 4);
1389 OutStreamer->emitLabel(NextInstr);
1390 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MFLR)
1391 .addReg(MI->getOperand(0).getReg()));
1392 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LWZ)
1393 .addReg(MI->getOperand(1).getReg())
1394 .addImm(0)
1395 .addReg(MI->getOperand(0).getReg()));
1396 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADD4)
1397 .addReg(MI->getOperand(0).getReg())
1398 .addReg(MI->getOperand(1).getReg())
1399 .addReg(MI->getOperand(0).getReg()));
1400 return;
1401 }
1402 case PPC::PPC32GOT: {
1403 MCSymbol *GOTSymbol =
1404 OutContext.getOrCreateSymbol(StringRef("_GLOBAL_OFFSET_TABLE_"));
1405 const MCExpr *SymGotTlsL =
1406 MCSpecifierExpr::create(GOTSymbol, PPC::S_LO, OutContext);
1407 const MCExpr *SymGotTlsHA =
1408 MCSpecifierExpr::create(GOTSymbol, PPC::S_HA, OutContext);
1409 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LI)
1410 .addReg(MI->getOperand(0).getReg())
1411 .addExpr(SymGotTlsL));
1412 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS)
1413 .addReg(MI->getOperand(0).getReg())
1414 .addReg(MI->getOperand(0).getReg())
1415 .addExpr(SymGotTlsHA));
1416 return;
1417 }
1418 case PPC::ADDIStlsgdHA: {
1419 // Transform: %xd = ADDIStlsgdHA %x2, @sym
1420 // Into: %xd = ADDIS8 %x2, sym@got@tlsgd@ha
1421 assert(IsPPC64 && "Not supported for 32-bit PowerPC");
1422 const MachineOperand &MO = MI->getOperand(2);
1423 const GlobalValue *GValue = MO.getGlobal();
1424 MCSymbol *MOSymbol = getSymbol(GValue);
1425 const MCExpr *SymGotTlsGD =
1426 symbolWithSpecifier(MOSymbol, PPC::S_GOT_TLSGD_HA);
1427 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
1428 .addReg(MI->getOperand(0).getReg())
1429 .addReg(MI->getOperand(1).getReg())
1430 .addExpr(SymGotTlsGD));
1431 return;
1432 }
1433 case PPC::ADDItlsgdL:
1434 // Transform: %xd = ADDItlsgdL %xs, @sym
1435 // Into: %xd = ADDI8 %xs, sym@got@tlsgd@l
1436 case PPC::ADDItlsgdL32: {
1437 // Transform: %rd = ADDItlsgdL32 %rs, @sym
1438 // Into: %rd = ADDI %rs, sym@got@tlsgd
1439 const MachineOperand &MO = MI->getOperand(2);
1440 const GlobalValue *GValue = MO.getGlobal();
1441 MCSymbol *MOSymbol = getSymbol(GValue);
1442 const MCExpr *SymGotTlsGD = symbolWithSpecifier(
1443 MOSymbol, IsPPC64 ? PPC::S_GOT_TLSGD_LO : PPC::S_GOT_TLSGD);
1444 EmitToStreamer(*OutStreamer,
1445 MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
1446 .addReg(MI->getOperand(0).getReg())
1447 .addReg(MI->getOperand(1).getReg())
1448 .addExpr(SymGotTlsGD));
1449 return;
1450 }
1451 case PPC::GETtlsMOD32AIX:
1452 case PPC::GETtlsMOD64AIX:
1453 // Transform: %r3 = GETtlsMODNNAIX %r3 (for NN == 32/64).
1454 // Into: BLA .__tls_get_mod()
1455 // Input parameter is a module handle (_$TLSML[TC]@ml) for all variables.
1456 case PPC::GETtlsADDR:
1457 // Transform: %x3 = GETtlsADDR %x3, @sym
1458 // Into: BL8_NOP_TLS __tls_get_addr(sym at tlsgd)
1459 case PPC::GETtlsADDRPCREL:
1460 case PPC::GETtlsADDR32AIX:
1461 case PPC::GETtlsADDR64AIX:
1462 // Transform: %r3 = GETtlsADDRNNAIX %r3, %r4 (for NN == 32/64).
1463 // Into: BLA .__tls_get_addr()
1464 // Unlike on Linux, there is no symbol or relocation needed for this call.
1465 case PPC::GETtlsADDR32: {
1466 // Transform: %r3 = GETtlsADDR32 %r3, @sym
1467 // Into: BL_TLS __tls_get_addr(sym at tlsgd)@PLT
1468 emitTlsCall(MI, PPC::S_TLSGD);
1469 return;
1470 }
1471 case PPC::GETtlsTpointer32AIX: {
1472 // Transform: %r3 = GETtlsTpointer32AIX
1473 // Into: BLA .__get_tpointer()
1474 EmitAIXTlsCallHelper(MI);
1475 return;
1476 }
1477 case PPC::ADDIStlsldHA: {
1478 // Transform: %xd = ADDIStlsldHA %x2, @sym
1479 // Into: %xd = ADDIS8 %x2, sym@got@tlsld@ha
1480 assert(IsPPC64 && "Not supported for 32-bit PowerPC");
1481 const MachineOperand &MO = MI->getOperand(2);
1482 const GlobalValue *GValue = MO.getGlobal();
1483 MCSymbol *MOSymbol = getSymbol(GValue);
1484 const MCExpr *SymGotTlsLD =
1485 symbolWithSpecifier(MOSymbol, PPC::S_GOT_TLSLD_HA);
1486 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS8)
1487 .addReg(MI->getOperand(0).getReg())
1488 .addReg(MI->getOperand(1).getReg())
1489 .addExpr(SymGotTlsLD));
1490 return;
1491 }
1492 case PPC::ADDItlsldL:
1493 // Transform: %xd = ADDItlsldL %xs, @sym
1494 // Into: %xd = ADDI8 %xs, sym@got@tlsld@l
1495 case PPC::ADDItlsldL32: {
1496 // Transform: %rd = ADDItlsldL32 %rs, @sym
1497 // Into: %rd = ADDI %rs, sym@got@tlsld
1498 const MachineOperand &MO = MI->getOperand(2);
1499 const GlobalValue *GValue = MO.getGlobal();
1500 MCSymbol *MOSymbol = getSymbol(GValue);
1501 const MCExpr *SymGotTlsLD = symbolWithSpecifier(
1502 MOSymbol, IsPPC64 ? PPC::S_GOT_TLSLD_LO : PPC::S_GOT_TLSLD);
1503 EmitToStreamer(*OutStreamer,
1504 MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
1505 .addReg(MI->getOperand(0).getReg())
1506 .addReg(MI->getOperand(1).getReg())
1507 .addExpr(SymGotTlsLD));
1508 return;
1509 }
1510 case PPC::GETtlsldADDR:
1511 // Transform: %x3 = GETtlsldADDR %x3, @sym
1512 // Into: BL8_NOP_TLS __tls_get_addr(sym at tlsld)
1513 case PPC::GETtlsldADDRPCREL:
1514 case PPC::GETtlsldADDR32: {
1515 // Transform: %r3 = GETtlsldADDR32 %r3, @sym
1516 // Into: BL_TLS __tls_get_addr(sym at tlsld)@PLT
1517 emitTlsCall(MI, PPC::S_TLSLD);
1518 return;
1519 }
1520 case PPC::ADDISdtprelHA:
1521 // Transform: %xd = ADDISdtprelHA %xs, @sym
1522 // Into: %xd = ADDIS8 %xs, sym@dtprel@ha
1523 case PPC::ADDISdtprelHA32: {
1524 // Transform: %rd = ADDISdtprelHA32 %rs, @sym
1525 // Into: %rd = ADDIS %rs, sym@dtprel@ha
1526 const MachineOperand &MO = MI->getOperand(2);
1527 const GlobalValue *GValue = MO.getGlobal();
1528 MCSymbol *MOSymbol = getSymbol(GValue);
1529 const MCExpr *SymDtprel = symbolWithSpecifier(MOSymbol, PPC::S_DTPREL_HA);
1530 EmitToStreamer(
1531 *OutStreamer,
1532 MCInstBuilder(IsPPC64 ? PPC::ADDIS8 : PPC::ADDIS)
1533 .addReg(MI->getOperand(0).getReg())
1534 .addReg(MI->getOperand(1).getReg())
1535 .addExpr(SymDtprel));
1536 return;
1537 }
1538 case PPC::PADDIdtprel: {
1539 // Transform: %rd = PADDIdtprel %rs, @sym
1540 // Into: %rd = PADDI8 %rs, sym@dtprel
1541 const MachineOperand &MO = MI->getOperand(2);
1542 const GlobalValue *GValue = MO.getGlobal();
1543 MCSymbol *MOSymbol = getSymbol(GValue);
1544 const MCExpr *SymDtprel = symbolWithSpecifier(MOSymbol, PPC::S_DTPREL);
1545 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::PADDI8)
1546 .addReg(MI->getOperand(0).getReg())
1547 .addReg(MI->getOperand(1).getReg())
1548 .addExpr(SymDtprel));
1549 return;
1550 }
1551
1552 case PPC::ADDIdtprelL:
1553 // Transform: %xd = ADDIdtprelL %xs, @sym
1554 // Into: %xd = ADDI8 %xs, sym@dtprel@l
1555 case PPC::ADDIdtprelL32: {
1556 // Transform: %rd = ADDIdtprelL32 %rs, @sym
1557 // Into: %rd = ADDI %rs, sym@dtprel@l
1558 const MachineOperand &MO = MI->getOperand(2);
1559 const GlobalValue *GValue = MO.getGlobal();
1560 MCSymbol *MOSymbol = getSymbol(GValue);
1561 const MCExpr *SymDtprel = symbolWithSpecifier(MOSymbol, PPC::S_DTPREL_LO);
1562 EmitToStreamer(*OutStreamer,
1563 MCInstBuilder(IsPPC64 ? PPC::ADDI8 : PPC::ADDI)
1564 .addReg(MI->getOperand(0).getReg())
1565 .addReg(MI->getOperand(1).getReg())
1566 .addExpr(SymDtprel));
1567 return;
1568 }
1569 case PPC::MFOCRF:
1570 case PPC::MFOCRF8:
1571 if (!Subtarget->hasMFOCRF()) {
1572 // Transform: %r3 = MFOCRF %cr7
1573 // Into: %r3 = MFCR ;; cr7
1574 unsigned NewOpcode =
1575 MI->getOpcode() == PPC::MFOCRF ? PPC::MFCR : PPC::MFCR8;
1576 OutStreamer->AddComment(PPCInstPrinter::
1577 getRegisterName(MI->getOperand(1).getReg()));
1578 EmitToStreamer(*OutStreamer, MCInstBuilder(NewOpcode)
1579 .addReg(MI->getOperand(0).getReg()));
1580 return;
1581 }
1582 break;
1583 case PPC::MTOCRF:
1584 case PPC::MTOCRF8:
1585 if (!Subtarget->hasMFOCRF()) {
1586 // Transform: %cr7 = MTOCRF %r3
1587 // Into: MTCRF mask, %r3 ;; cr7
1588 unsigned NewOpcode =
1589 MI->getOpcode() == PPC::MTOCRF ? PPC::MTCRF : PPC::MTCRF8;
1590 unsigned Mask = 0x80 >> OutContext.getRegisterInfo()
1591 ->getEncodingValue(MI->getOperand(0).getReg());
1592 OutStreamer->AddComment(PPCInstPrinter::
1593 getRegisterName(MI->getOperand(0).getReg()));
1594 EmitToStreamer(*OutStreamer, MCInstBuilder(NewOpcode)
1595 .addImm(Mask)
1596 .addReg(MI->getOperand(1).getReg()));
1597 return;
1598 }
1599 break;
1600 case PPC::LD:
1601 case PPC::STD:
1602 case PPC::LWA_32:
1603 case PPC::LWA: {
1604 // Verify alignment is legal, so we don't create relocations
1605 // that can't be supported.
1606 unsigned OpNum = (MI->getOpcode() == PPC::STD) ? 2 : 1;
1607 // For non-TOC-based local-exec TLS accesses with non-zero offsets, the
1608 // machine operand (which is a TargetGlobalTLSAddress) is expected to be
1609 // the same operand for both loads and stores.
1610 for (const MachineOperand &TempMO : MI->operands()) {
1611 if (((TempMO.getTargetFlags() == PPCII::MO_TPREL_FLAG ||
1612 TempMO.getTargetFlags() == PPCII::MO_TLSLD_FLAG)) &&
1613 TempMO.getOperandNo() == 1)
1614 OpNum = 1;
1615 }
1616 const MachineOperand &MO = MI->getOperand(OpNum);
1617 if (MO.isGlobal()) {
1618 const DataLayout &DL = MO.getGlobal()->getDataLayout();
1619 if (MO.getGlobal()->getPointerAlignment(DL) < 4)
1620 llvm_unreachable("Global must be word-aligned for LD, STD, LWA!");
1621 }
1622 // As these load/stores share common code with the following load/stores,
1623 // fall through to the subsequent cases in order to either process the
1624 // non-TOC-based local-exec sequence or to process the instruction normally.
1625 [[fallthrough]];
1626 }
1627 case PPC::LBZ:
1628 case PPC::LBZ8:
1629 case PPC::LHA:
1630 case PPC::LHA8:
1631 case PPC::LHZ:
1632 case PPC::LHZ8:
1633 case PPC::LWZ:
1634 case PPC::LWZ8:
1635 case PPC::STB:
1636 case PPC::STB8:
1637 case PPC::STH:
1638 case PPC::STH8:
1639 case PPC::STW:
1640 case PPC::STW8:
1641 case PPC::LFS:
1642 case PPC::STFS:
1643 case PPC::LFD:
1644 case PPC::STFD:
1645 case PPC::ADDI8: {
1646 // A faster non-TOC-based local-[exec|dynamic] sequence is represented by
1647 // `addi` or a load/store instruction (that directly loads or stores off of
1648 // the thread pointer) with an immediate operand having the
1649 // [MO_TPREL_FLAG|MO_TLSLD_FLAG]. Such instructions do not otherwise arise.
1650 if (!HasAIXSmallLocalTLS)
1651 break;
1652 bool IsMIADDI8 = MI->getOpcode() == PPC::ADDI8;
1653 unsigned OpNum = IsMIADDI8 ? 2 : 1;
1654 const MachineOperand &MO = MI->getOperand(OpNum);
1655 unsigned Flag = MO.getTargetFlags();
1656 if (Flag == PPCII::MO_TPREL_FLAG ||
1659 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1660
1661 const MCExpr *Expr = getAdjustedFasterLocalExpr(MO, MO.getOffset());
1662 if (Expr)
1663 TmpInst.getOperand(OpNum) = MCOperand::createExpr(Expr);
1664
1665 // Change the opcode to load address if the original opcode is an `addi`.
1666 if (IsMIADDI8)
1667 TmpInst.setOpcode(PPC::LA8);
1668
1669 EmitToStreamer(*OutStreamer, TmpInst);
1670 return;
1671 }
1672 // Now process the instruction normally.
1673 break;
1674 }
1675 case PPC::PseudoEIEIO: {
1676 EmitToStreamer(
1677 *OutStreamer,
1678 MCInstBuilder(PPC::ORI).addReg(PPC::X2).addReg(PPC::X2).addImm(0));
1679 EmitToStreamer(
1680 *OutStreamer,
1681 MCInstBuilder(PPC::ORI).addReg(PPC::X2).addReg(PPC::X2).addImm(0));
1682 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::EnforceIEIO));
1683 return;
1684 }
1685 }
1686
1687 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
1688 EmitToStreamer(*OutStreamer, TmpInst);
1689}
1690
1691// For non-TOC-based local-[exec|dynamic] variables that have a non-zero offset,
1692// we need to create a new MCExpr that adds the non-zero offset to the address
1693// of the local-[exec|dynamic] variable that will be used in either an addi,
1694// load or store. However, the final displacement for these instructions must be
1695// between [-32768, 32768), so if the TLS address + its non-zero offset is
1696// greater than 32KB, a new MCExpr is produced to accommodate this situation.
1697const MCExpr *
1698PPCAsmPrinter::getAdjustedFasterLocalExpr(const MachineOperand &MO,
1699 int64_t Offset) {
1700 // Non-zero offsets (for loads, stores or `addi`) require additional handling.
1701 // When the offset is zero, there is no need to create an adjusted MCExpr.
1702 if (!Offset)
1703 return nullptr;
1704
1705 assert(MO.isGlobal() && "Only expecting a global MachineOperand here!");
1706 const GlobalValue *GValue = MO.getGlobal();
1707 TLSModel::Model Model = TM.getTLSModel(GValue);
1708 assert((Model == TLSModel::LocalExec || Model == TLSModel::LocalDynamic) &&
1709 "Only local-[exec|dynamic] accesses are handled!");
1710
1711 bool IsGlobalADeclaration = GValue->isDeclarationForLinker();
1712 // Find the GlobalVariable that corresponds to the particular TLS variable
1713 // in the TLS variable-to-address mapping. All TLS variables should exist
1714 // within this map, with the exception of TLS variables marked as extern.
1715 const auto TLSVarsMapEntryIter = TLSVarsToAddressMapping.find(GValue);
1716 if (TLSVarsMapEntryIter == TLSVarsToAddressMapping.end())
1717 assert(IsGlobalADeclaration &&
1718 "Only expecting to find extern TLS variables not present in the TLS "
1719 "variable-to-address map!");
1720
1721 unsigned TLSVarAddress =
1722 IsGlobalADeclaration ? 0 : TLSVarsMapEntryIter->second;
1723 ptrdiff_t FinalAddress = (TLSVarAddress + Offset);
1724 // If the address of the TLS variable + the offset is less than 32KB,
1725 // or if the TLS variable is extern, we simply produce an MCExpr to add the
1726 // non-zero offset to the TLS variable address.
1727 // For when TLS variables are extern, this is safe to do because we can
1728 // assume that the address of extern TLS variables are zero.
1729 const MCExpr *Expr = MCSymbolRefExpr::create(
1730 getSymbol(GValue),
1732 OutContext);
1734 Expr, MCConstantExpr::create(Offset, OutContext), OutContext);
1735 if (FinalAddress >= 32768) {
1736 // Handle the written offset for cases where:
1737 // TLS variable address + Offset > 32KB.
1738
1739 // The assembly that is printed will look like:
1740 // TLSVar@le + Offset - Delta
1741 // where Delta is a multiple of 64KB: ((FinalAddress + 32768) & ~0xFFFF).
1742 ptrdiff_t Delta = ((FinalAddress + 32768) & ~0xFFFF);
1743 // Check that the total instruction displacement fits within [-32768,32768).
1744 [[maybe_unused]] ptrdiff_t InstDisp = TLSVarAddress + Offset - Delta;
1745 assert(
1746 ((InstDisp < 32768) && (InstDisp >= -32768)) &&
1747 "Expecting the instruction displacement for local-[exec|dynamic] TLS "
1748 "variables to be between [-32768, 32768)!");
1750 Expr, MCConstantExpr::create(-Delta, OutContext), OutContext);
1751 }
1752
1753 return Expr;
1754}
1755
1756void PPCLinuxAsmPrinter::emitGNUAttributes(Module &M) {
1757 // Emit long double format into GNU attribute
1758 MDString *LongDoubleType =
1759 cast_or_null<MDString>(M.getModuleFlag("long-double-type"));
1760 if (!LongDoubleType)
1761 return;
1762
1763 // TODO: Support emitting soft-fp and hard double/single attributes.
1764 switch (*parseLongDoubleFormat(LongDoubleType->getString())) {
1765 case LongDoubleFormat::PPCDoubleDouble:
1766 OutStreamer->emitGNUAttribute(Tag_GNU_Power_ABI_FP,
1767 Val_GNU_Power_ABI_HardFloat_DP |
1768 Val_GNU_Power_ABI_LDBL_IBM128);
1769 break;
1770 case LongDoubleFormat::IEEEquad:
1771 OutStreamer->emitGNUAttribute(Tag_GNU_Power_ABI_FP,
1772 Val_GNU_Power_ABI_HardFloat_DP |
1773 Val_GNU_Power_ABI_LDBL_IEEE128);
1774 break;
1775 case LongDoubleFormat::IEEEdouble:
1776 OutStreamer->emitGNUAttribute(Tag_GNU_Power_ABI_FP,
1777 Val_GNU_Power_ABI_HardFloat_DP |
1778 Val_GNU_Power_ABI_LDBL_64);
1779 break;
1780 default:
1781 break;
1782 }
1783}
1784
1785void PPCLinuxAsmPrinter::emitInstruction(const MachineInstr *MI) {
1786 if (!Subtarget->isPPC64())
1787 return PPCAsmPrinter::emitInstruction(MI);
1788
1789 switch (MI->getOpcode()) {
1790 default:
1791 break;
1792 case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
1793 // .begin:
1794 // b .end # lis 0, FuncId[16..32]
1795 // nop # li 0, FuncId[0..15]
1796 // std 0, -8(1)
1797 // mflr 0
1798 // bl __xray_FunctionEntry
1799 // mtlr 0
1800 // .end:
1801 //
1802 // Update compiler-rt/lib/xray/xray_powerpc64.cc accordingly when number
1803 // of instructions change.
1804 // XRAY is only supported on PPC Linux little endian.
1805 const Function &F = MF->getFunction();
1806 unsigned Num = F.getFnAttributeAsParsedInteger("patchable-function-entry");
1807
1808 if (!MAI.isLittleEndian() || Num)
1809 break;
1810 MCSymbol *BeginOfSled = OutContext.createTempSymbol();
1811 MCSymbol *EndOfSled = OutContext.createTempSymbol();
1812 OutStreamer->emitLabel(BeginOfSled);
1813 EmitToStreamer(*OutStreamer,
1814 MCInstBuilder(PPC::B).addExpr(
1815 MCSymbolRefExpr::create(EndOfSled, OutContext)));
1816 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::NOP));
1817 EmitToStreamer(
1818 *OutStreamer,
1819 MCInstBuilder(PPC::STD).addReg(PPC::X0).addImm(-8).addReg(PPC::X1));
1820 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MFLR8).addReg(PPC::X0));
1821 EmitToStreamer(*OutStreamer,
1822 MCInstBuilder(PPC::BL8_NOP)
1823 .addExpr(MCSymbolRefExpr::create(
1824 OutContext.getOrCreateSymbol("__xray_FunctionEntry"),
1825 OutContext)));
1826 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MTLR8).addReg(PPC::X0));
1827 OutStreamer->emitLabel(EndOfSled);
1828 recordSled(BeginOfSled, *MI, SledKind::FUNCTION_ENTER, 2);
1829 break;
1830 }
1831 case TargetOpcode::PATCHABLE_RET: {
1832 unsigned RetOpcode = MI->getOperand(0).getImm();
1833 MCInst RetInst;
1834 RetInst.setOpcode(RetOpcode);
1835 for (const auto &MO : llvm::drop_begin(MI->operands())) {
1836 MCOperand MCOp;
1837 if (LowerPPCMachineOperandToMCOperand(MI->getOpcode(), MO, MCOp, *this))
1838 RetInst.addOperand(MCOp);
1839 }
1840
1841 bool IsConditional;
1842 if (RetOpcode == PPC::BCCLR) {
1843 IsConditional = true;
1844 } else if (RetOpcode == PPC::TCRETURNdi8 || RetOpcode == PPC::TCRETURNri8 ||
1845 RetOpcode == PPC::TCRETURNai8) {
1846 break;
1847 } else if (RetOpcode == PPC::BLR8 || RetOpcode == PPC::TAILB8) {
1848 IsConditional = false;
1849 } else {
1850 EmitToStreamer(*OutStreamer, RetInst);
1851 return;
1852 }
1853
1854 MCSymbol *FallthroughLabel;
1855 if (IsConditional) {
1856 // Before:
1857 // bgtlr cr0
1858 //
1859 // After:
1860 // ble cr0, .end
1861 // .p2align 3
1862 // .begin:
1863 // blr # lis 0, FuncId[16..32]
1864 // nop # li 0, FuncId[0..15]
1865 // std 0, -8(1)
1866 // mflr 0
1867 // bl __xray_FunctionExit
1868 // mtlr 0
1869 // blr
1870 // .end:
1871 //
1872 // Update compiler-rt/lib/xray/xray_powerpc64.cc accordingly when number
1873 // of instructions change.
1874 FallthroughLabel = OutContext.createTempSymbol();
1875 EmitToStreamer(
1876 *OutStreamer,
1877 MCInstBuilder(PPC::BCC)
1878 .addImm(PPC::InvertPredicate(
1879 static_cast<PPC::Predicate>(MI->getOperand(1).getImm())))
1880 .addReg(MI->getOperand(2).getReg())
1881 .addExpr(MCSymbolRefExpr::create(FallthroughLabel, OutContext)));
1882 RetInst = MCInst();
1883 RetInst.setOpcode(PPC::BLR8);
1884 }
1885 // .p2align 3
1886 // .begin:
1887 // b(lr)? # lis 0, FuncId[16..32]
1888 // nop # li 0, FuncId[0..15]
1889 // std 0, -8(1)
1890 // mflr 0
1891 // bl __xray_FunctionExit
1892 // mtlr 0
1893 // b(lr)?
1894 //
1895 // Update compiler-rt/lib/xray/xray_powerpc64.cc accordingly when number
1896 // of instructions change.
1897 OutStreamer->emitCodeAlignment(Align(8), getSubtargetInfo());
1898 MCSymbol *BeginOfSled = OutContext.createTempSymbol();
1899 OutStreamer->emitLabel(BeginOfSled);
1900 EmitToStreamer(*OutStreamer, RetInst);
1901 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::NOP));
1902 EmitToStreamer(
1903 *OutStreamer,
1904 MCInstBuilder(PPC::STD).addReg(PPC::X0).addImm(-8).addReg(PPC::X1));
1905 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MFLR8).addReg(PPC::X0));
1906 EmitToStreamer(*OutStreamer,
1907 MCInstBuilder(PPC::BL8_NOP)
1908 .addExpr(MCSymbolRefExpr::create(
1909 OutContext.getOrCreateSymbol("__xray_FunctionExit"),
1910 OutContext)));
1911 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::MTLR8).addReg(PPC::X0));
1912 EmitToStreamer(*OutStreamer, RetInst);
1913 if (IsConditional)
1914 OutStreamer->emitLabel(FallthroughLabel);
1915 recordSled(BeginOfSled, *MI, SledKind::FUNCTION_EXIT, 2);
1916 return;
1917 }
1918 case TargetOpcode::PATCHABLE_FUNCTION_EXIT:
1919 llvm_unreachable("PATCHABLE_FUNCTION_EXIT should never be emitted");
1920 case TargetOpcode::PATCHABLE_TAIL_CALL:
1921 // TODO: Define a trampoline `__xray_FunctionTailExit` and differentiate a
1922 // normal function exit from a tail exit.
1923 llvm_unreachable("Tail call is handled in the normal case. See comments "
1924 "around this assert.");
1925 }
1926 return PPCAsmPrinter::emitInstruction(MI);
1927}
1928
1929void PPCLinuxAsmPrinter::emitStartOfAsmFile(Module &M) {
1930 if (PPCTargetMachine::computeABI(M.getTargetTriple(),
1931 TM.getTargetABIName(M)) == PPC_ABI_ELFv2) {
1932 PPCTargetStreamer *TS =
1933 static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
1934 TS->emitAbiVersion(2);
1935 }
1936
1937 if (static_cast<const PPCTargetMachine &>(TM).isPPC64() ||
1938 !isPositionIndependent())
1940
1941 if (M.getPICLevel() == PICLevel::SmallPIC)
1943
1944 OutStreamer->switchSection(OutContext.getELFSection(
1946
1947 MCSymbol *TOCSym = OutContext.getOrCreateSymbol(Twine(".LTOC"));
1948 MCSymbol *CurrentPos = OutContext.createTempSymbol();
1949
1950 OutStreamer->emitLabel(CurrentPos);
1951
1952 // The GOT pointer points to the middle of the GOT, in order to reference the
1953 // entire 64kB range. 0x8000 is the midpoint.
1954 const MCExpr *tocExpr =
1955 MCBinaryExpr::createAdd(MCSymbolRefExpr::create(CurrentPos, OutContext),
1956 MCConstantExpr::create(0x8000, OutContext),
1957 OutContext);
1958
1959 OutStreamer->emitAssignment(TOCSym, tocExpr);
1960
1961 OutStreamer->switchSection(getObjFileLowering().getTextSection());
1962}
1963
1964void PPCLinuxAsmPrinter::emitFunctionEntryLabel() {
1965 // linux/ppc32 - Normal entry label.
1966 if (!Subtarget->isPPC64() &&
1967 (!isPositionIndependent() ||
1968 MF->getFunction().getParent()->getPICLevel() == PICLevel::SmallPIC))
1970
1971 if (!Subtarget->isPPC64()) {
1972 const PPCFunctionInfo *PPCFI = MF->getInfo<PPCFunctionInfo>();
1973 if (PPCFI->usesPICBase() && !Subtarget->isSecurePlt()) {
1974 MCSymbol *RelocSymbol = PPCFI->getPICOffsetSymbol(*MF);
1975 MCSymbol *PICBase = MF->getPICBaseSymbol();
1976 OutStreamer->emitLabel(RelocSymbol);
1977
1978 const MCExpr *OffsExpr =
1980 MCSymbolRefExpr::create(OutContext.getOrCreateSymbol(Twine(".LTOC")),
1981 OutContext),
1982 MCSymbolRefExpr::create(PICBase, OutContext),
1983 OutContext);
1984 OutStreamer->emitValue(OffsExpr, 4);
1985 OutStreamer->emitLabel(CurrentFnSym);
1986 return;
1987 } else
1989 }
1990
1991 // ELFv2 ABI - Normal entry label.
1992 if (Subtarget->isELFv2ABI()) {
1993 // In the Large code model, we allow arbitrary displacements between
1994 // the text section and its associated TOC section. We place the
1995 // full 8-byte offset to the TOC in memory immediately preceding
1996 // the function global entry point.
1997 if (TM.getCodeModel() == CodeModel::Large
1998 && !MF->getRegInfo().use_empty(PPC::X2)) {
1999 const PPCFunctionInfo *PPCFI = MF->getInfo<PPCFunctionInfo>();
2000
2001 MCSymbol *TOCSymbol = OutContext.getOrCreateSymbol(StringRef(".TOC."));
2002 MCSymbol *GlobalEPSymbol = PPCFI->getGlobalEPSymbol(*MF);
2003 const MCExpr *TOCDeltaExpr =
2004 MCBinaryExpr::createSub(MCSymbolRefExpr::create(TOCSymbol, OutContext),
2005 MCSymbolRefExpr::create(GlobalEPSymbol,
2006 OutContext),
2007 OutContext);
2008
2009 OutStreamer->emitLabel(PPCFI->getTOCOffsetSymbol(*MF));
2010 OutStreamer->emitValue(TOCDeltaExpr, 8);
2011 }
2013 }
2014
2015 // Emit an official procedure descriptor.
2016 MCSectionSubPair Current = OutStreamer->getCurrentSection();
2017 MCSectionELF *Section = OutStreamer->getContext().getELFSection(
2019 OutStreamer->switchSection(Section);
2020 OutStreamer->emitLabel(CurrentFnSym);
2021 OutStreamer->emitValueToAlignment(Align(8));
2022 MCSymbol *Symbol1 = CurrentFnSymForSize;
2023 // Generates a R_PPC64_ADDR64 (from FK_DATA_8) relocation for the function
2024 // entry point.
2025 OutStreamer->emitValue(MCSymbolRefExpr::create(Symbol1, OutContext),
2026 8 /*size*/);
2027 MCSymbol *Symbol2 = OutContext.getOrCreateSymbol(StringRef(".TOC."));
2028 // Generates a R_PPC64_TOC relocation for TOC base insertion.
2029 OutStreamer->emitValue(
2030 MCSymbolRefExpr::create(Symbol2, PPC::S_TOCBASE, OutContext), 8 /*size*/);
2031 // Emit a null environment pointer.
2032 OutStreamer->emitIntValue(0, 8 /* size */);
2033 OutStreamer->switchSection(Current.first, Current.second);
2034}
2035
2036void PPCLinuxAsmPrinter::emitEndOfAsmFile(Module &M) {
2037 const DataLayout &DL = getDataLayout();
2038
2039 bool isPPC64 = DL.getPointerSizeInBits() == 64;
2040
2041 PPCTargetStreamer *TS =
2042 static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
2043
2044 // If we are using any values provided by Glibc at fixed addresses,
2045 // we need to ensure that the Glibc used at link time actually provides
2046 // those values. All versions of Glibc that do will define the symbol
2047 // named "__parse_hwcap_and_convert_at_platform".
2048 if (static_cast<const PPCTargetMachine &>(TM).hasGlibcHWCAPAccess())
2049 OutStreamer->emitSymbolValue(
2050 GetExternalSymbolSymbol("__parse_hwcap_and_convert_at_platform"),
2051 MAI.getCodePointerSize());
2052 emitGNUAttributes(M);
2053
2054 if (!TOC.empty()) {
2055 const char *Name = isPPC64 ? ".toc" : ".got2";
2056 MCSectionELF *Section = OutContext.getELFSection(
2058 OutStreamer->switchSection(Section);
2059 if (!isPPC64)
2060 OutStreamer->emitValueToAlignment(Align(4));
2061
2062 for (const auto &TOCMapPair : TOC) {
2063 const MCSymbol *const TOCEntryTarget = TOCMapPair.first.first;
2064 MCSymbol *const TOCEntryLabel = TOCMapPair.second;
2065
2066 OutStreamer->emitLabel(TOCEntryLabel);
2067 if (isPPC64)
2068 TS->emitTCEntry(*TOCEntryTarget, TOCMapPair.first.second);
2069 else
2070 OutStreamer->emitSymbolValue(TOCEntryTarget, 4);
2071 }
2072 }
2073
2074 PPCAsmPrinter::emitEndOfAsmFile(M);
2075}
2076
2077/// EmitFunctionBodyStart - Emit a global entry point prefix for ELFv2.
2078void PPCLinuxAsmPrinter::emitFunctionBodyStart() {
2079 // In the ELFv2 ABI, in functions that use the TOC register, we need to
2080 // provide two entry points. The ABI guarantees that when calling the
2081 // local entry point, r2 is set up by the caller to contain the TOC base
2082 // for this function, and when calling the global entry point, r12 is set
2083 // up by the caller to hold the address of the global entry point. We
2084 // thus emit a prefix sequence along the following lines:
2085 //
2086 // func:
2087 // .Lfunc_gepNN:
2088 // # global entry point
2089 // addis r2,r12,(.TOC.-.Lfunc_gepNN)@ha
2090 // addi r2,r2,(.TOC.-.Lfunc_gepNN)@l
2091 // .Lfunc_lepNN:
2092 // .localentry func, .Lfunc_lepNN-.Lfunc_gepNN
2093 // # local entry point, followed by function body
2094 //
2095 // For the Large code model, we create
2096 //
2097 // .Lfunc_tocNN:
2098 // .quad .TOC.-.Lfunc_gepNN # done by EmitFunctionEntryLabel
2099 // func:
2100 // .Lfunc_gepNN:
2101 // # global entry point
2102 // ld r2,.Lfunc_tocNN-.Lfunc_gepNN(r12)
2103 // add r2,r2,r12
2104 // .Lfunc_lepNN:
2105 // .localentry func, .Lfunc_lepNN-.Lfunc_gepNN
2106 // # local entry point, followed by function body
2107 //
2108 // This ensures we have r2 set up correctly while executing the function
2109 // body, no matter which entry point is called.
2110 const PPCFunctionInfo *PPCFI = MF->getInfo<PPCFunctionInfo>();
2111 const bool UsesX2OrR2 = !MF->getRegInfo().use_empty(PPC::X2) ||
2112 !MF->getRegInfo().use_empty(PPC::R2);
2113 const bool PCrelGEPRequired = Subtarget->isUsingPCRelativeCalls() &&
2114 UsesX2OrR2 && PPCFI->usesTOCBasePtr();
2115 const bool NonPCrelGEPRequired = !Subtarget->isUsingPCRelativeCalls() &&
2116 Subtarget->isELFv2ABI() && UsesX2OrR2;
2117
2118 // Only do all that if the function uses R2 as the TOC pointer
2119 // in the first place. We don't need the global entry point if the
2120 // function uses R2 as an allocatable register.
2121 if (NonPCrelGEPRequired || PCrelGEPRequired) {
2122 // Note: The logic here must be synchronized with the code in the
2123 // branch-selection pass which sets the offset of the first block in the
2124 // function. This matters because it affects the alignment.
2125 MCSymbol *GlobalEntryLabel = PPCFI->getGlobalEPSymbol(*MF);
2126 OutStreamer->emitLabel(GlobalEntryLabel);
2127 const MCSymbolRefExpr *GlobalEntryLabelExp =
2128 MCSymbolRefExpr::create(GlobalEntryLabel, OutContext);
2129
2130 if (TM.getCodeModel() != CodeModel::Large) {
2131 MCSymbol *TOCSymbol = OutContext.getOrCreateSymbol(StringRef(".TOC."));
2132 const MCExpr *TOCDeltaExpr =
2133 MCBinaryExpr::createSub(MCSymbolRefExpr::create(TOCSymbol, OutContext),
2134 GlobalEntryLabelExp, OutContext);
2135
2136 const MCExpr *TOCDeltaHi =
2137 MCSpecifierExpr::create(TOCDeltaExpr, PPC::S_HA, OutContext);
2138 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDIS)
2139 .addReg(PPC::X2)
2140 .addReg(PPC::X12)
2141 .addExpr(TOCDeltaHi));
2142
2143 const MCExpr *TOCDeltaLo =
2144 MCSpecifierExpr::create(TOCDeltaExpr, PPC::S_LO, OutContext);
2145 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADDI)
2146 .addReg(PPC::X2)
2147 .addReg(PPC::X2)
2148 .addExpr(TOCDeltaLo));
2149 } else {
2150 MCSymbol *TOCOffset = PPCFI->getTOCOffsetSymbol(*MF);
2151 const MCExpr *TOCOffsetDeltaExpr =
2152 MCBinaryExpr::createSub(MCSymbolRefExpr::create(TOCOffset, OutContext),
2153 GlobalEntryLabelExp, OutContext);
2154
2155 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::LD)
2156 .addReg(PPC::X2)
2157 .addExpr(TOCOffsetDeltaExpr)
2158 .addReg(PPC::X12));
2159 EmitToStreamer(*OutStreamer, MCInstBuilder(PPC::ADD8)
2160 .addReg(PPC::X2)
2161 .addReg(PPC::X2)
2162 .addReg(PPC::X12));
2163 }
2164
2165 MCSymbol *LocalEntryLabel = PPCFI->getLocalEPSymbol(*MF);
2166 OutStreamer->emitLabel(LocalEntryLabel);
2167 const MCSymbolRefExpr *LocalEntryLabelExp =
2168 MCSymbolRefExpr::create(LocalEntryLabel, OutContext);
2169 const MCExpr *LocalOffsetExp =
2170 MCBinaryExpr::createSub(LocalEntryLabelExp,
2171 GlobalEntryLabelExp, OutContext);
2172
2173 PPCTargetStreamer *TS =
2174 static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
2175 TS->emitLocalEntry(static_cast<MCSymbolELF *>(CurrentFnSym),
2176 LocalOffsetExp);
2177 } else if (Subtarget->isUsingPCRelativeCalls()) {
2178 // When generating the entry point for a function we have a few scenarios
2179 // based on whether or not that function uses R2 and whether or not that
2180 // function makes calls (or is a leaf function).
2181 // 1) A leaf function that does not use R2 (or treats it as callee-saved
2182 // and preserves it). In this case st_other=0 and both
2183 // the local and global entry points for the function are the same.
2184 // No special entry point code is required.
2185 // 2) A function uses the TOC pointer R2. This function may or may not have
2186 // calls. In this case st_other=[2,6] and the global and local entry
2187 // points are different. Code to correctly setup the TOC pointer in R2
2188 // is put between the global and local entry points. This case is
2189 // covered by the if statatement above.
2190 // 3) A function does not use the TOC pointer R2 but does have calls.
2191 // In this case st_other=1 since we do not know whether or not any
2192 // of the callees clobber R2. This case is dealt with in this else if
2193 // block. Tail calls are considered calls and the st_other should also
2194 // be set to 1 in that case as well.
2195 // 4) The function does not use the TOC pointer but R2 is used inside
2196 // the function. In this case st_other=1 once again.
2197 // 5) This function uses inline asm. We mark R2 as reserved if the function
2198 // has inline asm as we have to assume that it may be used.
2199 if (MF->getFrameInfo().hasCalls() || MF->getFrameInfo().hasTailCall() ||
2200 MF->hasInlineAsm() || (!PPCFI->usesTOCBasePtr() && UsesX2OrR2)) {
2201 PPCTargetStreamer *TS =
2202 static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
2203 TS->emitLocalEntry(static_cast<MCSymbolELF *>(CurrentFnSym),
2204 MCConstantExpr::create(1, OutContext));
2205 }
2206 }
2207}
2208
2209/// EmitFunctionBodyEnd - Print the traceback table before the .size
2210/// directive.
2211///
2212void PPCLinuxAsmPrinter::emitFunctionBodyEnd() {
2213 // Only the 64-bit target requires a traceback table. For now,
2214 // we only emit the word of zeroes that GDB requires to find
2215 // the end of the function, and zeroes for the eight-byte
2216 // mandatory fields.
2217 // FIXME: We should fill in the eight-byte mandatory fields as described in
2218 // the PPC64 ELF ABI (this is a low-priority item because GDB does not
2219 // currently make use of these fields).
2220 if (Subtarget->isPPC64()) {
2221 OutStreamer->emitIntValue(0, 4/*size*/);
2222 OutStreamer->emitIntValue(0, 8/*size*/);
2223 }
2224}
2225
2226char PPCLinuxAsmPrinter::ID = 0;
2227
2228INITIALIZE_PASS(PPCLinuxAsmPrinter, "ppc-linux-asm-printer",
2229 "Linux PPC Assembly Printer", false, false)
2230
2231void PPCAIXAsmPrinter::emitLinkage(const GlobalValue *GV,
2232 MCSymbol *GVSym) const {
2233 MCSymbolAttr LinkageAttr = MCSA_Invalid;
2234 switch (GV->getLinkage()) {
2235 case GlobalValue::ExternalLinkage:
2236 LinkageAttr = GV->isDeclaration() ? MCSA_Extern : MCSA_Global;
2237 break;
2238 case GlobalValue::LinkOnceAnyLinkage:
2239 case GlobalValue::LinkOnceODRLinkage:
2240 case GlobalValue::WeakAnyLinkage:
2241 case GlobalValue::WeakODRLinkage:
2242 case GlobalValue::ExternalWeakLinkage:
2243 LinkageAttr = MCSA_Weak;
2244 break;
2245 case GlobalValue::AvailableExternallyLinkage:
2246 LinkageAttr = MCSA_Extern;
2247 break;
2248 case GlobalValue::PrivateLinkage:
2249 return;
2250 case GlobalValue::InternalLinkage:
2251 assert(GV->getVisibility() == GlobalValue::DefaultVisibility &&
2252 "InternalLinkage should not have other visibility setting.");
2253 LinkageAttr = MCSA_LGlobal;
2254 break;
2255 case GlobalValue::AppendingLinkage:
2256 llvm_unreachable("Should never emit this");
2257 case GlobalValue::CommonLinkage:
2258 llvm_unreachable("CommonLinkage of XCOFF should not come to this path");
2259 }
2260
2261 assert(LinkageAttr != MCSA_Invalid && "LinkageAttr should not MCSA_Invalid.");
2262
2263 MCSymbolAttr VisibilityAttr = MCSA_Invalid;
2264 if (!TM.getIgnoreXCOFFVisibility()) {
2265 if (GV->hasDLLExportStorageClass() && !GV->hasDefaultVisibility())
2266 report_fatal_error(
2267 "Cannot not be both dllexport and non-default visibility");
2268 switch (GV->getVisibility()) {
2269
2270 // TODO: "internal" Visibility needs to go here.
2271 case GlobalValue::DefaultVisibility:
2272 if (GV->hasDLLExportStorageClass())
2273 VisibilityAttr = MAI.getExportedVisibilityAttr();
2274 break;
2275 case GlobalValue::HiddenVisibility:
2276 VisibilityAttr = MAI.getHiddenVisibilityAttr();
2277 break;
2278 case GlobalValue::ProtectedVisibility:
2279 VisibilityAttr = MAI.getProtectedVisibilityAttr();
2280 break;
2281 }
2282 }
2283
2284 // Do not emit the _$TLSML symbol.
2285 if (GV->getThreadLocalMode() == GlobalVariable::LocalDynamicTLSModel &&
2286 GV->hasName() && GV->getName() == "_$TLSML")
2287 return;
2288
2289 OutStreamer->emitXCOFFSymbolLinkageWithVisibility(GVSym, LinkageAttr,
2290 VisibilityAttr);
2291}
2292
2293void PPCAIXAsmPrinter::SetupMachineFunction(MachineFunction &MF) {
2294 // Setup CurrentFnDescSym and its containing csect.
2295 auto *FnDescSec = static_cast<MCSectionXCOFF *>(
2296 getObjFileLowering().getSectionForFunctionDescriptor(&MF.getFunction(),
2297 TM));
2298 FnDescSec->setAlignment(Align(Subtarget->isPPC64() ? 8 : 4));
2299
2300 CurrentFnDescSym = FnDescSec->getQualNameSymbol();
2301
2303}
2304
2305uint16_t PPCAIXAsmPrinter::getNumberOfVRSaved() {
2306 // Calculate the number of VRs be saved.
2307 // Vector registers 20 through 31 are marked as reserved and cannot be used
2308 // in the default ABI.
2309 const PPCSubtarget &Subtarget = MF->getSubtarget<PPCSubtarget>();
2310 if (Subtarget.isAIXABI() && Subtarget.hasAltivec() &&
2311 Subtarget.isAIXExtendedAltivecABI()) {
2312 const MachineRegisterInfo &MRI = MF->getRegInfo();
2313 for (unsigned Reg = PPC::V20; Reg <= PPC::V31; ++Reg)
2315 // Number of VRs saved.
2316 return PPC::V31 - Reg + 1;
2317 }
2318 return 0;
2319}
2320
2321void PPCAIXAsmPrinter::emitFunctionBodyEnd() {
2322
2323 if (!TM.getXCOFFTracebackTable())
2324 return;
2325
2326 emitTracebackTable();
2327
2328 // If ShouldEmitEHBlock returns true, then the eh info table
2329 // will be emitted via `AIXException::endFunction`. Otherwise, we
2330 // need to emit a dumy eh info table when VRs are saved. We could not
2331 // consolidate these two places into one because there is no easy way
2332 // to access register information in `AIXException` class.
2334 (getNumberOfVRSaved() > 0)) {
2335 // Emit dummy EH Info Table.
2336 OutStreamer->switchSection(getObjFileLowering().getCompactUnwindSection());
2337 MCSymbol *EHInfoLabel =
2339 OutStreamer->emitLabel(EHInfoLabel);
2340
2341 // Version number.
2342 OutStreamer->emitInt32(0);
2343
2344 const DataLayout &DL = MMI->getModule()->getDataLayout();
2345 const unsigned PointerSize = DL.getPointerSize();
2346 // Add necessary paddings in 64 bit mode.
2347 OutStreamer->emitValueToAlignment(Align(PointerSize));
2348
2349 OutStreamer->emitIntValue(0, PointerSize);
2350 OutStreamer->emitIntValue(0, PointerSize);
2351 OutStreamer->switchSection(MF->getSection());
2352 }
2353}
2354
2355void PPCAIXAsmPrinter::emitTracebackTable() {
2356
2357 // Create a symbol for the end of function.
2358 MCSymbol *FuncEnd = createTempSymbol(MF->getName());
2359 OutStreamer->emitLabel(FuncEnd);
2360
2361 OutStreamer->AddComment("Traceback table begin");
2362 // Begin with a fullword of zero.
2363 OutStreamer->emitIntValueInHexWithPadding(0, 4 /*size*/);
2364
2365 SmallString<128> CommentString;
2366 raw_svector_ostream CommentOS(CommentString);
2367
2368 auto EmitComment = [&]() {
2369 OutStreamer->AddComment(CommentOS.str());
2370 CommentString.clear();
2371 };
2372
2373 auto EmitCommentAndValue = [&](uint64_t Value, int Size) {
2374 EmitComment();
2375 OutStreamer->emitIntValueInHexWithPadding(Value, Size);
2376 };
2377
2378 unsigned int Version = 0;
2379 CommentOS << "Version = " << Version;
2380 EmitCommentAndValue(Version, 1);
2381
2382 // There is a lack of information in the IR to assist with determining the
2383 // source language. AIX exception handling mechanism would only search for
2384 // personality routine and LSDA area when such language supports exception
2385 // handling. So to be conservatively correct and allow runtime to do its job,
2386 // we need to set it to C++ for now.
2387 TracebackTable::LanguageID LanguageIdentifier =
2389
2390 CommentOS << "Language = "
2391 << getNameForTracebackTableLanguageId(LanguageIdentifier);
2392 EmitCommentAndValue(LanguageIdentifier, 1);
2393
2394 // This is only populated for the third and fourth bytes.
2395 uint32_t FirstHalfOfMandatoryField = 0;
2396
2397 // Emit the 3rd byte of the mandatory field.
2398
2399 // We always set traceback offset bit to true.
2400 FirstHalfOfMandatoryField |= TracebackTable::HasTraceBackTableOffsetMask;
2401
2402 const PPCFunctionInfo *FI = MF->getInfo<PPCFunctionInfo>();
2403 const MachineRegisterInfo &MRI = MF->getRegInfo();
2404
2405 // Check the function uses floating-point processor instructions or not
2406 for (unsigned Reg = PPC::F0; Reg <= PPC::F31; ++Reg) {
2407 if (MRI.isPhysRegUsed(Reg, /* SkipRegMaskTest */ true)) {
2408 FirstHalfOfMandatoryField |= TracebackTable::IsFloatingPointPresentMask;
2409 break;
2410 }
2411 }
2412
2413#define GENBOOLCOMMENT(Prefix, V, Field) \
2414 CommentOS << (Prefix) << ((V) & (TracebackTable::Field##Mask) ? "+" : "-") \
2415 << #Field
2416
2417#define GENVALUECOMMENT(PrefixAndName, V, Field) \
2418 CommentOS << (PrefixAndName) << " = " \
2419 << static_cast<unsigned>(((V) & (TracebackTable::Field##Mask)) >> \
2420 (TracebackTable::Field##Shift))
2421
2422 GENBOOLCOMMENT("", FirstHalfOfMandatoryField, IsGlobalLinkage);
2423 GENBOOLCOMMENT(", ", FirstHalfOfMandatoryField, IsOutOfLineEpilogOrPrologue);
2424 EmitComment();
2425
2426 GENBOOLCOMMENT("", FirstHalfOfMandatoryField, HasTraceBackTableOffset);
2427 GENBOOLCOMMENT(", ", FirstHalfOfMandatoryField, IsInternalProcedure);
2428 EmitComment();
2429
2430 GENBOOLCOMMENT("", FirstHalfOfMandatoryField, HasControlledStorage);
2431 GENBOOLCOMMENT(", ", FirstHalfOfMandatoryField, IsTOCless);
2432 EmitComment();
2433
2434 GENBOOLCOMMENT("", FirstHalfOfMandatoryField, IsFloatingPointPresent);
2435 EmitComment();
2436 GENBOOLCOMMENT("", FirstHalfOfMandatoryField,
2437 IsFloatingPointOperationLogOrAbortEnabled);
2438 EmitComment();
2439
2440 OutStreamer->emitIntValueInHexWithPadding(
2441 (FirstHalfOfMandatoryField & 0x0000ff00) >> 8, 1);
2442
2443 // Set the 4th byte of the mandatory field.
2444 FirstHalfOfMandatoryField |= TracebackTable::IsFunctionNamePresentMask;
2445
2446 const PPCRegisterInfo *RegInfo = Subtarget->getRegisterInfo();
2447 Register FrameReg = RegInfo->getFrameRegister(*MF);
2448 if (FrameReg == (Subtarget->isPPC64() ? PPC::X31 : PPC::R31))
2449 FirstHalfOfMandatoryField |= TracebackTable::IsAllocaUsedMask;
2450
2451 const SmallVectorImpl<Register> &MustSaveCRs = FI->getMustSaveCRs();
2452 if (!MustSaveCRs.empty())
2453 FirstHalfOfMandatoryField |= TracebackTable::IsCRSavedMask;
2454
2455 if (FI->mustSaveLR())
2456 FirstHalfOfMandatoryField |= TracebackTable::IsLRSavedMask;
2457
2458 GENBOOLCOMMENT("", FirstHalfOfMandatoryField, IsInterruptHandler);
2459 GENBOOLCOMMENT(", ", FirstHalfOfMandatoryField, IsFunctionNamePresent);
2460 GENBOOLCOMMENT(", ", FirstHalfOfMandatoryField, IsAllocaUsed);
2461 EmitComment();
2462 GENVALUECOMMENT("OnConditionDirective", FirstHalfOfMandatoryField,
2463 OnConditionDirective);
2464 GENBOOLCOMMENT(", ", FirstHalfOfMandatoryField, IsCRSaved);
2465 GENBOOLCOMMENT(", ", FirstHalfOfMandatoryField, IsLRSaved);
2466 EmitComment();
2467 OutStreamer->emitIntValueInHexWithPadding((FirstHalfOfMandatoryField & 0xff),
2468 1);
2469
2470 // Set the 5th byte of mandatory field.
2471 uint32_t SecondHalfOfMandatoryField = 0;
2472
2473 SecondHalfOfMandatoryField |= MF->getFrameInfo().getStackSize()
2475 : 0;
2476
2477 uint32_t FPRSaved = 0;
2478 for (unsigned Reg = PPC::F14; Reg <= PPC::F31; ++Reg) {
2479 if (MRI.isPhysRegModified(Reg)) {
2480 FPRSaved = PPC::F31 - Reg + 1;
2481 break;
2482 }
2483 }
2484 SecondHalfOfMandatoryField |= (FPRSaved << TracebackTable::FPRSavedShift) &
2486 GENBOOLCOMMENT("", SecondHalfOfMandatoryField, IsBackChainStored);
2487 GENBOOLCOMMENT(", ", SecondHalfOfMandatoryField, IsFixup);
2488 GENVALUECOMMENT(", NumOfFPRsSaved", SecondHalfOfMandatoryField, FPRSaved);
2489 EmitComment();
2490 OutStreamer->emitIntValueInHexWithPadding(
2491 (SecondHalfOfMandatoryField & 0xff000000) >> 24, 1);
2492
2493 // Set the 6th byte of mandatory field.
2494
2495 // Check whether has Vector Instruction,We only treat instructions uses vector
2496 // register as vector instructions.
2497 bool HasVectorInst = false;
2498 for (unsigned Reg = PPC::V0; Reg <= PPC::V31; ++Reg)
2499 if (MRI.isPhysRegUsed(Reg, /* SkipRegMaskTest */ true)) {
2500 // Has VMX instruction.
2501 HasVectorInst = true;
2502 break;
2503 }
2504
2505 if (FI->hasVectorParms() || HasVectorInst)
2506 SecondHalfOfMandatoryField |= TracebackTable::HasVectorInfoMask;
2507
2508 uint16_t NumOfVRSaved = getNumberOfVRSaved();
2509 bool ShouldEmitEHBlock =
2511
2512 if (ShouldEmitEHBlock)
2513 SecondHalfOfMandatoryField |= TracebackTable::HasExtensionTableMask;
2514
2515 uint32_t GPRSaved = 0;
2516
2517 // X13 is reserved under 64-bit environment.
2518 unsigned GPRBegin = Subtarget->isPPC64() ? PPC::X14 : PPC::R13;
2519 unsigned GPREnd = Subtarget->isPPC64() ? PPC::X31 : PPC::R31;
2520
2521 for (unsigned Reg = GPRBegin; Reg <= GPREnd; ++Reg) {
2522 if (MRI.isPhysRegModified(Reg)) {
2523 GPRSaved = GPREnd - Reg + 1;
2524 break;
2525 }
2526 }
2527
2528 SecondHalfOfMandatoryField |= (GPRSaved << TracebackTable::GPRSavedShift) &
2530
2531 GENBOOLCOMMENT("", SecondHalfOfMandatoryField, HasExtensionTable);
2532 GENBOOLCOMMENT(", ", SecondHalfOfMandatoryField, HasVectorInfo);
2533 GENVALUECOMMENT(", NumOfGPRsSaved", SecondHalfOfMandatoryField, GPRSaved);
2534 EmitComment();
2535 OutStreamer->emitIntValueInHexWithPadding(
2536 (SecondHalfOfMandatoryField & 0x00ff0000) >> 16, 1);
2537
2538 // Set the 7th byte of mandatory field.
2539 uint32_t NumberOfFixedParms = FI->getFixedParmsNum();
2540 SecondHalfOfMandatoryField |=
2541 (NumberOfFixedParms << TracebackTable::NumberOfFixedParmsShift) &
2543 GENVALUECOMMENT("NumberOfFixedParms", SecondHalfOfMandatoryField,
2544 NumberOfFixedParms);
2545 EmitComment();
2546 OutStreamer->emitIntValueInHexWithPadding(
2547 (SecondHalfOfMandatoryField & 0x0000ff00) >> 8, 1);
2548
2549 // Set the 8th byte of mandatory field.
2550
2551 // Always set parameter on stack.
2552 SecondHalfOfMandatoryField |= TracebackTable::HasParmsOnStackMask;
2553
2554 uint32_t NumberOfFPParms = FI->getFloatingPointParmsNum();
2555 SecondHalfOfMandatoryField |=
2558
2559 GENVALUECOMMENT("NumberOfFPParms", SecondHalfOfMandatoryField,
2560 NumberOfFloatingPointParms);
2561 GENBOOLCOMMENT(", ", SecondHalfOfMandatoryField, HasParmsOnStack);
2562 EmitComment();
2563 OutStreamer->emitIntValueInHexWithPadding(SecondHalfOfMandatoryField & 0xff,
2564 1);
2565
2566 // Generate the optional fields of traceback table.
2567
2568 // Parameter type.
2569 if (NumberOfFixedParms || NumberOfFPParms) {
2570 uint32_t ParmsTypeValue = FI->getParmsType();
2571
2572 Expected<SmallString<32>> ParmsType =
2573 FI->hasVectorParms()
2575 ParmsTypeValue, NumberOfFixedParms, NumberOfFPParms,
2576 FI->getVectorParmsNum())
2577 : XCOFF::parseParmsType(ParmsTypeValue, NumberOfFixedParms,
2578 NumberOfFPParms);
2579
2580 assert(ParmsType && toString(ParmsType.takeError()).c_str());
2581 if (ParmsType) {
2582 CommentOS << "Parameter type = " << ParmsType.get();
2583 EmitComment();
2584 }
2585 OutStreamer->emitIntValueInHexWithPadding(ParmsTypeValue,
2586 sizeof(ParmsTypeValue));
2587 }
2588 // Traceback table offset.
2589 OutStreamer->AddComment("Function size");
2590 if (FirstHalfOfMandatoryField & TracebackTable::HasTraceBackTableOffsetMask) {
2591 MCSymbol *FuncSectSym = getObjFileLowering().getFunctionEntryPointSymbol(
2592 &(MF->getFunction()), TM);
2593 OutStreamer->emitAbsoluteSymbolDiff(FuncEnd, FuncSectSym, 4);
2594 }
2595
2596 // Since we unset the Int_Handler.
2597 if (FirstHalfOfMandatoryField & TracebackTable::IsInterruptHandlerMask)
2598 report_fatal_error("Hand_Mask not implement yet");
2599
2600 if (FirstHalfOfMandatoryField & TracebackTable::HasControlledStorageMask)
2601 report_fatal_error("Ctl_Info not implement yet");
2602
2603 if (FirstHalfOfMandatoryField & TracebackTable::IsFunctionNamePresentMask) {
2604 StringRef Name = MF->getName().substr(0, INT16_MAX);
2605 int16_t NameLength = Name.size();
2606 CommentOS << "Function name len = "
2607 << static_cast<unsigned int>(NameLength);
2608 EmitCommentAndValue(NameLength, 2);
2609 OutStreamer->AddComment("Function Name");
2610 OutStreamer->emitBytes(Name);
2611 }
2612
2613 if (FirstHalfOfMandatoryField & TracebackTable::IsAllocaUsedMask) {
2614 uint8_t AllocReg = XCOFF::AllocRegNo;
2615 OutStreamer->AddComment("AllocaUsed");
2616 OutStreamer->emitIntValueInHex(AllocReg, sizeof(AllocReg));
2617 }
2618
2619 if (SecondHalfOfMandatoryField & TracebackTable::HasVectorInfoMask) {
2620 uint16_t VRData = 0;
2621 if (NumOfVRSaved) {
2622 // Number of VRs saved.
2623 VRData |= (NumOfVRSaved << TracebackTable::NumberOfVRSavedShift) &
2625 // This bit is supposed to set only when the special register
2626 // VRSAVE is saved on stack.
2627 // However, IBM XL compiler sets the bit when any vector registers
2628 // are saved on the stack. We will follow XL's behavior on AIX
2629 // so that we don't get surprise behavior change for C code.
2631 }
2632
2633 // Set has_varargs.
2634 if (FI->getVarArgsFrameIndex())
2636
2637 // Vector parameters number.
2638 unsigned VectorParmsNum = FI->getVectorParmsNum();
2639 VRData |= (VectorParmsNum << TracebackTable::NumberOfVectorParmsShift) &
2641
2642 if (HasVectorInst)
2644
2645 GENVALUECOMMENT("NumOfVRsSaved", VRData, NumberOfVRSaved);
2646 GENBOOLCOMMENT(", ", VRData, IsVRSavedOnStack);
2647 GENBOOLCOMMENT(", ", VRData, HasVarArgs);
2648 EmitComment();
2649 OutStreamer->emitIntValueInHexWithPadding((VRData & 0xff00) >> 8, 1);
2650
2651 GENVALUECOMMENT("NumOfVectorParams", VRData, NumberOfVectorParms);
2652 GENBOOLCOMMENT(", ", VRData, HasVMXInstruction);
2653 EmitComment();
2654 OutStreamer->emitIntValueInHexWithPadding(VRData & 0x00ff, 1);
2655
2656 uint32_t VecParmTypeValue = FI->getVecExtParmsType();
2657
2658 Expected<SmallString<32>> VecParmsType =
2659 XCOFF::parseVectorParmsType(VecParmTypeValue, VectorParmsNum);
2660 assert(VecParmsType && toString(VecParmsType.takeError()).c_str());
2661 if (VecParmsType) {
2662 CommentOS << "Vector Parameter type = " << VecParmsType.get();
2663 EmitComment();
2664 }
2665 OutStreamer->emitIntValueInHexWithPadding(VecParmTypeValue,
2666 sizeof(VecParmTypeValue));
2667 // Padding 2 bytes.
2668 CommentOS << "Padding";
2669 EmitCommentAndValue(0, 2);
2670 }
2671
2672 uint8_t ExtensionTableFlag = 0;
2673 if (SecondHalfOfMandatoryField & TracebackTable::HasExtensionTableMask) {
2674 if (ShouldEmitEHBlock)
2675 ExtensionTableFlag |= ExtendedTBTableFlag::TB_EH_INFO;
2676 if (Subtarget->getCLOpts().aix_ssp_tb_bit &&
2678 ExtensionTableFlag |= ExtendedTBTableFlag::TB_SSP_CANARY;
2679
2680 CommentOS << "ExtensionTableFlag = "
2681 << getExtendedTBTableFlagString(ExtensionTableFlag);
2682 EmitCommentAndValue(ExtensionTableFlag, sizeof(ExtensionTableFlag));
2683 }
2684
2685 if (ExtensionTableFlag & ExtendedTBTableFlag::TB_EH_INFO) {
2686 auto &Ctx = OutStreamer->getContext();
2687 MCSymbol *EHInfoSym =
2689 MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(EHInfoSym, TOCType_EHBlock);
2690 const MCSymbol *TOCBaseSym = static_cast<const MCSectionXCOFF *>(
2691 getObjFileLowering().getTOCBaseSection())
2692 ->getQualNameSymbol();
2693 const MCExpr *Exp =
2695 MCSymbolRefExpr::create(TOCBaseSym, Ctx), Ctx);
2696
2697 const DataLayout &DL = getDataLayout();
2698 OutStreamer->emitValueToAlignment(Align(4));
2699 OutStreamer->AddComment("EHInfo Table");
2700 OutStreamer->emitValue(Exp, DL.getPointerSize());
2701 }
2702#undef GENBOOLCOMMENT
2703#undef GENVALUECOMMENT
2704}
2705
2707 return GV->hasAppendingLinkage() &&
2709 // TODO: Linker could still eliminate the GV if we just skip
2710 // handling llvm.used array. Skipping them for now until we or the
2711 // AIX OS team come up with a good solution.
2712 .Case("llvm.used", true)
2713 // It's correct to just skip llvm.compiler.used array here.
2714 .Case("llvm.compiler.used", true)
2715 .Default(false);
2716}
2717
2719 return StringSwitch<bool>(GV->getName())
2720 .Cases({"llvm.global_ctors", "llvm.global_dtors"}, true)
2721 .Default(false);
2722}
2723
2724uint64_t PPCAIXAsmPrinter::getAliasOffset(const Constant *C) {
2725 if (auto *GA = dyn_cast<GlobalAlias>(C))
2726 return getAliasOffset(GA->getAliasee());
2727 if (auto *CE = dyn_cast<ConstantExpr>(C)) {
2728 const MCExpr *LowC = lowerConstant(CE);
2729 const MCBinaryExpr *CBE = dyn_cast<MCBinaryExpr>(LowC);
2730 if (!CBE)
2731 return 0;
2732 if (CBE->getOpcode() != MCBinaryExpr::Add)
2733 report_fatal_error("Only adding an offset is supported now.");
2734 auto *RHS = dyn_cast<MCConstantExpr>(CBE->getRHS());
2735 if (!RHS)
2736 report_fatal_error("Unable to get the offset of alias.");
2737 return RHS->getValue();
2738 }
2739 return 0;
2740}
2741
2742static void tocDataChecks(unsigned PointerSize, const GlobalVariable *GV) {
2743 // TODO: These asserts should be updated as more support for the toc data
2744 // transformation is added (struct support, etc.).
2745 assert(
2746 PointerSize >= GV->getAlign().valueOrOne().value() &&
2747 "GlobalVariables with an alignment requirement stricter than TOC entry "
2748 "size not supported by the toc data transformation.");
2749
2750 Type *GVType = GV->getValueType();
2751 assert(GVType->isSized() && "A GlobalVariable's size must be known to be "
2752 "supported by the toc data transformation.");
2753 if (GV->getDataLayout().getTypeSizeInBits(GVType) >
2754 PointerSize * 8)
2756 "A GlobalVariable with size larger than a TOC entry is not currently "
2757 "supported by the toc data transformation.");
2758 if (GV->hasPrivateLinkage())
2759 report_fatal_error("A GlobalVariable with private linkage is not "
2760 "currently supported by the toc data transformation.");
2761}
2762
2763void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
2764 // Special LLVM global arrays have been handled at the initialization.
2766 return;
2767
2768 // Ignore non-emitted data.
2769 if (GV->getSection() == "llvm.metadata")
2770 return;
2771
2772 // If the Global Variable has the toc-data attribute, it needs to be emitted
2773 // when we emit the .toc section.
2774 if (GV->hasAttribute("toc-data")) {
2775 unsigned PointerSize = GV->getDataLayout().getPointerSize();
2776 tocDataChecks(PointerSize, GV);
2777 TOCDataGlobalVars.push_back(GV);
2778 return;
2779 }
2780
2781 emitGlobalVariableHelper(GV);
2782}
2783
2784void PPCAIXAsmPrinter::emitGlobalVariableHelper(const GlobalVariable *GV) {
2785 assert(!GV->getName().starts_with("llvm.") &&
2786 "Unhandled intrinsic global variable.");
2787
2788 if (GV->hasComdat())
2789 report_fatal_error("COMDAT not yet supported by AIX.");
2790
2791 auto *GVSym = static_cast<MCSymbolXCOFF *>(getSymbol(GV));
2792
2793 if (GV->isDeclarationForLinker()) {
2794 emitLinkage(GV, GVSym);
2795 return;
2796 }
2797
2798 SectionKind GVKind = getObjFileLowering().getKindForGlobal(GV, TM);
2799 if (!GVKind.isGlobalWriteableData() && !GVKind.isReadOnly() &&
2800 !GVKind.isThreadLocal()) // Checks for both ThreadData and ThreadBSS.
2801 report_fatal_error("Encountered a global variable kind that is "
2802 "not supported yet.");
2803
2804 // Print GV in verbose mode
2805 if (isVerbose()) {
2806 if (GV->hasInitializer()) {
2807 GV->printAsOperand(OutStreamer->getCommentOS(),
2808 /*PrintType=*/false, GV->getParent());
2809 OutStreamer->getCommentOS() << '\n';
2810 }
2811 }
2812
2813 auto *Csect = static_cast<MCSectionXCOFF *>(
2814 getObjFileLowering().SectionForGlobal(GV, GVKind, TM));
2815
2816 // Switch to the containing csect.
2817 OutStreamer->switchSection(Csect);
2818
2819 if (GV->hasMetadata(LLVMContext::MD_implicit_ref)) {
2820 emitRefMetadata(GV);
2821 }
2822
2823 const DataLayout &DL = GV->getDataLayout();
2824
2825 // Handle common and zero-initialized local symbols.
2826 if (GV->hasCommonLinkage() || GVKind.isBSSLocal() ||
2827 GVKind.isThreadBSSLocal()) {
2828 Align Alignment = GV->getAlign().value_or(DL.getPreferredAlign(GV));
2830 GVSym->setStorageClass(
2832
2833 if (GVKind.isBSSLocal() && Csect->getMappingClass() == XCOFF::XMC_TD) {
2834 OutStreamer->emitZeros(Size);
2835 } else if (GVKind.isBSSLocal() || GVKind.isThreadBSSLocal()) {
2836 assert(Csect->getMappingClass() != XCOFF::XMC_TD &&
2837 "BSS local toc-data already handled and TLS variables "
2838 "incompatible with XMC_TD");
2839 OutStreamer->emitXCOFFLocalCommonSymbol(
2840 OutContext.getOrCreateSymbol(GVSym->getSymbolTableName()), Size,
2841 GVSym, Alignment);
2842 } else {
2843 OutStreamer->emitCommonSymbol(GVSym, Size, Alignment);
2844 }
2845 return;
2846 }
2847
2848 MCSymbol *EmittedInitSym = GVSym;
2849
2850 // Emit linkage for the global variable and its aliases.
2851 emitLinkage(GV, EmittedInitSym);
2852 for (const GlobalAlias *GA : GOAliasMap[GV])
2853 emitLinkage(GA, getSymbol(GA));
2854
2855 emitAlignment(getGVAlignment(GV, DL), GV);
2856
2857 // When -fdata-sections is enabled, every GlobalVariable will
2858 // be put into its own csect; therefore, label is not necessary here.
2859 if (!TM.getDataSections() || GV->hasSection()) {
2860 if (Csect->getMappingClass() != XCOFF::XMC_TD)
2861 OutStreamer->emitLabel(EmittedInitSym);
2862 }
2863
2864 // No alias to emit.
2865 if (!GOAliasMap[GV].size()) {
2866 emitGlobalConstant(GV->getDataLayout(), GV->getInitializer());
2867 return;
2868 }
2869
2870 // Aliases with the same offset should be aligned. Record the list of aliases
2871 // associated with the offset.
2872 AliasMapTy AliasList;
2873 for (const GlobalAlias *GA : GOAliasMap[GV])
2874 AliasList[getAliasOffset(GA->getAliasee())].push_back(GA);
2875
2876 // Emit alias label and element value for global variable.
2877 emitGlobalConstant(GV->getDataLayout(), GV->getInitializer(),
2878 &AliasList);
2879}
2880
2881void PPCAIXAsmPrinter::emitFunctionDescriptor() {
2882 const DataLayout &DL = getDataLayout();
2883 const unsigned PointerSize = DL.getPointerSizeInBits() == 64 ? 8 : 4;
2884
2885 MCSectionSubPair Current = OutStreamer->getCurrentSection();
2886 // Emit function descriptor.
2887 OutStreamer->switchSection(
2888 static_cast<MCSymbolXCOFF *>(CurrentFnDescSym)->getRepresentedCsect());
2889
2890 // Emit aliasing label for function descriptor csect.
2891 // An Ifunc doesn't have a corresponding machine function.
2892 if (MF)
2893 for (const GlobalAlias *Alias : GOAliasMap[&MF->getFunction()])
2894 OutStreamer->emitLabel(getSymbol(Alias));
2895
2896 // Emit function entry point address.
2897 OutStreamer->emitValue(MCSymbolRefExpr::create(CurrentFnSym, OutContext),
2898 PointerSize);
2899 // Emit TOC base address.
2900 const MCSymbol *TOCBaseSym = static_cast<const MCSectionXCOFF *>(
2901 getObjFileLowering().getTOCBaseSection())
2902 ->getQualNameSymbol();
2903 OutStreamer->emitValue(MCSymbolRefExpr::create(TOCBaseSym, OutContext),
2904 PointerSize);
2905 // Emit a null environment pointer.
2906 OutStreamer->emitIntValue(0, PointerSize);
2907
2908 OutStreamer->switchSection(Current.first, Current.second);
2909}
2910
2911void PPCAIXAsmPrinter::emitFunctionEntryLabel() {
2912 // For functions without user defined section, it's not necessary to emit the
2913 // label when we have individual function in its own csect.
2914 if (!TM.getFunctionSections() || (MF && MF->getFunction().hasSection()))
2915 PPCAsmPrinter::emitFunctionEntryLabel();
2916
2917 // an ifunc does not have an associated MachineFunction
2918 if (!MF)
2919 return;
2920
2921 const Function *F = &MF->getFunction();
2922 // Emit aliasing label for function entry point label.
2923 for (const GlobalAlias *Alias : GOAliasMap[F])
2924 OutStreamer->emitLabel(
2925 getObjFileLowering().getFunctionEntryPointSymbol(Alias, TM));
2926
2927 if (F->hasMetadata(LLVMContext::MD_implicit_ref)) {
2928 emitRefMetadata(F);
2929 }
2930}
2931
2932void PPCAIXAsmPrinter::emitPGORefs(Module &M) {
2933 if (!OutContext.hasXCOFFSection(
2934 "__llvm_prf_cnts",
2935 XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD)))
2936 return;
2937
2938 // When inside a csect `foo`, a .ref directive referring to a csect `bar`
2939 // translates into a relocation entry from `foo` to` bar`. The referring
2940 // csect, `foo`, is identified by its address. If multiple csects have the
2941 // same address (because one or more of them are zero-length), the referring
2942 // csect cannot be determined. Hence, we don't generate the .ref directives
2943 // if `__llvm_prf_cnts` is an empty section.
2944 bool HasNonZeroLengthPrfCntsSection = false;
2945 const DataLayout &DL = M.getDataLayout();
2946 for (GlobalVariable &GV : M.globals())
2947 if (GV.hasSection() && GV.getSection() == "__llvm_prf_cnts" &&
2948 GV.getGlobalSize(DL) > 0) {
2949 HasNonZeroLengthPrfCntsSection = true;
2950 break;
2951 }
2952
2953 if (HasNonZeroLengthPrfCntsSection) {
2954 MCSection *CntsSection = OutContext.getXCOFFSection(
2955 "__llvm_prf_cnts", SectionKind::getData(),
2956 XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD),
2957 /*MultiSymbolsAllowed*/ true);
2958
2959 OutStreamer->switchSection(CntsSection);
2960 if (OutContext.hasXCOFFSection(
2961 "__llvm_prf_data",
2962 XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD))) {
2963 MCSymbol *S = OutContext.getOrCreateSymbol("__llvm_prf_data[RW]");
2964 OutStreamer->emitXCOFFRefDirective(S);
2965 }
2966 if (OutContext.hasXCOFFSection(
2967 "__llvm_prf_names",
2968 XCOFF::CsectProperties(XCOFF::XMC_RO, XCOFF::XTY_SD))) {
2969 MCSymbol *S = OutContext.getOrCreateSymbol("__llvm_prf_names[RO]");
2970 OutStreamer->emitXCOFFRefDirective(S);
2971 }
2972 if (OutContext.hasXCOFFSection(
2973 "__llvm_prf_vnds",
2974 XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD))) {
2975 MCSymbol *S = OutContext.getOrCreateSymbol("__llvm_prf_vnds[RW]");
2976 OutStreamer->emitXCOFFRefDirective(S);
2977 }
2978 }
2979}
2980
2981void PPCAIXAsmPrinter::emitGCOVRefs() {
2982 if (!OutContext.hasXCOFFSection(
2983 "__llvm_gcov_ctr_section",
2984 XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD)))
2985 return;
2986
2987 MCSection *CtrSection = OutContext.getXCOFFSection(
2988 "__llvm_gcov_ctr_section", SectionKind::getData(),
2989 XCOFF::CsectProperties(XCOFF::XMC_RW, XCOFF::XTY_SD),
2990 /*MultiSymbolsAllowed*/ true);
2991
2992 OutStreamer->switchSection(CtrSection);
2993 const XCOFF::StorageMappingClass MappingClass =
2994 TM.Options.XCOFFReadOnlyPointers ? XCOFF::XMC_RO : XCOFF::XMC_RW;
2995 if (OutContext.hasXCOFFSection(
2996 "__llvm_covinit",
2997 XCOFF::CsectProperties(MappingClass, XCOFF::XTY_SD))) {
2998 const char *SymbolStr = TM.Options.XCOFFReadOnlyPointers
2999 ? "__llvm_covinit[RO]"
3000 : "__llvm_covinit[RW]";
3001 MCSymbol *S = OutContext.getOrCreateSymbol(SymbolStr);
3002 OutStreamer->emitXCOFFRefDirective(S);
3003 }
3004}
3005
3006void PPCAIXAsmPrinter::emitEndOfAsmFile(Module &M) {
3007 // If there are no functions and there are no toc-data definitions in this
3008 // module, we will never need to reference the TOC base.
3009 if (M.empty() && TOCDataGlobalVars.empty())
3010 return;
3011
3012 emitPGORefs(M);
3013 emitGCOVRefs();
3014
3015 // Switch to section to emit TOC base.
3016 OutStreamer->switchSection(getObjFileLowering().getTOCBaseSection());
3017
3018 PPCTargetStreamer *TS =
3019 static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
3020
3021 for (auto &I : TOC) {
3022 MCSectionXCOFF *TCEntry;
3023 // Setup the csect for the current TC entry. If the variant kind is
3024 // VK_AIX_TLSGDM the entry represents the region handle, we create a
3025 // new symbol to prefix the name with a dot.
3026 // If TLS model opt is turned on, create a new symbol to prefix the name
3027 // with a dot.
3028 if (I.first.second == PPC::S_AIX_TLSGDM ||
3029 (Subtarget->hasAIXShLibTLSModelOpt() &&
3030 I.first.second == PPC::S_AIX_TLSLD)) {
3031 SmallString<128> Name;
3032 StringRef Prefix = ".";
3033 Name += Prefix;
3034 Name += static_cast<const MCSymbolXCOFF *>(I.first.first)
3035 ->getSymbolTableName();
3036 MCSymbol *S = OutContext.getOrCreateSymbol(Name);
3037 TCEntry = static_cast<MCSectionXCOFF *>(
3038 getObjFileLowering().getSectionForTOCEntry(S, TM));
3039 } else {
3040 TCEntry = static_cast<MCSectionXCOFF *>(
3041 getObjFileLowering().getSectionForTOCEntry(I.first.first, TM));
3042 }
3043 OutStreamer->switchSection(TCEntry);
3044
3045 OutStreamer->emitLabel(I.second);
3046 TS->emitTCEntry(*I.first.first, I.first.second);
3047 }
3048
3049 // Traverse the list of global variables twice, emitting all of the
3050 // non-common global variables before the common ones, as emitting a
3051 // .comm directive changes the scope from .toc to the common symbol.
3052 for (const auto *GV : TOCDataGlobalVars) {
3053 if (!GV->hasCommonLinkage())
3054 emitGlobalVariableHelper(GV);
3055 }
3056 for (const auto *GV : TOCDataGlobalVars) {
3057 if (GV->hasCommonLinkage())
3058 emitGlobalVariableHelper(GV);
3059 }
3060}
3061
3062bool PPCAIXAsmPrinter::doInitialization(Module &M) {
3063 const bool Result = PPCAsmPrinter::doInitialization(M);
3064
3065 // Emit the .machine directive on AIX.
3066 const Triple &Target = M.getTargetTriple();
3068 // Walk through the "target-cpu" attribute of functions and use the newest
3069 // level as the CPU of the module.
3070 for (auto &F : M) {
3071 XCOFF::CFileCpuId FunCpuId =
3072 XCOFF::getCpuID(TM.getSubtargetImpl(F)->getCPU());
3073 if (FunCpuId > TargetCpuId)
3074 TargetCpuId = FunCpuId;
3075 }
3076 // If there is no "target-cpu" attribute within the functions, take the
3077 // "-mcpu" value. If both are omitted, use getNormalizedPPCTargetCPU() to
3078 // determine the default CPU.
3079 if (!TargetCpuId) {
3080 StringRef TargetCPU = TM.getTargetCPU();
3081 TargetCpuId = XCOFF::getCpuID(
3082 TargetCPU.empty() ? PPC::getNormalizedPPCTargetCPU(Target) : TargetCPU);
3083 }
3084
3085 PPCTargetStreamer *TS =
3086 static_cast<PPCTargetStreamer *>(OutStreamer->getTargetStreamer());
3087 TS->emitMachine(XCOFF::getTCPUString(TargetCpuId));
3088
3089 auto setCsectAlignment = [this](const GlobalObject *GO) {
3090 // Declarations have 0 alignment which is set by default.
3091 if (GO->isDeclarationForLinker())
3092 return;
3093
3094 SectionKind GOKind = getObjFileLowering().getKindForGlobal(GO, TM);
3095 auto *Csect = static_cast<MCSectionXCOFF *>(
3096 getObjFileLowering().SectionForGlobal(GO, GOKind, TM));
3097
3098 Align GOAlign = getGVAlignment(GO, GO->getDataLayout());
3099 Csect->ensureMinAlignment(GOAlign);
3100 };
3101
3102 // For all TLS variables, calculate their corresponding addresses and store
3103 // them into TLSVarsToAddressMapping, which will be used to determine whether
3104 // or not local-exec TLS variables require special assembly printing.
3105 uint64_t TLSVarAddress = 0;
3106 auto DL = M.getDataLayout();
3107 for (const auto &G : M.globals()) {
3108 if (G.isThreadLocal() && !G.isDeclaration()) {
3109 TLSVarAddress = alignTo(TLSVarAddress, getGVAlignment(&G, DL));
3110 TLSVarsToAddressMapping[&G] = TLSVarAddress;
3111 TLSVarAddress += G.getGlobalSize(DL);
3112 }
3113 }
3114
3115 // We need to know, up front, the alignment of csects for the assembly path,
3116 // because once a .csect directive gets emitted, we could not change the
3117 // alignment value on it.
3118 for (const auto &G : M.globals()) {
3120 continue;
3121
3123 // Generate a format indicator and a unique module id to be a part of
3124 // the sinit and sterm function names.
3125 if (FormatIndicatorAndUniqueModId.empty()) {
3126 std::string UniqueModuleId = getUniqueModuleId(&M);
3127 if (UniqueModuleId != "")
3128 // TODO: Use source file full path to generate the unique module id
3129 // and add a format indicator as a part of function name in case we
3130 // will support more than one format.
3131 FormatIndicatorAndUniqueModId = "clang_" + UniqueModuleId;
3132 else {
3133 // Use threadId, Pid, and current time as the unique module id when we
3134 // cannot generate one based on a module's strong external symbols.
3135 auto CurTime =
3136 std::chrono::duration_cast<std::chrono::nanoseconds>(
3137 std::chrono::steady_clock::now().time_since_epoch())
3138 .count();
3139 FormatIndicatorAndUniqueModId =
3140 "clangPidTidTime_" + llvm::itostr(sys::Process::getProcessId()) +
3141 "_" + llvm::itostr(llvm::get_threadid()) + "_" +
3142 llvm::itostr(CurTime);
3143 }
3144 }
3145
3146 emitSpecialLLVMGlobal(&G);
3147 continue;
3148 }
3149
3150 setCsectAlignment(&G);
3151 std::optional<CodeModel::Model> OptionalCodeModel = G.getCodeModel();
3152 if (OptionalCodeModel)
3153 setOptionalCodeModel(static_cast<MCSymbolXCOFF *>(getSymbol(&G)),
3154 *OptionalCodeModel);
3155 }
3156
3157 for (const auto &F : M)
3158 setCsectAlignment(&F);
3159
3160 // Construct an aliasing list for each GlobalObject.
3161 for (const auto &Alias : M.aliases()) {
3162 const GlobalObject *Aliasee = Alias.getAliaseeObject();
3163 if (!Aliasee)
3165 "alias without a base object is not yet supported on AIX");
3166
3167 if (Aliasee->hasCommonLinkage()) {
3168 report_fatal_error("Aliases to common variables are not allowed on AIX:"
3169 "\n\tAlias attribute for " +
3170 Alias.getName() + " is invalid because " +
3171 Aliasee->getName() + " is common.",
3172 false);
3173 }
3174
3175 const GlobalVariable *GVar =
3176 dyn_cast_or_null<GlobalVariable>(Alias.getAliaseeObject());
3177 if (GVar) {
3178 std::optional<CodeModel::Model> OptionalCodeModel = GVar->getCodeModel();
3179 if (OptionalCodeModel)
3180 setOptionalCodeModel(static_cast<MCSymbolXCOFF *>(getSymbol(&Alias)),
3181 *OptionalCodeModel);
3182 }
3183
3184 GOAliasMap[Aliasee].push_back(&Alias);
3185 }
3186
3187 return Result;
3188}
3189
3190void PPCAIXAsmPrinter::emitInstruction(const MachineInstr *MI) {
3191 switch (MI->getOpcode()) {
3192 default:
3193 break;
3194 case PPC::TW:
3195 case PPC::TWI:
3196 case PPC::TD:
3197 case PPC::TDI: {
3198 if (MI->getNumOperands() < 5)
3199 break;
3200 const MachineOperand &LangMO = MI->getOperand(3);
3201 const MachineOperand &ReasonMO = MI->getOperand(4);
3202 if (!LangMO.isImm() || !ReasonMO.isImm())
3203 break;
3204 MCSymbol *TempSym = OutContext.createNamedTempSymbol();
3205 OutStreamer->emitLabel(TempSym);
3206 OutStreamer->emitXCOFFExceptDirective(
3207 CurrentFnSym, TempSym, LangMO.getImm(), ReasonMO.getImm(),
3208 Subtarget->isPPC64() ? MI->getMF()->getInstructionCount() * 8
3209 : MI->getMF()->getInstructionCount() * 4,
3210 hasDebugInfo());
3211 break;
3212 }
3213 case PPC::GETtlsMOD32AIX:
3214 case PPC::GETtlsMOD64AIX:
3215 case PPC::GETtlsTpointer32AIX:
3216 case PPC::GETtlsADDR64AIX:
3217 case PPC::GETtlsADDR32AIX: {
3218 // A reference to .__tls_get_mod/.__tls_get_addr/.__get_tpointer is unknown
3219 // to the assembler so we need to emit an external symbol reference.
3220 MCSymbol *TlsGetAddr =
3221 createMCSymbolForTlsGetAddr(OutContext, MI->getOpcode());
3222 ExtSymSDNodeSymbols.insert(TlsGetAddr);
3223 break;
3224 }
3225 case PPC::BL8:
3226 case PPC::BL:
3227 case PPC::BL8_NOP:
3228 case PPC::BL_NOP:
3229 case PPC::BL_LWZinto_toc:
3230 case PPC::BL_LWZinto_toc_RM:
3231 case PPC::BL8_LDinto_toc:
3232 case PPC::BL8_LDinto_toc_RM: {
3233 const MachineOperand &MO = MI->getOperand(0);
3234 if (MO.isSymbol()) {
3235 auto *S = static_cast<MCSymbolXCOFF *>(
3236 OutContext.getOrCreateSymbol(MO.getSymbolName()));
3237 ExtSymSDNodeSymbols.insert(S);
3238 }
3239 } break;
3240 case PPC::BL_TLS:
3241 case PPC::BL8_TLS:
3242 case PPC::BL8_TLS_:
3243 case PPC::BL8_NOP_TLS:
3244 report_fatal_error("TLS call not yet implemented");
3245 case PPC::TAILB:
3246 case PPC::TAILB8:
3247 case PPC::TAILBA:
3248 case PPC::TAILBA8:
3249 case PPC::TAILBCTR:
3250 case PPC::TAILBCTR8:
3251 if (MI->getOperand(0).isSymbol())
3252 report_fatal_error("Tail call for extern symbol not yet supported.");
3253 break;
3254 case PPC::DST:
3255 case PPC::DST64:
3256 case PPC::DSTT:
3257 case PPC::DSTT64:
3258 case PPC::DSTST:
3259 case PPC::DSTST64:
3260 case PPC::DSTSTT:
3261 case PPC::DSTSTT64:
3262 EmitToStreamer(
3263 *OutStreamer,
3264 MCInstBuilder(PPC::ORI).addReg(PPC::R0).addReg(PPC::R0).addImm(0));
3265 return;
3266 }
3267 return PPCAsmPrinter::emitInstruction(MI);
3268}
3269
3270bool PPCAIXAsmPrinter::doFinalization(Module &M) {
3271 for (MCSymbol *Sym : ExtSymSDNodeSymbols)
3272 OutStreamer->emitSymbolAttribute(Sym, MCSA_Extern);
3273 return PPCAsmPrinter::doFinalization(M);
3274}
3275
3276static unsigned mapToSinitPriority(int P) {
3277 if (P < 0 || P > 65535)
3278 report_fatal_error("invalid init priority");
3279
3280 if (P <= 20)
3281 return P;
3282
3283 if (P < 81)
3284 return 20 + (P - 20) * 16;
3285
3286 if (P <= 1124)
3287 return 1004 + (P - 81);
3288
3289 if (P < 64512)
3290 return 2047 + (P - 1124) * 33878;
3291
3292 return 2147482625u + (P - 64512);
3293}
3294
3295static std::string convertToSinitPriority(int Priority) {
3296 // This helper function converts clang init priority to values used in sinit
3297 // and sterm functions.
3298 //
3299 // The conversion strategies are:
3300 // We map the reserved clang/gnu priority range [0, 100] into the sinit/sterm
3301 // reserved priority range [0, 1023] by
3302 // - directly mapping the first 21 and the last 20 elements of the ranges
3303 // - linear interpolating the intermediate values with a step size of 16.
3304 //
3305 // We map the non reserved clang/gnu priority range of [101, 65535] into the
3306 // sinit/sterm priority range [1024, 2147483648] by:
3307 // - directly mapping the first and the last 1024 elements of the ranges
3308 // - linear interpolating the intermediate values with a step size of 33878.
3309 unsigned int P = mapToSinitPriority(Priority);
3310
3311 std::string PrioritySuffix;
3312 llvm::raw_string_ostream os(PrioritySuffix);
3313 os << llvm::format_hex_no_prefix(P, 8);
3314 return PrioritySuffix;
3315}
3316
3317void PPCAIXAsmPrinter::emitXXStructorList(const DataLayout &DL,
3318 const Constant *List, bool IsCtor) {
3319 SmallVector<Structor, 8> Structors;
3320 preprocessXXStructorList(DL, List, Structors);
3321 if (Structors.empty())
3322 return;
3323
3324 unsigned Index = 0;
3325 for (Structor &S : Structors) {
3326 if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(S.Func))
3327 S.Func = CE->getOperand(0);
3328
3331 (IsCtor ? llvm::Twine("__sinit") : llvm::Twine("__sterm")) +
3332 llvm::Twine(convertToSinitPriority(S.Priority)) +
3333 llvm::Twine("_", FormatIndicatorAndUniqueModId) +
3334 llvm::Twine("_", llvm::utostr(Index++)),
3335 cast<Function>(S.Func));
3336 }
3337}
3338
3339void PPCAIXAsmPrinter::emitTTypeReference(const GlobalValue *GV,
3340 unsigned Encoding) {
3341 if (GV) {
3342 TOCEntryType GlobalType = TOCType_GlobalInternal;
3347 GlobalType = TOCType_GlobalExternal;
3348 MCSymbol *TypeInfoSym = TM.getSymbol(GV);
3349 MCSymbol *TOCEntry = lookUpOrCreateTOCEntry(TypeInfoSym, GlobalType);
3350 const MCSymbol *TOCBaseSym = static_cast<const MCSectionXCOFF *>(
3351 getObjFileLowering().getTOCBaseSection())
3352 ->getQualNameSymbol();
3353 auto &Ctx = OutStreamer->getContext();
3354 const MCExpr *Exp =
3356 MCSymbolRefExpr::create(TOCBaseSym, Ctx), Ctx);
3357 OutStreamer->emitValue(Exp, GetSizeOfEncodedValue(Encoding));
3358 } else
3359 OutStreamer->emitIntValue(0, GetSizeOfEncodedValue(Encoding));
3360}
3361
3362void PPCAIXAsmPrinter::emitRefMetadata(const GlobalObject *GO) {
3364 GO->getMetadata(LLVMContext::MD_implicit_ref, MDs);
3365 assert(MDs.size() && "Expected !implicit.ref metadata nodes");
3366
3367 for (const MDNode *MD : MDs) {
3368 const ValueAsMetadata *VAM = cast<ValueAsMetadata>(MD->getOperand(0).get());
3369 const GlobalValue *GV = cast<GlobalValue>(VAM->getValue());
3370 MCSymbol *Referenced =
3371 isa<Function>(GV)
3372 ? getObjFileLowering().getFunctionEntryPointSymbol(GV, TM)
3373 : TM.getSymbol(GV);
3374 OutStreamer->emitXCOFFRefDirective(Referenced);
3375 }
3376}
3377
3378// Return a pass that prints the PPC assembly code for a MachineFunction to the
3379// given output stream.
3380static AsmPrinter *
3382 std::unique_ptr<MCStreamer> &&Streamer) {
3383 if (tm.getTargetTriple().isOSAIX())
3384 return new PPCAIXAsmPrinter(tm, std::move(Streamer));
3385
3386 return new PPCLinuxAsmPrinter(tm, std::move(Streamer));
3387}
3388
3389void PPCAIXAsmPrinter::emitModuleCommandLines(Module &M) {
3390 const NamedMDNode *NMD = M.getNamedMetadata("llvm.commandline");
3391 if (!NMD || !NMD->getNumOperands())
3392 return;
3393
3394 std::string S;
3395 raw_string_ostream RSOS(S);
3396 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
3397 const MDNode *N = NMD->getOperand(i);
3398 assert(N->getNumOperands() == 1 &&
3399 "llvm.commandline metadata entry can have only one operand");
3400 const MDString *MDS = cast<MDString>(N->getOperand(0));
3401 // Add "@(#)" to support retrieving the command line information with the
3402 // AIX "what" command
3403 RSOS << "@(#)opt " << MDS->getString() << "\n";
3404 RSOS.write('\0');
3405 }
3406 OutStreamer->emitXCOFFCInfoSym(".GCC.command.line", RSOS.str());
3407}
3408
3410 bool LocalIfProven) {
3411 enum class IsLocal {
3412 Unknown, // Structure of the llvm::Value is not one of the recognizable
3413 // structures, and so it's unknown if the llvm::Value is the
3414 // address of a local function at runtime.
3415 True, // We can statically prove that all runtime values of the
3416 // llvm::Value is an address of a local function.
3417 False // We can statically prove that one of the runtime values of the
3418 // llvm::Value is the address of a non-local function; it could be
3419 // the case that at runtime the non-local function is never
3420 // selected but we don't care.
3421 };
3422 auto Combine = [](IsLocal LHS, IsLocal RHS) -> IsLocal {
3423 if (LHS == IsLocal::False || RHS == IsLocal::False)
3424 return IsLocal::False;
3425 if (LHS == IsLocal::True && RHS == IsLocal::True)
3426 return IsLocal::True;
3427 return IsLocal::Unknown;
3428 };
3429
3430 // Query if the given function is local to the load module.
3431 auto IsLocalFunc = [](const Function *F) -> IsLocal {
3432 bool Result = F->isDSOLocal();
3433 LLVM_DEBUG(dbgs() << F->getName() << " is "
3434 << (Result ? "dso_local\n" : "not dso_local\n"));
3435 return Result ? IsLocal::True : IsLocal::False;
3436 };
3437
3438 // Recursive walker that visits certain patterns that make up the given Value,
3439 // and returns
3440 // - false if at least one non-local function was seen,
3441 // - otherwise, return unknown if some unrecognizable pattern was seen,
3442 // - otherwise, return true (which means only recognizable patterns were seen
3443 // and all possible values are local functions).
3444 std::function<IsLocal(const Value *)> ValueIsALocalFunc =
3445 [&IsLocalFunc, &Combine, &ValueIsALocalFunc](const Value *V) -> IsLocal {
3446 if (auto *F = dyn_cast<Function>(V))
3447 return IsLocalFunc(F);
3448 if (!isa<Instruction>(V))
3449 return IsLocal::Unknown;
3450
3451 auto *I = cast<Instruction>(V);
3452 // return isP9 ? foo_p9 : foo_default;
3453 if (auto *SI = dyn_cast<SelectInst>(I))
3454 return Combine(ValueIsALocalFunc(SI->getTrueValue()),
3455 ValueIsALocalFunc(SI->getFalseValue()));
3456 else if (auto *PN = dyn_cast<PHINode>(I)) {
3457 IsLocal Res = IsLocal::True;
3458 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
3459 Res = Combine(Res, ValueIsALocalFunc(PN->getIncomingValue(i)));
3460 if (Res == IsLocal::False)
3461 return Res;
3462 }
3463 return Res;
3464 }
3465 // clang-format off
3466 // @switch.table.resolve_foo = private unnamed_addr constant [3 x ptr] [ptr @foo_static, ptr @foo_hidden, ptr @foo_protected]
3467 // %switch.gep = getelementptr inbounds nuw ptr, ptr @switch.table, i64 %2
3468 // V = load ptr, ptr %switch.gep,
3469 // clang-format on
3470 else if (auto *Op = getPointerOperand(I)) {
3471 while (isa<GEPOperator>(Op))
3472 Op = cast<GEPOperator>(Op)->getPointerOperand();
3473
3474 if (!isa<GlobalVariable>(Op))
3475 return IsLocal::Unknown;
3476 auto *GV = dyn_cast<GlobalVariable>(Op);
3477 if (!GV->hasInitializer() || !isa<ConstantArray>(GV->getInitializer()))
3478 return IsLocal::Unknown;
3479 auto *Init = cast<ConstantArray>(GV->getInitializer());
3480 IsLocal Res = IsLocal::True;
3481 for (unsigned Idx = 0, End = Init->getNumOperands(); Idx != End; ++Idx) {
3482 Res = Combine(Res, ValueIsALocalFunc(Init->getOperand(Idx)));
3483 if (Res == IsLocal::False)
3484 return Res;
3485 }
3486 return Res;
3487 }
3488 return IsLocal::Unknown;
3489 };
3490
3491 auto *Resolver = GI.getResolverFunction();
3492 // If the resolver is preemptible then we cannot rely on its implementation.
3493 if (IsLocalFunc(Resolver) == IsLocal::False && LocalIfProven)
3494 return true;
3495
3496 // If one of the return values of the resolver function is not a
3497 // local function, then we have to conservatively do a TOC save/restore.
3498 IsLocal Res = IsLocal::True;
3499 for (auto &BB : *Resolver) {
3500 if (!isa<ReturnInst>(BB.getTerminator()))
3501 continue;
3502 auto *Ret = cast<ReturnInst>(BB.getTerminator());
3503 Value *RV = Ret->getReturnValue();
3504 assert(RV);
3505 Res = Combine(Res, ValueIsALocalFunc(RV));
3506 if (Res == IsLocal::False)
3507 break;
3508 }
3509 // no TOC save/restore needed if either all functions were local or we're
3510 // being optimistic and no preemptible functions were seen.
3511 if (Res == IsLocal::True || (Res == IsLocal::Unknown && !LocalIfProven))
3512 return false;
3513 return true;
3514}
3515/*
3516 * .csect .foo[PR],5
3517 * .globl foo[DS]
3518 * .globl .foo[PR]
3519 * .lglobl ifunc_sec.foo[RW]
3520 * .align 4
3521 * .csect foo[DS],2
3522 * .vbyte 4, .foo[PR]
3523 * .vbyte 4, TOC[TC0]
3524 * .vbyte 4, 0
3525 * .csect .foo[PR],5
3526 * .ref ifunc_sec.foo[RW]
3527 * lwz 12, L..foo_desc(2) # load foo's descriptor address
3528 * lwz 11, 8(12) # load the env pointer (for non-C/C++ functions)
3529 * lwz 12, 0(12) # load foo.addr
3530 * mtctr 12
3531 * bctr # branch to CR without setting LR so that callee
3532 * # returns to the caller of .foo
3533 * # -- End function
3534 */
3535void PPCAIXAsmPrinter::emitGlobalIFunc(Module &M, const GlobalIFunc &GI) {
3536 // Set the Subtarget to that of the resolver.
3537 const TargetSubtargetInfo *STI =
3538 TM.getSubtargetImpl(*GI.getResolverFunction());
3539 bool IsPPC64 = static_cast<const PPCSubtarget *>(STI)->isPPC64();
3540 const PPCOptions &CLOpts =
3541 static_cast<const PPCTargetMachine &>(TM).getCLOpts();
3542
3543 // Create syms and sections that are part of the ifunc implementation:
3544 // - Function descriptor symbol foo[RW]
3545 // - Function entry symbol .foo[PR]
3546 MCSectionXCOFF *FnDescSec = static_cast<MCSectionXCOFF *>(
3547 getObjFileLowering().getSectionForFunctionDescriptor(&GI, TM));
3548 FnDescSec->setAlignment(Align(IsPPC64 ? 8 : 4));
3549
3550 CurrentFnDescSym = FnDescSec->getQualNameSymbol();
3551
3552 CurrentFnSym = getObjFileLowering().getFunctionEntryPointSymbol(&GI, TM);
3553
3554 // Start codegen:
3555 if (TM.getFunctionSections())
3556 OutStreamer->switchSection(
3557 static_cast<MCSymbolXCOFF *>(CurrentFnSym)->getRepresentedCsect());
3558 else
3559 OutStreamer->switchSection(getObjFileLowering().getTextSection());
3560
3561 if (GI.hasMetadata(LLVMContext::MD_implicit_ref))
3562 emitRefMetadata(&GI);
3563
3564 // generate linkage for foo and .foo
3565 emitLinkage(&GI, CurrentFnDescSym);
3566 emitLinkage(&GI, CurrentFnSym);
3567
3568 // .align 4
3570 emitAlignment(Alignment, nullptr);
3571
3572 // generate foo's function descriptor
3573 emitFunctionDescriptor();
3574
3575 emitFunctionEntryLabel();
3576
3577 // generate the code for .foo now:
3579 CLOpts.ifunc_local_if_proven)) {
3580 SmallString<128> Msg;
3581 Msg.append("unimplemented: TOC register save/restore needed for ifunc \"");
3582 getNameWithPrefix(Msg, &GI);
3583 Msg.append("\", because couldn't prove all candidates are static or "
3584 "hidden/protected visibility definitions");
3585 if (!CLOpts.test_ifunc_warn_noerror)
3587 else
3588 dbgs() << Msg << "\n";
3589 }
3590
3591 auto FnDescTOCEntryType = getTOCEntryTypeForLinkage(GI.getLinkage());
3592 auto *FnDescTOCEntrySym =
3593 lookUpOrCreateTOCEntry(CurrentFnDescSym, FnDescTOCEntryType);
3594
3595 if (TM.getCodeModel() == CodeModel::Large) {
3596 // addis 12, L..foo_desc@u(2)
3597 // lwz 12, L..foo_desc@l(12)
3598 auto *Exp_U = symbolWithSpecifier(FnDescTOCEntrySym, PPC::S_U);
3599 OutStreamer->emitInstruction(MCInstBuilder(PPC::ADDIS)
3600 .addReg(PPC::X12)
3601 .addReg(PPC::X2)
3602 .addExpr(Exp_U),
3603 *Subtarget);
3604 auto *Exp_L = symbolWithSpecifier(FnDescTOCEntrySym, PPC::S_L);
3605 OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::LD : PPC::LWZ)
3606 .addReg(PPC::X12)
3607 .addExpr(Exp_L)
3608 .addReg(PPC::X12),
3609 *Subtarget);
3610 } else {
3611 // lwz 12, L..foo_desc(2)
3612 auto *Exp = MCSymbolRefExpr::create(FnDescTOCEntrySym, OutContext);
3613 // Exp = getTOCEntryLoadingExprForXCOFF(MOSymbol, Exp, VK);
3614 // TODO: do we need to uncomment this?
3615 OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::LD : PPC::LWZ)
3616 .addReg(PPC::X12)
3617 .addExpr(Exp)
3618 .addReg(PPC::X2),
3619 *Subtarget);
3620 }
3621 // lwz 11, 8(12)
3622 OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::LD : PPC::LWZ)
3623 .addReg(PPC::X11)
3624 .addImm(IsPPC64 ? 16 : 8)
3625 .addReg(PPC::X12),
3626 *Subtarget);
3627 // lwz 12, 0(12)
3628 OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::LD : PPC::LWZ)
3629 .addReg(PPC::X12)
3630 .addImm(0)
3631 .addReg(PPC::X12),
3632 *Subtarget);
3633 // mtctr 12
3634 OutStreamer->emitInstruction(
3635 MCInstBuilder(IsPPC64 ? PPC::MTCTR8 : PPC::MTCTR).addReg(PPC::X12),
3636 *Subtarget);
3637 // bctr
3638 OutStreamer->emitInstruction(MCInstBuilder(IsPPC64 ? PPC::BCTR8 : PPC::BCTR),
3639 *Subtarget);
3640}
3641
3642char PPCAIXAsmPrinter::ID = 0;
3643
3644INITIALIZE_PASS(PPCAIXAsmPrinter, "ppc-aix-asm-printer",
3645 "AIX PPC Assembly Printer", false, false)
3646
3647// Force static initialization.
3648extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
3649LLVMInitializePowerPCAsmPrinter() {
3658}
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
uint64_t uint64_t
static AMDGPUMCExpr::Specifier getSpecifier(unsigned MOFlags)
AMDGPU Uniform Intrinsic Combine
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:211
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
DXIL Finalize Linkage
static bool hasDebugInfo(const MachineFunction *MF)
@ Default
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define RegName(no)
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
static std::string getRegisterName(const TargetRegisterInfo *TRI, Register Reg)
Machine Check Debug Module
Register Reg
This file implements a map that provides insertion order iteration.
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define P(N)
static void collectTOCStats(PPCAsmPrinter::TOCEntryType Type)
static bool isSpecialLLVMGlobalArrayForStaticInit(const GlobalVariable *GV)
static bool TOCRestoreNeededForCallToImplementation(const GlobalIFunc &GI, bool LocalIfProven)
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 PPCAsmPrinter::TOCEntryType getTOCEntryTypeForLinkage(GlobalValue::LinkageTypes Linkage)
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)
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
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)
MachineRegisterInfo & MRI
const char * Msg
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:479
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)
Definition Statistic.h:171
This file contains some functions that are useful when dealing with strings.
#define LLVM_DEBUG(...)
Definition Debug.h:119
std::unique_ptr< MCStreamer > && Streamer
Value * RHS
Value * LHS
const AArch64RegisterInfo * getRegisterInfo() const override
const AArch64Options & getCLOpts() const
const AArch64FrameLowering * getFrameLowering() const override
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:94
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...
Definition AsmPrinter.h:646
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.
Definition AsmPrinter.h:477
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:
Definition DataLayout.h:794
Error takeError()
Take ownership of the stored error.
Definition Error.h:612
reference get()
Returns a reference to the stored T value.
Definition Error.h:582
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...
Definition Globals.cpp:692
LLVM_ABI const Function * getResolverFunction() const
Definition Globals.cpp:759
StringRef getSection() const
Get the custom section of this global if it has one.
bool hasMetadata() const
Return true if this GlobalObject has any metadata attached to it.
bool hasComdat() const
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this GlobalObject.
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.
Definition Globals.cpp:205
bool hasCommonLinkage() const
bool hasAppendingLinkage() const
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition GlobalValue.h:52
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition GlobalValue.h:54
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition GlobalValue.h:62
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.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
Definition Globals.cpp:640
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:342
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition MCExpr.h:448
Opcode getOpcode() const
Get the kind of this binary expression.
Definition MCExpr.h:442
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:427
@ Add
Addition.
Definition MCExpr.h:301
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
Context object for machine code objects.
Definition MCContext.h:84
void addOperand(const MCOperand Op)
Definition MCInst.h:215
void setOpcode(unsigned Op)
Definition MCInst.h:201
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:210
static MCOperand createExpr(const MCExpr *Val)
Definition MCInst.h:166
MCRegister getReg() const
Returns the register number.
Definition MCInst.h:73
MCSymbolXCOFF * getQualNameSymbol() const
void setAlignment(Align Value)
Definition MCSection.h:665
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:743
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:213
void setPerSymbolCodeModel(MCSymbolXCOFF::CodeModel Model)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition MCSymbol.cpp:60
LLVM_ABI StringRef getString() const
Definition Metadata.cpp:613
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
const MachineFunction * getParent() const
Return the MachineFunction containing 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
int64_t getImm() 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.
LLVM_ABI bool isPhysRegModified(MCRegister PhysReg, bool SkipNoReturnDef=false) const
Return true if the specified register is modified in this function.
LLVM_ABI bool isPhysRegUsed(MCRegister PhysReg, bool SkipRegMaskTest=false) const
Return true if the specified register is modified or read in this function.
iterator find(const KeyT &Key)
Definition MapVector.h:157
iterator end()
Definition MapVector.h:70
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
MCSymbol * getPICOffsetSymbol(MachineFunction &MF) const
const SmallVectorImpl< Register > & getMustSaveCRs() const
unsigned getFloatingPointParmsNum() const
MCSymbol * getGlobalEPSymbol(MachineFunction &MF) const
MCSymbol * getLocalEPSymbol(MachineFunction &MF) const
MCSymbol * getTOCOffsetSymbol(MachineFunction &MF) const
static const char * getRegisterName(MCRegister Reg)
static bool hasTLSFlag(unsigned TF)
Register getFrameRegister(const MachineFunction &MF) const override
CodeModel::Model getCodeModel(const TargetMachine &TM, const GlobalValue *GV) const
Calculates the effective code model for argument GV.
static PPCABI computeABI(const Triple &TT, StringRef ABIName)
Compute the ABI variant for TT and ABIName (the "target-abi" module flag), falling back to the triple...
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)
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Definition Record.h:2295
bool isThreadBSSLocal() const
static SectionKind getText()
bool isBSSLocal() const
static SectionKind getData()
bool isThreadLocal() const
bool isReadOnly() const
bool isGlobalWriteableData() const
bool insert(const value_type &X)
Insert a new element into the SetVector.
Definition SetVector.h:157
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.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:589
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition StringRef.h:258
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & Cases(std::initializer_list< StringLiteral > CaseStrings, T Value)
Align getMinFunctionAlignment() const
Return the minimum function alignment.
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
CodeModel::Model getCodeModel() const
Returns the code model.
virtual const TargetLowering * getTargetLowering() const
bool isOSAIX() const
Tests whether the OS is AIX.
Definition Triple.h:858
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
bool isSized() const
Return true if it makes sense to take the size of this type.
Definition Type.h:321
Value * getValue() const
Definition Metadata.h:511
LLVM Value Representation.
Definition Value.h:75
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.
Definition Value.cpp:985
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.
bool hasName() const
Definition Value.h:263
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Definition Value.cpp:314
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
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.
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
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.
@ SHF_ALLOC
Definition ELF.h:1098
@ SHF_WRITE
Definition ELF.h:1095
@ SHT_PROGBITS
Definition ELF.h:996
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...
Definition PPC.h:157
@ MO_TPREL_PCREL_FLAG
MO_TPREL_PCREL_FLAG = MO_PCREL_FLAG | MO_TPREL_FLAG.
Definition PPC.h:208
@ MO_GOT_TPREL_PCREL_FLAG
MO_GOT_TPREL_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
Definition PPC.h:183
@ MO_TLSGDM_FLAG
MO_TLSGDM_FLAG - If this bit is set the symbol reference is relative to the region handle of TLS Gene...
Definition PPC.h:165
@ MO_TLSLD_FLAG
MO_TLSLD_FLAG - If this bit is set the symbol reference is relative to TLS Local Dynamic model.
Definition PPC.h:161
@ MO_TPREL_FLAG
MO_TPREL_FLAG - If this bit is set, the symbol reference is relative to the thread pointer and the sy...
Definition PPC.h:151
@ MO_GOT_TLSLD_PCREL_FLAG
MO_GOT_TLSLD_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
Definition PPC.h:177
@ MO_TLSGD_FLAG
MO_TLSGD_FLAG - If this bit is set the symbol reference is relative to TLS General Dynamic model for ...
Definition PPC.h:146
@ MO_GOT_TLSGD_PCREL_FLAG
MO_GOT_TLSGD_PCREL_FLAG - A combintaion of flags, if these bits are set they should produce the reloc...
Definition PPC.h:171
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...
Predicate InvertPredicate(Predicate Opcode)
Invert the specified predicate. != -> ==, < -> >=.
static bool isVRRegister(MCRegister Reg)
static bool isVFRegister(MCRegister Reg)
@ CE
Windows NT (Windows on ARM)
Definition MCAsmInfo.h:51
void emitInstruction(MCObjectStreamer &, const MCInst &Inst, const MCSubtargetInfo &STI)
LLVM_ABI SmallString< 32 > getExtendedTBTableFlagString(uint8_t Flag)
Definition XCOFF.cpp:221
LLVM_ABI XCOFF::CFileCpuId getCpuID(StringRef CPU)
Definition XCOFF.cpp:112
LLVM_ABI Expected< SmallString< 32 > > parseParmsTypeWithVecInfo(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum, unsigned VectorParmsNum)
Definition XCOFF.cpp:247
LLVM_ABI Expected< SmallString< 32 > > parseParmsType(uint32_t Value, unsigned FixedParmsNum, unsigned FloatingParmsNum)
Definition XCOFF.cpp:169
LLVM_ABI Expected< SmallString< 32 > > parseVectorParmsType(uint32_t Value, unsigned ParmsNum)
Definition XCOFF.cpp:299
@ TCPU_INVALID
Invalid id - assumes POWER for old objects.
Definition XCOFF.h:339
StorageMappingClass
Storage Mapping Class definitions.
Definition XCOFF.h:104
@ XMC_RW
Read Write Data.
Definition XCOFF.h:118
@ XMC_RO
Read Only Constant.
Definition XCOFF.h:107
@ XMC_TD
Scalar data item in the TOC.
Definition XCOFF.h:121
@ XMC_PR
Program Code.
Definition XCOFF.h:106
LLVM_ABI StringRef getTCPUString(XCOFF::CFileCpuId TCPU)
Definition XCOFF.cpp:141
LLVM_ABI StringRef getNameForTracebackTableLanguageId(TracebackTable::LanguageID LangId)
Definition XCOFF.cpp:89
constexpr uint8_t AllocRegNo
Definition XCOFF.h:45
@ XTY_SD
Csect definition for initialized storage.
Definition XCOFF.h:243
@ XTY_ER
External reference.
Definition XCOFF.h:242
unsigned combineHashValue(unsigned a, unsigned b)
Simplistic combination of 32-bit hash values into 32-bit hash values.
This is an optimization pass for GlobalISel generic memory operations.
std::optional< LongDoubleFormat > parseLongDoubleFormat(StringRef Name)
Parses an IR floating-point type name into a LongDoubleFormat, returning std::nullopt if it does not ...
Definition CodeGen.h:144
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
Definition STLExtras.h:316
@ Offset
Definition DWP.cpp:577
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.
Definition STLExtras.h:1685
@ Unknown
Not known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
auto cast_or_null(const Y &Val)
Definition Casting.h:714
Target & getThePPC32Target()
std::string utostr(uint64_t X, bool isNeg=false)
const Value * getPointerOperand(const Value *V)
A helper function that returns the pointer operand of a load, store or GEP instruction.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
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.
Definition Debug.cpp:209
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
bool LowerPPCMachineOperandToMCOperand(unsigned MIOpcode, const MachineOperand &MO, MCOperand &OutMO, AsmPrinter &AP)
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.
Definition Format.h:177
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
Target & getThePPC64Target()
LLVM_ABI uint64_t get_threadid()
Return the current thread id, as used in various OS system calls.
Definition Threading.cpp:33
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.
Definition MathExtras.h:554
Target & getThePPC32LETarget()
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
std::pair< MCSection *, uint32_t > MCSectionSubPair
Definition MCStreamer.h:68
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
@ PPC_ABI_ELFv2
Definition PPC.h:104
std::string itostr(int64_t X)
@ MCSA_Extern
.extern (XCOFF)
@ MCSA_Invalid
Not a valid directive.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
#define N
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:82
std::pair< const MCSymbol *, PPCMCExpr::Specifier > TOCKey
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.
Definition Alignment.h:135
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn)
RegisterAsmPrinter - Register an AsmPrinter implementation for the given target.
static constexpr uint32_t FPRSavedMask
Definition XCOFF.h:437
static constexpr uint16_t NumberOfVRSavedMask
Definition XCOFF.h:467
static constexpr uint8_t NumberOfFloatingPointParmsShift
Definition XCOFF.h:453
static constexpr uint32_t NumberOfFixedParmsMask
Definition XCOFF.h:447
static constexpr uint16_t HasVMXInstructionMask
Definition XCOFF.h:473
static constexpr uint32_t IsLRSavedMask
Definition XCOFF.h:431
static constexpr uint16_t HasVarArgsMask
Definition XCOFF.h:469
static constexpr uint32_t IsAllocaUsedMask
Definition XCOFF.h:428
static constexpr uint16_t IsVRSavedOnStackMask
Definition XCOFF.h:468
static constexpr uint16_t NumberOfVectorParmsMask
Definition XCOFF.h:472
static constexpr uint32_t IsFloatingPointPresentMask
Definition XCOFF.h:421
static constexpr uint32_t FPRSavedShift
Definition XCOFF.h:438
static constexpr uint32_t NumberOfFloatingPointParmsMask
Definition XCOFF.h:451
static constexpr uint32_t HasControlledStorageMask
Definition XCOFF.h:419
static constexpr uint32_t HasExtensionTableMask
Definition XCOFF.h:441
static constexpr uint32_t HasTraceBackTableOffsetMask
Definition XCOFF.h:417
static constexpr uint32_t IsCRSavedMask
Definition XCOFF.h:430
static constexpr uint8_t NumberOfFixedParmsShift
Definition XCOFF.h:448
static constexpr uint32_t GPRSavedMask
Definition XCOFF.h:443
static constexpr uint8_t NumberOfVectorParmsShift
Definition XCOFF.h:474
static constexpr uint32_t HasParmsOnStackMask
Definition XCOFF.h:452
static constexpr uint32_t IsFunctionNamePresentMask
Definition XCOFF.h:427
static constexpr uint32_t IsBackChainStoredMask
Definition XCOFF.h:435
static constexpr uint32_t IsInterruptHandlerMask
Definition XCOFF.h:426
static constexpr uint32_t HasVectorInfoMask
Definition XCOFF.h:442
static constexpr uint8_t NumberOfVRSavedShift
Definition XCOFF.h:470
static constexpr uint32_t GPRSavedShift
Definition XCOFF.h:444