Path: blob/main/contrib/llvm-project/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
35269 views
//===-- ARMAsmPrinter.cpp - Print machine code to an ARM .s file ----------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains a printer that converts from our internal representation9// of machine-dependent LLVM code to GAS-format ARM assembly language.10//11//===----------------------------------------------------------------------===//1213#include "ARMAsmPrinter.h"14#include "ARM.h"15#include "ARMConstantPoolValue.h"16#include "ARMMachineFunctionInfo.h"17#include "ARMTargetMachine.h"18#include "ARMTargetObjectFile.h"19#include "MCTargetDesc/ARMAddressingModes.h"20#include "MCTargetDesc/ARMInstPrinter.h"21#include "MCTargetDesc/ARMMCExpr.h"22#include "TargetInfo/ARMTargetInfo.h"23#include "llvm/ADT/SmallString.h"24#include "llvm/BinaryFormat/COFF.h"25#include "llvm/CodeGen/MachineFunctionPass.h"26#include "llvm/CodeGen/MachineJumpTableInfo.h"27#include "llvm/CodeGen/MachineModuleInfoImpls.h"28#include "llvm/IR/Constants.h"29#include "llvm/IR/DataLayout.h"30#include "llvm/IR/Mangler.h"31#include "llvm/IR/Module.h"32#include "llvm/IR/Type.h"33#include "llvm/MC/MCAsmInfo.h"34#include "llvm/MC/MCAssembler.h"35#include "llvm/MC/MCContext.h"36#include "llvm/MC/MCELFStreamer.h"37#include "llvm/MC/MCInst.h"38#include "llvm/MC/MCInstBuilder.h"39#include "llvm/MC/MCObjectStreamer.h"40#include "llvm/MC/MCStreamer.h"41#include "llvm/MC/MCSymbol.h"42#include "llvm/MC/TargetRegistry.h"43#include "llvm/Support/ARMBuildAttributes.h"44#include "llvm/Support/Debug.h"45#include "llvm/Support/ErrorHandling.h"46#include "llvm/Support/raw_ostream.h"47#include "llvm/Target/TargetMachine.h"48using namespace llvm;4950#define DEBUG_TYPE "asm-printer"5152ARMAsmPrinter::ARMAsmPrinter(TargetMachine &TM,53std::unique_ptr<MCStreamer> Streamer)54: AsmPrinter(TM, std::move(Streamer)), Subtarget(nullptr), AFI(nullptr),55MCP(nullptr), InConstantPool(false), OptimizationGoals(-1) {}5657void ARMAsmPrinter::emitFunctionBodyEnd() {58// Make sure to terminate any constant pools that were at the end59// of the function.60if (!InConstantPool)61return;62InConstantPool = false;63OutStreamer->emitDataRegion(MCDR_DataRegionEnd);64}6566void ARMAsmPrinter::emitFunctionEntryLabel() {67if (AFI->isThumbFunction()) {68OutStreamer->emitAssemblerFlag(MCAF_Code16);69OutStreamer->emitThumbFunc(CurrentFnSym);70} else {71OutStreamer->emitAssemblerFlag(MCAF_Code32);72}7374// Emit symbol for CMSE non-secure entry point75if (AFI->isCmseNSEntryFunction()) {76MCSymbol *S =77OutContext.getOrCreateSymbol("__acle_se_" + CurrentFnSym->getName());78emitLinkage(&MF->getFunction(), S);79OutStreamer->emitSymbolAttribute(S, MCSA_ELF_TypeFunction);80OutStreamer->emitLabel(S);81}82AsmPrinter::emitFunctionEntryLabel();83}8485void ARMAsmPrinter::emitXXStructor(const DataLayout &DL, const Constant *CV) {86uint64_t Size = getDataLayout().getTypeAllocSize(CV->getType());87assert(Size && "C++ constructor pointer had zero size!");8889const GlobalValue *GV = dyn_cast<GlobalValue>(CV->stripPointerCasts());90assert(GV && "C++ constructor pointer was not a GlobalValue!");9192const MCExpr *E = MCSymbolRefExpr::create(GetARMGVSymbol(GV,93ARMII::MO_NO_FLAG),94(Subtarget->isTargetELF()95? MCSymbolRefExpr::VK_ARM_TARGET196: MCSymbolRefExpr::VK_None),97OutContext);9899OutStreamer->emitValue(E, Size);100}101102void ARMAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {103if (PromotedGlobals.count(GV))104// The global was promoted into a constant pool. It should not be emitted.105return;106AsmPrinter::emitGlobalVariable(GV);107}108109/// runOnMachineFunction - This uses the emitInstruction()110/// method to print assembly for each instruction.111///112bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {113AFI = MF.getInfo<ARMFunctionInfo>();114MCP = MF.getConstantPool();115Subtarget = &MF.getSubtarget<ARMSubtarget>();116117SetupMachineFunction(MF);118const Function &F = MF.getFunction();119const TargetMachine& TM = MF.getTarget();120121// Collect all globals that had their storage promoted to a constant pool.122// Functions are emitted before variables, so this accumulates promoted123// globals from all functions in PromotedGlobals.124for (const auto *GV : AFI->getGlobalsPromotedToConstantPool())125PromotedGlobals.insert(GV);126127// Calculate this function's optimization goal.128unsigned OptimizationGoal;129if (F.hasOptNone())130// For best debugging illusion, speed and small size sacrificed131OptimizationGoal = 6;132else if (F.hasMinSize())133// Aggressively for small size, speed and debug illusion sacrificed134OptimizationGoal = 4;135else if (F.hasOptSize())136// For small size, but speed and debugging illusion preserved137OptimizationGoal = 3;138else if (TM.getOptLevel() == CodeGenOptLevel::Aggressive)139// Aggressively for speed, small size and debug illusion sacrificed140OptimizationGoal = 2;141else if (TM.getOptLevel() > CodeGenOptLevel::None)142// For speed, but small size and good debug illusion preserved143OptimizationGoal = 1;144else // TM.getOptLevel() == CodeGenOptLevel::None145// For good debugging, but speed and small size preserved146OptimizationGoal = 5;147148// Combine a new optimization goal with existing ones.149if (OptimizationGoals == -1) // uninitialized goals150OptimizationGoals = OptimizationGoal;151else if (OptimizationGoals != (int)OptimizationGoal) // conflicting goals152OptimizationGoals = 0;153154if (Subtarget->isTargetCOFF()) {155bool Local = F.hasLocalLinkage();156COFF::SymbolStorageClass Scl =157Local ? COFF::IMAGE_SYM_CLASS_STATIC : COFF::IMAGE_SYM_CLASS_EXTERNAL;158int Type = COFF::IMAGE_SYM_DTYPE_FUNCTION << COFF::SCT_COMPLEX_TYPE_SHIFT;159160OutStreamer->beginCOFFSymbolDef(CurrentFnSym);161OutStreamer->emitCOFFSymbolStorageClass(Scl);162OutStreamer->emitCOFFSymbolType(Type);163OutStreamer->endCOFFSymbolDef();164}165166// Emit the rest of the function body.167emitFunctionBody();168169// Emit the XRay table for this function.170emitXRayTable();171172// If we need V4T thumb mode Register Indirect Jump pads, emit them.173// These are created per function, rather than per TU, since it's174// relatively easy to exceed the thumb branch range within a TU.175if (! ThumbIndirectPads.empty()) {176OutStreamer->emitAssemblerFlag(MCAF_Code16);177emitAlignment(Align(2));178for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {179OutStreamer->emitLabel(TIP.second);180EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)181.addReg(TIP.first)182// Add predicate operands.183.addImm(ARMCC::AL)184.addReg(0));185}186ThumbIndirectPads.clear();187}188189// We didn't modify anything.190return false;191}192193void ARMAsmPrinter::PrintSymbolOperand(const MachineOperand &MO,194raw_ostream &O) {195assert(MO.isGlobal() && "caller should check MO.isGlobal");196unsigned TF = MO.getTargetFlags();197if (TF & ARMII::MO_LO16)198O << ":lower16:";199else if (TF & ARMII::MO_HI16)200O << ":upper16:";201else if (TF & ARMII::MO_LO_0_7)202O << ":lower0_7:";203else if (TF & ARMII::MO_LO_8_15)204O << ":lower8_15:";205else if (TF & ARMII::MO_HI_0_7)206O << ":upper0_7:";207else if (TF & ARMII::MO_HI_8_15)208O << ":upper8_15:";209210GetARMGVSymbol(MO.getGlobal(), TF)->print(O, MAI);211printOffset(MO.getOffset(), O);212}213214void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,215raw_ostream &O) {216const MachineOperand &MO = MI->getOperand(OpNum);217218switch (MO.getType()) {219default: llvm_unreachable("<unknown operand type>");220case MachineOperand::MO_Register: {221Register Reg = MO.getReg();222assert(Reg.isPhysical());223assert(!MO.getSubReg() && "Subregs should be eliminated!");224if(ARM::GPRPairRegClass.contains(Reg)) {225const MachineFunction &MF = *MI->getParent()->getParent();226const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();227Reg = TRI->getSubReg(Reg, ARM::gsub_0);228}229O << ARMInstPrinter::getRegisterName(Reg);230break;231}232case MachineOperand::MO_Immediate: {233O << '#';234unsigned TF = MO.getTargetFlags();235if (TF == ARMII::MO_LO16)236O << ":lower16:";237else if (TF == ARMII::MO_HI16)238O << ":upper16:";239else if (TF == ARMII::MO_LO_0_7)240O << ":lower0_7:";241else if (TF == ARMII::MO_LO_8_15)242O << ":lower8_15:";243else if (TF == ARMII::MO_HI_0_7)244O << ":upper0_7:";245else if (TF == ARMII::MO_HI_8_15)246O << ":upper8_15:";247O << MO.getImm();248break;249}250case MachineOperand::MO_MachineBasicBlock:251MO.getMBB()->getSymbol()->print(O, MAI);252return;253case MachineOperand::MO_GlobalAddress: {254PrintSymbolOperand(MO, O);255break;256}257case MachineOperand::MO_ConstantPoolIndex:258if (Subtarget->genExecuteOnly())259llvm_unreachable("execute-only should not generate constant pools");260GetCPISymbol(MO.getIndex())->print(O, MAI);261break;262}263}264265MCSymbol *ARMAsmPrinter::GetCPISymbol(unsigned CPID) const {266// The AsmPrinter::GetCPISymbol superclass method tries to use CPID as267// indexes in MachineConstantPool, which isn't in sync with indexes used here.268const DataLayout &DL = getDataLayout();269return OutContext.getOrCreateSymbol(Twine(DL.getPrivateGlobalPrefix()) +270"CPI" + Twine(getFunctionNumber()) + "_" +271Twine(CPID));272}273274//===--------------------------------------------------------------------===//275276MCSymbol *ARMAsmPrinter::277GetARMJTIPICJumpTableLabel(unsigned uid) const {278const DataLayout &DL = getDataLayout();279SmallString<60> Name;280raw_svector_ostream(Name) << DL.getPrivateGlobalPrefix() << "JTI"281<< getFunctionNumber() << '_' << uid;282return OutContext.getOrCreateSymbol(Name);283}284285bool ARMAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,286const char *ExtraCode, raw_ostream &O) {287// Does this asm operand have a single letter operand modifier?288if (ExtraCode && ExtraCode[0]) {289if (ExtraCode[1] != 0) return true; // Unknown modifier.290291switch (ExtraCode[0]) {292default:293// See if this is a generic print operand294return AsmPrinter::PrintAsmOperand(MI, OpNum, ExtraCode, O);295case 'P': // Print a VFP double precision register.296case 'q': // Print a NEON quad precision register.297printOperand(MI, OpNum, O);298return false;299case 'y': // Print a VFP single precision register as indexed double.300if (MI->getOperand(OpNum).isReg()) {301MCRegister Reg = MI->getOperand(OpNum).getReg().asMCReg();302const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();303// Find the 'd' register that has this 's' register as a sub-register,304// and determine the lane number.305for (MCPhysReg SR : TRI->superregs(Reg)) {306if (!ARM::DPRRegClass.contains(SR))307continue;308bool Lane0 = TRI->getSubReg(SR, ARM::ssub_0) == Reg;309O << ARMInstPrinter::getRegisterName(SR) << (Lane0 ? "[0]" : "[1]");310return false;311}312}313return true;314case 'B': // Bitwise inverse of integer or symbol without a preceding #.315if (!MI->getOperand(OpNum).isImm())316return true;317O << ~(MI->getOperand(OpNum).getImm());318return false;319case 'L': // The low 16 bits of an immediate constant.320if (!MI->getOperand(OpNum).isImm())321return true;322O << (MI->getOperand(OpNum).getImm() & 0xffff);323return false;324case 'M': { // A register range suitable for LDM/STM.325if (!MI->getOperand(OpNum).isReg())326return true;327const MachineOperand &MO = MI->getOperand(OpNum);328Register RegBegin = MO.getReg();329// This takes advantage of the 2 operand-ness of ldm/stm and that we've330// already got the operands in registers that are operands to the331// inline asm statement.332O << "{";333if (ARM::GPRPairRegClass.contains(RegBegin)) {334const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();335Register Reg0 = TRI->getSubReg(RegBegin, ARM::gsub_0);336O << ARMInstPrinter::getRegisterName(Reg0) << ", ";337RegBegin = TRI->getSubReg(RegBegin, ARM::gsub_1);338}339O << ARMInstPrinter::getRegisterName(RegBegin);340341// FIXME: The register allocator not only may not have given us the342// registers in sequence, but may not be in ascending registers. This343// will require changes in the register allocator that'll need to be344// propagated down here if the operands change.345unsigned RegOps = OpNum + 1;346while (MI->getOperand(RegOps).isReg()) {347O << ", "348<< ARMInstPrinter::getRegisterName(MI->getOperand(RegOps).getReg());349RegOps++;350}351352O << "}";353354return false;355}356case 'R': // The most significant register of a pair.357case 'Q': { // The least significant register of a pair.358if (OpNum == 0)359return true;360const MachineOperand &FlagsOP = MI->getOperand(OpNum - 1);361if (!FlagsOP.isImm())362return true;363InlineAsm::Flag F(FlagsOP.getImm());364365// This operand may not be the one that actually provides the register. If366// it's tied to a previous one then we should refer instead to that one367// for registers and their classes.368unsigned TiedIdx;369if (F.isUseOperandTiedToDef(TiedIdx)) {370for (OpNum = InlineAsm::MIOp_FirstOperand; TiedIdx; --TiedIdx) {371unsigned OpFlags = MI->getOperand(OpNum).getImm();372const InlineAsm::Flag F(OpFlags);373OpNum += F.getNumOperandRegisters() + 1;374}375F = InlineAsm::Flag(MI->getOperand(OpNum).getImm());376377// Later code expects OpNum to be pointing at the register rather than378// the flags.379OpNum += 1;380}381382const unsigned NumVals = F.getNumOperandRegisters();383unsigned RC;384bool FirstHalf;385const ARMBaseTargetMachine &ATM =386static_cast<const ARMBaseTargetMachine &>(TM);387388// 'Q' should correspond to the low order register and 'R' to the high389// order register. Whether this corresponds to the upper or lower half390// depends on the endianess mode.391if (ExtraCode[0] == 'Q')392FirstHalf = ATM.isLittleEndian();393else394// ExtraCode[0] == 'R'.395FirstHalf = !ATM.isLittleEndian();396const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();397if (F.hasRegClassConstraint(RC) &&398ARM::GPRPairRegClass.hasSubClassEq(TRI->getRegClass(RC))) {399if (NumVals != 1)400return true;401const MachineOperand &MO = MI->getOperand(OpNum);402if (!MO.isReg())403return true;404const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();405Register Reg =406TRI->getSubReg(MO.getReg(), FirstHalf ? ARM::gsub_0 : ARM::gsub_1);407O << ARMInstPrinter::getRegisterName(Reg);408return false;409}410if (NumVals != 2)411return true;412unsigned RegOp = FirstHalf ? OpNum : OpNum + 1;413if (RegOp >= MI->getNumOperands())414return true;415const MachineOperand &MO = MI->getOperand(RegOp);416if (!MO.isReg())417return true;418Register Reg = MO.getReg();419O << ARMInstPrinter::getRegisterName(Reg);420return false;421}422423case 'e': // The low doubleword register of a NEON quad register.424case 'f': { // The high doubleword register of a NEON quad register.425if (!MI->getOperand(OpNum).isReg())426return true;427Register Reg = MI->getOperand(OpNum).getReg();428if (!ARM::QPRRegClass.contains(Reg))429return true;430const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo();431Register SubReg =432TRI->getSubReg(Reg, ExtraCode[0] == 'e' ? ARM::dsub_0 : ARM::dsub_1);433O << ARMInstPrinter::getRegisterName(SubReg);434return false;435}436437// This modifier is not yet supported.438case 'h': // A range of VFP/NEON registers suitable for VLD1/VST1.439return true;440case 'H': { // The highest-numbered register of a pair.441const MachineOperand &MO = MI->getOperand(OpNum);442if (!MO.isReg())443return true;444const MachineFunction &MF = *MI->getParent()->getParent();445const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();446Register Reg = MO.getReg();447if(!ARM::GPRPairRegClass.contains(Reg))448return false;449Reg = TRI->getSubReg(Reg, ARM::gsub_1);450O << ARMInstPrinter::getRegisterName(Reg);451return false;452}453}454}455456printOperand(MI, OpNum, O);457return false;458}459460bool ARMAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,461unsigned OpNum, const char *ExtraCode,462raw_ostream &O) {463// Does this asm operand have a single letter operand modifier?464if (ExtraCode && ExtraCode[0]) {465if (ExtraCode[1] != 0) return true; // Unknown modifier.466467switch (ExtraCode[0]) {468case 'A': // A memory operand for a VLD1/VST1 instruction.469default: return true; // Unknown modifier.470case 'm': // The base register of a memory operand.471if (!MI->getOperand(OpNum).isReg())472return true;473O << ARMInstPrinter::getRegisterName(MI->getOperand(OpNum).getReg());474return false;475}476}477478const MachineOperand &MO = MI->getOperand(OpNum);479assert(MO.isReg() && "unexpected inline asm memory operand");480O << "[" << ARMInstPrinter::getRegisterName(MO.getReg()) << "]";481return false;482}483484static bool isThumb(const MCSubtargetInfo& STI) {485return STI.hasFeature(ARM::ModeThumb);486}487488void ARMAsmPrinter::emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,489const MCSubtargetInfo *EndInfo) const {490// If either end mode is unknown (EndInfo == NULL) or different than491// the start mode, then restore the start mode.492const bool WasThumb = isThumb(StartInfo);493if (!EndInfo || WasThumb != isThumb(*EndInfo)) {494OutStreamer->emitAssemblerFlag(WasThumb ? MCAF_Code16 : MCAF_Code32);495}496}497498void ARMAsmPrinter::emitStartOfAsmFile(Module &M) {499const Triple &TT = TM.getTargetTriple();500// Use unified assembler syntax.501OutStreamer->emitAssemblerFlag(MCAF_SyntaxUnified);502503// Emit ARM Build Attributes504if (TT.isOSBinFormatELF())505emitAttributes();506507// Use the triple's architecture and subarchitecture to determine508// if we're thumb for the purposes of the top level code16 assembler509// flag.510if (!M.getModuleInlineAsm().empty() && TT.isThumb())511OutStreamer->emitAssemblerFlag(MCAF_Code16);512}513514static void515emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,516MachineModuleInfoImpl::StubValueTy &MCSym) {517// L_foo$stub:518OutStreamer.emitLabel(StubLabel);519// .indirect_symbol _foo520OutStreamer.emitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);521522if (MCSym.getInt())523// External to current translation unit.524OutStreamer.emitIntValue(0, 4/*size*/);525else526// Internal to current translation unit.527//528// When we place the LSDA into the TEXT section, the type info529// pointers need to be indirect and pc-rel. We accomplish this by530// using NLPs; however, sometimes the types are local to the file.531// We need to fill in the value for the NLP in those cases.532OutStreamer.emitValue(533MCSymbolRefExpr::create(MCSym.getPointer(), OutStreamer.getContext()),5344 /*size*/);535}536537538void ARMAsmPrinter::emitEndOfAsmFile(Module &M) {539const Triple &TT = TM.getTargetTriple();540if (TT.isOSBinFormatMachO()) {541// All darwin targets use mach-o.542const TargetLoweringObjectFileMachO &TLOFMacho =543static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());544MachineModuleInfoMachO &MMIMacho =545MMI->getObjFileInfo<MachineModuleInfoMachO>();546547// Output non-lazy-pointers for external and common global variables.548MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetGVStubList();549550if (!Stubs.empty()) {551// Switch with ".non_lazy_symbol_pointer" directive.552OutStreamer->switchSection(TLOFMacho.getNonLazySymbolPointerSection());553emitAlignment(Align(4));554555for (auto &Stub : Stubs)556emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);557558Stubs.clear();559OutStreamer->addBlankLine();560}561562Stubs = MMIMacho.GetThreadLocalGVStubList();563if (!Stubs.empty()) {564// Switch with ".non_lazy_symbol_pointer" directive.565OutStreamer->switchSection(TLOFMacho.getThreadLocalPointerSection());566emitAlignment(Align(4));567568for (auto &Stub : Stubs)569emitNonLazySymbolPointer(*OutStreamer, Stub.first, Stub.second);570571Stubs.clear();572OutStreamer->addBlankLine();573}574575// Funny Darwin hack: This flag tells the linker that no global symbols576// contain code that falls through to other global symbols (e.g. the obvious577// implementation of multiple entry points). If this doesn't occur, the578// linker can safely perform dead code stripping. Since LLVM never579// generates code that does this, it is always safe to set.580OutStreamer->emitAssemblerFlag(MCAF_SubsectionsViaSymbols);581}582583// The last attribute to be emitted is ABI_optimization_goals584MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();585ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);586587if (OptimizationGoals > 0 &&588(Subtarget->isTargetAEABI() || Subtarget->isTargetGNUAEABI() ||589Subtarget->isTargetMuslAEABI()))590ATS.emitAttribute(ARMBuildAttrs::ABI_optimization_goals, OptimizationGoals);591OptimizationGoals = -1;592593ATS.finishAttributeSection();594}595596//===----------------------------------------------------------------------===//597// Helper routines for emitStartOfAsmFile() and emitEndOfAsmFile()598// FIXME:599// The following seem like one-off assembler flags, but they actually need600// to appear in the .ARM.attributes section in ELF.601// Instead of subclassing the MCELFStreamer, we do the work here.602603// Returns true if all functions have the same function attribute value.604// It also returns true when the module has no functions.605static bool checkFunctionsAttributeConsistency(const Module &M, StringRef Attr,606StringRef Value) {607return !any_of(M, [&](const Function &F) {608return F.getFnAttribute(Attr).getValueAsString() != Value;609});610}611// Returns true if all functions have the same denormal mode.612// It also returns true when the module has no functions.613static bool checkDenormalAttributeConsistency(const Module &M,614StringRef Attr,615DenormalMode Value) {616return !any_of(M, [&](const Function &F) {617StringRef AttrVal = F.getFnAttribute(Attr).getValueAsString();618return parseDenormalFPAttribute(AttrVal) != Value;619});620}621622void ARMAsmPrinter::emitAttributes() {623MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();624ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);625626ATS.emitTextAttribute(ARMBuildAttrs::conformance, "2.09");627628ATS.switchVendor("aeabi");629630// Compute ARM ELF Attributes based on the default subtarget that631// we'd have constructed. The existing ARM behavior isn't LTO clean632// anyhow.633// FIXME: For ifunc related functions we could iterate over and look634// for a feature string that doesn't match the default one.635const Triple &TT = TM.getTargetTriple();636StringRef CPU = TM.getTargetCPU();637StringRef FS = TM.getTargetFeatureString();638std::string ArchFS = ARM_MC::ParseARMTriple(TT, CPU);639if (!FS.empty()) {640if (!ArchFS.empty())641ArchFS = (Twine(ArchFS) + "," + FS).str();642else643ArchFS = std::string(FS);644}645const ARMBaseTargetMachine &ATM =646static_cast<const ARMBaseTargetMachine &>(TM);647const ARMSubtarget STI(TT, std::string(CPU), ArchFS, ATM,648ATM.isLittleEndian());649650// Emit build attributes for the available hardware.651ATS.emitTargetAttributes(STI);652653// RW data addressing.654if (isPositionIndependent()) {655ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,656ARMBuildAttrs::AddressRWPCRel);657} else if (STI.isRWPI()) {658// RWPI specific attributes.659ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RW_data,660ARMBuildAttrs::AddressRWSBRel);661}662663// RO data addressing.664if (isPositionIndependent() || STI.isROPI()) {665ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_RO_data,666ARMBuildAttrs::AddressROPCRel);667}668669// GOT use.670if (isPositionIndependent()) {671ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,672ARMBuildAttrs::AddressGOT);673} else {674ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_GOT_use,675ARMBuildAttrs::AddressDirect);676}677678// Set FP Denormals.679if (checkDenormalAttributeConsistency(*MMI->getModule(), "denormal-fp-math",680DenormalMode::getPreserveSign()))681ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,682ARMBuildAttrs::PreserveFPSign);683else if (checkDenormalAttributeConsistency(*MMI->getModule(),684"denormal-fp-math",685DenormalMode::getPositiveZero()))686ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,687ARMBuildAttrs::PositiveZero);688else if (!TM.Options.UnsafeFPMath)689ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,690ARMBuildAttrs::IEEEDenormals);691else {692if (!STI.hasVFP2Base()) {693// When the target doesn't have an FPU (by design or694// intention), the assumptions made on the software support695// mirror that of the equivalent hardware support *if it696// existed*. For v7 and better we indicate that denormals are697// flushed preserving sign, and for V6 we indicate that698// denormals are flushed to positive zero.699if (STI.hasV7Ops())700ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,701ARMBuildAttrs::PreserveFPSign);702} else if (STI.hasVFP3Base()) {703// In VFPv4, VFPv4U, VFPv3, or VFPv3U, it is preserved. That is,704// the sign bit of the zero matches the sign bit of the input or705// result that is being flushed to zero.706ATS.emitAttribute(ARMBuildAttrs::ABI_FP_denormal,707ARMBuildAttrs::PreserveFPSign);708}709// For VFPv2 implementations it is implementation defined as710// to whether denormals are flushed to positive zero or to711// whatever the sign of zero is (ARM v7AR ARM 2.7.5). Historically712// LLVM has chosen to flush this to positive zero (most likely for713// GCC compatibility), so that's the chosen value here (the714// absence of its emission implies zero).715}716717// Set FP exceptions and rounding718if (checkFunctionsAttributeConsistency(*MMI->getModule(),719"no-trapping-math", "true") ||720TM.Options.NoTrappingFPMath)721ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions,722ARMBuildAttrs::Not_Allowed);723else if (!TM.Options.UnsafeFPMath) {724ATS.emitAttribute(ARMBuildAttrs::ABI_FP_exceptions, ARMBuildAttrs::Allowed);725726// If the user has permitted this code to choose the IEEE 754727// rounding at run-time, emit the rounding attribute.728if (TM.Options.HonorSignDependentRoundingFPMathOption)729ATS.emitAttribute(ARMBuildAttrs::ABI_FP_rounding, ARMBuildAttrs::Allowed);730}731732// TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath is the733// equivalent of GCC's -ffinite-math-only flag.734if (TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath)735ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,736ARMBuildAttrs::Allowed);737else738ATS.emitAttribute(ARMBuildAttrs::ABI_FP_number_model,739ARMBuildAttrs::AllowIEEE754);740741// FIXME: add more flags to ARMBuildAttributes.h742// 8-bytes alignment stuff.743ATS.emitAttribute(ARMBuildAttrs::ABI_align_needed, 1);744ATS.emitAttribute(ARMBuildAttrs::ABI_align_preserved, 1);745746// Hard float. Use both S and D registers and conform to AAPCS-VFP.747if (STI.isAAPCS_ABI() && TM.Options.FloatABIType == FloatABI::Hard)748ATS.emitAttribute(ARMBuildAttrs::ABI_VFP_args, ARMBuildAttrs::HardFPAAPCS);749750// FIXME: To support emitting this build attribute as GCC does, the751// -mfp16-format option and associated plumbing must be752// supported. For now the __fp16 type is exposed by default, so this753// attribute should be emitted with value 1.754ATS.emitAttribute(ARMBuildAttrs::ABI_FP_16bit_format,755ARMBuildAttrs::FP16FormatIEEE);756757if (const Module *SourceModule = MMI->getModule()) {758// ABI_PCS_wchar_t to indicate wchar_t width759// FIXME: There is no way to emit value 0 (wchar_t prohibited).760if (auto WCharWidthValue = mdconst::extract_or_null<ConstantInt>(761SourceModule->getModuleFlag("wchar_size"))) {762int WCharWidth = WCharWidthValue->getZExtValue();763assert((WCharWidth == 2 || WCharWidth == 4) &&764"wchar_t width must be 2 or 4 bytes");765ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_wchar_t, WCharWidth);766}767768// ABI_enum_size to indicate enum width769// FIXME: There is no way to emit value 0 (enums prohibited) or value 3770// (all enums contain a value needing 32 bits to encode).771if (auto EnumWidthValue = mdconst::extract_or_null<ConstantInt>(772SourceModule->getModuleFlag("min_enum_size"))) {773int EnumWidth = EnumWidthValue->getZExtValue();774assert((EnumWidth == 1 || EnumWidth == 4) &&775"Minimum enum width must be 1 or 4 bytes");776int EnumBuildAttr = EnumWidth == 1 ? 1 : 2;777ATS.emitAttribute(ARMBuildAttrs::ABI_enum_size, EnumBuildAttr);778}779780auto *PACValue = mdconst::extract_or_null<ConstantInt>(781SourceModule->getModuleFlag("sign-return-address"));782if (PACValue && PACValue->isOne()) {783// If "+pacbti" is used as an architecture extension,784// Tag_PAC_extension is emitted in785// ARMTargetStreamer::emitTargetAttributes().786if (!STI.hasPACBTI()) {787ATS.emitAttribute(ARMBuildAttrs::PAC_extension,788ARMBuildAttrs::AllowPACInNOPSpace);789}790ATS.emitAttribute(ARMBuildAttrs::PACRET_use, ARMBuildAttrs::PACRETUsed);791}792793auto *BTIValue = mdconst::extract_or_null<ConstantInt>(794SourceModule->getModuleFlag("branch-target-enforcement"));795if (BTIValue && BTIValue->isOne()) {796// If "+pacbti" is used as an architecture extension,797// Tag_BTI_extension is emitted in798// ARMTargetStreamer::emitTargetAttributes().799if (!STI.hasPACBTI()) {800ATS.emitAttribute(ARMBuildAttrs::BTI_extension,801ARMBuildAttrs::AllowBTIInNOPSpace);802}803ATS.emitAttribute(ARMBuildAttrs::BTI_use, ARMBuildAttrs::BTIUsed);804}805}806807// We currently do not support using R9 as the TLS pointer.808if (STI.isRWPI())809ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,810ARMBuildAttrs::R9IsSB);811else if (STI.isR9Reserved())812ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,813ARMBuildAttrs::R9Reserved);814else815ATS.emitAttribute(ARMBuildAttrs::ABI_PCS_R9_use,816ARMBuildAttrs::R9IsGPR);817}818819//===----------------------------------------------------------------------===//820821static MCSymbol *getBFLabel(StringRef Prefix, unsigned FunctionNumber,822unsigned LabelId, MCContext &Ctx) {823824MCSymbol *Label = Ctx.getOrCreateSymbol(Twine(Prefix)825+ "BF" + Twine(FunctionNumber) + "_" + Twine(LabelId));826return Label;827}828829static MCSymbol *getPICLabel(StringRef Prefix, unsigned FunctionNumber,830unsigned LabelId, MCContext &Ctx) {831832MCSymbol *Label = Ctx.getOrCreateSymbol(Twine(Prefix)833+ "PC" + Twine(FunctionNumber) + "_" + Twine(LabelId));834return Label;835}836837static MCSymbolRefExpr::VariantKind838getModifierVariantKind(ARMCP::ARMCPModifier Modifier) {839switch (Modifier) {840case ARMCP::no_modifier:841return MCSymbolRefExpr::VK_None;842case ARMCP::TLSGD:843return MCSymbolRefExpr::VK_TLSGD;844case ARMCP::TPOFF:845return MCSymbolRefExpr::VK_TPOFF;846case ARMCP::GOTTPOFF:847return MCSymbolRefExpr::VK_GOTTPOFF;848case ARMCP::SBREL:849return MCSymbolRefExpr::VK_ARM_SBREL;850case ARMCP::GOT_PREL:851return MCSymbolRefExpr::VK_ARM_GOT_PREL;852case ARMCP::SECREL:853return MCSymbolRefExpr::VK_SECREL;854}855llvm_unreachable("Invalid ARMCPModifier!");856}857858MCSymbol *ARMAsmPrinter::GetARMGVSymbol(const GlobalValue *GV,859unsigned char TargetFlags) {860if (Subtarget->isTargetMachO()) {861bool IsIndirect =862(TargetFlags & ARMII::MO_NONLAZY) && Subtarget->isGVIndirectSymbol(GV);863864if (!IsIndirect)865return getSymbol(GV);866867// FIXME: Remove this when Darwin transition to @GOT like syntax.868MCSymbol *MCSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");869MachineModuleInfoMachO &MMIMachO =870MMI->getObjFileInfo<MachineModuleInfoMachO>();871MachineModuleInfoImpl::StubValueTy &StubSym =872GV->isThreadLocal() ? MMIMachO.getThreadLocalGVStubEntry(MCSym)873: MMIMachO.getGVStubEntry(MCSym);874875if (!StubSym.getPointer())876StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV),877!GV->hasInternalLinkage());878return MCSym;879} else if (Subtarget->isTargetCOFF()) {880assert(Subtarget->isTargetWindows() &&881"Windows is the only supported COFF target");882883bool IsIndirect =884(TargetFlags & (ARMII::MO_DLLIMPORT | ARMII::MO_COFFSTUB));885if (!IsIndirect)886return getSymbol(GV);887888SmallString<128> Name;889if (TargetFlags & ARMII::MO_DLLIMPORT)890Name = "__imp_";891else if (TargetFlags & ARMII::MO_COFFSTUB)892Name = ".refptr.";893getNameWithPrefix(Name, GV);894895MCSymbol *MCSym = OutContext.getOrCreateSymbol(Name);896897if (TargetFlags & ARMII::MO_COFFSTUB) {898MachineModuleInfoCOFF &MMICOFF =899MMI->getObjFileInfo<MachineModuleInfoCOFF>();900MachineModuleInfoImpl::StubValueTy &StubSym =901MMICOFF.getGVStubEntry(MCSym);902903if (!StubSym.getPointer())904StubSym = MachineModuleInfoImpl::StubValueTy(getSymbol(GV), true);905}906907return MCSym;908} else if (Subtarget->isTargetELF()) {909return getSymbolPreferLocal(*GV);910}911llvm_unreachable("unexpected target");912}913914void ARMAsmPrinter::emitMachineConstantPoolValue(915MachineConstantPoolValue *MCPV) {916const DataLayout &DL = getDataLayout();917int Size = DL.getTypeAllocSize(MCPV->getType());918919ARMConstantPoolValue *ACPV = static_cast<ARMConstantPoolValue*>(MCPV);920921if (ACPV->isPromotedGlobal()) {922// This constant pool entry is actually a global whose storage has been923// promoted into the constant pool. This global may be referenced still924// by debug information, and due to the way AsmPrinter is set up, the debug925// info is immutable by the time we decide to promote globals to constant926// pools. Because of this, we need to ensure we emit a symbol for the global927// with private linkage (the default) so debug info can refer to it.928//929// However, if this global is promoted into several functions we must ensure930// we don't try and emit duplicate symbols!931auto *ACPC = cast<ARMConstantPoolConstant>(ACPV);932for (const auto *GV : ACPC->promotedGlobals()) {933if (!EmittedPromotedGlobalLabels.count(GV)) {934MCSymbol *GVSym = getSymbol(GV);935OutStreamer->emitLabel(GVSym);936EmittedPromotedGlobalLabels.insert(GV);937}938}939return emitGlobalConstant(DL, ACPC->getPromotedGlobalInit());940}941942MCSymbol *MCSym;943if (ACPV->isLSDA()) {944MCSym = getMBBExceptionSym(MF->front());945} else if (ACPV->isBlockAddress()) {946const BlockAddress *BA =947cast<ARMConstantPoolConstant>(ACPV)->getBlockAddress();948MCSym = GetBlockAddressSymbol(BA);949} else if (ACPV->isGlobalValue()) {950const GlobalValue *GV = cast<ARMConstantPoolConstant>(ACPV)->getGV();951952// On Darwin, const-pool entries may get the "FOO$non_lazy_ptr" mangling, so953// flag the global as MO_NONLAZY.954unsigned char TF = Subtarget->isTargetMachO() ? ARMII::MO_NONLAZY : 0;955MCSym = GetARMGVSymbol(GV, TF);956} else if (ACPV->isMachineBasicBlock()) {957const MachineBasicBlock *MBB = cast<ARMConstantPoolMBB>(ACPV)->getMBB();958MCSym = MBB->getSymbol();959} else {960assert(ACPV->isExtSymbol() && "unrecognized constant pool value");961auto Sym = cast<ARMConstantPoolSymbol>(ACPV)->getSymbol();962MCSym = GetExternalSymbolSymbol(Sym);963}964965// Create an MCSymbol for the reference.966const MCExpr *Expr =967MCSymbolRefExpr::create(MCSym, getModifierVariantKind(ACPV->getModifier()),968OutContext);969970if (ACPV->getPCAdjustment()) {971MCSymbol *PCLabel =972getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),973ACPV->getLabelId(), OutContext);974const MCExpr *PCRelExpr = MCSymbolRefExpr::create(PCLabel, OutContext);975PCRelExpr =976MCBinaryExpr::createAdd(PCRelExpr,977MCConstantExpr::create(ACPV->getPCAdjustment(),978OutContext),979OutContext);980if (ACPV->mustAddCurrentAddress()) {981// We want "(<expr> - .)", but MC doesn't have a concept of the '.'982// label, so just emit a local label end reference that instead.983MCSymbol *DotSym = OutContext.createTempSymbol();984OutStreamer->emitLabel(DotSym);985const MCExpr *DotExpr = MCSymbolRefExpr::create(DotSym, OutContext);986PCRelExpr = MCBinaryExpr::createSub(PCRelExpr, DotExpr, OutContext);987}988Expr = MCBinaryExpr::createSub(Expr, PCRelExpr, OutContext);989}990OutStreamer->emitValue(Expr, Size);991}992993void ARMAsmPrinter::emitJumpTableAddrs(const MachineInstr *MI) {994const MachineOperand &MO1 = MI->getOperand(1);995unsigned JTI = MO1.getIndex();996997// Make sure the Thumb jump table is 4-byte aligned. This will be a nop for998// ARM mode tables.999emitAlignment(Align(4));10001001// Emit a label for the jump table.1002MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);1003OutStreamer->emitLabel(JTISymbol);10041005// Mark the jump table as data-in-code.1006OutStreamer->emitDataRegion(MCDR_DataRegionJT32);10071008// Emit each entry of the table.1009const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();1010const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();1011const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;10121013for (MachineBasicBlock *MBB : JTBBs) {1014// Construct an MCExpr for the entry. We want a value of the form:1015// (BasicBlockAddr - TableBeginAddr)1016//1017// For example, a table with entries jumping to basic blocks BB0 and BB11018// would look like:1019// LJTI_0_0:1020// .word (LBB0 - LJTI_0_0)1021// .word (LBB1 - LJTI_0_0)1022const MCExpr *Expr = MCSymbolRefExpr::create(MBB->getSymbol(), OutContext);10231024if (isPositionIndependent() || Subtarget->isROPI())1025Expr = MCBinaryExpr::createSub(Expr, MCSymbolRefExpr::create(JTISymbol,1026OutContext),1027OutContext);1028// If we're generating a table of Thumb addresses in static relocation1029// model, we need to add one to keep interworking correctly.1030else if (AFI->isThumbFunction())1031Expr = MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(1,OutContext),1032OutContext);1033OutStreamer->emitValue(Expr, 4);1034}1035// Mark the end of jump table data-in-code region.1036OutStreamer->emitDataRegion(MCDR_DataRegionEnd);1037}10381039void ARMAsmPrinter::emitJumpTableInsts(const MachineInstr *MI) {1040const MachineOperand &MO1 = MI->getOperand(1);1041unsigned JTI = MO1.getIndex();10421043// Make sure the Thumb jump table is 4-byte aligned. This will be a nop for1044// ARM mode tables.1045emitAlignment(Align(4));10461047// Emit a label for the jump table.1048MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);1049OutStreamer->emitLabel(JTISymbol);10501051// Emit each entry of the table.1052const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();1053const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();1054const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;10551056for (MachineBasicBlock *MBB : JTBBs) {1057const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),1058OutContext);1059// If this isn't a TBB or TBH, the entries are direct branch instructions.1060EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2B)1061.addExpr(MBBSymbolExpr)1062.addImm(ARMCC::AL)1063.addReg(0));1064}1065}10661067void ARMAsmPrinter::emitJumpTableTBInst(const MachineInstr *MI,1068unsigned OffsetWidth) {1069assert((OffsetWidth == 1 || OffsetWidth == 2) && "invalid tbb/tbh width");1070const MachineOperand &MO1 = MI->getOperand(1);1071unsigned JTI = MO1.getIndex();10721073if (Subtarget->isThumb1Only())1074emitAlignment(Align(4));10751076MCSymbol *JTISymbol = GetARMJTIPICJumpTableLabel(JTI);1077OutStreamer->emitLabel(JTISymbol);10781079// Emit each entry of the table.1080const MachineJumpTableInfo *MJTI = MF->getJumpTableInfo();1081const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();1082const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;10831084// Mark the jump table as data-in-code.1085OutStreamer->emitDataRegion(OffsetWidth == 1 ? MCDR_DataRegionJT81086: MCDR_DataRegionJT16);10871088for (auto *MBB : JTBBs) {1089const MCExpr *MBBSymbolExpr = MCSymbolRefExpr::create(MBB->getSymbol(),1090OutContext);1091// Otherwise it's an offset from the dispatch instruction. Construct an1092// MCExpr for the entry. We want a value of the form:1093// (BasicBlockAddr - TBBInstAddr + 4) / 21094//1095// For example, a TBB table with entries jumping to basic blocks BB0 and BB11096// would look like:1097// LJTI_0_0:1098// .byte (LBB0 - (LCPI0_0 + 4)) / 21099// .byte (LBB1 - (LCPI0_0 + 4)) / 21100// where LCPI0_0 is a label defined just before the TBB instruction using1101// this table.1102MCSymbol *TBInstPC = GetCPISymbol(MI->getOperand(0).getImm());1103const MCExpr *Expr = MCBinaryExpr::createAdd(1104MCSymbolRefExpr::create(TBInstPC, OutContext),1105MCConstantExpr::create(4, OutContext), OutContext);1106Expr = MCBinaryExpr::createSub(MBBSymbolExpr, Expr, OutContext);1107Expr = MCBinaryExpr::createDiv(Expr, MCConstantExpr::create(2, OutContext),1108OutContext);1109OutStreamer->emitValue(Expr, OffsetWidth);1110}1111// Mark the end of jump table data-in-code region. 32-bit offsets use1112// actual branch instructions here, so we don't mark those as a data-region1113// at all.1114OutStreamer->emitDataRegion(MCDR_DataRegionEnd);11151116// Make sure the next instruction is 2-byte aligned.1117emitAlignment(Align(2));1118}11191120std::tuple<const MCSymbol *, uint64_t, const MCSymbol *,1121codeview::JumpTableEntrySize>1122ARMAsmPrinter::getCodeViewJumpTableInfo(int JTI,1123const MachineInstr *BranchInstr,1124const MCSymbol *BranchLabel) const {1125codeview::JumpTableEntrySize EntrySize;1126const MCSymbol *BaseLabel;1127uint64_t BaseOffset = 0;1128switch (BranchInstr->getOpcode()) {1129case ARM::BR_JTadd:1130case ARM::BR_JTr:1131case ARM::tBR_JTr:1132// Word relative to the jump table address.1133EntrySize = codeview::JumpTableEntrySize::UInt32;1134BaseLabel = GetARMJTIPICJumpTableLabel(JTI);1135break;1136case ARM::tTBH_JT:1137case ARM::t2TBH_JT:1138// half-word shifted left, relative to *after* the branch instruction.1139EntrySize = codeview::JumpTableEntrySize::UInt16ShiftLeft;1140BranchLabel = GetCPISymbol(BranchInstr->getOperand(3).getImm());1141BaseLabel = BranchLabel;1142BaseOffset = 4;1143break;1144case ARM::tTBB_JT:1145case ARM::t2TBB_JT:1146// byte shifted left, relative to *after* the branch instruction.1147EntrySize = codeview::JumpTableEntrySize::UInt8ShiftLeft;1148BranchLabel = GetCPISymbol(BranchInstr->getOperand(3).getImm());1149BaseLabel = BranchLabel;1150BaseOffset = 4;1151break;1152case ARM::t2BR_JT:1153// Direct jump.1154BaseLabel = nullptr;1155EntrySize = codeview::JumpTableEntrySize::Pointer;1156break;1157default:1158llvm_unreachable("Unknown jump table instruction");1159}11601161return std::make_tuple(BaseLabel, BaseOffset, BranchLabel, EntrySize);1162}11631164void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {1165assert(MI->getFlag(MachineInstr::FrameSetup) &&1166"Only instruction which are involved into frame setup code are allowed");11671168MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();1169ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);1170const MachineFunction &MF = *MI->getParent()->getParent();1171const TargetRegisterInfo *TargetRegInfo =1172MF.getSubtarget().getRegisterInfo();1173const MachineRegisterInfo &MachineRegInfo = MF.getRegInfo();11741175Register FramePtr = TargetRegInfo->getFrameRegister(MF);1176unsigned Opc = MI->getOpcode();1177unsigned SrcReg, DstReg;11781179switch (Opc) {1180case ARM::tPUSH:1181// special case: tPUSH does not have src/dst regs.1182SrcReg = DstReg = ARM::SP;1183break;1184case ARM::tLDRpci:1185case ARM::t2MOVi16:1186case ARM::t2MOVTi16:1187case ARM::tMOVi8:1188case ARM::tADDi8:1189case ARM::tLSLri:1190// special cases:1191// 1) for Thumb1 code we sometimes materialize the constant via constpool1192// load.1193// 2) for Thumb1 execute only code we materialize the constant via the1194// following pattern:1195// movs r3, #:upper8_15:<const>1196// lsls r3, #81197// adds r3, #:upper0_7:<const>1198// lsls r3, #81199// adds r3, #:lower8_15:<const>1200// lsls r3, #81201// adds r3, #:lower0_7:<const>1202// So we need to special-case MOVS, ADDS and LSLS, and keep track of1203// where we are in the sequence with the simplest of state machines.1204// 3) for Thumb2 execute only code we materialize the constant via1205// immediate constants in 2 separate instructions (MOVW/MOVT).1206SrcReg = ~0U;1207DstReg = MI->getOperand(0).getReg();1208break;1209default:1210SrcReg = MI->getOperand(1).getReg();1211DstReg = MI->getOperand(0).getReg();1212break;1213}12141215// Try to figure out the unwinding opcode out of src / dst regs.1216if (MI->mayStore()) {1217// Register saves.1218assert(DstReg == ARM::SP &&1219"Only stack pointer as a destination reg is supported");12201221SmallVector<unsigned, 4> RegList;1222// Skip src & dst reg, and pred ops.1223unsigned StartOp = 2 + 2;1224// Use all the operands.1225unsigned NumOffset = 0;1226// Amount of SP adjustment folded into a push, before the1227// registers are stored (pad at higher addresses).1228unsigned PadBefore = 0;1229// Amount of SP adjustment folded into a push, after the1230// registers are stored (pad at lower addresses).1231unsigned PadAfter = 0;12321233switch (Opc) {1234default:1235MI->print(errs());1236llvm_unreachable("Unsupported opcode for unwinding information");1237case ARM::tPUSH:1238// Special case here: no src & dst reg, but two extra imp ops.1239StartOp = 2; NumOffset = 2;1240[[fallthrough]];1241case ARM::STMDB_UPD:1242case ARM::t2STMDB_UPD:1243case ARM::VSTMDDB_UPD:1244assert(SrcReg == ARM::SP &&1245"Only stack pointer as a source reg is supported");1246for (unsigned i = StartOp, NumOps = MI->getNumOperands() - NumOffset;1247i != NumOps; ++i) {1248const MachineOperand &MO = MI->getOperand(i);1249// Actually, there should never be any impdef stuff here. Skip it1250// temporary to workaround PR11902.1251if (MO.isImplicit())1252continue;1253// Registers, pushed as a part of folding an SP update into the1254// push instruction are marked as undef and should not be1255// restored when unwinding, because the function can modify the1256// corresponding stack slots.1257if (MO.isUndef()) {1258assert(RegList.empty() &&1259"Pad registers must come before restored ones");1260unsigned Width =1261TargetRegInfo->getRegSizeInBits(MO.getReg(), MachineRegInfo) / 8;1262PadAfter += Width;1263continue;1264}1265// Check for registers that are remapped (for a Thumb1 prologue that1266// saves high registers).1267Register Reg = MO.getReg();1268if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(Reg))1269Reg = RemappedReg;1270RegList.push_back(Reg);1271}1272break;1273case ARM::STR_PRE_IMM:1274case ARM::STR_PRE_REG:1275case ARM::t2STR_PRE:1276assert(MI->getOperand(2).getReg() == ARM::SP &&1277"Only stack pointer as a source reg is supported");1278if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(SrcReg))1279SrcReg = RemappedReg;12801281RegList.push_back(SrcReg);1282break;1283case ARM::t2STRD_PRE:1284assert(MI->getOperand(3).getReg() == ARM::SP &&1285"Only stack pointer as a source reg is supported");1286SrcReg = MI->getOperand(1).getReg();1287if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(SrcReg))1288SrcReg = RemappedReg;1289RegList.push_back(SrcReg);1290SrcReg = MI->getOperand(2).getReg();1291if (unsigned RemappedReg = AFI->EHPrologueRemappedRegs.lookup(SrcReg))1292SrcReg = RemappedReg;1293RegList.push_back(SrcReg);1294PadBefore = -MI->getOperand(4).getImm() - 8;1295break;1296}1297if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {1298if (PadBefore)1299ATS.emitPad(PadBefore);1300ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);1301// Account for the SP adjustment, folded into the push.1302if (PadAfter)1303ATS.emitPad(PadAfter);1304}1305} else {1306// Changes of stack / frame pointer.1307if (SrcReg == ARM::SP) {1308int64_t Offset = 0;1309switch (Opc) {1310default:1311MI->print(errs());1312llvm_unreachable("Unsupported opcode for unwinding information");1313case ARM::MOVr:1314case ARM::tMOVr:1315Offset = 0;1316break;1317case ARM::ADDri:1318case ARM::t2ADDri:1319case ARM::t2ADDri12:1320case ARM::t2ADDspImm:1321case ARM::t2ADDspImm12:1322Offset = -MI->getOperand(2).getImm();1323break;1324case ARM::SUBri:1325case ARM::t2SUBri:1326case ARM::t2SUBri12:1327case ARM::t2SUBspImm:1328case ARM::t2SUBspImm12:1329Offset = MI->getOperand(2).getImm();1330break;1331case ARM::tSUBspi:1332Offset = MI->getOperand(2).getImm()*4;1333break;1334case ARM::tADDspi:1335case ARM::tADDrSPi:1336Offset = -MI->getOperand(2).getImm()*4;1337break;1338case ARM::tADDhirr:1339Offset =1340-AFI->EHPrologueOffsetInRegs.lookup(MI->getOperand(2).getReg());1341break;1342}13431344if (MAI->getExceptionHandlingType() == ExceptionHandling::ARM) {1345if (DstReg == FramePtr && FramePtr != ARM::SP)1346// Set-up of the frame pointer. Positive values correspond to "add"1347// instruction.1348ATS.emitSetFP(FramePtr, ARM::SP, -Offset);1349else if (DstReg == ARM::SP) {1350// Change of SP by an offset. Positive values correspond to "sub"1351// instruction.1352ATS.emitPad(Offset);1353} else {1354// Move of SP to a register. Positive values correspond to an "add"1355// instruction.1356ATS.emitMovSP(DstReg, -Offset);1357}1358}1359} else if (DstReg == ARM::SP) {1360MI->print(errs());1361llvm_unreachable("Unsupported opcode for unwinding information");1362} else {1363int64_t Offset = 0;1364switch (Opc) {1365case ARM::tMOVr:1366// If a Thumb1 function spills r8-r11, we copy the values to low1367// registers before pushing them. Record the copy so we can emit the1368// correct ".save" later.1369AFI->EHPrologueRemappedRegs[DstReg] = SrcReg;1370break;1371case ARM::tLDRpci: {1372// Grab the constpool index and check, whether it corresponds to1373// original or cloned constpool entry.1374unsigned CPI = MI->getOperand(1).getIndex();1375const MachineConstantPool *MCP = MF.getConstantPool();1376if (CPI >= MCP->getConstants().size())1377CPI = AFI->getOriginalCPIdx(CPI);1378assert(CPI != -1U && "Invalid constpool index");13791380// Derive the actual offset.1381const MachineConstantPoolEntry &CPE = MCP->getConstants()[CPI];1382assert(!CPE.isMachineConstantPoolEntry() && "Invalid constpool entry");1383Offset = cast<ConstantInt>(CPE.Val.ConstVal)->getSExtValue();1384AFI->EHPrologueOffsetInRegs[DstReg] = Offset;1385break;1386}1387case ARM::t2MOVi16:1388Offset = MI->getOperand(1).getImm();1389AFI->EHPrologueOffsetInRegs[DstReg] = Offset;1390break;1391case ARM::t2MOVTi16:1392Offset = MI->getOperand(2).getImm();1393AFI->EHPrologueOffsetInRegs[DstReg] |= (Offset << 16);1394break;1395case ARM::tMOVi8:1396Offset = MI->getOperand(2).getImm();1397AFI->EHPrologueOffsetInRegs[DstReg] = Offset;1398break;1399case ARM::tLSLri:1400assert(MI->getOperand(3).getImm() == 8 &&1401"The shift amount is not equal to 8");1402assert(MI->getOperand(2).getReg() == MI->getOperand(0).getReg() &&1403"The source register is not equal to the destination register");1404AFI->EHPrologueOffsetInRegs[DstReg] <<= 8;1405break;1406case ARM::tADDi8:1407assert(MI->getOperand(2).getReg() == MI->getOperand(0).getReg() &&1408"The source register is not equal to the destination register");1409Offset = MI->getOperand(3).getImm();1410AFI->EHPrologueOffsetInRegs[DstReg] += Offset;1411break;1412case ARM::t2PAC:1413case ARM::t2PACBTI:1414AFI->EHPrologueRemappedRegs[ARM::R12] = ARM::RA_AUTH_CODE;1415break;1416default:1417MI->print(errs());1418llvm_unreachable("Unsupported opcode for unwinding information");1419}1420}1421}1422}14231424// Simple pseudo-instructions have their lowering (with expansion to real1425// instructions) auto-generated.1426#include "ARMGenMCPseudoLowering.inc"14271428void ARMAsmPrinter::emitInstruction(const MachineInstr *MI) {1429// TODOD FIXME: Enable feature predicate checks once all the test pass.1430// ARM_MC::verifyInstructionPredicates(MI->getOpcode(),1431// getSubtargetInfo().getFeatureBits());14321433const DataLayout &DL = getDataLayout();1434MCTargetStreamer &TS = *OutStreamer->getTargetStreamer();1435ARMTargetStreamer &ATS = static_cast<ARMTargetStreamer &>(TS);14361437// If we just ended a constant pool, mark it as such.1438if (InConstantPool && MI->getOpcode() != ARM::CONSTPOOL_ENTRY) {1439OutStreamer->emitDataRegion(MCDR_DataRegionEnd);1440InConstantPool = false;1441}14421443// Emit unwinding stuff for frame-related instructions1444if (Subtarget->isTargetEHABICompatible() &&1445MI->getFlag(MachineInstr::FrameSetup))1446EmitUnwindingInstruction(MI);14471448// Do any auto-generated pseudo lowerings.1449if (emitPseudoExpansionLowering(*OutStreamer, MI))1450return;14511452assert(!convertAddSubFlagsOpcode(MI->getOpcode()) &&1453"Pseudo flag setting opcode should be expanded early");14541455// Check for manual lowerings.1456unsigned Opc = MI->getOpcode();1457switch (Opc) {1458case ARM::t2MOVi32imm: llvm_unreachable("Should be lowered by thumb2it pass");1459case ARM::DBG_VALUE: llvm_unreachable("Should be handled by generic printing");1460case ARM::LEApcrel:1461case ARM::tLEApcrel:1462case ARM::t2LEApcrel: {1463// FIXME: Need to also handle globals and externals1464MCSymbol *CPISymbol = GetCPISymbol(MI->getOperand(1).getIndex());1465EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==1466ARM::t2LEApcrel ? ARM::t2ADR1467: (MI->getOpcode() == ARM::tLEApcrel ? ARM::tADR1468: ARM::ADR))1469.addReg(MI->getOperand(0).getReg())1470.addExpr(MCSymbolRefExpr::create(CPISymbol, OutContext))1471// Add predicate operands.1472.addImm(MI->getOperand(2).getImm())1473.addReg(MI->getOperand(3).getReg()));1474return;1475}1476case ARM::LEApcrelJT:1477case ARM::tLEApcrelJT:1478case ARM::t2LEApcrelJT: {1479MCSymbol *JTIPICSymbol =1480GetARMJTIPICJumpTableLabel(MI->getOperand(1).getIndex());1481EmitToStreamer(*OutStreamer, MCInstBuilder(MI->getOpcode() ==1482ARM::t2LEApcrelJT ? ARM::t2ADR1483: (MI->getOpcode() == ARM::tLEApcrelJT ? ARM::tADR1484: ARM::ADR))1485.addReg(MI->getOperand(0).getReg())1486.addExpr(MCSymbolRefExpr::create(JTIPICSymbol, OutContext))1487// Add predicate operands.1488.addImm(MI->getOperand(2).getImm())1489.addReg(MI->getOperand(3).getReg()));1490return;1491}1492// Darwin call instructions are just normal call instructions with different1493// clobber semantics (they clobber R9).1494case ARM::BX_CALL: {1495EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)1496.addReg(ARM::LR)1497.addReg(ARM::PC)1498// Add predicate operands.1499.addImm(ARMCC::AL)1500.addReg(0)1501// Add 's' bit operand (always reg0 for this)1502.addReg(0));15031504assert(Subtarget->hasV4TOps());1505EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)1506.addReg(MI->getOperand(0).getReg()));1507return;1508}1509case ARM::tBX_CALL: {1510if (Subtarget->hasV5TOps())1511llvm_unreachable("Expected BLX to be selected for v5t+");15121513// On ARM v4t, when doing a call from thumb mode, we need to ensure1514// that the saved lr has its LSB set correctly (the arch doesn't1515// have blx).1516// So here we generate a bl to a small jump pad that does bx rN.1517// The jump pads are emitted after the function body.15181519Register TReg = MI->getOperand(0).getReg();1520MCSymbol *TRegSym = nullptr;1521for (std::pair<unsigned, MCSymbol *> &TIP : ThumbIndirectPads) {1522if (TIP.first == TReg) {1523TRegSym = TIP.second;1524break;1525}1526}15271528if (!TRegSym) {1529TRegSym = OutContext.createTempSymbol();1530ThumbIndirectPads.push_back(std::make_pair(TReg, TRegSym));1531}15321533// Create a link-saving branch to the Reg Indirect Jump Pad.1534EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBL)1535// Predicate comes first here.1536.addImm(ARMCC::AL).addReg(0)1537.addExpr(MCSymbolRefExpr::create(TRegSym, OutContext)));1538return;1539}1540case ARM::BMOVPCRX_CALL: {1541EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)1542.addReg(ARM::LR)1543.addReg(ARM::PC)1544// Add predicate operands.1545.addImm(ARMCC::AL)1546.addReg(0)1547// Add 's' bit operand (always reg0 for this)1548.addReg(0));15491550EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)1551.addReg(ARM::PC)1552.addReg(MI->getOperand(0).getReg())1553// Add predicate operands.1554.addImm(ARMCC::AL)1555.addReg(0)1556// Add 's' bit operand (always reg0 for this)1557.addReg(0));1558return;1559}1560case ARM::BMOVPCB_CALL: {1561EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVr)1562.addReg(ARM::LR)1563.addReg(ARM::PC)1564// Add predicate operands.1565.addImm(ARMCC::AL)1566.addReg(0)1567// Add 's' bit operand (always reg0 for this)1568.addReg(0));15691570const MachineOperand &Op = MI->getOperand(0);1571const GlobalValue *GV = Op.getGlobal();1572const unsigned TF = Op.getTargetFlags();1573MCSymbol *GVSym = GetARMGVSymbol(GV, TF);1574const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);1575EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::Bcc)1576.addExpr(GVSymExpr)1577// Add predicate operands.1578.addImm(ARMCC::AL)1579.addReg(0));1580return;1581}1582case ARM::MOVi16_ga_pcrel:1583case ARM::t2MOVi16_ga_pcrel: {1584MCInst TmpInst;1585TmpInst.setOpcode(Opc == ARM::MOVi16_ga_pcrel? ARM::MOVi16 : ARM::t2MOVi16);1586TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));15871588unsigned TF = MI->getOperand(1).getTargetFlags();1589const GlobalValue *GV = MI->getOperand(1).getGlobal();1590MCSymbol *GVSym = GetARMGVSymbol(GV, TF);1591const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);15921593MCSymbol *LabelSym =1594getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),1595MI->getOperand(2).getImm(), OutContext);1596const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);1597unsigned PCAdj = (Opc == ARM::MOVi16_ga_pcrel) ? 8 : 4;1598const MCExpr *PCRelExpr =1599ARMMCExpr::createLower16(MCBinaryExpr::createSub(GVSymExpr,1600MCBinaryExpr::createAdd(LabelSymExpr,1601MCConstantExpr::create(PCAdj, OutContext),1602OutContext), OutContext), OutContext);1603TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));16041605// Add predicate operands.1606TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));1607TmpInst.addOperand(MCOperand::createReg(0));1608// Add 's' bit operand (always reg0 for this)1609TmpInst.addOperand(MCOperand::createReg(0));1610EmitToStreamer(*OutStreamer, TmpInst);1611return;1612}1613case ARM::MOVTi16_ga_pcrel:1614case ARM::t2MOVTi16_ga_pcrel: {1615MCInst TmpInst;1616TmpInst.setOpcode(Opc == ARM::MOVTi16_ga_pcrel1617? ARM::MOVTi16 : ARM::t2MOVTi16);1618TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));1619TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));16201621unsigned TF = MI->getOperand(2).getTargetFlags();1622const GlobalValue *GV = MI->getOperand(2).getGlobal();1623MCSymbol *GVSym = GetARMGVSymbol(GV, TF);1624const MCExpr *GVSymExpr = MCSymbolRefExpr::create(GVSym, OutContext);16251626MCSymbol *LabelSym =1627getPICLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),1628MI->getOperand(3).getImm(), OutContext);1629const MCExpr *LabelSymExpr= MCSymbolRefExpr::create(LabelSym, OutContext);1630unsigned PCAdj = (Opc == ARM::MOVTi16_ga_pcrel) ? 8 : 4;1631const MCExpr *PCRelExpr =1632ARMMCExpr::createUpper16(MCBinaryExpr::createSub(GVSymExpr,1633MCBinaryExpr::createAdd(LabelSymExpr,1634MCConstantExpr::create(PCAdj, OutContext),1635OutContext), OutContext), OutContext);1636TmpInst.addOperand(MCOperand::createExpr(PCRelExpr));1637// Add predicate operands.1638TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));1639TmpInst.addOperand(MCOperand::createReg(0));1640// Add 's' bit operand (always reg0 for this)1641TmpInst.addOperand(MCOperand::createReg(0));1642EmitToStreamer(*OutStreamer, TmpInst);1643return;1644}1645case ARM::t2BFi:1646case ARM::t2BFic:1647case ARM::t2BFLi:1648case ARM::t2BFr:1649case ARM::t2BFLr: {1650// This is a Branch Future instruction.16511652const MCExpr *BranchLabel = MCSymbolRefExpr::create(1653getBFLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),1654MI->getOperand(0).getIndex(), OutContext),1655OutContext);16561657auto MCInst = MCInstBuilder(Opc).addExpr(BranchLabel);1658if (MI->getOperand(1).isReg()) {1659// For BFr/BFLr1660MCInst.addReg(MI->getOperand(1).getReg());1661} else {1662// For BFi/BFLi/BFic1663const MCExpr *BranchTarget;1664if (MI->getOperand(1).isMBB())1665BranchTarget = MCSymbolRefExpr::create(1666MI->getOperand(1).getMBB()->getSymbol(), OutContext);1667else if (MI->getOperand(1).isGlobal()) {1668const GlobalValue *GV = MI->getOperand(1).getGlobal();1669BranchTarget = MCSymbolRefExpr::create(1670GetARMGVSymbol(GV, MI->getOperand(1).getTargetFlags()), OutContext);1671} else if (MI->getOperand(1).isSymbol()) {1672BranchTarget = MCSymbolRefExpr::create(1673GetExternalSymbolSymbol(MI->getOperand(1).getSymbolName()),1674OutContext);1675} else1676llvm_unreachable("Unhandled operand kind in Branch Future instruction");16771678MCInst.addExpr(BranchTarget);1679}16801681if (Opc == ARM::t2BFic) {1682const MCExpr *ElseLabel = MCSymbolRefExpr::create(1683getBFLabel(DL.getPrivateGlobalPrefix(), getFunctionNumber(),1684MI->getOperand(2).getIndex(), OutContext),1685OutContext);1686MCInst.addExpr(ElseLabel);1687MCInst.addImm(MI->getOperand(3).getImm());1688} else {1689MCInst.addImm(MI->getOperand(2).getImm())1690.addReg(MI->getOperand(3).getReg());1691}16921693EmitToStreamer(*OutStreamer, MCInst);1694return;1695}1696case ARM::t2BF_LabelPseudo: {1697// This is a pseudo op for a label used by a branch future instruction16981699// Emit the label.1700OutStreamer->emitLabel(getBFLabel(DL.getPrivateGlobalPrefix(),1701getFunctionNumber(),1702MI->getOperand(0).getIndex(), OutContext));1703return;1704}1705case ARM::tPICADD: {1706// This is a pseudo op for a label + instruction sequence, which looks like:1707// LPC0:1708// add r0, pc1709// This adds the address of LPC0 to r0.17101711// Emit the label.1712OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),1713getFunctionNumber(),1714MI->getOperand(2).getImm(), OutContext));17151716// Form and emit the add.1717EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)1718.addReg(MI->getOperand(0).getReg())1719.addReg(MI->getOperand(0).getReg())1720.addReg(ARM::PC)1721// Add predicate operands.1722.addImm(ARMCC::AL)1723.addReg(0));1724return;1725}1726case ARM::PICADD: {1727// This is a pseudo op for a label + instruction sequence, which looks like:1728// LPC0:1729// add r0, pc, r01730// This adds the address of LPC0 to r0.17311732// Emit the label.1733OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),1734getFunctionNumber(),1735MI->getOperand(2).getImm(), OutContext));17361737// Form and emit the add.1738EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)1739.addReg(MI->getOperand(0).getReg())1740.addReg(ARM::PC)1741.addReg(MI->getOperand(1).getReg())1742// Add predicate operands.1743.addImm(MI->getOperand(3).getImm())1744.addReg(MI->getOperand(4).getReg())1745// Add 's' bit operand (always reg0 for this)1746.addReg(0));1747return;1748}1749case ARM::PICSTR:1750case ARM::PICSTRB:1751case ARM::PICSTRH:1752case ARM::PICLDR:1753case ARM::PICLDRB:1754case ARM::PICLDRH:1755case ARM::PICLDRSB:1756case ARM::PICLDRSH: {1757// This is a pseudo op for a label + instruction sequence, which looks like:1758// LPC0:1759// OP r0, [pc, r0]1760// The LCP0 label is referenced by a constant pool entry in order to get1761// a PC-relative address at the ldr instruction.17621763// Emit the label.1764OutStreamer->emitLabel(getPICLabel(DL.getPrivateGlobalPrefix(),1765getFunctionNumber(),1766MI->getOperand(2).getImm(), OutContext));17671768// Form and emit the load1769unsigned Opcode;1770switch (MI->getOpcode()) {1771default:1772llvm_unreachable("Unexpected opcode!");1773case ARM::PICSTR: Opcode = ARM::STRrs; break;1774case ARM::PICSTRB: Opcode = ARM::STRBrs; break;1775case ARM::PICSTRH: Opcode = ARM::STRH; break;1776case ARM::PICLDR: Opcode = ARM::LDRrs; break;1777case ARM::PICLDRB: Opcode = ARM::LDRBrs; break;1778case ARM::PICLDRH: Opcode = ARM::LDRH; break;1779case ARM::PICLDRSB: Opcode = ARM::LDRSB; break;1780case ARM::PICLDRSH: Opcode = ARM::LDRSH; break;1781}1782EmitToStreamer(*OutStreamer, MCInstBuilder(Opcode)1783.addReg(MI->getOperand(0).getReg())1784.addReg(ARM::PC)1785.addReg(MI->getOperand(1).getReg())1786.addImm(0)1787// Add predicate operands.1788.addImm(MI->getOperand(3).getImm())1789.addReg(MI->getOperand(4).getReg()));17901791return;1792}1793case ARM::CONSTPOOL_ENTRY: {1794if (Subtarget->genExecuteOnly())1795llvm_unreachable("execute-only should not generate constant pools");17961797/// CONSTPOOL_ENTRY - This instruction represents a floating constant pool1798/// in the function. The first operand is the ID# for this instruction, the1799/// second is the index into the MachineConstantPool that this is, the third1800/// is the size in bytes of this constant pool entry.1801/// The required alignment is specified on the basic block holding this MI.1802unsigned LabelId = (unsigned)MI->getOperand(0).getImm();1803unsigned CPIdx = (unsigned)MI->getOperand(1).getIndex();18041805// If this is the first entry of the pool, mark it.1806if (!InConstantPool) {1807OutStreamer->emitDataRegion(MCDR_DataRegion);1808InConstantPool = true;1809}18101811OutStreamer->emitLabel(GetCPISymbol(LabelId));18121813const MachineConstantPoolEntry &MCPE = MCP->getConstants()[CPIdx];1814if (MCPE.isMachineConstantPoolEntry())1815emitMachineConstantPoolValue(MCPE.Val.MachineCPVal);1816else1817emitGlobalConstant(DL, MCPE.Val.ConstVal);1818return;1819}1820case ARM::JUMPTABLE_ADDRS:1821emitJumpTableAddrs(MI);1822return;1823case ARM::JUMPTABLE_INSTS:1824emitJumpTableInsts(MI);1825return;1826case ARM::JUMPTABLE_TBB:1827case ARM::JUMPTABLE_TBH:1828emitJumpTableTBInst(MI, MI->getOpcode() == ARM::JUMPTABLE_TBB ? 1 : 2);1829return;1830case ARM::t2BR_JT: {1831EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)1832.addReg(ARM::PC)1833.addReg(MI->getOperand(0).getReg())1834// Add predicate operands.1835.addImm(ARMCC::AL)1836.addReg(0));1837return;1838}1839case ARM::t2TBB_JT:1840case ARM::t2TBH_JT: {1841unsigned Opc = MI->getOpcode() == ARM::t2TBB_JT ? ARM::t2TBB : ARM::t2TBH;1842// Lower and emit the PC label, then the instruction itself.1843OutStreamer->emitLabel(GetCPISymbol(MI->getOperand(3).getImm()));1844EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)1845.addReg(MI->getOperand(0).getReg())1846.addReg(MI->getOperand(1).getReg())1847// Add predicate operands.1848.addImm(ARMCC::AL)1849.addReg(0));1850return;1851}1852case ARM::tTBB_JT:1853case ARM::tTBH_JT: {18541855bool Is8Bit = MI->getOpcode() == ARM::tTBB_JT;1856Register Base = MI->getOperand(0).getReg();1857Register Idx = MI->getOperand(1).getReg();1858assert(MI->getOperand(1).isKill() && "We need the index register as scratch!");18591860// Multiply up idx if necessary.1861if (!Is8Bit)1862EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLSLri)1863.addReg(Idx)1864.addReg(ARM::CPSR)1865.addReg(Idx)1866.addImm(1)1867// Add predicate operands.1868.addImm(ARMCC::AL)1869.addReg(0));18701871if (Base == ARM::PC) {1872// TBB [base, idx] =1873// ADDS idx, idx, base1874// LDRB idx, [idx, #4] ; or LDRH if TBH1875// LSLS idx, #11876// ADDS pc, pc, idx18771878// When using PC as the base, it's important that there is no padding1879// between the last ADDS and the start of the jump table. The jump table1880// is 4-byte aligned, so we ensure we're 4 byte aligned here too.1881//1882// FIXME: Ideally we could vary the LDRB index based on the padding1883// between the sequence and jump table, however that relies on MCExprs1884// for load indexes which are currently not supported.1885OutStreamer->emitCodeAlignment(Align(4), &getSubtargetInfo());1886EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)1887.addReg(Idx)1888.addReg(Idx)1889.addReg(Base)1890// Add predicate operands.1891.addImm(ARMCC::AL)1892.addReg(0));18931894unsigned Opc = Is8Bit ? ARM::tLDRBi : ARM::tLDRHi;1895EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)1896.addReg(Idx)1897.addReg(Idx)1898.addImm(Is8Bit ? 4 : 2)1899// Add predicate operands.1900.addImm(ARMCC::AL)1901.addReg(0));1902} else {1903// TBB [base, idx] =1904// LDRB idx, [base, idx] ; or LDRH if TBH1905// LSLS idx, #11906// ADDS pc, pc, idx19071908unsigned Opc = Is8Bit ? ARM::tLDRBr : ARM::tLDRHr;1909EmitToStreamer(*OutStreamer, MCInstBuilder(Opc)1910.addReg(Idx)1911.addReg(Base)1912.addReg(Idx)1913// Add predicate operands.1914.addImm(ARMCC::AL)1915.addReg(0));1916}19171918EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLSLri)1919.addReg(Idx)1920.addReg(ARM::CPSR)1921.addReg(Idx)1922.addImm(1)1923// Add predicate operands.1924.addImm(ARMCC::AL)1925.addReg(0));19261927OutStreamer->emitLabel(GetCPISymbol(MI->getOperand(3).getImm()));1928EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDhirr)1929.addReg(ARM::PC)1930.addReg(ARM::PC)1931.addReg(Idx)1932// Add predicate operands.1933.addImm(ARMCC::AL)1934.addReg(0));1935return;1936}1937case ARM::tBR_JTr:1938case ARM::BR_JTr: {1939// mov pc, target1940MCInst TmpInst;1941unsigned Opc = MI->getOpcode() == ARM::BR_JTr ?1942ARM::MOVr : ARM::tMOVr;1943TmpInst.setOpcode(Opc);1944TmpInst.addOperand(MCOperand::createReg(ARM::PC));1945TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));1946// Add predicate operands.1947TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));1948TmpInst.addOperand(MCOperand::createReg(0));1949// Add 's' bit operand (always reg0 for this)1950if (Opc == ARM::MOVr)1951TmpInst.addOperand(MCOperand::createReg(0));1952EmitToStreamer(*OutStreamer, TmpInst);1953return;1954}1955case ARM::BR_JTm_i12: {1956// ldr pc, target1957MCInst TmpInst;1958TmpInst.setOpcode(ARM::LDRi12);1959TmpInst.addOperand(MCOperand::createReg(ARM::PC));1960TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));1961TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));1962// Add predicate operands.1963TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));1964TmpInst.addOperand(MCOperand::createReg(0));1965EmitToStreamer(*OutStreamer, TmpInst);1966return;1967}1968case ARM::BR_JTm_rs: {1969// ldr pc, target1970MCInst TmpInst;1971TmpInst.setOpcode(ARM::LDRrs);1972TmpInst.addOperand(MCOperand::createReg(ARM::PC));1973TmpInst.addOperand(MCOperand::createReg(MI->getOperand(0).getReg()));1974TmpInst.addOperand(MCOperand::createReg(MI->getOperand(1).getReg()));1975TmpInst.addOperand(MCOperand::createImm(MI->getOperand(2).getImm()));1976// Add predicate operands.1977TmpInst.addOperand(MCOperand::createImm(ARMCC::AL));1978TmpInst.addOperand(MCOperand::createReg(0));1979EmitToStreamer(*OutStreamer, TmpInst);1980return;1981}1982case ARM::BR_JTadd: {1983// add pc, target, idx1984EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDrr)1985.addReg(ARM::PC)1986.addReg(MI->getOperand(0).getReg())1987.addReg(MI->getOperand(1).getReg())1988// Add predicate operands.1989.addImm(ARMCC::AL)1990.addReg(0)1991// Add 's' bit operand (always reg0 for this)1992.addReg(0));1993return;1994}1995case ARM::SPACE:1996OutStreamer->emitZeros(MI->getOperand(1).getImm());1997return;1998case ARM::TRAP: {1999// Non-Darwin binutils don't yet support the "trap" mnemonic.2000// FIXME: Remove this special case when they do.2001if (!Subtarget->isTargetMachO()) {2002uint32_t Val = 0xe7ffdefeUL;2003OutStreamer->AddComment("trap");2004ATS.emitInst(Val);2005return;2006}2007break;2008}2009case ARM::TRAPNaCl: {2010uint32_t Val = 0xe7fedef0UL;2011OutStreamer->AddComment("trap");2012ATS.emitInst(Val);2013return;2014}2015case ARM::tTRAP: {2016// Non-Darwin binutils don't yet support the "trap" mnemonic.2017// FIXME: Remove this special case when they do.2018if (!Subtarget->isTargetMachO()) {2019uint16_t Val = 0xdefe;2020OutStreamer->AddComment("trap");2021ATS.emitInst(Val, 'n');2022return;2023}2024break;2025}2026case ARM::t2Int_eh_sjlj_setjmp:2027case ARM::t2Int_eh_sjlj_setjmp_nofp:2028case ARM::tInt_eh_sjlj_setjmp: {2029// Two incoming args: GPR:$src, GPR:$val2030// mov $val, pc2031// adds $val, #72032// str $val, [$src, #4]2033// movs r0, #02034// b LSJLJEH2035// movs r0, #12036// LSJLJEH:2037Register SrcReg = MI->getOperand(0).getReg();2038Register ValReg = MI->getOperand(1).getReg();2039MCSymbol *Label = OutContext.createTempSymbol("SJLJEH");2040OutStreamer->AddComment("eh_setjmp begin");2041EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)2042.addReg(ValReg)2043.addReg(ARM::PC)2044// Predicate.2045.addImm(ARMCC::AL)2046.addReg(0));20472048EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tADDi3)2049.addReg(ValReg)2050// 's' bit operand2051.addReg(ARM::CPSR)2052.addReg(ValReg)2053.addImm(7)2054// Predicate.2055.addImm(ARMCC::AL)2056.addReg(0));20572058EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tSTRi)2059.addReg(ValReg)2060.addReg(SrcReg)2061// The offset immediate is #4. The operand value is scaled by 4 for the2062// tSTR instruction.2063.addImm(1)2064// Predicate.2065.addImm(ARMCC::AL)2066.addReg(0));20672068EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)2069.addReg(ARM::R0)2070.addReg(ARM::CPSR)2071.addImm(0)2072// Predicate.2073.addImm(ARMCC::AL)2074.addReg(0));20752076const MCExpr *SymbolExpr = MCSymbolRefExpr::create(Label, OutContext);2077EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tB)2078.addExpr(SymbolExpr)2079.addImm(ARMCC::AL)2080.addReg(0));20812082OutStreamer->AddComment("eh_setjmp end");2083EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVi8)2084.addReg(ARM::R0)2085.addReg(ARM::CPSR)2086.addImm(1)2087// Predicate.2088.addImm(ARMCC::AL)2089.addReg(0));20902091OutStreamer->emitLabel(Label);2092return;2093}20942095case ARM::Int_eh_sjlj_setjmp_nofp:2096case ARM::Int_eh_sjlj_setjmp: {2097// Two incoming args: GPR:$src, GPR:$val2098// add $val, pc, #82099// str $val, [$src, #+4]2100// mov r0, #02101// add pc, pc, #02102// mov r0, #12103Register SrcReg = MI->getOperand(0).getReg();2104Register ValReg = MI->getOperand(1).getReg();21052106OutStreamer->AddComment("eh_setjmp begin");2107EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)2108.addReg(ValReg)2109.addReg(ARM::PC)2110.addImm(8)2111// Predicate.2112.addImm(ARMCC::AL)2113.addReg(0)2114// 's' bit operand (always reg0 for this).2115.addReg(0));21162117EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::STRi12)2118.addReg(ValReg)2119.addReg(SrcReg)2120.addImm(4)2121// Predicate.2122.addImm(ARMCC::AL)2123.addReg(0));21242125EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)2126.addReg(ARM::R0)2127.addImm(0)2128// Predicate.2129.addImm(ARMCC::AL)2130.addReg(0)2131// 's' bit operand (always reg0 for this).2132.addReg(0));21332134EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::ADDri)2135.addReg(ARM::PC)2136.addReg(ARM::PC)2137.addImm(0)2138// Predicate.2139.addImm(ARMCC::AL)2140.addReg(0)2141// 's' bit operand (always reg0 for this).2142.addReg(0));21432144OutStreamer->AddComment("eh_setjmp end");2145EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::MOVi)2146.addReg(ARM::R0)2147.addImm(1)2148// Predicate.2149.addImm(ARMCC::AL)2150.addReg(0)2151// 's' bit operand (always reg0 for this).2152.addReg(0));2153return;2154}2155case ARM::Int_eh_sjlj_longjmp: {2156// ldr sp, [$src, #8]2157// ldr $scratch, [$src, #4]2158// ldr r7, [$src]2159// bx $scratch2160Register SrcReg = MI->getOperand(0).getReg();2161Register ScratchReg = MI->getOperand(1).getReg();2162EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)2163.addReg(ARM::SP)2164.addReg(SrcReg)2165.addImm(8)2166// Predicate.2167.addImm(ARMCC::AL)2168.addReg(0));21692170EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)2171.addReg(ScratchReg)2172.addReg(SrcReg)2173.addImm(4)2174// Predicate.2175.addImm(ARMCC::AL)2176.addReg(0));21772178const MachineFunction &MF = *MI->getParent()->getParent();2179const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();21802181if (STI.isTargetDarwin() || STI.isTargetWindows()) {2182// These platforms always use the same frame register2183EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)2184.addReg(STI.getFramePointerReg())2185.addReg(SrcReg)2186.addImm(0)2187// Predicate.2188.addImm(ARMCC::AL)2189.addReg(0));2190} else {2191// If the calling code might use either R7 or R11 as2192// frame pointer register, restore it into both.2193EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)2194.addReg(ARM::R7)2195.addReg(SrcReg)2196.addImm(0)2197// Predicate.2198.addImm(ARMCC::AL)2199.addReg(0));2200EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::LDRi12)2201.addReg(ARM::R11)2202.addReg(SrcReg)2203.addImm(0)2204// Predicate.2205.addImm(ARMCC::AL)2206.addReg(0));2207}22082209assert(Subtarget->hasV4TOps());2210EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::BX)2211.addReg(ScratchReg)2212// Predicate.2213.addImm(ARMCC::AL)2214.addReg(0));2215return;2216}2217case ARM::tInt_eh_sjlj_longjmp: {2218// ldr $scratch, [$src, #8]2219// mov sp, $scratch2220// ldr $scratch, [$src, #4]2221// ldr r7, [$src]2222// bx $scratch2223Register SrcReg = MI->getOperand(0).getReg();2224Register ScratchReg = MI->getOperand(1).getReg();22252226const MachineFunction &MF = *MI->getParent()->getParent();2227const ARMSubtarget &STI = MF.getSubtarget<ARMSubtarget>();22282229EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)2230.addReg(ScratchReg)2231.addReg(SrcReg)2232// The offset immediate is #8. The operand value is scaled by 4 for the2233// tLDR instruction.2234.addImm(2)2235// Predicate.2236.addImm(ARMCC::AL)2237.addReg(0));22382239EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tMOVr)2240.addReg(ARM::SP)2241.addReg(ScratchReg)2242// Predicate.2243.addImm(ARMCC::AL)2244.addReg(0));22452246EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)2247.addReg(ScratchReg)2248.addReg(SrcReg)2249.addImm(1)2250// Predicate.2251.addImm(ARMCC::AL)2252.addReg(0));22532254if (STI.isTargetDarwin() || STI.isTargetWindows()) {2255// These platforms always use the same frame register2256EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)2257.addReg(STI.getFramePointerReg())2258.addReg(SrcReg)2259.addImm(0)2260// Predicate.2261.addImm(ARMCC::AL)2262.addReg(0));2263} else {2264// If the calling code might use either R7 or R11 as2265// frame pointer register, restore it into both.2266EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)2267.addReg(ARM::R7)2268.addReg(SrcReg)2269.addImm(0)2270// Predicate.2271.addImm(ARMCC::AL)2272.addReg(0));2273EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tLDRi)2274.addReg(ARM::R11)2275.addReg(SrcReg)2276.addImm(0)2277// Predicate.2278.addImm(ARMCC::AL)2279.addReg(0));2280}22812282EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::tBX)2283.addReg(ScratchReg)2284// Predicate.2285.addImm(ARMCC::AL)2286.addReg(0));2287return;2288}2289case ARM::tInt_WIN_eh_sjlj_longjmp: {2290// ldr.w r11, [$src, #0]2291// ldr.w sp, [$src, #8]2292// ldr.w pc, [$src, #4]22932294Register SrcReg = MI->getOperand(0).getReg();22952296EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)2297.addReg(ARM::R11)2298.addReg(SrcReg)2299.addImm(0)2300// Predicate2301.addImm(ARMCC::AL)2302.addReg(0));2303EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)2304.addReg(ARM::SP)2305.addReg(SrcReg)2306.addImm(8)2307// Predicate2308.addImm(ARMCC::AL)2309.addReg(0));2310EmitToStreamer(*OutStreamer, MCInstBuilder(ARM::t2LDRi12)2311.addReg(ARM::PC)2312.addReg(SrcReg)2313.addImm(4)2314// Predicate2315.addImm(ARMCC::AL)2316.addReg(0));2317return;2318}2319case ARM::PATCHABLE_FUNCTION_ENTER:2320LowerPATCHABLE_FUNCTION_ENTER(*MI);2321return;2322case ARM::PATCHABLE_FUNCTION_EXIT:2323LowerPATCHABLE_FUNCTION_EXIT(*MI);2324return;2325case ARM::PATCHABLE_TAIL_CALL:2326LowerPATCHABLE_TAIL_CALL(*MI);2327return;2328case ARM::SpeculationBarrierISBDSBEndBB: {2329// Print DSB SYS + ISB2330MCInst TmpInstDSB;2331TmpInstDSB.setOpcode(ARM::DSB);2332TmpInstDSB.addOperand(MCOperand::createImm(0xf));2333EmitToStreamer(*OutStreamer, TmpInstDSB);2334MCInst TmpInstISB;2335TmpInstISB.setOpcode(ARM::ISB);2336TmpInstISB.addOperand(MCOperand::createImm(0xf));2337EmitToStreamer(*OutStreamer, TmpInstISB);2338return;2339}2340case ARM::t2SpeculationBarrierISBDSBEndBB: {2341// Print DSB SYS + ISB2342MCInst TmpInstDSB;2343TmpInstDSB.setOpcode(ARM::t2DSB);2344TmpInstDSB.addOperand(MCOperand::createImm(0xf));2345TmpInstDSB.addOperand(MCOperand::createImm(ARMCC::AL));2346TmpInstDSB.addOperand(MCOperand::createReg(0));2347EmitToStreamer(*OutStreamer, TmpInstDSB);2348MCInst TmpInstISB;2349TmpInstISB.setOpcode(ARM::t2ISB);2350TmpInstISB.addOperand(MCOperand::createImm(0xf));2351TmpInstISB.addOperand(MCOperand::createImm(ARMCC::AL));2352TmpInstISB.addOperand(MCOperand::createReg(0));2353EmitToStreamer(*OutStreamer, TmpInstISB);2354return;2355}2356case ARM::SpeculationBarrierSBEndBB: {2357// Print SB2358MCInst TmpInstSB;2359TmpInstSB.setOpcode(ARM::SB);2360EmitToStreamer(*OutStreamer, TmpInstSB);2361return;2362}2363case ARM::t2SpeculationBarrierSBEndBB: {2364// Print SB2365MCInst TmpInstSB;2366TmpInstSB.setOpcode(ARM::t2SB);2367EmitToStreamer(*OutStreamer, TmpInstSB);2368return;2369}23702371case ARM::SEH_StackAlloc:2372ATS.emitARMWinCFIAllocStack(MI->getOperand(0).getImm(),2373MI->getOperand(1).getImm());2374return;23752376case ARM::SEH_SaveRegs:2377case ARM::SEH_SaveRegs_Ret:2378ATS.emitARMWinCFISaveRegMask(MI->getOperand(0).getImm(),2379MI->getOperand(1).getImm());2380return;23812382case ARM::SEH_SaveSP:2383ATS.emitARMWinCFISaveSP(MI->getOperand(0).getImm());2384return;23852386case ARM::SEH_SaveFRegs:2387ATS.emitARMWinCFISaveFRegs(MI->getOperand(0).getImm(),2388MI->getOperand(1).getImm());2389return;23902391case ARM::SEH_SaveLR:2392ATS.emitARMWinCFISaveLR(MI->getOperand(0).getImm());2393return;23942395case ARM::SEH_Nop:2396case ARM::SEH_Nop_Ret:2397ATS.emitARMWinCFINop(MI->getOperand(0).getImm());2398return;23992400case ARM::SEH_PrologEnd:2401ATS.emitARMWinCFIPrologEnd(/*Fragment=*/false);2402return;24032404case ARM::SEH_EpilogStart:2405ATS.emitARMWinCFIEpilogStart(ARMCC::AL);2406return;24072408case ARM::SEH_EpilogEnd:2409ATS.emitARMWinCFIEpilogEnd();2410return;24112412case ARM::PseudoARMInitUndefMQPR:2413case ARM::PseudoARMInitUndefSPR:2414case ARM::PseudoARMInitUndefDPR_VFP2:2415case ARM::PseudoARMInitUndefGPR:2416return;2417}24182419MCInst TmpInst;2420LowerARMMachineInstrToMCInst(MI, TmpInst, *this);24212422EmitToStreamer(*OutStreamer, TmpInst);2423}24242425//===----------------------------------------------------------------------===//2426// Target Registry Stuff2427//===----------------------------------------------------------------------===//24282429// Force static initialization.2430extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeARMAsmPrinter() {2431RegisterAsmPrinter<ARMAsmPrinter> X(getTheARMLETarget());2432RegisterAsmPrinter<ARMAsmPrinter> Y(getTheARMBETarget());2433RegisterAsmPrinter<ARMAsmPrinter> A(getTheThumbLETarget());2434RegisterAsmPrinter<ARMAsmPrinter> B(getTheThumbBETarget());2435}243624372438