aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp80
1 files changed, 69 insertions, 11 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 2badbe34ae6a..e760564779c2 100644
--- a/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/contrib/llvm-project/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -58,6 +58,7 @@
#include "llvm/MC/MCValue.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/Base64.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/ErrorHandling.h"
@@ -127,7 +128,7 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
if (Ctx.getAsmInfo()->getExceptionHandlingType() == ExceptionHandling::ARM)
break;
// Fallthrough if not using EHABI
- LLVM_FALLTHROUGH;
+ [[fallthrough]];
case Triple::ppc:
case Triple::ppcle:
case Triple::x86:
@@ -289,6 +290,14 @@ void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
TTypeEncoding = dwarf::DW_EH_PE_absptr;
}
break;
+ case Triple::loongarch32:
+ case Triple::loongarch64:
+ LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
+ PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
+ dwarf::DW_EH_PE_sdata4;
+ TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
+ dwarf::DW_EH_PE_sdata4;
+ break;
default:
break;
}
@@ -358,6 +367,31 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,
}
}
+ if (NamedMDNode *LLVMStats = M.getNamedMetadata("llvm.stats")) {
+ // Emit the metadata for llvm statistics into .llvm_stats section, which is
+ // formatted as a list of key/value pair, the value is base64 encoded.
+ auto *S = C.getObjectFileInfo()->getLLVMStatsSection();
+ Streamer.switchSection(S);
+ for (const auto *Operand : LLVMStats->operands()) {
+ const auto *MD = cast<MDNode>(Operand);
+ assert(MD->getNumOperands() % 2 == 0 &&
+ ("Operand num should be even for a list of key/value pair"));
+ for (size_t I = 0; I < MD->getNumOperands(); I += 2) {
+ // Encode the key string size.
+ auto *Key = cast<MDString>(MD->getOperand(I));
+ Streamer.emitULEB128IntValue(Key->getString().size());
+ Streamer.emitBytes(Key->getString());
+ // Encode the value into a Base64 string.
+ std::string Value = encodeBase64(
+ Twine(mdconst::dyn_extract<ConstantInt>(MD->getOperand(I + 1))
+ ->getZExtValue())
+ .str());
+ Streamer.emitULEB128IntValue(Value.size());
+ Streamer.emitBytes(Value);
+ }
+ }
+ }
+
unsigned Version = 0;
unsigned Flags = 0;
StringRef Section;
@@ -400,7 +434,7 @@ void TargetLoweringObjectFileELF::emitPersonalityValue(
ELF::SHT_PROGBITS, Flags, 0);
unsigned Size = DL.getPointerSize();
Streamer.switchSection(Sec);
- Streamer.emitValueToAlignment(DL.getPointerABIAlignment(0).value());
+ Streamer.emitValueToAlignment(DL.getPointerABIAlignment(0));
Streamer.emitSymbolAttribute(Label, MCSA_ELF_TypeObject);
const MCExpr *E = MCConstantExpr::create(Size, getContext());
Streamer.emitELFSize(Label, E);
@@ -636,7 +670,7 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
bool HasPrefix = false;
if (const auto *F = dyn_cast<Function>(GO)) {
- if (Optional<StringRef> Prefix = F->getSectionPrefix()) {
+ if (std::optional<StringRef> Prefix = F->getSectionPrefix()) {
raw_svector_ostream(Name) << '.' << *Prefix;
HasPrefix = true;
}
@@ -1686,7 +1720,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
StringRef COMDATSymName = Sym->getName();
if (const auto *F = dyn_cast<Function>(GO))
- if (Optional<StringRef> Prefix = F->getSectionPrefix())
+ if (std::optional<StringRef> Prefix = F->getSectionPrefix())
raw_svector_ostream(Name) << '$' << *Prefix;
// Append "$symbol" to the section name *before* IR-level mangling is
@@ -1889,11 +1923,24 @@ static MCSectionCOFF *getCOFFStaticStructorSection(MCContext &Ctx,
// string that sorts between .CRT$XCA and .CRT$XCU. In the general case, we
// make a name like ".CRT$XCT12345", since that runs before .CRT$XCU. Really
// low priorities need to sort before 'L', since the CRT uses that
- // internally, so we use ".CRT$XCA00001" for them.
+ // internally, so we use ".CRT$XCA00001" for them. We have a contract with
+ // the frontend that "init_seg(compiler)" corresponds to priority 200 and
+ // "init_seg(lib)" corresponds to priority 400, and those respectively use
+ // 'C' and 'L' without the priority suffix. Priorities between 200 and 400
+ // use 'C' with the priority as a suffix.
SmallString<24> Name;
+ char LastLetter = 'T';
+ bool AddPrioritySuffix = Priority != 200 && Priority != 400;
+ if (Priority < 200)
+ LastLetter = 'A';
+ else if (Priority < 400)
+ LastLetter = 'C';
+ else if (Priority == 400)
+ LastLetter = 'L';
raw_svector_ostream OS(Name);
- OS << ".CRT$X" << (IsCtor ? "C" : "T") <<
- (Priority < 200 ? 'A' : 'T') << format("%05u", Priority);
+ OS << ".CRT$X" << (IsCtor ? "C" : "T") << LastLetter;
+ if (AddPrioritySuffix)
+ OS << format("%05u", Priority);
MCSectionCOFF *Sec = Ctx.getCOFFSection(
Name, COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ,
SectionKind::getReadOnly());
@@ -2245,16 +2292,16 @@ TargetLoweringObjectFileXCOFF::getTargetSymbol(const GlobalValue *GV,
// function entry point. We choose to always return a function descriptor
// here.
if (const GlobalObject *GO = dyn_cast<GlobalObject>(GV)) {
+ if (GO->isDeclarationForLinker())
+ return cast<MCSectionXCOFF>(getSectionForExternalReference(GO, TM))
+ ->getQualNameSymbol();
+
if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV))
if (GVar->hasAttribute("toc-data"))
return cast<MCSectionXCOFF>(
SectionForGlobal(GVar, SectionKind::getData(), TM))
->getQualNameSymbol();
- if (GO->isDeclarationForLinker())
- return cast<MCSectionXCOFF>(getSectionForExternalReference(GO, TM))
- ->getQualNameSymbol();
-
SectionKind GOKind = getKindForGlobal(GO, TM);
if (GOKind.isText())
return cast<MCSectionXCOFF>(
@@ -2313,6 +2360,10 @@ MCSection *TargetLoweringObjectFileXCOFF::getSectionForExternalReference(
if (GO->isThreadLocal())
SMC = XCOFF::XMC_UL;
+ if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO))
+ if (GVar->hasAttribute("toc-data"))
+ SMC = XCOFF::XMC_TD;
+
// Externals go into a csect of type ER.
return getContext().getXCOFFSection(
Name, SectionKind::getMetadata(),
@@ -2469,6 +2520,13 @@ void TargetLoweringObjectFileXCOFF::Initialize(MCContext &Ctx,
PersonalityEncoding = 0;
LSDAEncoding = 0;
CallSiteEncoding = dwarf::DW_EH_PE_udata4;
+
+ // AIX debug for thread local location is not ready. And for integrated as
+ // mode, the relocatable address for the thread local variable will cause
+ // linker error. So disable the location attribute generation for thread local
+ // variables for now.
+ // FIXME: when TLS debug on AIX is ready, remove this setting.
+ SupportDebugThreadLocalLocation = false;
}
MCSection *TargetLoweringObjectFileXCOFF::getStaticCtorSection(