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