LLVM 17.0.0git
ARMAsmPrinter.cpp
Go to the documentation of this file.
1//===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===//
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 GAS-format ARM assembly language.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ARMAsmPrinter.h"
15#include "ARM.h"
18#include "ARMTargetMachine.h"
19#include "ARMTargetObjectFile.h"
29#include "llvm/IR/Constants.h"
30#include "llvm/IR/DataLayout.h"
31#include "llvm/IR/Mangler.h"
32#include "llvm/IR/Module.h"
33#include "llvm/IR/Type.h"
34#include "llvm/MC/MCAsmInfo.h"
35#include "llvm/MC/MCAssembler.h"
36#include "llvm/MC/MCContext.h"
38#include "llvm/MC/MCInst.h"
41#include "llvm/MC/MCStreamer.h"
42#include "llvm/MC/MCSymbol.h"
45#include "llvm/Support/Debug.h"
49using namespace llvm;
50
51#define DEBUG_TYPE "asm-printer"
52
54 std::unique_ptr<MCStreamer> Streamer)
55 : AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), AFI(nullptr),
56 MCP(nullptr), InConstantPool(false), OptimizationGoals(-1) {}
57
59 // Make sure to terminate any constant pools that were at the end
60 // of the function.
61 if (!InConstantPool)
62 return;
63 InConstantPool = false;
64 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
65}
66
68 if (AFI->isThumbFunction()) {
69 OutStreamer->emitAssemblerFlag(MCAF_Code16);
70 OutStreamer->emitThumbFunc(CurrentFnSym);
71 } else {
72 OutStreamer->emitAssemblerFlag(MCAF_Code32);
73 }
74
75 // Emit symbol for CMSE non-secure entry point
76 if (AFI->isCmseNSEntryFunction()) {
77 MCSymbol *S =
80 OutStreamer->emitSymbolAttribute(S, MCSA_ELF_TypeFunction);
81 OutStreamer->emitLabel(S);
82 }
84}
85
88 assert(Size && "C++ constructor pointer had zero size!");
89
90 const GlobalValue *GV = dyn_cast<GlobalValue>(CV->stripPointerCasts());
91 assert(GV && "C++ constructor pointer was not a GlobalValue!");
92
93 const MCExpr *E = MCSymbolRefExpr::create(GetARMGVSymbol(GV,
95 (Subtarget->isTargetELF()
99
100 OutStreamer->emitValue(E, Size);
101}
102
104 if (PromotedGlobals.count(GV))
105 // The global was promoted into a constant pool. It should not be emitted.
106 return;
108}
109
110/// runOnMachineFunction - This uses the emitInstruction()
111/// method to print assembly for each instruction.
112///
114 AFI = MF.getInfo<ARMFunctionInfo>();
115 MCP = MF.getConstantPool();
116 Subtarget = &MF.getSubtarget<ARMSubtarget>();
117
119 const Function &F = MF.getFunction();
120 const TargetMachine& TM = MF.getTarget();
121
122 // Collect all globals that had their storage promoted to a constant pool.
123 // Functions are emitted before variables, so this accumulates promoted
124 // globals from all functions in PromotedGlobals.
125 for (const auto *GV : AFI->getGlobalsPromotedToConstantPool())
126 PromotedGlobals.insert(GV);
127
128 // Calculate this function's optimization goal.
129 unsigned OptimizationGoal;
130 if (F.hasOptNone())
131 // For best debugging illusion, speed and small size sacrificed
132 OptimizationGoal = 6;
133 else if (F.hasMinSize())
134 // Aggressively for small size, speed and debug illusion sacrificed
135 OptimizationGoal = 4;
136 else if (F.hasOptSize())
137 // For small size, but speed and debugging illusion preserved
138 OptimizationGoal = 3;
140 // Aggressively for speed, small size and debug illusion sacrificed
141 OptimizationGoal = 2;
142 else if (TM.getOptLevel() > CodeGenOpt::None)
143 // For speed, but small size and good debug illusion preserved
144 OptimizationGoal = 1;
145 else // TM.getOptLevel() == CodeGenOpt::None
146 // For good debugging, but speed and small size preserved
147 OptimizationGoal = 5;
148
149 // Combine a new optimization goal with existing ones.
150 if (OptimizationGoals == -1) // uninitialized goals
151 OptimizationGoals = OptimizationGoal;
152 else if (OptimizationGoals != (int)OptimizationGoal) // conflicting goals
153 OptimizationGoals = 0;
154
155 if (Subtarget->isTargetCOFF()) {
156 bool Internal = F.hasInternalLinkage();
160
161 OutStreamer->beginCOFFSymbolDef(CurrentFnSym);
162 OutStreamer->emitCOFFSymbolStorageClass(Scl);
163 OutStreamer->emitCOFFSymbolType(Type);
164 OutStreamer->endCOFFSymbolDef();
165 }
166
167 // Emit the rest of the function body.
169
170 // Emit the XRay table for this function.
172
173 // If we need V4T thumb mode Register Indirect Jump pads, emit them.
174 // These are created per function, rather than per TU, since it's
175 // relatively easy to exceed the thumb branch range within a TU.
176 if (! ThumbIndirectPads.empty()) {
177 OutStreamer->emitAssemblerFlag(MCAF_Code16);
179 for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {
180 OutStreamer->emitLabel(TIP.second);
182 .addReg(TIP.first)
183 // Add predicate operands.
185 .addReg(0));
186 }
187 ThumbIndirectPads.clear();
188 }
189
190 // We didn't modify anything.
191 return false;
192}
193
195 raw_ostream &O) {
196 assert(MO.isGlobal() && "caller should check MO.isGlobal");
197 unsigned TF = MO.getTargetFlags();
198 if (TF & ARMII::MO_LO16)
199 O << ":lower16:";
200 else if (TF & ARMII::MO_HI16)
201 O << ":upper16:";
202 GetARMGVSymbol(MO.getGlobal(), TF)->print(O, MAI);
203 printOffset(MO.getOffset(), O);
204}
205
207 raw_ostream &O) {
208 const MachineOperand &MO = MI->getOperand(OpNum);
209
210 switch (MO.getType()) {
211 default: llvm_unreachable("<unknown operand type>");
213 Register Reg = MO.getReg();
214 assert(Reg.isPhysical());
215 assert(!MO.getSubReg() && "Subregs should be eliminated!");
216 if(ARM::GPRPairRegClass.contains(Reg)) {
217 const MachineFunction &MF = *MI->getParent()->getParent();
219 Reg = TRI->getSubReg(Reg, ARM::gsub_0);
220 }
222 break;
223 }
225 O << '#';
226 unsigned TF = MO.getTargetFlags();
227 if (TF == ARMII::MO_LO16)
228 O << ":lower16:";
229 else if (TF == ARMII::MO_HI16)
230 O << ":upper16:";
231 O << MO.getImm();
232 break;
233 }
235 MO.getMBB()->getSymbol()->print(O, MAI);
236 return;
238 PrintSymbolOperand(MO, O);
239 break;
240 }
242 if (Subtarget->genExecuteOnly())
243 llvm_unreachable("execute-only should not generate constant pools");
244 GetCPISymbol(MO.getIndex())->print(O, MAI);
245 break;
246 }
247}
248
250 // The AsmPrinter::GetCPISymbol superclass method tries to use CPID as
251 // indexes in MachineConstantPool, which isn't in sync with indexes used here.
252 const DataLayout &DL = getDataLayout();
253 return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +
254 "CPI" + Twine(getFunctionNumber()) + "_" +
255 Twine(CPID));
256}
257
258//===--------------------------------------------------------------------===//
259
260MCSymbol *ARMAsmPrinter::
261GetARMJTIPICJumpTableLabel(unsigned uid) const {
262 const DataLayout &DL = getDataLayout();
264 raw_svector_ostream(Name) << DL.getPrivateGlobalPrefix() << "JTI"
265 << getFunctionNumber() << '_' << uid;
267}
268
270 const char *ExtraCode, raw_ostream &O) {
271 // Does this asm operand have a single letter operand modifier?
272 if (ExtraCode && ExtraCode[0]) {
273 if (ExtraCode[1] != 0) return true; // Unknown modifier.
274
275 switch (ExtraCode[0]) {
276 default:
277 // See if this is a generic print operand
278 return AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);
279 case 'P': // Print a VFP double precision register.
280 case 'q': // Print a NEON quad precision register.
281 printOperand(MI, OpNum, O);
282 return false;
283 case 'y': // Print a VFP single precision register as indexed double.
284 if (MI->getOperand(OpNum).isReg()) {
285 MCRegister Reg = MI->getOperand(OpNum).getReg().asMCReg();
287 // Find the 'd' register that has this 's' register as a sub-register,
288 // and determine the lane number.
289 for (MCPhysReg SR : TRI->superregs(Reg)) {
290 if (!ARM::DPRRegClass.contains(SR))
291 continue;
292 bool Lane0 = TRI->getSubReg(SR, ARM::ssub_0) == Reg;
293 O << ARMInstPrinter::getRegisterName(SR) << (Lane0 ? "[0]" : "[1]");
294 return false;
295 }
296 }
297 return true;
298 case 'B': // Bitwise inverse of integer or symbol without a preceding #.
299 if (!MI->getOperand(OpNum).isImm())
300 return true;
301 O << ~(MI->getOperand(OpNum).getImm());
302 return false;
303 case 'L': // The low 16 bits of an immediate constant.
304 if (!MI->getOperand(OpNum).isImm())
305 return true;
306 O << (MI->getOperand(OpNum).getImm() & 0xffff);
307 return false;
308 case 'M': { // A register range suitable for LDM/STM.
309 if (!MI->getOperand(OpNum).isReg())
310 return true;
311 const MachineOperand &MO = MI->getOperand(OpNum);
312 Register RegBegin = MO.getReg();
313 // This takes advantage of the 2 operand-ness of ldm/stm and that we've
314 // already got the operands in registers that are operands to the
315 // inline asm statement.
316 O << "{";
317 if (ARM::GPRPairRegClass.contains(RegBegin)) {
319 Register Reg0 = TRI->getSubReg(RegBegin, ARM::gsub_0);
320 O << ARMInstPrinter::getRegisterName(Reg0) << ", ";
321 RegBegin = TRI->getSubReg(RegBegin, ARM::gsub_1);
322 }
323 O << ARMInstPrinter::getRegisterName(RegBegin);
324
325 // FIXME: The register allocator not only may not have given us the
326 // registers in sequence, but may not be in ascending registers. This
327 // will require changes in the register allocator that'll need to be
328 // propagated down here if the operands change.
329 unsigned RegOps = OpNum + 1;
330 while (MI->getOperand(RegOps).isReg()) {
331 O << ", "
332 << ARMInstPrinter::getRegisterName(MI->getOperand(RegOps).getReg());
333 RegOps++;
334 }
335
336 O << "}";
337
338 return false;
339 }
340 case 'R': // The most significant register of a pair.
341 case 'Q': { // The least significant register of a pair.
342 if (OpNum == 0)
343 return true;
344 const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);
345 if (!FlagsOP.isImm())
346 return true;
347 unsigned Flags = FlagsOP.getImm();
348
349 // This operand may not be the one that actually provides the register. If
350 // it's tied to a previous one then we should refer instead to that one
351 // for registers and their classes.
352 unsigned TiedIdx;
354 for (OpNum = InlineAsm::MIOp_FirstOperand; TiedIdx; --TiedIdx) {
355 unsigned OpFlags = MI->getOperand(OpNum).getImm();
356 OpNum += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
357 }
358 Flags = MI->getOperand(OpNum).getImm();
359
360 // Later code expects OpNum to be pointing at the register rather than
361 // the flags.
362 OpNum += 1;
363 }
364
365 unsigned NumVals = InlineAsm::getNumOperandRegisters(Flags);
366 unsigned RC;
367 bool FirstHalf;
368 const ARMBaseTargetMachine &ATM =
369 static_cast<const ARMBaseTargetMachine &>(TM);
370
371 // 'Q' should correspond to the low order register and 'R' to the high
372 // order register. Whether this corresponds to the upper or lower half
373 // depends on the endianess mode.
374 if (ExtraCode[0] == 'Q')
375 FirstHalf = ATM.isLittleEndian();
376 else
377 // ExtraCode[0] == 'R'.
378 FirstHalf = !ATM.isLittleEndian();
381 ARM::GPRPairRegClass.hasSubClassEq(TRI->getRegClass(RC))) {
382 if (NumVals != 1)
383 return true;
384 const MachineOperand &MO = MI->getOperand(OpNum);
385 if (!MO.isReg())
386 return true;
388 Register Reg =
389 TRI->getSubReg(MO.getReg(), FirstHalf ? ARM::gsub_0 : ARM::gsub_1);
391 return false;
392 }
393 if (NumVals != 2)
394 return true;
395 unsigned RegOp = FirstHalf ? OpNum : OpNum + 1;
396 if (RegOp >= MI->getNumOperands())
397 return true;
398 const MachineOperand &MO = MI->getOperand(RegOp);
399 if (!MO.isReg())
400 return true;
401 Register Reg = MO.getReg();
403 return false;
404 }
405
406 case 'e': // The low doubleword register of a NEON quad register.
407 case 'f': { // The high doubleword register of a NEON quad register.
408 if (!MI->getOperand(OpNum).isReg())
409 return true;
410 Register Reg = MI->getOperand(OpNum).getReg();
411 if (!ARM::QPRRegClass.contains(Reg))
412 return true;
415 TRI->getSubReg(Reg, ExtraCode[0] == 'e' ? ARM::dsub_0 : ARM::dsub_1);
417 return false;
418 }
419
420 // This modifier is not yet supported.
421 case 'h': // A range of VFP/NEON registers suitable for VLD1/VST1.
422 return true;
423 case 'H': { // The highest-numbered register of a pair.
424 const MachineOperand &MO = MI->getOperand(OpNum);
425 if (!MO.isReg())
426 return true;
427 const MachineFunction &MF = *MI->getParent()->getParent();
429 Register Reg = MO.getReg();
430 if(!ARM::GPRPairRegClass.contains(Reg))
431 return false;
432 Reg = TRI->getSubReg(Reg, ARM::gsub_1);
434 return false;
435 }
436 }
437 }
438
439 printOperand(MI, OpNum, O);
440 return false;
441}
442
444 unsigned OpNum, const char *ExtraCode,
445 raw_ostream &O) {
446 // Does this asm operand have a single letter operand modifier?
447 if (ExtraCode && ExtraCode[0]) {
448 if (ExtraCode[1] != 0) return true; // Unknown modifier.
449
450 switch (ExtraCode[0]) {
451 case 'A': // A memory operand for a VLD1/VST1 instruction.
452 default: return true; // Unknown modifier.
453 case 'm': // The base register of a memory operand.
454 if (!MI->getOperand(OpNum).isReg())
455 return true;
456 O << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());
457 return false;
458 }
459 }
460
461 const MachineOperand &MO = MI->getOperand(OpNum);
462 assert(MO.isReg() && "unexpected inline asm memory operand");
463 O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]";
464 return false;
465}
466
467static bool isThumb(const MCSubtargetInfo& STI) {
468 return STI.hasFeature(ARM::ModeThumb);
469}
470
472 const MCSubtargetInfo *EndInfo) const {
473 // If either end mode is unknown (EndInfo == NULL) or different than
474 // the start mode, then restore the start mode.
475 const bool WasThumb = isThumb(StartInfo);
476 if (!EndInfo || WasThumb != isThumb(*EndInfo)) {
477 OutStreamer->emitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);
478 }
479}
480
482 const Triple &TT = TM.getTargetTriple();
483 // Use unified assembler syntax.
484 OutStreamer->emitAssemblerFlag(MCAF_SyntaxUnified);
485
486 // Emit ARM Build Attributes
487 if (TT.isOSBinFormatELF())
488 emitAttributes();
489
490 // Use the triple's architecture and subarchitecture to determine
491 // if we're thumb for the purposes of the top level code16 assembler
492 // flag.
493 if (!M.getModuleInlineAsm().empty() && TT.isThumb())
494 OutStreamer->emitAssemblerFlag(MCAF_Code16);
495}
496
497static void
500 // L_foo$stub:
501 OutStreamer.emitLabel(StubLabel);
502 // .indirect_symbol _foo
504
505 if (MCSym.getInt())
506 // External to current translation unit.
507 OutStreamer.emitIntValue(0, 4/*size*/);
508 else
509 // Internal to current translation unit.
510 //
511 // When we place the LSDA into the TEXT section, the type info
512 // pointers need to be indirect and pc-rel. We accomplish this by
513 // using NLPs; however, sometimes the types are local to the file.
514 // We need to fill in the value for the NLP in those cases.
515 OutStreamer.emitValue(
516 MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),
517 4 /*size*/);
518}
519
520
522 const Triple &TT = TM.getTargetTriple();
523 if (TT.isOSBinFormatMachO()) {
524 // All darwin targets use mach-o.
525 const TargetLoweringObjectFileMachO &TLOFMacho =
527 MachineModuleInfoMachO &MMIMacho =
529
530 // Output non-lazy-pointers for external and common global variables.
532
533 if (!Stubs.empty()) {
534 // Switch with ".non_lazy_symbol_pointer" directive.
535 OutStreamer->switchSection(TLOFMacho.getNonLazySymbolPointerSection());
537
538 for (auto &Stub : Stubs)
539 emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
540
541 Stubs.clear();
542 OutStreamer->addBlankLine();
543 }
544
545 Stubs = MMIMacho.GetThreadLocalGVStubList();
546 if (!Stubs.empty()) {
547 // Switch with ".non_lazy_symbol_pointer" directive.
548 OutStreamer->switchSection(TLOFMacho.getThreadLocalPointerSection());
550
551 for (auto &Stub : Stubs)
552 emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);
553
554 Stubs.clear();
555 OutStreamer->addBlankLine();
556 }
557
558 // Funny Darwin hack: This flag tells the linker that no global symbols
559 // contain code that falls through to other global symbols (e.g. the obvious
560 // implementation of multiple entry points). If this doesn't occur, the
561 // linker can safely perform dead code stripping. Since LLVM never
562 // generates code that does this, it is always safe to set.
563 OutStreamer->emitAssemblerFlag(MCAF_SubsectionsViaSymbols);
564 }
565
566 // The last attribute to be emitted is ABI_optimization_goals
567 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
568 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
569
570 if (OptimizationGoals > 0 &&
571 (Subtarget->isTargetAEABI() || Subtarget->isTargetGNUAEABI() ||
572 Subtarget->isTargetMuslAEABI()))
574 OptimizationGoals = -1;
575
577}
578
579//===----------------------------------------------------------------------===//
580// Helper routines for emitStartOfAsmFile() and emitEndOfAsmFile()
581// FIXME:
582// The following seem like one-off assembler flags, but they actually need
583// to appear in the .ARM.attributes section in ELF.
584// Instead of subclassing the MCELFStreamer, we do the work here.
585
586 // Returns true if all functions have the same function attribute value.
587 // It also returns true when the module has no functions.
590 return !any_of(M, [&](const Function &F) {
591 return F.getFnAttribute(Attr).getValueAsString() != Value;
592 });
593}
594// Returns true if all functions have the same denormal mode.
595// It also returns true when the module has no functions.
597 StringRef Attr,
599 return !any_of(M, [&](const Function &F) {
600 StringRef AttrVal = F.getFnAttribute(Attr).getValueAsString();
601 return parseDenormalFPAttribute(AttrVal) != Value;
602 });
603}
604
605void ARMAsmPrinter::emitAttributes() {
606 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
607 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
608
610
611 ATS.switchVendor("aeabi");
612
613 // Compute ARM ELF Attributes based on the default subtarget that
614 // we'd have constructed. The existing ARM behavior isn't LTO clean
615 // anyhow.
616 // FIXME: For ifunc related functions we could iterate over and look
617 // for a feature string that doesn't match the default one.
618 const Triple &TT = TM.getTargetTriple();
619 StringRef CPU = TM.getTargetCPU();
621 std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);
622 if (!FS.empty()) {
623 if (!ArchFS.empty())
624 ArchFS = (Twine(ArchFS) + "," + FS).str();
625 else
626 ArchFS = std::string(FS);
627 }
628 const ARMBaseTargetMachine &ATM =
629 static_cast<const ARMBaseTargetMachine &>(TM);
630 const ARMSubtarget STI(TT, std::string(CPU), ArchFS, ATM,
631 ATM.isLittleEndian());
632
633 // Emit build attributes for the available hardware.
634 ATS.emitTargetAttributes(STI);
635
636 // RW data addressing.
637 if (isPositionIndependent()) {
640 } else if (STI.isRWPI()) {
641 // RWPI specific attributes.
644 }
645
646 // RO data addressing.
647 if (isPositionIndependent() || STI.isROPI()) {
650 }
651
652 // GOT use.
653 if (isPositionIndependent()) {
656 } else {
659 }
660
661 // Set FP Denormals.
662 if (checkDenormalAttributeConsistency(*MMI->getModule(), "denormal-fp-math",
667 "denormal-fp-math",
671 else if (!TM.Options.UnsafeFPMath)
674 else {
675 if (!STI.hasVFP2Base()) {
676 // When the target doesn't have an FPU (by design or
677 // intention), the assumptions made on the software support
678 // mirror that of the equivalent hardware support *if it
679 // existed*. For v7 and better we indicate that denormals are
680 // flushed preserving sign, and for V6 we indicate that
681 // denormals are flushed to positive zero.
682 if (STI.hasV7Ops())
685 } else if (STI.hasVFP3Base()) {
686 // In VFPv4, VFPv4U, VFPv3, or VFPv3U, it is preserved. That is,
687 // the sign bit of the zero matches the sign bit of the input or
688 // result that is being flushed to zero.
691 }
692 // For VFPv2 implementations it is implementation defined as
693 // to whether denormals are flushed to positive zero or to
694 // whatever the sign of zero is (ARM v7AR ARM 2.7.5). Historically
695 // LLVM has chosen to flush this to positive zero (most likely for
696 // GCC compatibility), so that's the chosen value here (the
697 // absence of its emission implies zero).
698 }
699
700 // Set FP exceptions and rounding
702 "no-trapping-math", "true") ||
706 else if (!TM.Options.UnsafeFPMath) {
708
709 // If the user has permitted this code to choose the IEEE 754
710 // rounding at run-time, emit the rounding attribute.
713 }
714
715 // TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the
716 // equivalent of GCC's -ffinite-math-only flag.
720 else
723
724 // FIXME: add more flags to ARMBuildAttributes.h
725 // 8-bytes alignment stuff.
728
729 // Hard float. Use both S and D registers and conform to AAPCS-VFP.
730 if (STI.isAAPCS_ABI() && TM.Options.FloatABIType == FloatABI::Hard)
732
733 // FIXME: To support emitting this build attribute as GCC does, the
734 // -mfp16-format option and associated plumbing must be
735 // supported. For now the __fp16 type is exposed by default, so this
736 // attribute should be emitted with value 1.
739
740 if (const Module *SourceModule = MMI->getModule()) {
741 // ABI_PCS_wchar_t to indicate wchar_t width
742 // FIXME: There is no way to emit value 0 (wchar_t prohibited).
743 if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>(
744 SourceModule->getModuleFlag("wchar_size"))) {
745 int WCharWidth = WCharWidthValue->getZExtValue();
746 assert((WCharWidth == 2 || WCharWidth == 4) &&
747 "wchar_t width must be 2 or 4 bytes");
749 }
750
751 // ABI_enum_size to indicate enum width
752 // FIXME: There is no way to emit value 0 (enums prohibited) or value 3
753 // (all enums contain a value needing 32 bits to encode).
754 if (auto EnumWidthValue = mdconst::extract_or_null<ConstantInt>(
755 SourceModule->getModuleFlag("min_enum_size"))) {
756 int EnumWidth = EnumWidthValue->getZExtValue();
757 assert((EnumWidth == 1 || EnumWidth == 4) &&
758 "Minimum enum width must be 1 or 4 bytes");
759 int EnumBuildAttr = EnumWidth == 1 ? 1 : 2;
761 }
762
763 auto *PACValue = mdconst::extract_or_null<ConstantInt>(
764 SourceModule->getModuleFlag("sign-return-address"));
765 if (PACValue && PACValue->isOne()) {
766 // If "+pacbti" is used as an architecture extension,
767 // Tag_PAC_extension is emitted in
768 // ARMTargetStreamer::emitTargetAttributes().
769 if (!STI.hasPACBTI()) {
772 }
774 }
775
776 auto *BTIValue = mdconst::extract_or_null<ConstantInt>(
777 SourceModule->getModuleFlag("branch-target-enforcement"));
778 if (BTIValue && BTIValue->isOne()) {
779 // If "+pacbti" is used as an architecture extension,
780 // Tag_BTI_extension is emitted in
781 // ARMTargetStreamer::emitTargetAttributes().
782 if (!STI.hasPACBTI()) {
785 }
787 }
788 }
789
790 // We currently do not support using R9 as the TLS pointer.
791 if (STI.isRWPI())
794 else if (STI.isR9Reserved())
797 else
800}
801
802//===----------------------------------------------------------------------===//
803
804static MCSymbol *getBFLabel(StringRef Prefix, unsigned FunctionNumber,
805 unsigned LabelId, MCContext &Ctx) {
806
807 MCSymbol *Label = Ctx.getOrCreateSymbol(Twine(Prefix)
808 + "BF" + Twine(FunctionNumber) + "_" + Twine(LabelId));
809 return Label;
810}
811
812static MCSymbol *getPICLabel(StringRef Prefix, unsigned FunctionNumber,
813 unsigned LabelId, MCContext &Ctx) {
814
815 MCSymbol *Label = Ctx.getOrCreateSymbol(Twine(Prefix)
816 + "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId));
817 return Label;
818}
819
822 switch (Modifier) {
825 case ARMCP::TLSGD:
827 case ARMCP::TPOFF:
829 case ARMCP::GOTTPOFF:
831 case ARMCP::SBREL:
833 case ARMCP::GOT_PREL:
835 case ARMCP::SECREL:
837 }
838 llvm_unreachable("Invalid ARMCPModifier!");
839}
840
841MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,
842 unsigned char TargetFlags) {
843 if (Subtarget->isTargetMachO()) {
844 bool IsIndirect =
845 (TargetFlags & ARMII::MO_NONLAZY) && Subtarget->isGVIndirectSymbol(GV);
846
847 if (!IsIndirect)
848 return getSymbol(GV);
849
850 // FIXME: Remove this when Darwin transition to @GOT like syntax.
851 MCSymbol *MCSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
852 MachineModuleInfoMachO &MMIMachO =
855 GV->isThreadLocal() ? MMIMachO.getThreadLocalGVStubEntry(MCSym)
856 : MMIMachO.getGVStubEntry(MCSym);
857
858 if (!StubSym.getPointer())
860 !GV->hasInternalLinkage());
861 return MCSym;
862 } else if (Subtarget->isTargetCOFF()) {
863 assert(Subtarget->isTargetWindows() &&
864 "Windows is the only supported COFF target");
865
866 bool IsIndirect =
867 (TargetFlags & (ARMII::MO_DLLIMPORT | ARMII::MO_COFFSTUB));
868 if (!IsIndirect)
869 return getSymbol(GV);
870
872 if (TargetFlags & ARMII::MO_DLLIMPORT)
873 Name = "__imp_";
874 else if (TargetFlags & ARMII::MO_COFFSTUB)
875 Name = ".refptr.";
877
879
880 if (TargetFlags & ARMII::MO_COFFSTUB) {
881 MachineModuleInfoCOFF &MMICOFF =
884 MMICOFF.getGVStubEntry(MCSym);
885
886 if (!StubSym.getPointer())
888 }
889
890 return MCSym;
891 } else if (Subtarget->isTargetELF()) {
892 return getSymbolPreferLocal(*GV);
893 }
894 llvm_unreachable("unexpected target");
895}
896
899 const DataLayout &DL = getDataLayout();
900 int Size = DL.getTypeAllocSize(MCPV->getType());
901
902 ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);
903
904 if (ACPV->isPromotedGlobal()) {
905 // This constant pool entry is actually a global whose storage has been
906 // promoted into the constant pool. This global may be referenced still
907 // by debug information, and due to the way AsmPrinter is set up, the debug
908 // info is immutable by the time we decide to promote globals to constant
909 // pools. Because of this, we need to ensure we emit a symbol for the global
910 // with private linkage (the default) so debug info can refer to it.
911 //
912 // However, if this global is promoted into several functions we must ensure
913 // we don't try and emit duplicate symbols!
914 auto *ACPC = cast<ARMConstantPoolConstant>(ACPV);
915 for (const auto *GV : ACPC->promotedGlobals()) {
916 if (!EmittedPromotedGlobalLabels.count(GV)) {
917 MCSymbol *GVSym = getSymbol(GV);
918 OutStreamer->emitLabel(GVSym);
919 EmittedPromotedGlobalLabels.insert(GV);
920 }
921 }
922 return emitGlobalConstant(DL, ACPC->getPromotedGlobalInit());
923 }
924
925 MCSymbol *MCSym;
926 if (ACPV->isLSDA()) {
927 MCSym = getMBBExceptionSym(MF->front());
928 } else if (ACPV->isBlockAddress()) {
929 const BlockAddress *BA =
930 cast<ARMConstantPoolConstant>(ACPV)->getBlockAddress();
931 MCSym = GetBlockAddressSymbol(BA);
932 } else if (ACPV->isGlobalValue()) {
933 const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();
934
935 // On Darwin, const-pool entries may get the "FOO$non_lazy_ptr" mangling, so
936 // flag the global as MO_NONLAZY.
937 unsigned char TF = Subtarget->isTargetMachO() ? ARMII::MO_NONLAZY : 0;
938 MCSym = GetARMGVSymbol(GV, TF);
939 } else if (ACPV->isMachineBasicBlock()) {
940 const MachineBasicBlock *MBB = cast<ARMConstantPoolMBB>(ACPV)->getMBB();
941 MCSym = MBB->getSymbol();
942 } else {
943 assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
944 auto Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();
946 }
947
948 // Create an MCSymbol for the reference.
949 const MCExpr *Expr =
951 OutContext);
952
953 if (ACPV->getPCAdjustment()) {
954 MCSymbol *PCLabel =
955 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
956 ACPV->getLabelId(), OutContext);
957 const MCExpr *PCRelExpr = MCSymbolRefExpr::create(PCLabel, OutContext);
958 PCRelExpr =
959 MCBinaryExpr::createAdd(PCRelExpr,
961 OutContext),
962 OutContext);
963 if (ACPV->mustAddCurrentAddress()) {
964 // We want "(<expr> - .)", but MC doesn't have a concept of the '.'
965 // label, so just emit a local label end reference that instead.
967 OutStreamer->emitLabel(DotSym);
968 const MCExpr *DotExpr = MCSymbolRefExpr::create(DotSym, OutContext);
969 PCRelExpr = MCBinaryExpr::createSub(PCRelExpr, DotExpr, OutContext);
970 }
971 Expr = MCBinaryExpr::createSub(Expr, PCRelExpr, OutContext);
972 }
973 OutStreamer->emitValue(Expr, Size);
974}
975
977 const MachineOperand &MO1 = MI->getOperand(1);
978 unsigned JTI = MO1.getIndex();
979
980 // Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
981 // ARM mode tables.
983
984 // Emit a label for the jump table.
985 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
986 OutStreamer->emitLabel(JTISymbol);
987
988 // Mark the jump table as data-in-code.
989 OutStreamer->emitDataRegion(MCDR_DataRegionJT32);
990
991 // Emit each entry of the table.
993 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
994 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
995
996 for (MachineBasicBlock *MBB : JTBBs) {
997 // Construct an MCExpr for the entry. We want a value of the form:
998 // (BasicBlockAddr - TableBeginAddr)
999 //
1000 // For example, a table with entries jumping to basic blocks BB0 and BB1
1001 // would look like:
1002 // LJTI_0_0:
1003 // .word (LBB0 - LJTI_0_0)
1004 // .word (LBB1 - LJTI_0_0)
1006
1007 if (isPositionIndependent() || Subtarget->isROPI())
1008 Expr = MCBinaryExpr::createSub(Expr, MCSymbolRefExpr::create(JTISymbol,
1009 OutContext),
1010 OutContext);
1011 // If we're generating a table of Thumb addresses in static relocation
1012 // model, we need to add one to keep interworking correctly.
1013 else if (AFI->isThumbFunction())
1015 OutContext);
1016 OutStreamer->emitValue(Expr, 4);
1017 }
1018 // Mark the end of jump table data-in-code region.
1019 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
1020}
1021
1023 const MachineOperand &MO1 = MI->getOperand(1);
1024 unsigned JTI = MO1.getIndex();
1025
1026 // Make sure the Thumb jump table is 4-byte aligned. This will be a nop for
1027 // ARM mode tables.
1028 emitAlignment(Align(4));
1029
1030 // Emit a label for the jump table.
1031 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
1032 OutStreamer->emitLabel(JTISymbol);
1033
1034 // Emit each entry of the table.
1035 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1036 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1037 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1038
1039 for (MachineBasicBlock *MBB : JTBBs) {
1040 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
1041 OutContext);
1042 // If this isn't a TBB or TBH, the entries are direct branch instructions.
1044 .addExpr(MBBSymbolExpr)
1045 .addImm(ARMCC::AL)
1046 .addReg(0));
1047 }
1048}
1049
1051 unsigned OffsetWidth) {
1052 assert((OffsetWidth == 1 || OffsetWidth == 2) && "invalid tbb/tbh width");
1053 const MachineOperand &MO1 = MI->getOperand(1);
1054 unsigned JTI = MO1.getIndex();
1055
1056 if (Subtarget->isThumb1Only())
1057 emitAlignment(Align(4));
1058
1059 MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);
1060 OutStreamer->emitLabel(JTISymbol);
1061
1062 // Emit each entry of the table.
1063 const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();
1064 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
1065 const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
1066
1067 // Mark the jump table as data-in-code.
1068 OutStreamer->emitDataRegion(OffsetWidth == 1 ? MCDR_DataRegionJT8
1070
1071 for (auto *MBB : JTBBs) {
1072 const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),
1073 OutContext);
1074 // Otherwise it's an offset from the dispatch instruction. Construct an
1075 // MCExpr for the entry. We want a value of the form:
1076 // (BasicBlockAddr - TBBInstAddr + 4) / 2
1077 //
1078 // For example, a TBB table with entries jumping to basic blocks BB0 and BB1
1079 // would look like:
1080 // LJTI_0_0:
1081 // .byte (LBB0 - (LCPI0_0 + 4)) / 2
1082 // .byte (LBB1 - (LCPI0_0 + 4)) / 2
1083 // where LCPI0_0 is a label defined just before the TBB instruction using
1084 // this table.
1085 MCSymbol *TBInstPC = GetCPISymbol(MI->getOperand(0).getImm());
1086 const MCExpr *Expr = MCBinaryExpr::createAdd(
1089 Expr = MCBinaryExpr::createSub(MBBSymbolExpr, Expr, OutContext);
1091 OutContext);
1092 OutStreamer->emitValue(Expr, OffsetWidth);
1093 }
1094 // Mark the end of jump table data-in-code region. 32-bit offsets use
1095 // actual branch instructions here, so we don't mark those as a data-region
1096 // at all.
1097 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
1098
1099 // Make sure the next instruction is 2-byte aligned.
1100 emitAlignment(Align(2));
1101}
1102
1103void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
1105 "Only instruction which are involved into frame setup code are allowed");
1106
1107 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
1108 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1109 const MachineFunction &MF = *MI->getParent()->getParent();
1110 const TargetRegisterInfo *TargetRegInfo =
1112 const MachineRegisterInfo &MachineRegInfo = MF.getRegInfo();
1113
1114 Register FramePtr = TargetRegInfo->getFrameRegister(MF);
1115 unsigned Opc = MI->getOpcode();
1116 unsigned SrcReg, DstReg;
1117
1118 switch (Opc) {
1119 case ARM::tPUSH:
1120 // special case: tPUSH does not have src/dst regs.
1121 SrcReg = DstReg = ARM::SP;
1122 break;
1123 case ARM::tLDRpci:
1124 case ARM::t2MOVi16:
1125 case ARM::t2MOVTi16:
1126 // special cases:
1127 // 1) for Thumb1 code we sometimes materialize the constant via constpool
1128 // load.
1129 // 2) for Thumb2 execute only code we materialize the constant via
1130 // immediate constants in 2 separate instructions (MOVW/MOVT).
1131 SrcReg = ~0U;
1132 DstReg = MI->getOperand(0).getReg();
1133 break;
1134 default:
1135 SrcReg = MI->getOperand(1).getReg();
1136 DstReg = MI->getOperand(0).getReg();
1137 break;
1138 }
1139
1140 // Try to figure out the unwinding opcode out of src / dst regs.
1141 if (MI->mayStore()) {
1142 // Register saves.
1143 assert(DstReg == ARM::SP &&
1144 "Only stack pointer as a destination reg is supported");
1145
1147 // Skip src & dst reg, and pred ops.
1148 unsigned StartOp = 2 + 2;
1149 // Use all the operands.
1150 unsigned NumOffset = 0;
1151 // Amount of SP adjustment folded into a push, before the
1152 // registers are stored (pad at higher addresses).
1153 unsigned PadBefore = 0;
1154 // Amount of SP adjustment folded into a push, after the
1155 // registers are stored (pad at lower addresses).
1156 unsigned PadAfter = 0;
1157
1158 switch (Opc) {
1159 default:
1160 MI->print(errs());
1161 llvm_unreachable("Unsupported opcode for unwinding information");
1162 case ARM::tPUSH:
1163 // Special case here: no src & dst reg, but two extra imp ops.
1164 StartOp = 2; NumOffset = 2;
1165 [[fallthrough]];
1166 case ARM::STMDB_UPD:
1167 case ARM::t2STMDB_UPD:
1168 case ARM::VSTMDDB_UPD:
1169 assert(SrcReg == ARM::SP &&
1170 "Only stack pointer as a source reg is supported");
1171 for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset;
1172 i != NumOps; ++i) {
1173 const MachineOperand &MO = MI->getOperand(i);
1174 // Actually, there should never be any impdef stuff here. Skip it
1175 // temporary to workaround PR11902.
1176 if (MO.isImplicit())
1177 continue;
1178 // Registers, pushed as a part of folding an SP update into the
1179 // push instruction are marked as undef and should not be
1180 // restored when unwinding, because the function can modify the
1181 // corresponding stack slots.
1182 if (MO.isUndef()) {
1183 assert(RegList.empty() &&
1184 "Pad registers must come before restored ones");
1185 unsigned Width =
1186 TargetRegInfo->getRegSizeInBits(MO.getReg(), MachineRegInfo) / 8;
1187 PadAfter += Width;
1188 continue;
1189 }
1190 // Check for registers that are remapped (for a Thumb1 prologue that
1191 // saves high registers).
1192 Register Reg = MO.getReg();
1193 if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(Reg))
1194 Reg = RemappedReg;
1195 RegList.push_back(Reg);
1196 }
1197 break;
1198 case ARM::STR_PRE_IMM:
1199 case ARM::STR_PRE_REG:
1200 case ARM::t2STR_PRE:
1201 assert(MI->getOperand(2).getReg() == ARM::SP &&
1202 "Only stack pointer as a source reg is supported");
1203 if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(SrcReg))
1204 SrcReg = RemappedReg;
1205
1206 RegList.push_back(SrcReg);
1207 break;
1208 case ARM::t2STRD_PRE:
1209 assert(MI->getOperand(3).getReg() == ARM::SP &&
1210 "Only stack pointer as a source reg is supported");
1211 SrcReg = MI->getOperand(1).getReg();
1212 if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(SrcReg))
1213 SrcReg = RemappedReg;
1214 RegList.push_back(SrcReg);
1215 SrcReg = MI->getOperand(2).getReg();
1216 if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(SrcReg))
1217 SrcReg = RemappedReg;
1218 RegList.push_back(SrcReg);
1219 PadBefore = -MI->getOperand(4).getImm() - 8;
1220 break;
1221 }
1223 if (PadBefore)
1224 ATS.emitPad(PadBefore);
1225 ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
1226 // Account for the SP adjustment, folded into the push.
1227 if (PadAfter)
1228 ATS.emitPad(PadAfter);
1229 }
1230 } else {
1231 // Changes of stack / frame pointer.
1232 if (SrcReg == ARM::SP) {
1233 int64_t Offset = 0;
1234 switch (Opc) {
1235 default:
1236 MI->print(errs());
1237 llvm_unreachable("Unsupported opcode for unwinding information");
1238 case ARM::MOVr:
1239 case ARM::tMOVr:
1240 Offset = 0;
1241 break;
1242 case ARM::ADDri:
1243 case ARM::t2ADDri:
1244 case ARM::t2ADDri12:
1245 case ARM::t2ADDspImm:
1246 case ARM::t2ADDspImm12:
1247 Offset = -MI->getOperand(2).getImm();
1248 break;
1249 case ARM::SUBri:
1250 case ARM::t2SUBri:
1251 case ARM::t2SUBri12:
1252 case ARM::t2SUBspImm:
1253 case ARM::t2SUBspImm12:
1254 Offset = MI->getOperand(2).getImm();
1255 break;
1256 case ARM::tSUBspi:
1257 Offset = MI->getOperand(2).getImm()*4;
1258 break;
1259 case ARM::tADDspi:
1260 case ARM::tADDrSPi:
1261 Offset = -MI->getOperand(2).getImm()*4;
1262 break;
1263 case ARM::tADDhirr:
1264 Offset =
1265 -AFI->EHPrologueOffsetInRegs.lookup(MI->getOperand(2).getReg());
1266 break;
1267 }
1268
1270 if (DstReg == FramePtr && FramePtr != ARM::SP)
1271 // Set-up of the frame pointer. Positive values correspond to "add"
1272 // instruction.
1273 ATS.emitSetFP(FramePtr, ARM::SP, -Offset);
1274 else if (DstReg == ARM::SP) {
1275 // Change of SP by an offset. Positive values correspond to "sub"
1276 // instruction.
1277 ATS.emitPad(Offset);
1278 } else {
1279 // Move of SP to a register. Positive values correspond to an "add"
1280 // instruction.
1281 ATS.emitMovSP(DstReg, -Offset);
1282 }
1283 }
1284 } else if (DstReg == ARM::SP) {
1285 MI->print(errs());
1286 llvm_unreachable("Unsupported opcode for unwinding information");
1287 } else {
1288 int64_t Offset = 0;
1289 switch (Opc) {
1290 case ARM::tMOVr:
1291 // If a Thumb1 function spills r8-r11, we copy the values to low
1292 // registers before pushing them. Record the copy so we can emit the
1293 // correct ".save" later.
1294 AFI->EHPrologueRemappedRegs[DstReg] = SrcReg;
1295 break;
1296 case ARM::tLDRpci: {
1297 // Grab the constpool index and check, whether it corresponds to
1298 // original or cloned constpool entry.
1299 unsigned CPI = MI->getOperand(1).getIndex();
1300 const MachineConstantPool *MCP = MF.getConstantPool();
1301 if (CPI >= MCP->getConstants().size())
1302 CPI = AFI->getOriginalCPIdx(CPI);
1303 assert(CPI != -1U && "Invalid constpool index");
1304
1305 // Derive the actual offset.
1306 const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];
1307 assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry");
1308 Offset = cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue();
1309 AFI->EHPrologueOffsetInRegs[DstReg] = Offset;
1310 break;
1311 }
1312 case ARM::t2MOVi16:
1313 Offset = MI->getOperand(1).getImm();
1314 AFI->EHPrologueOffsetInRegs[DstReg] = Offset;
1315 break;
1316 case ARM::t2MOVTi16:
1317 Offset = MI->getOperand(2).getImm();
1318 AFI->EHPrologueOffsetInRegs[DstReg] |= (Offset << 16);
1319 break;
1320 case ARM::t2PAC:
1321 case ARM::t2PACBTI:
1322 AFI->EHPrologueRemappedRegs[ARM::R12] = ARM::RA_AUTH_CODE;
1323 break;
1324 default:
1325 MI->print(errs());
1326 llvm_unreachable("Unsupported opcode for unwinding information");
1327 }
1328 }
1329 }
1330}
1331
1332// Simple pseudo-instructions have their lowering (with expansion to real
1333// instructions) auto-generated.
1334#include "ARMGenMCPseudoLowering.inc"
1335
1337 // TODOD FIXME: Enable feature predicate checks once all the test pass.
1338 // ARM_MC::verifyInstructionPredicates(MI->getOpcode(),
1339 // getSubtargetInfo().getFeatureBits());
1340
1341 const DataLayout &DL = getDataLayout();
1342 MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();
1343 ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);
1344
1345 // If we just ended a constant pool, mark it as such.
1346 if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {
1347 OutStreamer->emitDataRegion(MCDR_DataRegionEnd);
1348 InConstantPool = false;
1349 }
1350
1351 // Emit unwinding stuff for frame-related instructions
1352 if (Subtarget->isTargetEHABICompatible() &&
1353 MI->getFlag(MachineInstr::FrameSetup))
1354 EmitUnwindingInstruction(MI);
1355
1356 // Do any auto-generated pseudo lowerings.
1357 if (emitPseudoExpansionLowering(*OutStreamer, MI))
1358 return;
1359
1360 assert(!convertAddSubFlagsOpcode(MI->getOpcode()) &&
1361 "Pseudo flag setting opcode should be expanded early");
1362
1363 // Check for manual lowerings.
1364 unsigned Opc = MI->getOpcode();
1365 switch (Opc) {
1366 case ARM::t2MOVi32imm: llvm_unreachable("Should be lowered by thumb2it pass");
1367 case ARM::DBG_VALUE: llvm_unreachable("Should be handled by generic printing");
1368 case ARM::LEApcrel:
1369 case ARM::tLEApcrel:
1370 case ARM::t2LEApcrel: {
1371 // FIXME: Need to also handle globals and externals
1372 MCSymbol *CPISymbol = GetCPISymbol(MI->getOperand(1).getIndex());
1373 EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
1374 ARM::t2LEApcrel ? ARM::t2ADR
1375 : (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR
1376 : ARM::ADR))
1377 .addReg(MI->getOperand(0).getReg())
1379 // Add predicate operands.
1380 .addImm(MI->getOperand(2).getImm())
1381 .addReg(MI->getOperand(3).getReg()));
1382 return;
1383 }
1384 case ARM::LEApcrelJT:
1385 case ARM::tLEApcrelJT:
1386 case ARM::t2LEApcrelJT: {
1387 MCSymbol *JTIPICSymbol =
1388 GetARMJTIPICJumpTableLabel(MI->getOperand(1).getIndex());
1389 EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==
1390 ARM::t2LEApcrelJT ? ARM::t2ADR
1391 : (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR
1392 : ARM::ADR))
1393 .addReg(MI->getOperand(0).getReg())
1395 // Add predicate operands.
1396 .addImm(MI->getOperand(2).getImm())
1397 .addReg(MI->getOperand(3).getReg()));
1398 return;
1399 }
1400 // Darwin call instructions are just normal call instructions with different
1401 // clobber semantics (they clobber R9).
1402 case ARM::BX_CALL: {
1404 .addReg(ARM::LR)
1405 .addReg(ARM::PC)
1406 // Add predicate operands.
1407 .addImm(ARMCC::AL)
1408 .addReg(0)
1409 // Add 's' bit operand (always reg0 for this)
1410 .addReg(0));
1411
1412 assert(Subtarget->hasV4TOps());
1414 .addReg(MI->getOperand(0).getReg()));
1415 return;
1416 }
1417 case ARM::tBX_CALL: {
1418 if (Subtarget->hasV5TOps())
1419 llvm_unreachable("Expected BLX to be selected for v5t+");
1420
1421 // On ARM v4t, when doing a call from thumb mode, we need to ensure
1422 // that the saved lr has its LSB set correctly (the arch doesn't
1423 // have blx).
1424 // So here we generate a bl to a small jump pad that does bx rN.
1425 // The jump pads are emitted after the function body.
1426
1427 Register TReg = MI->getOperand(0).getReg();
1428 MCSymbol *TRegSym = nullptr;
1429 for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {
1430 if (TIP.first == TReg) {
1431 TRegSym = TIP.second;
1432 break;
1433 }
1434 }
1435
1436 if (!TRegSym) {
1437 TRegSym = OutContext.createTempSymbol();
1438 ThumbIndirectPads.push_back(std::make_pair(TReg, TRegSym));
1439 }
1440
1441 // Create a link-saving branch to the Reg Indirect Jump Pad.
1443 // Predicate comes first here.
1444 .addImm(ARMCC::AL).addReg(0)
1445 .addExpr(MCSymbolRefExpr::create(TRegSym, OutContext)));
1446 return;
1447 }
1448 case ARM::BMOVPCRX_CALL: {
1450 .addReg(ARM::LR)
1451 .addReg(ARM::PC)
1452 // Add predicate operands.
1453 .addImm(ARMCC::AL)
1454 .addReg(0)
1455 // Add 's' bit operand (always reg0 for this)
1456 .addReg(0));
1457
1459 .addReg(ARM::PC)
1460 .addReg(MI->getOperand(0).getReg())
1461 // Add predicate operands.
1463 .addReg(0)
1464 // Add 's' bit operand (always reg0 for this)
1465 .addReg(0));
1466 return;
1467 }
1468 case ARM::BMOVPCB_CALL: {
1470 .addReg(ARM::LR)
1471 .addReg(ARM::PC)
1472 // Add predicate operands.
1473 .addImm(ARMCC::AL)
1474 .addReg(0)
1475 // Add 's' bit operand (always reg0 for this)
1476 .addReg(0));
1477
1478 const MachineOperand &Op = MI->getOperand(0);
1479 const GlobalValue *GV = Op.getGlobal();
1480 const unsigned TF = Op.getTargetFlags();
1481 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1482 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1484 .addExpr(GVSymExpr)
1485 // Add predicate operands.
1486 .addImm(ARMCC::AL)
1487 .addReg(0));
1488 return;
1489 }
1490 case ARM::MOVi16_ga_pcrel:
1491 case ARM::t2MOVi16_ga_pcrel: {
1492 MCInst TmpInst;
1493 TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16);
1494 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1495
1496 unsigned TF = MI->getOperand(1).getTargetFlags();
1497 const GlobalValue *GV = MI->getOperand(1).getGlobal();
1498 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1499 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1500
1501 MCSymbol *LabelSym =
1502 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1503 MI->getOperand(2).getImm(), OutContext);
1504 const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
1505 unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;
1506 const MCExpr *PCRelExpr =
1508 MCBinaryExpr::createAdd(LabelSymExpr,
1511 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
1512
1513 // Add predicate operands.
1515 TmpInst.addOperand(MCOperand::createReg(0));
1516 // Add 's' bit operand (always reg0 for this)
1517 TmpInst.addOperand(MCOperand::createReg(0));
1518 EmitToStreamer(*OutStreamer, TmpInst);
1519 return;
1520 }
1521 case ARM::MOVTi16_ga_pcrel:
1522 case ARM::t2MOVTi16_ga_pcrel: {
1523 MCInst TmpInst;
1524 TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel
1525 ? ARM::MOVTi16 : ARM::t2MOVTi16);
1526 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1527 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
1528
1529 unsigned TF = MI->getOperand(2).getTargetFlags();
1530 const GlobalValue *GV = MI->getOperand(2).getGlobal();
1531 MCSymbol *GVSym = GetARMGVSymbol(GV, TF);
1532 const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);
1533
1534 MCSymbol *LabelSym =
1535 getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1536 MI->getOperand(3).getImm(), OutContext);
1537 const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);
1538 unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;
1539 const MCExpr *PCRelExpr =
1541 MCBinaryExpr::createAdd(LabelSymExpr,
1544 TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));
1545 // Add predicate operands.
1547 TmpInst.addOperand(MCOperand::createReg(0));
1548 // Add 's' bit operand (always reg0 for this)
1549 TmpInst.addOperand(MCOperand::createReg(0));
1550 EmitToStreamer(*OutStreamer, TmpInst);
1551 return;
1552 }
1553 case ARM::t2BFi:
1554 case ARM::t2BFic:
1555 case ARM::t2BFLi:
1556 case ARM::t2BFr:
1557 case ARM::t2BFLr: {
1558 // This is a Branch Future instruction.
1559
1560 const MCExpr *BranchLabel = MCSymbolRefExpr::create(
1561 getBFLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1562 MI->getOperand(0).getIndex(), OutContext),
1563 OutContext);
1564
1565 auto MCInst = MCInstBuilder(Opc).addExpr(BranchLabel);
1566 if (MI->getOperand(1).isReg()) {
1567 // For BFr/BFLr
1568 MCInst.addReg(MI->getOperand(1).getReg());
1569 } else {
1570 // For BFi/BFLi/BFic
1571 const MCExpr *BranchTarget;
1572 if (MI->getOperand(1).isMBB())
1573 BranchTarget = MCSymbolRefExpr::create(
1574 MI->getOperand(1).getMBB()->getSymbol(), OutContext);
1575 else if (MI->getOperand(1).isGlobal()) {
1576 const GlobalValue *GV = MI->getOperand(1).getGlobal();
1577 BranchTarget = MCSymbolRefExpr::create(
1578 GetARMGVSymbol(GV, MI->getOperand(1).getTargetFlags()), OutContext);
1579 } else if (MI->getOperand(1).isSymbol()) {
1580 BranchTarget = MCSymbolRefExpr::create(
1581 GetExternalSymbolSymbol(MI->getOperand(1).getSymbolName()),
1582 OutContext);
1583 } else
1584 llvm_unreachable("Unhandled operand kind in Branch Future instruction");
1585
1586 MCInst.addExpr(BranchTarget);
1587 }
1588
1589 if (Opc == ARM::t2BFic) {
1590 const MCExpr *ElseLabel = MCSymbolRefExpr::create(
1591 getBFLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),
1592 MI->getOperand(2).getIndex(), OutContext),
1593 OutContext);
1594 MCInst.addExpr(ElseLabel);
1595 MCInst.addImm(MI->getOperand(3).getImm());
1596 } else {
1597 MCInst.addImm(MI->getOperand(2).getImm())
1598 .addReg(MI->getOperand(3).getReg());
1599 }
1600
1602 return;
1603 }
1604 case ARM::t2BF_LabelPseudo: {
1605 // This is a pseudo op for a label used by a branch future instruction
1606
1607 // Emit the label.
1608 OutStreamer->emitLabel(getBFLabel(DL.getPrivateGlobalPrefix(),
1610 MI->getOperand(0).getIndex(), OutContext));
1611 return;
1612 }
1613 case ARM::tPICADD: {
1614 // This is a pseudo op for a label + instruction sequence, which looks like:
1615 // LPC0:
1616 // add r0, pc
1617 // This adds the address of LPC0 to r0.
1618
1619 // Emit the label.
1620 OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
1622 MI->getOperand(2).getImm(), OutContext));
1623
1624 // Form and emit the add.
1626 .addReg(MI->getOperand(0).getReg())
1627 .addReg(MI->getOperand(0).getReg())
1628 .addReg(ARM::PC)
1629 // Add predicate operands.
1631 .addReg(0));
1632 return;
1633 }
1634 case ARM::PICADD: {
1635 // This is a pseudo op for a label + instruction sequence, which looks like:
1636 // LPC0:
1637 // add r0, pc, r0
1638 // This adds the address of LPC0 to r0.
1639
1640 // Emit the label.
1641 OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
1643 MI->getOperand(2).getImm(), OutContext));
1644
1645 // Form and emit the add.
1647 .addReg(MI->getOperand(0).getReg())
1648 .addReg(ARM::PC)
1649 .addReg(MI->getOperand(1).getReg())
1650 // Add predicate operands.
1651 .addImm(MI->getOperand(3).getImm())
1652 .addReg(MI->getOperand(4).getReg())
1653 // Add 's' bit operand (always reg0 for this)
1654 .addReg(0));
1655 return;
1656 }
1657 case ARM::PICSTR:
1658 case ARM::PICSTRB:
1659 case ARM::PICSTRH:
1660 case ARM::PICLDR:
1661 case ARM::PICLDRB:
1662 case ARM::PICLDRH:
1663 case ARM::PICLDRSB:
1664 case ARM::PICLDRSH: {
1665 // This is a pseudo op for a label + instruction sequence, which looks like:
1666 // LPC0:
1667 // OP r0, [pc, r0]
1668 // The LCP0 label is referenced by a constant pool entry in order to get
1669 // a PC-relative address at the ldr instruction.
1670
1671 // Emit the label.
1672 OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),
1674 MI->getOperand(2).getImm(), OutContext));
1675
1676 // Form and emit the load
1677 unsigned Opcode;
1678 switch (MI->getOpcode()) {
1679 default:
1680 llvm_unreachable("Unexpected opcode!");
1681 case ARM::PICSTR: Opcode = ARM::STRrs; break;
1682 case ARM::PICSTRB: Opcode = ARM::STRBrs; break;
1683 case ARM::PICSTRH: Opcode = ARM::STRH; break;
1684 case ARM::PICLDR: Opcode = ARM::LDRrs; break;
1685 case ARM::PICLDRB: Opcode = ARM::LDRBrs; break;
1686 case ARM::PICLDRH: Opcode = ARM::LDRH; break;
1687 case ARM::PICLDRSB: Opcode = ARM::LDRSB; break;
1688 case ARM::PICLDRSH: Opcode = ARM::LDRSH; break;
1689 }
1691 .addReg(MI->getOperand(0).getReg())
1692 .addReg(ARM::PC)
1693 .addReg(MI->getOperand(1).getReg())
1694 .addImm(0)
1695 // Add predicate operands.
1696 .addImm(MI->getOperand(3).getImm())
1697 .addReg(MI->getOperand(4).getReg()));
1698
1699 return;
1700 }
1701 case ARM::CONSTPOOL_ENTRY: {
1702 if (Subtarget->genExecuteOnly())
1703 llvm_unreachable("execute-only should not generate constant pools");
1704
1705 /// CONSTPOOL_ENTRY - This instruction represents a floating constant pool
1706 /// in the function. The first operand is the ID# for this instruction, the
1707 /// second is the index into the MachineConstantPool that this is, the third
1708 /// is the size in bytes of this constant pool entry.
1709 /// The required alignment is specified on the basic block holding this MI.
1710 unsigned LabelId = (unsigned)MI->getOperand(0).getImm();
1711 unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();
1712
1713 // If this is the first entry of the pool, mark it.
1714 if (!InConstantPool) {
1715 OutStreamer->emitDataRegion(MCDR_DataRegion);
1716 InConstantPool = true;
1717 }
1718
1719 OutStreamer->emitLabel(GetCPISymbol(LabelId));
1720
1721 const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];
1722 if (MCPE.isMachineConstantPoolEntry())
1724 else
1726 return;
1727 }
1728 case ARM::JUMPTABLE_ADDRS:
1730 return;
1731 case ARM::JUMPTABLE_INSTS:
1733 return;
1734 case ARM::JUMPTABLE_TBB:
1735 case ARM::JUMPTABLE_TBH:
1736 emitJumpTableTBInst(MI, MI->getOpcode() == ARM::JUMPTABLE_TBB ? 1 : 2);
1737 return;
1738 case ARM::t2BR_JT: {
1740 .addReg(ARM::PC)
1741 .addReg(MI->getOperand(0).getReg())
1742 // Add predicate operands.
1744 .addReg(0));
1745 return;
1746 }
1747 case ARM::t2TBB_JT:
1748 case ARM::t2TBH_JT: {
1749 unsigned Opc = MI->getOpcode() == ARM::t2TBB_JT ? ARM::t2TBB : ARM::t2TBH;
1750 // Lower and emit the PC label, then the instruction itself.
1751 OutStreamer->emitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
1753 .addReg(MI->getOperand(0).getReg())
1754 .addReg(MI->getOperand(1).getReg())
1755 // Add predicate operands.
1757 .addReg(0));
1758 return;
1759 }
1760 case ARM::tTBB_JT:
1761 case ARM::tTBH_JT: {
1762
1763 bool Is8Bit = MI->getOpcode() == ARM::tTBB_JT;
1764 Register Base = MI->getOperand(0).getReg();
1765 Register Idx = MI->getOperand(1).getReg();
1766 assert(MI->getOperand(1).isKill() && "We need the index register as scratch!");
1767
1768 // Multiply up idx if necessary.
1769 if (!Is8Bit)
1771 .addReg(Idx)
1772 .addReg(ARM::CPSR)
1773 .addReg(Idx)
1774 .addImm(1)
1775 // Add predicate operands.
1776 .addImm(ARMCC::AL)
1777 .addReg(0));
1778
1779 if (Base == ARM::PC) {
1780 // TBB [base, idx] =
1781 // ADDS idx, idx, base
1782 // LDRB idx, [idx, #4] ; or LDRH if TBH
1783 // LSLS idx, #1
1784 // ADDS pc, pc, idx
1785
1786 // When using PC as the base, it's important that there is no padding
1787 // between the last ADDS and the start of the jump table. The jump table
1788 // is 4-byte aligned, so we ensure we're 4 byte aligned here too.
1789 //
1790 // FIXME: Ideally we could vary the LDRB index based on the padding
1791 // between the sequence and jump table, however that relies on MCExprs
1792 // for load indexes which are currently not supported.
1793 OutStreamer->emitCodeAlignment(Align(4), &getSubtargetInfo());
1795 .addReg(Idx)
1796 .addReg(Idx)
1797 .addReg(Base)
1798 // Add predicate operands.
1799 .addImm(ARMCC::AL)
1800 .addReg(0));
1801
1802 unsigned Opc = Is8Bit ? ARM::tLDRBi : ARM::tLDRHi;
1804 .addReg(Idx)
1805 .addReg(Idx)
1806 .addImm(Is8Bit ? 4 : 2)
1807 // Add predicate operands.
1808 .addImm(ARMCC::AL)
1809 .addReg(0));
1810 } else {
1811 // TBB [base, idx] =
1812 // LDRB idx, [base, idx] ; or LDRH if TBH
1813 // LSLS idx, #1
1814 // ADDS pc, pc, idx
1815
1816 unsigned Opc = Is8Bit ? ARM::tLDRBr : ARM::tLDRHr;
1818 .addReg(Idx)
1819 .addReg(Base)
1820 .addReg(Idx)
1821 // Add predicate operands.
1822 .addImm(ARMCC::AL)
1823 .addReg(0));
1824 }
1825
1827 .addReg(Idx)
1828 .addReg(ARM::CPSR)
1829 .addReg(Idx)
1830 .addImm(1)
1831 // Add predicate operands.
1832 .addImm(ARMCC::AL)
1833 .addReg(0));
1834
1835 OutStreamer->emitLabel(GetCPISymbol(MI->getOperand(3).getImm()));
1837 .addReg(ARM::PC)
1838 .addReg(ARM::PC)
1839 .addReg(Idx)
1840 // Add predicate operands.
1841 .addImm(ARMCC::AL)
1842 .addReg(0));
1843 return;
1844 }
1845 case ARM::tBR_JTr:
1846 case ARM::BR_JTr: {
1847 // mov pc, target
1848 MCInst TmpInst;
1849 unsigned Opc = MI->getOpcode() == ARM::BR_JTr ?
1850 ARM::MOVr : ARM::tMOVr;
1851 TmpInst.setOpcode(Opc);
1852 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1853 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1854 // Add predicate operands.
1856 TmpInst.addOperand(MCOperand::createReg(0));
1857 // Add 's' bit operand (always reg0 for this)
1858 if (Opc == ARM::MOVr)
1859 TmpInst.addOperand(MCOperand::createReg(0));
1860 EmitToStreamer(*OutStreamer, TmpInst);
1861 return;
1862 }
1863 case ARM::BR_JTm_i12: {
1864 // ldr pc, target
1865 MCInst TmpInst;
1866 TmpInst.setOpcode(ARM::LDRi12);
1867 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1868 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1869 TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
1870 // Add predicate operands.
1872 TmpInst.addOperand(MCOperand::createReg(0));
1873 EmitToStreamer(*OutStreamer, TmpInst);
1874 return;
1875 }
1876 case ARM::BR_JTm_rs: {
1877 // ldr pc, target
1878 MCInst TmpInst;
1879 TmpInst.setOpcode(ARM::LDRrs);
1880 TmpInst.addOperand(MCOperand::createReg(ARM::PC));
1881 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));
1882 TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));
1883 TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));
1884 // Add predicate operands.
1886 TmpInst.addOperand(MCOperand::createReg(0));
1887 EmitToStreamer(*OutStreamer, TmpInst);
1888 return;
1889 }
1890 case ARM::BR_JTadd: {
1891 // add pc, target, idx
1893 .addReg(ARM::PC)
1894 .addReg(MI->getOperand(0).getReg())
1895 .addReg(MI->getOperand(1).getReg())
1896 // Add predicate operands.
1898 .addReg(0)
1899 // Add 's' bit operand (always reg0 for this)
1900 .addReg(0));
1901 return;
1902 }
1903 case ARM::SPACE:
1904 OutStreamer->emitZeros(MI->getOperand(1).getImm());
1905 return;
1906 case ARM::TRAP: {
1907 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1908 // FIXME: Remove this special case when they do.
1909 if (!Subtarget->isTargetMachO()) {
1910 uint32_t Val = 0xe7ffdefeUL;
1911 OutStreamer->AddComment("trap");
1912 ATS.emitInst(Val);
1913 return;
1914 }
1915 break;
1916 }
1917 case ARM::TRAPNaCl: {
1918 uint32_t Val = 0xe7fedef0UL;
1919 OutStreamer->AddComment("trap");
1920 ATS.emitInst(Val);
1921 return;
1922 }
1923 case ARM::tTRAP: {
1924 // Non-Darwin binutils don't yet support the "trap" mnemonic.
1925 // FIXME: Remove this special case when they do.
1926 if (!Subtarget->isTargetMachO()) {
1927 uint16_t Val = 0xdefe;
1928 OutStreamer->AddComment("trap");
1929 ATS.emitInst(Val, 'n');
1930 return;
1931 }
1932 break;
1933 }
1934 case ARM::t2Int_eh_sjlj_setjmp:
1935 case ARM::t2Int_eh_sjlj_setjmp_nofp:
1936 case ARM::tInt_eh_sjlj_setjmp: {
1937 // Two incoming args: GPR:$src, GPR:$val
1938 // mov $val, pc
1939 // adds $val, #7
1940 // str $val, [$src, #4]
1941 // movs r0, #0
1942 // b LSJLJEH
1943 // movs r0, #1
1944 // LSJLJEH:
1945 Register SrcReg = MI->getOperand(0).getReg();
1946 Register ValReg = MI->getOperand(1).getReg();
1947 MCSymbol *Label = OutContext.createTempSymbol("SJLJEH");
1948 OutStreamer->AddComment("eh_setjmp begin");
1950 .addReg(ValReg)
1951 .addReg(ARM::PC)
1952 // Predicate.
1953 .addImm(ARMCC::AL)
1954 .addReg(0));
1955
1957 .addReg(ValReg)
1958 // 's' bit operand
1959 .addReg(ARM::CPSR)
1960 .addReg(ValReg)
1961 .addImm(7)
1962 // Predicate.
1963 .addImm(ARMCC::AL)
1964 .addReg(0));
1965
1967 .addReg(ValReg)
1968 .addReg(SrcReg)
1969 // The offset immediate is #4. The operand value is scaled by 4 for the
1970 // tSTR instruction.
1971 .addImm(1)
1972 // Predicate.
1973 .addImm(ARMCC::AL)
1974 .addReg(0));
1975
1977 .addReg(ARM::R0)
1978 .addReg(ARM::CPSR)
1979 .addImm(0)
1980 // Predicate.
1981 .addImm(ARMCC::AL)
1982 .addReg(0));
1983
1984 const MCExpr *SymbolExpr = MCSymbolRefExpr::create(Label, OutContext);
1986 .addExpr(SymbolExpr)
1987 .addImm(ARMCC::AL)
1988 .addReg(0));
1989
1990 OutStreamer->AddComment("eh_setjmp end");
1992 .addReg(ARM::R0)
1993 .addReg(ARM::CPSR)
1994 .addImm(1)
1995 // Predicate.
1996 .addImm(ARMCC::AL)
1997 .addReg(0));
1998
1999 OutStreamer->emitLabel(Label);
2000 return;
2001 }
2002
2003 case ARM::Int_eh_sjlj_setjmp_nofp:
2004 case ARM::Int_eh_sjlj_setjmp: {
2005 // Two incoming args: GPR:$src, GPR:$val
2006 // add $val, pc, #8
2007 // str $val, [$src, #+4]
2008 // mov r0, #0
2009 // add pc, pc, #0
2010 // mov r0, #1
2011 Register SrcReg = MI->getOperand(0).getReg();
2012 Register ValReg = MI->getOperand(1).getReg();
2013
2014 OutStreamer->AddComment("eh_setjmp begin");
2016 .addReg(ValReg)
2017 .addReg(ARM::PC)
2018 .addImm(8)
2019 // Predicate.
2020 .addImm(ARMCC::AL)
2021 .addReg(0)
2022 // 's' bit operand (always reg0 for this).
2023 .addReg(0));
2024
2026 .addReg(ValReg)
2027 .addReg(SrcReg)
2028 .addImm(4)
2029 // Predicate.
2030 .addImm(ARMCC::AL)
2031 .addReg(0));
2032
2034 .addReg(ARM::R0)
2035 .addImm(0)
2036 // Predicate.
2037 .addImm(ARMCC::AL)
2038 .addReg(0)
2039 // 's' bit operand (always reg0 for this).
2040 .addReg(0));
2041
2043 .addReg(ARM::PC)
2044 .addReg(ARM::PC)
2045 .addImm(0)
2046 // Predicate.
2047 .addImm(ARMCC::AL)
2048 .addReg(0)
2049 // 's' bit operand (always reg0 for this).
2050 .addReg(0));
2051
2052 OutStreamer->AddComment("eh_setjmp end");
2054 .addReg(ARM::R0)
2055 .addImm(1)
2056 // Predicate.
2057 .addImm(ARMCC::AL)
2058 .addReg(0)
2059 // 's' bit operand (always reg0 for this).
2060 .addReg(0));
2061 return;
2062 }
2063 case ARM::Int_eh_sjlj_longjmp: {
2064 // ldr sp, [$src, #8]
2065 // ldr $scratch, [$src, #4]
2066 // ldr r7, [$src]
2067 // bx $scratch
2068 Register SrcReg = MI->getOperand(0).getReg();
2069 Register ScratchReg = MI->getOperand(1).getReg();
2071 .addReg(ARM::SP)
2072 .addReg(SrcReg)
2073 .addImm(8)
2074 // Predicate.
2075 .addImm(ARMCC::AL)
2076 .addReg(0));
2077
2079 .addReg(ScratchReg)
2080 .addReg(SrcReg)
2081 .addImm(4)
2082 // Predicate.
2083 .addImm(ARMCC::AL)
2084 .addReg(0));
2085
2086 const MachineFunction &MF = *MI->getParent()->getParent();
2087 const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
2088
2089 if (STI.isTargetDarwin() || STI.isTargetWindows()) {
2090 // These platforms always use the same frame register
2092 .addReg(STI.getFramePointerReg())
2093 .addReg(SrcReg)
2094 .addImm(0)
2095 // Predicate.
2097 .addReg(0));
2098 } else {
2099 // If the calling code might use either R7 or R11 as
2100 // frame pointer register, restore it into both.
2102 .addReg(ARM::R7)
2103 .addReg(SrcReg)
2104 .addImm(0)
2105 // Predicate.
2106 .addImm(ARMCC::AL)
2107 .addReg(0));
2109 .addReg(ARM::R11)
2110 .addReg(SrcReg)
2111 .addImm(0)
2112 // Predicate.
2113 .addImm(ARMCC::AL)
2114 .addReg(0));
2115 }
2116
2117 assert(Subtarget->hasV4TOps());
2119 .addReg(ScratchReg)
2120 // Predicate.
2121 .addImm(ARMCC::AL)
2122 .addReg(0));
2123 return;
2124 }
2125 case ARM::tInt_eh_sjlj_longjmp: {
2126 // ldr $scratch, [$src, #8]
2127 // mov sp, $scratch
2128 // ldr $scratch, [$src, #4]
2129 // ldr r7, [$src]
2130 // bx $scratch
2131 Register SrcReg = MI->getOperand(0).getReg();
2132 Register ScratchReg = MI->getOperand(1).getReg();
2133
2134 const MachineFunction &MF = *MI->getParent()->getParent();
2135 const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();
2136
2138 .addReg(ScratchReg)
2139 .addReg(SrcReg)
2140 // The offset immediate is #8. The operand value is scaled by 4 for the
2141 // tLDR instruction.
2142 .addImm(2)
2143 // Predicate.
2144 .addImm(ARMCC::AL)
2145 .addReg(0));
2146
2148 .addReg(ARM::SP)
2149 .addReg(ScratchReg)
2150 // Predicate.
2151 .addImm(ARMCC::AL)
2152 .addReg(0));
2153
2155 .addReg(ScratchReg)
2156 .addReg(SrcReg)
2157 .addImm(1)
2158 // Predicate.
2159 .addImm(ARMCC::AL)
2160 .addReg(0));
2161
2162 if (STI.isTargetDarwin() || STI.isTargetWindows()) {
2163 // These platforms always use the same frame register
2165 .addReg(STI.getFramePointerReg())
2166 .addReg(SrcReg)
2167 .addImm(0)
2168 // Predicate.
2170 .addReg(0));
2171 } else {
2172 // If the calling code might use either R7 or R11 as
2173 // frame pointer register, restore it into both.
2175 .addReg(ARM::R7)
2176 .addReg(SrcReg)
2177 .addImm(0)
2178 // Predicate.
2179 .addImm(ARMCC::AL)
2180 .addReg(0));
2182 .addReg(ARM::R11)
2183 .addReg(SrcReg)
2184 .addImm(0)
2185 // Predicate.
2186 .addImm(ARMCC::AL)
2187 .addReg(0));
2188 }
2189
2191 .addReg(ScratchReg)
2192 // Predicate.
2193 .addImm(ARMCC::AL)
2194 .addReg(0));
2195 return;
2196 }
2197 case ARM::tInt_WIN_eh_sjlj_longjmp: {
2198 // ldr.w r11, [$src, #0]
2199 // ldr.w sp, [$src, #8]
2200 // ldr.w pc, [$src, #4]
2201
2202 Register SrcReg = MI->getOperand(0).getReg();
2203
2205 .addReg(ARM::R11)
2206 .addReg(SrcReg)
2207 .addImm(0)
2208 // Predicate
2209 .addImm(ARMCC::AL)
2210 .addReg(0));
2212 .addReg(ARM::SP)
2213 .addReg(SrcReg)
2214 .addImm(8)
2215 // Predicate
2216 .addImm(ARMCC::AL)
2217 .addReg(0));
2219 .addReg(ARM::PC)
2220 .addReg(SrcReg)
2221 .addImm(4)
2222 // Predicate
2223 .addImm(ARMCC::AL)
2224 .addReg(0));
2225 return;
2226 }
2227 case ARM::PATCHABLE_FUNCTION_ENTER:
2229 return;
2230 case ARM::PATCHABLE_FUNCTION_EXIT:
2232 return;
2233 case ARM::PATCHABLE_TAIL_CALL:
2235 return;
2236 case ARM::SpeculationBarrierISBDSBEndBB: {
2237 // Print DSB SYS + ISB
2238 MCInst TmpInstDSB;
2239 TmpInstDSB.setOpcode(ARM::DSB);
2240 TmpInstDSB.addOperand(MCOperand::createImm(0xf));
2241 EmitToStreamer(*OutStreamer, TmpInstDSB);
2242 MCInst TmpInstISB;
2243 TmpInstISB.setOpcode(ARM::ISB);
2244 TmpInstISB.addOperand(MCOperand::createImm(0xf));
2245 EmitToStreamer(*OutStreamer, TmpInstISB);
2246 return;
2247 }
2248 case ARM::t2SpeculationBarrierISBDSBEndBB: {
2249 // Print DSB SYS + ISB
2250 MCInst TmpInstDSB;
2251 TmpInstDSB.setOpcode(ARM::t2DSB);
2252 TmpInstDSB.addOperand(MCOperand::createImm(0xf));
2254 TmpInstDSB.addOperand(MCOperand::createReg(0));
2255 EmitToStreamer(*OutStreamer, TmpInstDSB);
2256 MCInst TmpInstISB;
2257 TmpInstISB.setOpcode(ARM::t2ISB);
2258 TmpInstISB.addOperand(MCOperand::createImm(0xf));
2260 TmpInstISB.addOperand(MCOperand::createReg(0));
2261 EmitToStreamer(*OutStreamer, TmpInstISB);
2262 return;
2263 }
2264 case ARM::SpeculationBarrierSBEndBB: {
2265 // Print SB
2266 MCInst TmpInstSB;
2267 TmpInstSB.setOpcode(ARM::SB);
2268 EmitToStreamer(*OutStreamer, TmpInstSB);
2269 return;
2270 }
2271 case ARM::t2SpeculationBarrierSBEndBB: {
2272 // Print SB
2273 MCInst TmpInstSB;
2274 TmpInstSB.setOpcode(ARM::t2SB);
2275 EmitToStreamer(*OutStreamer, TmpInstSB);
2276 return;
2277 }
2278
2279 case ARM::SEH_StackAlloc:
2280 ATS.emitARMWinCFIAllocStack(MI->getOperand(0).getImm(),
2281 MI->getOperand(1).getImm());
2282 return;
2283
2284 case ARM::SEH_SaveRegs:
2285 case ARM::SEH_SaveRegs_Ret:
2286 ATS.emitARMWinCFISaveRegMask(MI->getOperand(0).getImm(),
2287 MI->getOperand(1).getImm());
2288 return;
2289
2290 case ARM::SEH_SaveSP:
2291 ATS.emitARMWinCFISaveSP(MI->getOperand(0).getImm());
2292 return;
2293
2294 case ARM::SEH_SaveFRegs:
2295 ATS.emitARMWinCFISaveFRegs(MI->getOperand(0).getImm(),
2296 MI->getOperand(1).getImm());
2297 return;
2298
2299 case ARM::SEH_SaveLR:
2300 ATS.emitARMWinCFISaveLR(MI->getOperand(0).getImm());
2301 return;
2302
2303 case ARM::SEH_Nop:
2304 case ARM::SEH_Nop_Ret:
2305 ATS.emitARMWinCFINop(MI->getOperand(0).getImm());
2306 return;
2307
2308 case ARM::SEH_PrologEnd:
2309 ATS.emitARMWinCFIPrologEnd(/*Fragment=*/false);
2310 return;
2311
2312 case ARM::SEH_EpilogStart:
2314 return;
2315
2316 case ARM::SEH_EpilogEnd:
2318 return;
2319 }
2320
2321 MCInst TmpInst;
2322 LowerARMMachineInstrToMCInst(MI, TmpInst, *this);
2323
2324 EmitToStreamer(*OutStreamer, TmpInst);
2325}
2326
2327//===----------------------------------------------------------------------===//
2328// Target Registry Stuff
2329//===----------------------------------------------------------------------===//
2330
2331// Force static initialization.
2337}
unsigned SubReg
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel, MachineModuleInfoImpl::StubValueTy &MCSym)
static MCSymbolRefExpr::VariantKind getModifierVariantKind(ARMCP::ARMCPModifier Modifier)
static MCSymbol * getPICLabel(StringRef Prefix, unsigned FunctionNumber, unsigned LabelId, MCContext &Ctx)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARMAsmPrinter()
static bool checkFunctionsAttributeConsistency(const Module &M, StringRef Attr, StringRef Value)
static bool isThumb(const MCSubtargetInfo &STI)
static MCSymbol * getBFLabel(StringRef Prefix, unsigned FunctionNumber, unsigned LabelId, MCContext &Ctx)
static bool checkDenormalAttributeConsistency(const Module &M, StringRef Attr, DenormalMode Value)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:127
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:463
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
unsigned const TargetRegisterInfo * TRI
Module.h This file contains the declarations for the Module class.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
@ Flags
Definition: TextStubV5.cpp:93
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition: Value.cpp:470
static const unsigned FramePtr
void emitJumpTableAddrs(const MachineInstr *MI)
void emitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth)
void emitFunctionBodyEnd() override
Targets can override this to emit stuff after the last basic block in the function.
bool runOnMachineFunction(MachineFunction &F) override
runOnMachineFunction - This uses the emitInstruction() method to print assembly for each instruction.
MCSymbol * GetCPISymbol(unsigned CPID) const override
Return the symbol for the specified constant pool entry.
void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O)
void emitStartOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the start of their fi...
ARMAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > Streamer)
void emitFunctionEntryLabel() override
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo, const MCSubtargetInfo *EndInfo) const override
Let the target do anything it needs to do after emitting inlineasm.
void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI)
void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override
EmitMachineConstantPoolValue - Print a machine constantpool value to the .s file.
bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
void emitXXStructor(const DataLayout &DL, const Constant *CV) override
Targets can override this to change how global constants that are part of a C++ static/global constru...
void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI)
void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI)
void emitEndOfAsmFile(Module &M) override
This virtual method can be overridden by targets that want to emit something at the end of their file...
void emitJumpTableInsts(const MachineInstr *MI)
void emitGlobalVariable(const GlobalVariable *GV) override
Emit the specified global variable to the .s file.
bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum, const char *ExtraCode, raw_ostream &O) override
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant as...
void emitInstruction(const MachineInstr *MI) override
Targets should implement this to emit instructions.
void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override
Print the MachineOperand as a symbol.
ARMConstantPoolValue - ARM specific constantpool value.
unsigned char getPCAdjustment() const
ARMCP::ARMCPModifier getModifier() const
ARMFunctionInfo - This class is derived from MachineFunctionInfo and contains private ARM-specific in...
SmallPtrSet< const GlobalVariable *, 2 > & getGlobalsPromotedToConstantPool()
DenseMap< unsigned, unsigned > EHPrologueRemappedRegs
DenseMap< unsigned, unsigned > EHPrologueOffsetInRegs
unsigned getOriginalCPIdx(unsigned CloneIdx) const
static const char * getRegisterName(MCRegister Reg, unsigned AltIdx=ARM::NoRegAltName)
static const ARMMCExpr * createLower16(const MCExpr *Expr, MCContext &Ctx)
Definition: ARMMCExpr.h:42
static const ARMMCExpr * createUpper16(const MCExpr *Expr, MCContext &Ctx)
Definition: ARMMCExpr.h:38
bool isTargetMachO() const
Definition: ARMSubtarget.h:371
bool isTargetAEABI() const
Definition: ARMSubtarget.h:380
bool isThumb1Only() const
Definition: ARMSubtarget.h:419
MCPhysReg getFramePointerReg() const
Definition: ARMSubtarget.h:429
bool isTargetWindows() const
Definition: ARMSubtarget.h:367
bool isTargetEHABICompatible() const
Definition: ARMSubtarget.h:399
bool isGVIndirectSymbol(const GlobalValue *GV) const
True if the GV will be accessed via an indirect symbol.
bool isTargetDarwin() const
Definition: ARMSubtarget.h:359
bool isROPI() const
bool isTargetCOFF() const
Definition: ARMSubtarget.h:369
bool isTargetGNUAEABI() const
Definition: ARMSubtarget.h:385
bool isTargetMuslAEABI() const
Definition: ARMSubtarget.h:390
bool isTargetELF() const
Definition: ARMSubtarget.h:370
void emitTargetAttributes(const MCSubtargetInfo &STI)
Emit the build attributes that only depend on the hardware that we expect.
virtual void finishAttributeSection()
virtual void emitARMWinCFISaveSP(unsigned Reg)
virtual void emitInst(uint32_t Inst, char Suffix='\0')
virtual void emitARMWinCFISaveLR(unsigned Offset)
virtual void emitRegSave(const SmallVectorImpl< unsigned > &RegList, bool isVector)
virtual void emitTextAttribute(unsigned Attribute, StringRef String)
virtual void emitARMWinCFIAllocStack(unsigned Size, bool Wide)
virtual void emitMovSP(unsigned Reg, int64_t Offset=0)
virtual void emitARMWinCFISaveRegMask(unsigned Mask, bool Wide)
virtual void emitARMWinCFIEpilogEnd()
virtual void emitARMWinCFIPrologEnd(bool Fragment)
virtual void switchVendor(StringRef Vendor)
virtual void emitARMWinCFISaveFRegs(unsigned First, unsigned Last)
virtual void emitARMWinCFIEpilogStart(unsigned Condition)
virtual void emitPad(int64_t Offset)
virtual void emitAttribute(unsigned Attribute, unsigned Value)
virtual void emitARMWinCFINop(bool Wide)
virtual void emitSetFP(unsigned FpReg, unsigned SpReg, int64_t Offset=0)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:380
MCSymbol * getSymbolWithGlobalValueBase(const GlobalValue *GV, StringRef Suffix) const
Return the MCSymbol for a private symbol with global value name as its base, with the specified suffi...
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:663
void EmitToStreamer(MCStreamer &S, const MCInst &Inst)
Definition: AsmPrinter.cpp:399
virtual void emitGlobalVariable(const GlobalVariable *GV)
Emit the specified global variable to the .s file.
Definition: AsmPrinter.cpp:685
TargetMachine & TM
Target machine description.
Definition: AsmPrinter.h:87
void emitXRayTable()
Emit a table with all XRay instrumentation points.
MCSymbol * getMBBExceptionSym(const MachineBasicBlock &MBB)
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:90
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:102
virtual void SetupMachineFunction(MachineFunction &MF)
This should be called when a new MachineFunction is being processed from runOnMachineFunction.
void emitFunctionBody()
This method emits the body and trailer for a function.
virtual void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const
This emits linkage information about GVSym based on GV, if this is supported by the target.
Definition: AsmPrinter.cpp:618
unsigned getFunctionNumber() const
Return a unique ID for the current function.
Definition: AsmPrinter.cpp:376
void printOffset(int64_t Offset, raw_ostream &OS) const
This is just convenient handler for printing offsets.
void emitGlobalConstant(const DataLayout &DL, const Constant *CV, AliasMapTy *AliasList=nullptr)
EmitGlobalConstant - Print a general LLVM constant to the .s file.
MCSymbol * getSymbolPreferLocal(const GlobalValue &GV) const
Similar to getSymbol() but preferred for references.
Definition: AsmPrinter.cpp:667
MCSymbol * CurrentFnSym
The symbol for the current function.
Definition: AsmPrinter.h:121
MachineModuleInfo * MMI
This is a pointer to the current MachineModuleInfo.
Definition: AsmPrinter.h:105
void emitAlignment(Align Alignment, const GlobalObject *GV=nullptr, unsigned MaxBytesToEmit=0) const
Emit an alignment directive to the specified power of two boundary.
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:94
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
bool isPositionIndependent() const
Definition: AsmPrinter.cpp:371
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:99
void getNameWithPrefix(SmallVectorImpl< char > &Name, const GlobalValue *GV) const
Definition: AsmPrinter.cpp:658
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:384
virtual void emitFunctionEntryLabel()
EmitFunctionEntryLabel - Emit the label that is the entrypoint for the function.
const MCSubtargetInfo & getSubtargetInfo() const
Return information about subtarget.
Definition: AsmPrinter.cpp:394
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.
The address of a basic block.
Definition: Constants.h:874
This is an important base class in LLVM.
Definition: Constant.h:41
const Constant * stripPointerCasts() const
Definition: Constant.h:213
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:110
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Definition: DataLayout.h:500
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:202
bool isThreadLocal() const
If the value is "Thread Local", its value isn't shared by the threads.
Definition: GlobalValue.h:259
bool hasInternalLinkage() const
Definition: GlobalValue.h:521
static unsigned getNumOperandRegisters(unsigned Flag)
getNumOperandRegisters - Extract the number of registers field from the inline asm operand flag.
Definition: InlineAsm.h:363
static bool isUseOperandTiedToDef(unsigned Flag, unsigned &Idx)
isUseOperandTiedToDef - Return true if the flag of the inline asm operand indicates it is an use oper...
Definition: InlineAsm.h:369
static bool hasRegClassConstraint(unsigned Flag, unsigned &RC)
hasRegClassConstraint - Returns true if the flag contains a register class constraint.
Definition: InlineAsm.h:378
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:781
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:525
static const MCBinaryExpr * createDiv(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:535
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:610
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
Context object for machine code objects.
Definition: MCContext.h:76
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:318
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:201
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCInstBuilder & addReg(unsigned Reg)
Add a new register operand.
Definition: MCInstBuilder.h:31
MCInstBuilder & addImm(int64_t Val)
Add a new integer immediate operand.
Definition: MCInstBuilder.h:37
MCInstBuilder & addExpr(const MCExpr *Val)
Add a new MCExpr operand.
Definition: MCInstBuilder.h:55
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
void addOperand(const MCOperand Op)
Definition: MCInst.h:210
void setOpcode(unsigned Op)
Definition: MCInst.h:197
MCSection * getThreadLocalPointerSection() const
MCSection * getNonLazySymbolPointerSection() const
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:134
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:162
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:141
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:24
Streaming machine code generation interface.
Definition: MCStreamer.h:212
virtual bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute)=0
Add the given Attribute to Symbol.
MCContext & getContext() const
Definition: MCStreamer.h:297
void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:180
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:424
virtual void emitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers.
Definition: MCStreamer.cpp:134
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:386
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:58
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
Target specific streamer interface.
Definition: MCStreamer.h:93
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
This class is a data container for one entry in a MachineConstantPool.
bool isMachineConstantPoolEntry() const
isMachineConstantPoolEntry - Return true if the MachineConstantPoolEntry is indeed a target specific ...
MachineConstantPoolValue * MachineCPVal
union llvm::MachineConstantPoolEntry::@193 Val
The constant itself.
Abstract base class for all machine specific constantpool value subclasses.
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
const std::vector< MachineConstantPoolEntry > & getConstants() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
const MachineBasicBlock & front() const
const MachineJumpTableInfo * getJumpTableInfo() const
getJumpTableInfo - Return the jump table info object for the current function.
Representation of each machine instruction.
Definition: MachineInstr.h:68
const std::vector< MachineJumpTableEntry > & getJumpTables() const
MachineModuleInfoCOFF - This is a MachineModuleInfoImpl implementation for COFF targets.
StubValueTy & getGVStubEntry(MCSymbol *Sym)
std::vector< std::pair< MCSymbol *, StubValueTy > > SymbolListTy
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
StubValueTy & getGVStubEntry(MCSymbol *Sym)
StubValueTy & getThreadLocalGVStubEntry(MCSymbol *Sym)
SymbolListTy GetGVStubList()
Accessor methods to return the set of stubs in sorted order.
const Module * getModule() const
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
const GlobalValue * getGlobal() const
int64_t getImm() const
bool isImplicit() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
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.
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_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
int64_t getOffset() const
Return the offset from the symbol in this operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
Definition: Pass.cpp:130
PointerIntPair - This class implements a pair of a pointer and small integer.
IntType getInt() const
PointerTy getPointer() const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
bool empty() const
Definition: SmallVector.h:94
void push_back(const T &Elt)
Definition: SmallVector.h:416
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
const Triple & getTargetTriple() const
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
StringRef getTargetFeatureString() const
StringRef getTargetCPU() const
TargetOptions Options
unsigned UnsafeFPMath
UnsafeFPMath - This flag is enabled when the -enable-unsafe-fp-math flag is specified on the command ...
FloatABI::ABIType FloatABIType
FloatABIType - This setting is set by -float-abi=xxx option is specfied on the command line.
unsigned NoInfsFPMath
NoInfsFPMath - This flag is enabled when the -enable-no-infs-fp-math flag is specified on the command...
unsigned HonorSignDependentRoundingFPMathOption
HonorSignDependentRoundingFPMath - This returns true when the -enable-sign-dependent-rounding-fp-math...
unsigned NoNaNsFPMath
NoNaNsFPMath - This flag is enabled when the -enable-no-nans-fp-math flag is specified on the command...
unsigned NoTrappingFPMath
NoTrappingFPMath - This flag is enabled when the -enable-no-trapping-fp-math is specified on the comm...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:255
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:672
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ SECREL
Thread Pointer Offset.
@ GOT_PREL
Thread Local Storage (General Dynamic Mode)
@ SBREL
Section Relative (Windows TLS)
@ GOTTPOFF
Global Offset Table, PC Relative.
@ TPOFF
Global Offset Table, Thread Pointer Offset.
@ MO_LO16
MO_LO16 - On a symbol operand, this represents a relocation containing lower 16 bit of the address.
Definition: ARMBaseInfo.h:250
@ MO_NONLAZY
MO_NONLAZY - This is an independent flag, on a symbol operand "FOO" it represents a symbol which,...
Definition: ARMBaseInfo.h:288
@ MO_HI16
MO_HI16 - On a symbol operand, this represents a relocation containing higher 16 bit of the address.
Definition: ARMBaseInfo.h:254
@ MO_DLLIMPORT
MO_DLLIMPORT - On a symbol operand, this represents that the reference to the symbol is for an import...
Definition: ARMBaseInfo.h:275
@ MO_COFFSTUB
MO_COFFSTUB - On a symbol operand "FOO", this indicates that the reference is actually to the "....
Definition: ARMBaseInfo.h:263
std::string ParseARMTriple(const Triple &TT, StringRef CPU)
SymbolStorageClass
Storage class tells where and what the symbol represents.
Definition: COFF.h:213
@ IMAGE_SYM_CLASS_EXTERNAL
External symbol.
Definition: COFF.h:219
@ IMAGE_SYM_CLASS_STATIC
Static.
Definition: COFF.h:220
@ IMAGE_SYM_DTYPE_FUNCTION
A function that returns a base type.
Definition: COFF.h:271
@ SCT_COMPLEX_TYPE_SHIFT
Type is formed as (base + (derived << SCT_COMPLEX_TYPE_SHIFT))
Definition: COFF.h:275
@ Aggressive
-O3
Definition: CodeGen.h:61
@ FS
Definition: X86.h:208
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
Target & getTheThumbBETarget()
@ MCDR_DataRegionEnd
.end_data_region
Definition: MCDirectives.h:65
@ MCDR_DataRegion
.data_region
Definition: MCDirectives.h:61
@ MCDR_DataRegionJT8
.data_region jt8
Definition: MCDirectives.h:62
@ MCDR_DataRegionJT32
.data_region jt32
Definition: MCDirectives.h:64
@ MCDR_DataRegionJT16
.data_region jt16
Definition: MCDirectives.h:63
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1826
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void LowerARMMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, ARMAsmPrinter &AP)
@ MCAF_SyntaxUnified
.syntax (ARM/ELF)
Definition: MCDirectives.h:53
@ MCAF_Code16
.code16 (X86) / .code 16 (ARM)
Definition: MCDirectives.h:55
@ MCAF_Code32
.code32 (X86) / .code 32 (ARM)
Definition: MCDirectives.h:56
@ MCAF_SubsectionsViaSymbols
.subsections_via_symbols (MachO)
Definition: MCDirectives.h:54
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:1946
DenormalMode parseDenormalFPAttribute(StringRef Str)
Returns the denormal mode to use for inputs and outputs.
Target & getTheARMLETarget()
unsigned convertAddSubFlagsOpcode(unsigned OldOpc)
Map pseudo instructions that imply an 'S' bit onto real opcodes.
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
Definition: MCDirectives.h:35
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
Definition: MCDirectives.h:23
Target & getTheARMBETarget()
Target & getTheThumbLETarget()
Definition: BitVector.h:858
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
Represent subnormal handling kind for floating point instruction inputs and outputs.
static constexpr DenormalMode getPositiveZero()
static constexpr DenormalMode getPreserveSign()
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...