1//===- ModuleSymbolTable.cpp - symbol table for in-memory IR --------------===// 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 7//===----------------------------------------------------------------------===// 9// This class represents a symbol table built from in-memory IR. It provides 10// access to GlobalValues and should only be used if such access is required 11// (e.g. in the LTO implementation). 13//===----------------------------------------------------------------------===// 59 SymTab.push_back(&GV);
62 SymTab.push_back(
new (AsmSymbols.
Allocate())
70// This function may be called twice, once for ModuleSummaryIndexAnalysis and 71// the other when writing the IR symbol table. If parsing inline assembly has 72// caused errors in the first run, suppress the second run. 73if (M.getContext().getDiagHandlerPtr()->HasErrors)
80constTriple TT(M.getTargetTriple());
84 std::unique_ptr<MCRegisterInfo>
MRI(
T->createMCRegInfo(TT.str()));
89 std::unique_ptr<MCAsmInfo> MAI(
T->createMCAsmInfo(*
MRI, TT.str(), MCOptions));
93 std::unique_ptr<MCSubtargetInfo> STI(
94T->createMCSubtargetInfo(TT.str(),
"",
""));
98 std::unique_ptr<MCInstrInfo> MCII(
T->createMCInstrInfo());
102 std::unique_ptr<MemoryBuffer> Buffer(
108 std::unique_ptr<MCObjectFileInfo> MOFI(
109T->createMCObjectFileInfo(MCCtx,
/*PIC=*/false));
112T->createNullTargetStreamer(Streamer);
114 std::unique_ptr<MCAsmParser>
Parser(
117 std::unique_ptr<MCTargetAsmParser> TAP(
118T->createMCAsmParser(*STI, *
Parser, *MCII, MCOptions));
124 std::vector<const MDNode *> &LocInfos) {
125 M.getContext().diagnose(
129// Module-level inline asm is assumed to use At&t syntax (see 130// AsmPrinter::doInitialization()). 133Parser->setTargetParser(*TAP);
146for (
auto &KV : Streamer) {
149// FIXME: For now we just assume that all asm symbols are executable. 176// In ELF, object code generated for x86-32 and some code models of x86-64 may 177// reference the special symbol _GLOBAL_OFFSET_TABLE_ that is not used in the 178// IR. Record it like inline asm symbols. 179Triple TT(M.getTargetTriple());
180if (!TT.isOSBinFormatELF() || !TT.isX86())
182auto CM = M.getCodeModel();
195for (
auto &Alias : KV.second)
196 AsmSymver(KV.first->getName(), Alias);
201if (isa<AsmSymbol *>(S)) {
202 OS << cast<AsmSymbol *>(S)->first;
206auto *GV = cast<GlobalValue *>(S);
207if (GV->hasDLLImportStorageClass())
214if (isa<AsmSymbol *>(S))
215return cast<AsmSymbol *>(S)->second;
217auto *GV = cast<GlobalValue *>(S);
220if (GV->isDeclarationForLinker())
222elseif (GV->hasHiddenVisibility() && !GV->hasLocalLinkage())
225if (GVar->isConstant())
229if (isa<Function>(GO) || isa<GlobalIFunc>(GO))
231if (isa<GlobalAlias>(GV))
233if (GV->hasPrivateLinkage())
235if (!GV->hasLocalLinkage())
237if (GV->hasCommonLinkage())
239if (GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() ||
240 GV->hasExternalWeakLinkage())
243if (GV->getName().starts_with(
"llvm."))
245elseif (
auto *Var = dyn_cast<GlobalVariable>(GV)) {
246if (Var->getSection() ==
"llvm.metadata")
unsigned const MachineRegisterInfo * MRI
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
Module.h This file contains the declarations for the Module class.
static void initializeRecordStreamer(const Module &M, function_ref< void(RecordStreamer &)> Init)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Diagnostic information for SMDiagnostic reporting.
const GlobalObject * getAliaseeObject() const
Context object for machine code objects.
void setObjectFileInfo(const MCObjectFileInfo *Mofi)
void setDiagnosticHandler(DiagHandlerTy DiagHandler)
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
void addModule(Module *M)
static void CollectAsmSymvers(const Module &M, function_ref< void(StringRef, StringRef)> AsmSymver)
Parse inline ASM and collect the symvers directives that are defined in the current module.
std::pair< std::string, uint32_t > AsmSymbol
void printSymbolName(raw_ostream &OS, Symbol S) const
uint32_t getSymbolFlags(Symbol S) const
static void CollectAsmSymbols(const Module &M, function_ref< void(StringRef, object::BasicSymbolRef::Flags)> AsmSymbol)
Parse inline ASM and collect the symbols that are defined or referenced in the current module.
A Module instance is used to store all the information related to an LLVM module.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
iterator_range< const_symver_iterator > symverAliases()
void flushSymverDirectives()
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Represents a location in source code.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
T * Allocate(size_t num=1)
Allocate space for an array of objects without constructing them.
StringRef - Represent a constant reference to a string, i.e.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
LLVM Value Representation.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &, unsigned CB=0)
Create an MCAsmParser instance for parsing assembly similar to gas syntax.
static const Target * lookupTarget(StringRef Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.