Path: blob/main/contrib/llvm-project/llvm/lib/Target/ARM/ARMAsmPrinter.h
35267 views
//===-- ARMAsmPrinter.h - ARM implementation of AsmPrinter ------*- C++ -*-===//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//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H9#define LLVM_LIB_TARGET_ARM_ARMASMPRINTER_H1011#include "ARMSubtarget.h"12#include "llvm/CodeGen/AsmPrinter.h"13#include "llvm/Target/TargetMachine.h"1415namespace llvm {1617class ARMFunctionInfo;18class MCOperand;19class MachineConstantPool;20class MachineOperand;21class MCSymbol;2223namespace ARM {24enum DW_ISA {25DW_ISA_ARM_thumb = 1,26DW_ISA_ARM_arm = 227};28}2930class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {3132/// Subtarget - Keep a pointer to the ARMSubtarget around so that we can33/// make the right decision when printing asm code for different targets.34const ARMSubtarget *Subtarget;3536/// AFI - Keep a pointer to ARMFunctionInfo for the current37/// MachineFunction.38ARMFunctionInfo *AFI;3940/// MCP - Keep a pointer to constantpool entries of the current41/// MachineFunction.42const MachineConstantPool *MCP;4344/// InConstantPool - Maintain state when emitting a sequence of constant45/// pool entries so we can properly mark them as data regions.46bool InConstantPool;4748/// ThumbIndirectPads - These maintain a per-function list of jump pad49/// labels used for ARMv4t thumb code to make register indirect calls.50SmallVector<std::pair<unsigned, MCSymbol*>, 4> ThumbIndirectPads;5152/// OptimizationGoals - Maintain a combined optimization goal for all53/// functions in a module: one of Tag_ABI_optimization_goals values,54/// -1 if uninitialized, 0 if conflicting goals55int OptimizationGoals;5657/// List of globals that have had their storage promoted to a constant58/// pool. This lives between calls to runOnMachineFunction and collects59/// data from every MachineFunction. It is used during doFinalization60/// when all non-function globals are emitted.61SmallPtrSet<const GlobalVariable*,2> PromotedGlobals;62/// Set of globals in PromotedGlobals that we've emitted labels for.63/// We need to emit labels even for promoted globals so that DWARF64/// debug info can link properly.65SmallPtrSet<const GlobalVariable*,2> EmittedPromotedGlobalLabels;6667public:68explicit ARMAsmPrinter(TargetMachine &TM,69std::unique_ptr<MCStreamer> Streamer);7071StringRef getPassName() const override {72return "ARM Assembly Printer";73}7475void printOperand(const MachineInstr *MI, int OpNum, raw_ostream &O);7677void PrintSymbolOperand(const MachineOperand &MO, raw_ostream &O) override;78bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNum,79const char *ExtraCode, raw_ostream &O) override;80bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNum,81const char *ExtraCode, raw_ostream &O) override;8283void emitInlineAsmEnd(const MCSubtargetInfo &StartInfo,84const MCSubtargetInfo *EndInfo) const override;8586void emitJumpTableAddrs(const MachineInstr *MI);87void emitJumpTableInsts(const MachineInstr *MI);88void emitJumpTableTBInst(const MachineInstr *MI, unsigned OffsetWidth);89void emitInstruction(const MachineInstr *MI) override;90bool runOnMachineFunction(MachineFunction &F) override;91std::tuple<const MCSymbol *, uint64_t, const MCSymbol *,92codeview::JumpTableEntrySize>93getCodeViewJumpTableInfo(int JTI, const MachineInstr *BranchInstr,94const MCSymbol *BranchLabel) const override;9596void emitConstantPool() override {97// we emit constant pools customly!98}99void emitFunctionBodyEnd() override;100void emitFunctionEntryLabel() override;101void emitStartOfAsmFile(Module &M) override;102void emitEndOfAsmFile(Module &M) override;103void emitXXStructor(const DataLayout &DL, const Constant *CV) override;104void emitGlobalVariable(const GlobalVariable *GV) override;105106MCSymbol *GetCPISymbol(unsigned CPID) const override;107108// lowerOperand - Convert a MachineOperand into the equivalent MCOperand.109bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp);110111//===------------------------------------------------------------------===//112// XRay implementation113//===------------------------------------------------------------------===//114public:115// XRay-specific lowering for ARM.116void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr &MI);117void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr &MI);118void LowerPATCHABLE_TAIL_CALL(const MachineInstr &MI);119120private:121void EmitSled(const MachineInstr &MI, SledKind Kind);122123// Helpers for emitStartOfAsmFile() and emitEndOfAsmFile()124void emitAttributes();125126void EmitUnwindingInstruction(const MachineInstr *MI);127128// emitPseudoExpansionLowering - tblgen'erated.129bool emitPseudoExpansionLowering(MCStreamer &OutStreamer,130const MachineInstr *MI);131132public:133unsigned getISAEncoding() override {134// ARM/Darwin adds ISA to the DWARF info for each function.135const Triple &TT = TM.getTargetTriple();136if (!TT.isOSBinFormatMachO())137return 0;138bool isThumb = TT.isThumb() ||139TT.getSubArch() == Triple::ARMSubArch_v7m ||140TT.getSubArch() == Triple::ARMSubArch_v6m;141return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;142}143144private:145MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol);146MCSymbol *GetARMJTIPICJumpTableLabel(unsigned uid) const;147148MCSymbol *GetARMGVSymbol(const GlobalValue *GV, unsigned char TargetFlags);149150public:151/// EmitMachineConstantPoolValue - Print a machine constantpool value to152/// the .s file.153void emitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) override;154};155} // end namespace llvm156157#endif158159160