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