2017-02-11 00:27:28 +00:00
|
|
|
//===- MCAsmInfo.cpp - Asm Info -------------------------------------------===//
|
2006-09-06 18:35:33 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2006-09-06 18:35:33 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines target asm properties related what form asm statements
|
|
|
|
// should take.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-08-22 20:48:53 +00:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
2023-06-17 13:18:23 +01:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2017-06-07 03:48:56 +00:00
|
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
2011-05-01 03:50:49 +00:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2011-04-28 16:09:09 +00:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2018-04-03 17:28:55 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2017-02-11 00:27:28 +00:00
|
|
|
|
2006-09-06 18:35:33 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2021-05-07 11:15:43 -07:00
|
|
|
namespace {
|
2018-04-03 17:28:55 +00:00
|
|
|
enum DefaultOnOff { Default, Enable, Disable };
|
2021-05-07 11:15:43 -07:00
|
|
|
}
|
2018-04-03 17:28:55 +00:00
|
|
|
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));
|
|
|
|
|
2021-05-07 11:15:43 -07:00
|
|
|
namespace llvm {
|
2020-12-02 18:46:58 +00:00
|
|
|
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));
|
2021-05-07 11:15:43 -07:00
|
|
|
}
|
2020-12-02 18:46:58 +00:00
|
|
|
|
2010-01-20 06:34:14 +00:00
|
|
|
MCAsmInfo::MCAsmInfo() {
|
2011-03-24 18:46:34 +00:00
|
|
|
SeparatorString = ";";
|
2008-09-25 21:00:33 +00:00
|
|
|
CommentString = "#";
|
2010-09-22 22:19:53 +00:00
|
|
|
LabelSuffix = ":";
|
2013-12-02 23:39:26 +00:00
|
|
|
PrivateGlobalPrefix = "L";
|
2014-12-04 00:06:57 +00:00
|
|
|
PrivateLabelPrefix = PrivateGlobalPrefix;
|
2014-03-29 07:05:06 +00:00
|
|
|
LinkerPrivateGlobalPrefix = "";
|
2009-08-11 22:39:40 +00:00
|
|
|
InlineAsmStart = "APP";
|
|
|
|
InlineAsmEnd = "NO_APP";
|
2011-07-27 00:38:12 +00:00
|
|
|
Code16Directive = ".code16";
|
|
|
|
Code32Directive = ".code32";
|
|
|
|
Code64Directive = ".code64";
|
2008-09-25 21:00:33 +00:00
|
|
|
ZeroDirective = "\t.zero\t";
|
|
|
|
AsciiDirective = "\t.ascii\t";
|
|
|
|
AscizDirective = "\t.asciz\t";
|
|
|
|
Data8bitsDirective = "\t.byte\t";
|
|
|
|
Data16bitsDirective = "\t.short\t";
|
|
|
|
Data32bitsDirective = "\t.long\t";
|
|
|
|
Data64bitsDirective = "\t.quad\t";
|
|
|
|
GlobalDirective = "\t.globl\t";
|
2014-12-01 21:16:17 +00:00
|
|
|
WeakDirective = "\t.weak\t";
|
2018-04-03 17:28:55 +00:00
|
|
|
if (DwarfExtendedLoc != Default)
|
|
|
|
SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable;
|
2020-12-02 18:46:58 +00:00
|
|
|
if (UseLEB128Directives != cl::BOU_UNSET)
|
|
|
|
HasLEB128Directives = UseLEB128Directives == cl::BOU_TRUE;
|
2020-04-11 10:06:18 -07:00
|
|
|
UseIntegratedAssembler = true;
|
2021-07-02 15:46:49 +00:00
|
|
|
ParseInlineAsmUsingAsmParser = false;
|
2016-07-11 12:42:14 +00:00
|
|
|
PreserveAsmComments = true;
|
2023-11-06 12:30:19 -05:00
|
|
|
PPCUseFullRegisterNames = false;
|
2006-10-13 17:50:07 +00:00
|
|
|
}
|
2006-10-05 00:35:16 +00:00
|
|
|
|
2017-02-11 00:27:28 +00:00
|
|
|
MCAsmInfo::~MCAsmInfo() = default;
|
2006-10-13 17:50:07 +00:00
|
|
|
|
2019-04-12 06:57:45 +00:00
|
|
|
void MCAsmInfo::addInitialFrameState(const MCCFIInstruction &Inst) {
|
|
|
|
InitialFrameState.push_back(Inst);
|
|
|
|
}
|
|
|
|
|
2011-04-28 16:09:09 +00:00
|
|
|
const MCExpr *
|
|
|
|
MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
|
2011-05-01 03:50:49 +00:00
|
|
|
unsigned Encoding,
|
2011-04-28 16:09:09 +00:00
|
|
|
MCStreamer &Streamer) const {
|
2011-05-01 03:50:49 +00:00
|
|
|
return getExprForFDESymbol(Sym, Encoding, Streamer);
|
2011-04-28 21:04:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const MCExpr *
|
|
|
|
MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
|
2011-05-01 03:50:49 +00:00
|
|
|
unsigned Encoding,
|
2011-04-28 21:04:39 +00:00
|
|
|
MCStreamer &Streamer) const {
|
2011-05-01 03:50:49 +00:00
|
|
|
if (!(Encoding & dwarf::DW_EH_PE_pcrel))
|
2015-05-30 01:25:56 +00:00
|
|
|
return MCSymbolRefExpr::create(Sym, Streamer.getContext());
|
2011-05-01 03:50:49 +00:00
|
|
|
|
|
|
|
MCContext &Context = Streamer.getContext();
|
2015-05-30 01:25:56 +00:00
|
|
|
const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
|
2015-05-18 18:43:14 +00:00
|
|
|
MCSymbol *PCSym = Context.createTempSymbol();
|
2020-02-14 19:21:58 -08:00
|
|
|
Streamer.emitLabel(PCSym);
|
2015-05-30 01:25:56 +00:00
|
|
|
const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
|
|
|
|
return MCBinaryExpr::createSub(Res, PC, Context);
|
2011-04-28 16:09:09 +00:00
|
|
|
}
|
2015-06-09 00:31:39 +00:00
|
|
|
|
[XCOFF][AIX] Differentiate usage of label symbol and csect symbol
Summary:
We are using symbols to represent label and csect interchangeably before, and that could be a problem.
There are cases we would need to add storage mapping class to the symbol if that symbol is actually the name of a csect, but it's hard for us to figure out whether that symbol is a label or csect.
This patch intend to do the following:
1. Construct a QualName (A name include the storage mapping class)
MCSymbolXCOFF for every MCSectionXCOFF.
2. Keep a pointer to that QualName inside of MCSectionXCOFF.
3. Use that QualName whenever we need a symbol refers to that
MCSectionXCOFF.
4. Adapt the snowball effect from the above changes in
XCOFFObjectWriter.cpp.
Reviewers: xingxue, DiggerLin, sfertile, daltenty, hubert.reinterpretcast
Reviewed By: DiggerLin, daltenty
Subscribers: wuzish, nemanjai, mgorny, hiraditya, kbarton, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D69633
2019-11-08 09:26:28 -05:00
|
|
|
bool MCAsmInfo::isAcceptableChar(char C) const {
|
2022-03-25 15:40:46 -07:00
|
|
|
if (C == '@')
|
|
|
|
return doesAllowAtInName();
|
|
|
|
|
|
|
|
return isAlnum(C) || C == '_' || C == '$' || C == '.';
|
2015-06-09 00:31:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
|
|
|
|
if (Name.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If any of the characters in the string is an unacceptable character, force
|
|
|
|
// quotes.
|
|
|
|
for (char C : Name) {
|
|
|
|
if (!isAcceptableChar(C))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
MCAsmInfo: Allow targets to specify when the .section directive should be omitted
Summary:
The default behavior is to omit the .section directive for .text, .data,
and sometimes .bss, but some targets may want to omit this directive for
other sections too.
The AMDGPU backend will uses this to emit a simplified syntax for section
switches. For example if the section directive is not omitted (current
behavior), section switches to .hsatext will be printed like this:
.section .hsatext,#alloc,#execinstr,#write
This is actually wrong, because .hsatext has some custom STT_* flags,
which MC doesn't know how to print or parse.
If the section directive is omitted (made possible by this commit),
section switches will be printed like this:
.hsatext
The motivation for this patch is to make it possible to emit sections
with custom STT_* flags without having to teach MC about all the target
specific STT_* flags.
Reviewers: rafael, grosbach
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D12423
llvm-svn: 248618
2015-09-25 21:41:14 +00:00
|
|
|
|
|
|
|
bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
|
|
|
|
// FIXME: Does .section .bss/.data/.text work everywhere??
|
|
|
|
return SectionName == ".text" || SectionName == ".data" ||
|
|
|
|
(SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
|
|
|
|
}
|
2025-03-02 20:36:20 -08:00
|
|
|
|
|
|
|
void MCAsmInfo::initializeVariantKinds(ArrayRef<VariantKindDesc> Descs) {
|
|
|
|
assert(VariantKindToName.empty() && "cannot initialize twice");
|
|
|
|
for (auto Desc : Descs) {
|
|
|
|
[[maybe_unused]] auto It =
|
|
|
|
VariantKindToName.try_emplace(Desc.Kind, Desc.Name);
|
|
|
|
assert(It.second && "duplicate Kind");
|
|
|
|
[[maybe_unused]] auto It2 =
|
|
|
|
NameToVariantKind.try_emplace(Desc.Name.lower(), Desc.Kind);
|
2025-03-02 22:25:58 -08:00
|
|
|
// Workaround for VK_PPC_L/VK_PPC_LO ("l").
|
|
|
|
assert(It2.second || Desc.Name == "l");
|
2025-03-02 20:36:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef MCAsmInfo::getVariantKindName(uint32_t Kind) const {
|
2025-03-02 22:05:47 -08:00
|
|
|
auto It = VariantKindToName.find(Kind);
|
|
|
|
assert(It != VariantKindToName.end() &&
|
|
|
|
"ensure the VariantKind is set in initializeVariantKinds");
|
|
|
|
return It->second;
|
2025-03-02 20:36:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t MCAsmInfo::getVariantKindForName(StringRef Name) const {
|
|
|
|
auto It = NameToVariantKind.find(Name.lower());
|
|
|
|
if (It != NameToVariantKind.end())
|
|
|
|
return It->second;
|
|
|
|
return MCSymbolRefExpr::VK_Invalid;
|
|
|
|
}
|