LLVM: lib/Object/ModuleSymbolTable.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

44#include

45#include

46#include

47#include

48

49using namespace llvm;

50using namespace object;

51

53 if (FirstMod)

55 else

56 FirstMod = M;

57

58 for (GlobalValue &GV : M->global_values())

59 SymTab.push_back(&GV);

60

62 SymTab.push_back(new (AsmSymbols.Allocate())

64 });

65}

66

67static void

70

71

72

73 if (M.getContext().getDiagHandlerPtr()->HasErrors)

74 return;

77 return;

78

79 std::string Err;

80 const Triple TT(M.getTargetTriple());

82 assert(T && T->hasMCAsmParser());

83

84 std::unique_ptr MRI(T->createMCRegInfo(TT.str()));

86 return;

87

89 std::unique_ptr MAI(T->createMCAsmInfo(*MRI, TT.str(), MCOptions));

90 if (!MAI)

91 return;

92

93 std::unique_ptr STI(

94 T->createMCSubtargetInfo(TT.str(), "", ""));

95 if (!STI)

96 return;

97

98 std::unique_ptr MCII(T->createMCInstrInfo());

99 if (!MCII)

100 return;

101

102 std::unique_ptr Buffer(

106

108 std::unique_ptr MOFI(

109 T->createMCObjectFileInfo(MCCtx, false));

112 T->createNullTargetStreamer(Streamer);

113

114 std::unique_ptr Parser(

116

117 std::unique_ptr TAP(

118 T->createMCAsmParser(*STI, *Parser, *MCII, MCOptions));

119 if (!TAP)

120 return;

121

124 std::vector<const MDNode *> &LocInfos) {

125 M.getContext().diagnose(

127 });

128

129

130

132

133 Parser->setTargetParser(*TAP);

134 if (Parser->Run(false))

135 return;

136

137 Init(Streamer);

138}

139

145

146 for (auto &KV : Streamer) {

149

153 llvm_unreachable("NeverSeen should have been replaced earlier");

156 break;

158 break;

163 break;

167 break;

171 }

173 }

174 });

175

176

177

178

179 Triple TT(M.getTargetTriple());

180 if (!TT.isOSBinFormatELF() || !TT.isX86())

181 return;

182 auto CM = M.getCodeModel();

185 AsmSymbol("_GLOBAL_OFFSET_TABLE_",

188 }

189}

190

195 for (auto &Alias : KV.second)

196 AsmSymver(KV.first->getName(), Alias);

197 });

198}

199

201 if (isa<AsmSymbol *>(S)) {

202 OS << cast<AsmSymbol *>(S)->first;

203 return;

204 }

205

206 auto *GV = cast<GlobalValue *>(S);

207 if (GV->hasDLLImportStorageClass())

208 OS << "__imp_";

209

211}

212

214 if (isa<AsmSymbol *>(S))

215 return cast<AsmSymbol *>(S)->second;

216

217 auto *GV = cast<GlobalValue *>(S);

218

220 if (GV->isDeclarationForLinker())

222 else if (GV->hasHiddenVisibility() && !GV->hasLocalLinkage())

224 if (const GlobalVariable *GVar = dyn_cast(GV)) {

225 if (GVar->isConstant())

227 }

229 if (isa(GO) || isa(GO))

231 if (isa(GV))

233 if (GV->hasPrivateLinkage())

235 if (!GV->hasLocalLinkage())

237 if (GV->hasCommonLinkage())

239 if (GV->hasLinkOnceLinkage() || GV->hasWeakLinkage() ||

240 GV->hasExternalWeakLinkage())

242

243 if (GV->getName().starts_with("llvm."))

245 else if (auto *Var = dyn_cast(GV)) {

246 if (Var->getSection() == "llvm.metadata")

248 }

249

250 return Res;

251}

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.