LLVM 23.0.0git
MCAsmInfo.cpp
Go to the documentation of this file.
1//===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
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 defines target asm properties related what form asm statements
10// should take.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/MC/MCAsmInfo.h"
17#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCStreamer.h"
20#include "llvm/MC/MCValue.h"
23
24using namespace llvm;
25
26namespace {
28}
30 "dwarf-extended-loc", cl::Hidden,
31 cl::desc("Disable emission of the extended flags in .loc directives."),
32 cl::values(clEnumVal(Default, "Default for platform"),
33 clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")),
35
36namespace llvm {
38 "use-leb128-directives", cl::Hidden,
40 "Disable the usage of LEB128 directives, and generate .byte instead."),
42}
43
50
51MCAsmInfo::~MCAsmInfo() = default;
52
54 InitialFrameState.push_back(Inst);
55}
56
57const MCExpr *
59 unsigned Encoding,
60 MCStreamer &Streamer) const {
61 return getExprForFDESymbol(Sym, Encoding, Streamer);
62}
63
64const MCExpr *
66 unsigned Encoding,
67 MCStreamer &Streamer) const {
68 if (!(Encoding & dwarf::DW_EH_PE_pcrel))
69 return MCSymbolRefExpr::create(Sym, Streamer.getContext());
70
71 MCContext &Context = Streamer.getContext();
72 const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
73 MCSymbol *PCSym = Context.createTempSymbol();
74 Streamer.emitLabel(PCSym);
75 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
76 return MCBinaryExpr::createSub(Res, PC, Context);
77}
78
80 if (C == '@')
81 return doesAllowAtInName();
82
83 return isAlnum(C) || C == '_' || C == '$' || C == '.';
84}
85
87 if (Name.empty())
88 return false;
89
90 // If any of the characters in the string is an unacceptable character, force
91 // quotes.
92 for (char C : Name) {
93 if (!isAcceptableChar(C))
94 return false;
95 }
96
97 return true;
98}
99
101 // FIXME: Does .section .bss/.data/.text work everywhere??
102 return SectionName == ".text" || SectionName == ".data" ||
104}
105
107 assert(AtSpecifierToName.empty() && "cannot initialize twice");
108 UseAtForSpecifier = true;
109 for (auto Desc : Descs) {
110 [[maybe_unused]] auto It =
111 AtSpecifierToName.try_emplace(Desc.Kind, Desc.Name);
112 assert(It.second && "duplicate Kind");
113 [[maybe_unused]] auto It2 =
114 NameToAtSpecifier.try_emplace(Desc.Name.lower(), Desc.Kind);
115 assert(It2.second);
116 }
117}
118
120 auto It = AtSpecifierToName.find(S);
121 assert(It != AtSpecifierToName.end() &&
122 "ensure the specifier is set in initializeVariantKinds");
123 return It->second;
124}
125
126std::optional<uint32_t> MCAsmInfo::getSpecifierForName(StringRef Name) const {
127 auto It = NameToAtSpecifier.find(Name.lower());
128 if (It != NameToAtSpecifier.end())
129 return It->second;
130 return {};
131}
132
133void MCAsmInfo::printExpr(raw_ostream &OS, const MCExpr &Expr) const {
134 if (auto *SE = dyn_cast<MCSpecifierExpr>(&Expr))
135 printSpecifierExpr(OS, *SE);
136 else
137 Expr.print(OS, this);
138}
139
141 MCValue &Res,
142 const MCAssembler *Asm) const {
143 if (!E.getSubExpr()->evaluateAsRelocatable(Res, Asm))
144 return false;
145
146 Res.setSpecifier(E.getSpecifier());
147 return !Res.getSubSym();
148}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define clEnumVal(ENUMVAL, DESC)
DefaultOnOff
@ Default
@ Enable
@ Disable
This file contains constants used for implementing Dwarf debug support.
static cl::opt< DefaultOnOff > DwarfExtendedLoc("dwarf-extended-loc", cl::Hidden, cl::desc("Disable emission of the extended flags in .loc directives."), cl::values(clEnumVal(Default, "Default for platform"), clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")), cl::init(Default))
This file contains some functions that are useful when dealing with strings.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
void addInitialFrameState(const MCCFIInstruction &Inst)
Definition MCAsmInfo.cpp:53
bool UseAtForSpecifier
True if target uses @ (expr@specifier) for relocation specifiers.
Definition MCAsmInfo.h:387
virtual void printSpecifierExpr(raw_ostream &, const MCSpecifierExpr &) const
Definition MCAsmInfo.h:728
std::vector< MCCFIInstruction > InitialFrameState
Definition MCAsmInfo.h:399
llvm::StringMap< uint32_t > NameToAtSpecifier
Definition MCAsmInfo.h:433
void initializeAtSpecifiers(ArrayRef< AtSpecifier >)
llvm::DenseMap< uint32_t, StringRef > AtSpecifierToName
Definition MCAsmInfo.h:432
virtual ~MCAsmInfo()
virtual bool evaluateAsRelocatableImpl(const MCSpecifierExpr &, MCValue &Res, const MCAssembler *Asm) const
bool doesAllowAtInName() const
Definition MCAsmInfo.h:563
StringRef getSpecifierName(uint32_t S) const
std::optional< uint32_t > getSpecifierForName(StringRef Name) const
void printExpr(raw_ostream &, const MCExpr &) const
virtual const MCExpr * getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition MCAsmInfo.cpp:65
virtual bool isAcceptableChar(char C) const
Return true if C is an acceptable character inside a symbol name.
Definition MCAsmInfo.cpp:79
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
bool usesELFSectionDirectiveForBSS() const
Definition MCAsmInfo.h:511
bool SupportsExtendedDwarfLocDirective
True if the target supports flags in ".loc" directive, false if only location is allowed.
Definition MCAsmInfo.h:395
virtual const MCExpr * getExprForPersonalitySymbol(const MCSymbol *Sym, unsigned Encoding, MCStreamer &Streamer) const
Definition MCAsmInfo.cpp:58
bool HasLEB128Directives
True if the target supports LEB128 directives.
Definition MCAsmInfo.h:214
virtual bool isValidUnquotedName(StringRef Name) const
Return true if the identifier Name does not need quotes to be syntactically correct.
Definition MCAsmInfo.cpp:86
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition MCExpr.h:428
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition MCExpr.h:495
Streaming machine code generation interface.
Definition MCStreamer.h:221
MCContext & getContext() const
Definition MCStreamer.h:322
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
void setSpecifier(uint32_t S)
Definition MCValue.h:47
const MCSymbol * getSubSym() const
Definition MCValue.h:51
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
@ DW_EH_PE_pcrel
Definition Dwarf.h:879
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
Op::Description Desc
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
cl::opt< cl::boolOrDefault > UseLEB128Directives("use-leb128-directives", cl::Hidden, cl::desc("Disable the usage of LEB128 directives, and generate .byte instead."), cl::init(cl::BOU_UNSET))
@ Default
The result values are uniform if and only if all operands are uniform.
Definition Uniformity.h:20
@ Enable
Enable colors.
Definition WithColor.h:47