LLVM  8.0.1
MCContext.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/MC/MCContext.h"
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ADT/StringMap.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/BinaryFormat/COFF.h"
18 #include "llvm/BinaryFormat/ELF.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCCodeView.h"
21 #include "llvm/MC/MCDwarf.h"
22 #include "llvm/MC/MCExpr.h"
23 #include "llvm/MC/MCFragment.h"
24 #include "llvm/MC/MCLabel.h"
26 #include "llvm/MC/MCSectionCOFF.h"
27 #include "llvm/MC/MCSectionELF.h"
28 #include "llvm/MC/MCSectionMachO.h"
29 #include "llvm/MC/MCSectionWasm.h"
30 #include "llvm/MC/MCStreamer.h"
31 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/MC/MCSymbolCOFF.h"
33 #include "llvm/MC/MCSymbolELF.h"
34 #include "llvm/MC/MCSymbolMachO.h"
35 #include "llvm/MC/MCSymbolWasm.h"
36 #include "llvm/MC/SectionKind.h"
37 #include "llvm/Support/Casting.h"
41 #include "llvm/Support/Signals.h"
42 #include "llvm/Support/SourceMgr.h"
44 #include <cassert>
45 #include <cstdlib>
46 #include <tuple>
47 #include <utility>
48 
49 using namespace llvm;
50 
51 static cl::opt<char*>
52 AsSecureLogFileName("as-secure-log-file-name",
53  cl::desc("As secure log file name (initialized from "
54  "AS_SECURE_LOG_FILE env variable)"),
55  cl::init(getenv("AS_SECURE_LOG_FILE")), cl::Hidden);
56 
58  const MCObjectFileInfo *mofi, const SourceMgr *mgr,
59  bool DoAutoReset)
60  : SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai), MRI(mri), MOFI(mofi),
61  Symbols(Allocator), UsedNames(Allocator),
62  CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
63  AutoReset(DoAutoReset) {
64  SecureLogFile = AsSecureLogFileName;
65 
66  if (SrcMgr && SrcMgr->getNumBuffers())
67  MainFileName =
68  SrcMgr->getMemoryBuffer(SrcMgr->getMainFileID())->getBufferIdentifier();
69 }
70 
72  if (AutoReset)
73  reset();
74 
75  // NOTE: The symbols are all allocated out of a bump pointer allocator,
76  // we don't need to free them here.
77 }
78 
79 //===----------------------------------------------------------------------===//
80 // Module Lifetime Management
81 //===----------------------------------------------------------------------===//
82 
84  // Call the destructors so the fragments are freed
85  COFFAllocator.DestroyAll();
86  ELFAllocator.DestroyAll();
87  MachOAllocator.DestroyAll();
88 
89  MCSubtargetAllocator.DestroyAll();
90  UsedNames.clear();
91  Symbols.clear();
92  Allocator.Reset();
93  Instances.clear();
94  CompilationDir.clear();
95  MainFileName.clear();
96  MCDwarfLineTablesCUMap.clear();
97  SectionsForRanges.clear();
98  MCGenDwarfLabelEntries.clear();
99  DwarfDebugFlags = StringRef();
100  DwarfCompileUnitID = 0;
101  CurrentDwarfLoc = MCDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0);
102 
103  CVContext.reset();
104 
105  MachOUniquingMap.clear();
106  ELFUniquingMap.clear();
107  COFFUniquingMap.clear();
108  WasmUniquingMap.clear();
109 
110  NextID.clear();
111  AllowTemporaryLabels = true;
112  DwarfLocSeen = false;
113  GenDwarfForAssembly = false;
114  GenDwarfFileNumber = 0;
115 
116  HadError = false;
117 }
118 
119 //===----------------------------------------------------------------------===//
120 // Symbol Manipulation
121 //===----------------------------------------------------------------------===//
122 
124  SmallString<128> NameSV;
125  StringRef NameRef = Name.toStringRef(NameSV);
126 
127  assert(!NameRef.empty() && "Normal symbols cannot be unnamed!");
128 
129  MCSymbol *&Sym = Symbols[NameRef];
130  if (!Sym)
131  Sym = createSymbol(NameRef, false, false);
132 
133  return Sym;
134 }
135 
137  unsigned Idx) {
138  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
139  "$frame_escape_" + Twine(Idx));
140 }
141 
143  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + FuncName +
144  "$parent_frame_offset");
145 }
146 
148  return getOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix()) + "__ehtable$" +
149  FuncName);
150 }
151 
152 MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
153  bool IsTemporary) {
154  if (MOFI) {
155  switch (MOFI->getObjectFileType()) {
157  return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
159  return new (Name, *this) MCSymbolELF(Name, IsTemporary);
161  return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
163  return new (Name, *this) MCSymbolWasm(Name, IsTemporary);
164  }
165  }
166  return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
167  IsTemporary);
168 }
169 
170 MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
171  bool CanBeUnnamed) {
172  if (CanBeUnnamed && !UseNamesOnTempLabels)
173  return createSymbolImpl(nullptr, true);
174 
175  // Determine whether this is a user written assembler temporary or normal
176  // label, if used.
177  bool IsTemporary = CanBeUnnamed;
178  if (AllowTemporaryLabels && !IsTemporary)
179  IsTemporary = Name.startswith(MAI->getPrivateGlobalPrefix());
180 
181  SmallString<128> NewName = Name;
182  bool AddSuffix = AlwaysAddSuffix;
183  unsigned &NextUniqueID = NextID[Name];
184  while (true) {
185  if (AddSuffix) {
186  NewName.resize(Name.size());
187  raw_svector_ostream(NewName) << NextUniqueID++;
188  }
189  auto NameEntry = UsedNames.insert(std::make_pair(NewName, true));
190  if (NameEntry.second || !NameEntry.first->second) {
191  // Ok, we found a name.
192  // Mark it as used for a non-section symbol.
193  NameEntry.first->second = true;
194  // Have the MCSymbol object itself refer to the copy of the string that is
195  // embedded in the UsedNames entry.
196  return createSymbolImpl(&*NameEntry.first, IsTemporary);
197  }
198  assert(IsTemporary && "Cannot rename non-temporary symbols");
199  AddSuffix = true;
200  }
201  llvm_unreachable("Infinite loop");
202 }
203 
204 MCSymbol *MCContext::createTempSymbol(const Twine &Name, bool AlwaysAddSuffix,
205  bool CanBeUnnamed) {
206  SmallString<128> NameSV;
207  raw_svector_ostream(NameSV) << MAI->getPrivateGlobalPrefix() << Name;
208  return createSymbol(NameSV, AlwaysAddSuffix, CanBeUnnamed);
209 }
210 
212  SmallString<128> NameSV;
213  raw_svector_ostream(NameSV) << MAI->getLinkerPrivateGlobalPrefix() << "tmp";
214  return createSymbol(NameSV, true, false);
215 }
216 
218  return createTempSymbol("tmp", true, CanBeUnnamed);
219 }
220 
221 unsigned MCContext::NextInstance(unsigned LocalLabelVal) {
222  MCLabel *&Label = Instances[LocalLabelVal];
223  if (!Label)
224  Label = new (*this) MCLabel(0);
225  return Label->incInstance();
226 }
227 
228 unsigned MCContext::GetInstance(unsigned LocalLabelVal) {
229  MCLabel *&Label = Instances[LocalLabelVal];
230  if (!Label)
231  Label = new (*this) MCLabel(0);
232  return Label->getInstance();
233 }
234 
235 MCSymbol *MCContext::getOrCreateDirectionalLocalSymbol(unsigned LocalLabelVal,
236  unsigned Instance) {
237  MCSymbol *&Sym = LocalSymbols[std::make_pair(LocalLabelVal, Instance)];
238  if (!Sym)
239  Sym = createTempSymbol(false);
240  return Sym;
241 }
242 
244  unsigned Instance = NextInstance(LocalLabelVal);
245  return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
246 }
247 
249  bool Before) {
250  unsigned Instance = GetInstance(LocalLabelVal);
251  if (!Before)
252  ++Instance;
253  return getOrCreateDirectionalLocalSymbol(LocalLabelVal, Instance);
254 }
255 
257  SmallString<128> NameSV;
258  StringRef NameRef = Name.toStringRef(NameSV);
259  return Symbols.lookup(NameRef);
260 }
261 
263  StringRef Sym,
264  uint64_t Val) {
265  auto Symbol = getOrCreateSymbol(Sym);
266  Streamer.EmitAssignment(Symbol, MCConstantExpr::create(Val, *this));
267 }
268 
269 //===----------------------------------------------------------------------===//
270 // Section Management
271 //===----------------------------------------------------------------------===//
272 
274  unsigned TypeAndAttributes,
275  unsigned Reserved2, SectionKind Kind,
276  const char *BeginSymName) {
277  // We unique sections by their segment/section pair. The returned section
278  // may not have the same flags as the requested section, if so this should be
279  // diagnosed by the client as an error.
280 
281  // Form the name to look up.
283  Name += Segment;
284  Name.push_back(',');
285  Name += Section;
286 
287  // Do the lookup, if we have a hit, return it.
288  MCSectionMachO *&Entry = MachOUniquingMap[Name];
289  if (Entry)
290  return Entry;
291 
292  MCSymbol *Begin = nullptr;
293  if (BeginSymName)
294  Begin = createTempSymbol(BeginSymName, false);
295 
296  // Otherwise, return a new section.
297  return Entry = new (MachOAllocator.Allocate()) MCSectionMachO(
298  Segment, Section, TypeAndAttributes, Reserved2, Kind, Begin);
299 }
300 
302  StringRef GroupName;
303  if (const MCSymbol *Group = Section->getGroup())
304  GroupName = Group->getName();
305 
306  unsigned UniqueID = Section->getUniqueID();
307  ELFUniquingMap.erase(
308  ELFSectionKey{Section->getSectionName(), GroupName, UniqueID});
309  auto I = ELFUniquingMap.insert(std::make_pair(
310  ELFSectionKey{Name, GroupName, UniqueID},
311  Section))
312  .first;
313  StringRef CachedName = I->first.SectionName;
314  const_cast<MCSectionELF *>(Section)->setSectionName(CachedName);
315 }
316 
317 MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
318  unsigned Flags, SectionKind K,
319  unsigned EntrySize,
320  const MCSymbolELF *Group,
321  unsigned UniqueID,
322  const MCSymbolELF *Associated) {
323  MCSymbolELF *R;
324  MCSymbol *&Sym = Symbols[Section];
325  // A section symbol can not redefine regular symbols. There may be multiple
326  // sections with the same name, in which case the first such section wins.
327  if (Sym && Sym->isDefined() &&
328  (!Sym->isInSection() || Sym->getSection().getBeginSymbol() != Sym))
329  reportError(SMLoc(), "invalid symbol redefinition");
330  if (Sym && Sym->isUndefined()) {
331  R = cast<MCSymbolELF>(Sym);
332  } else {
333  auto NameIter = UsedNames.insert(std::make_pair(Section, false)).first;
334  R = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
335  if (!Sym)
336  Sym = R;
337  }
340 
341  auto *Ret = new (ELFAllocator.Allocate()) MCSectionELF(
342  Section, Type, Flags, K, EntrySize, Group, UniqueID, R, Associated);
343 
344  auto *F = new MCDataFragment();
345  Ret->getFragmentList().insert(Ret->begin(), F);
346  F->setParent(Ret);
347  R->setFragment(F);
348 
349  return Ret;
350 }
351 
353  unsigned Flags, unsigned EntrySize,
354  const MCSymbolELF *Group,
355  const MCSectionELF *RelInfoSection) {
357  bool Inserted;
358  std::tie(I, Inserted) =
359  RelSecNames.insert(std::make_pair(Name.str(), true));
360 
361  return createELFSectionImpl(
362  I->getKey(), Type, Flags, SectionKind::getReadOnly(), EntrySize, Group,
363  true, cast<MCSymbolELF>(RelInfoSection->getBeginSymbol()));
364 }
365 
367  const Twine &Suffix, unsigned Type,
368  unsigned Flags,
369  unsigned EntrySize) {
370  return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix);
371 }
372 
373 MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
374  unsigned Flags, unsigned EntrySize,
375  const Twine &Group, unsigned UniqueID,
376  const MCSymbolELF *Associated) {
377  MCSymbolELF *GroupSym = nullptr;
378  if (!Group.isTriviallyEmpty() && !Group.str().empty())
379  GroupSym = cast<MCSymbolELF>(getOrCreateSymbol(Group));
380 
381  return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
382  Associated);
383 }
384 
385 MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
386  unsigned Flags, unsigned EntrySize,
387  const MCSymbolELF *GroupSym,
388  unsigned UniqueID,
389  const MCSymbolELF *Associated) {
390  StringRef Group = "";
391  if (GroupSym)
392  Group = GroupSym->getName();
393  // Do the lookup, if we have a hit, return it.
394  auto IterBool = ELFUniquingMap.insert(
395  std::make_pair(ELFSectionKey{Section.str(), Group, UniqueID}, nullptr));
396  auto &Entry = *IterBool.first;
397  if (!IterBool.second)
398  return Entry.second;
399 
400  StringRef CachedName = Entry.first.SectionName;
401 
403  if (Flags & ELF::SHF_ARM_PURECODE)
405  else if (Flags & ELF::SHF_EXECINSTR)
406  Kind = SectionKind::getText();
407  else
408  Kind = SectionKind::getReadOnly();
409 
410  MCSectionELF *Result = createELFSectionImpl(
411  CachedName, Type, Flags, Kind, EntrySize, GroupSym, UniqueID, Associated);
412  Entry.second = Result;
413  return Result;
414 }
415 
417  return createELFSectionImpl(".group", ELF::SHT_GROUP, 0,
418  SectionKind::getReadOnly(), 4, Group, ~0,
419  nullptr);
420 }
421 
423  unsigned Characteristics,
425  StringRef COMDATSymName, int Selection,
426  unsigned UniqueID,
427  const char *BeginSymName) {
428  MCSymbol *COMDATSymbol = nullptr;
429  if (!COMDATSymName.empty()) {
430  COMDATSymbol = getOrCreateSymbol(COMDATSymName);
431  COMDATSymName = COMDATSymbol->getName();
432  }
433 
434 
435  // Do the lookup, if we have a hit, return it.
436  COFFSectionKey T{Section, COMDATSymName, Selection, UniqueID};
437  auto IterBool = COFFUniquingMap.insert(std::make_pair(T, nullptr));
438  auto Iter = IterBool.first;
439  if (!IterBool.second)
440  return Iter->second;
441 
442  MCSymbol *Begin = nullptr;
443  if (BeginSymName)
444  Begin = createTempSymbol(BeginSymName, false);
445 
446  StringRef CachedName = Iter->first.SectionName;
447  MCSectionCOFF *Result = new (COFFAllocator.Allocate()) MCSectionCOFF(
448  CachedName, Characteristics, COMDATSymbol, Selection, Kind, Begin);
449 
450  Iter->second = Result;
451  return Result;
452 }
453 
455  unsigned Characteristics,
457  const char *BeginSymName) {
458  return getCOFFSection(Section, Characteristics, Kind, "", 0, GenericSectionID,
459  BeginSymName);
460 }
461 
463  COFFSectionKey T{Section, "", 0, GenericSectionID};
464  auto Iter = COFFUniquingMap.find(T);
465  if (Iter == COFFUniquingMap.end())
466  return nullptr;
467  return Iter->second;
468 }
469 
471  const MCSymbol *KeySym,
472  unsigned UniqueID) {
473  // Return the normal section if we don't have to be associative or unique.
474  if (!KeySym && UniqueID == GenericSectionID)
475  return Sec;
476 
477  // If we have a key symbol, make an associative section with the same name and
478  // kind as the normal section.
479  unsigned Characteristics = Sec->getCharacteristics();
480  if (KeySym) {
481  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
483  Sec->getKind(), KeySym->getName(),
485  }
486 
487  return getCOFFSection(Sec->getSectionName(), Characteristics, Sec->getKind(),
488  "", 0, UniqueID);
489 }
490 
492  const Twine &Group, unsigned UniqueID,
493  const char *BeginSymName) {
494  MCSymbolWasm *GroupSym = nullptr;
495  if (!Group.isTriviallyEmpty() && !Group.str().empty()) {
496  GroupSym = cast<MCSymbolWasm>(getOrCreateSymbol(Group));
497  GroupSym->setComdat(true);
498  }
499 
500  return getWasmSection(Section, K, GroupSym, UniqueID, BeginSymName);
501 }
502 
504  const MCSymbolWasm *GroupSym,
505  unsigned UniqueID,
506  const char *BeginSymName) {
507  StringRef Group = "";
508  if (GroupSym)
509  Group = GroupSym->getName();
510  // Do the lookup, if we have a hit, return it.
511  auto IterBool = WasmUniquingMap.insert(
512  std::make_pair(WasmSectionKey{Section.str(), Group, UniqueID}, nullptr));
513  auto &Entry = *IterBool.first;
514  if (!IterBool.second)
515  return Entry.second;
516 
517  StringRef CachedName = Entry.first.SectionName;
518 
519  MCSymbol *Begin = createSymbol(CachedName, false, false);
520  cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION);
521 
522  MCSectionWasm *Result = new (WasmAllocator.Allocate())
523  MCSectionWasm(CachedName, Kind, GroupSym, UniqueID, Begin);
524  Entry.second = Result;
525 
526  auto *F = new MCDataFragment();
527  Result->getFragmentList().insert(Result->begin(), F);
528  F->setParent(Result);
529  Begin->setFragment(F);
530 
531  return Result;
532 }
533 
535  return *new (MCSubtargetAllocator.Allocate()) MCSubtargetInfo(STI);
536 }
537 
538 void MCContext::addDebugPrefixMapEntry(const std::string &From,
539  const std::string &To) {
540  DebugPrefixMap.insert(std::make_pair(From, To));
541 }
542 
544  const auto &DebugPrefixMap = this->DebugPrefixMap;
545  const auto RemapDebugPath = [&DebugPrefixMap](std::string &Path) {
546  for (const auto &Entry : DebugPrefixMap)
547  if (StringRef(Path).startswith(Entry.first)) {
548  std::string RemappedPath =
549  (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
550  Path.swap(RemappedPath);
551  }
552  };
553 
554  // Remap compilation directory.
555  std::string CompDir = CompilationDir.str();
556  RemapDebugPath(CompDir);
557  CompilationDir = CompDir;
558 
559  // Remap MCDwarfDirs in all compilation units.
560  for (auto &CUIDTablePair : MCDwarfLineTablesCUMap)
561  for (auto &Dir : CUIDTablePair.second.getMCDwarfDirs())
562  RemapDebugPath(Dir);
563 }
564 
565 //===----------------------------------------------------------------------===//
566 // Dwarf Management
567 //===----------------------------------------------------------------------===//
568 
569 /// getDwarfFile - takes a file name and number to place in the dwarf file and
570 /// directory tables. If the file number has already been allocated it is an
571 /// error and zero is returned and the client reports the error, else the
572 /// allocated file number is returned. The file numbers may be in any order.
574  StringRef FileName,
575  unsigned FileNumber,
576  MD5::MD5Result *Checksum,
578  unsigned CUID) {
579  MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
580  return Table.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
581 }
582 
583 /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
584 /// currently is assigned and false otherwise.
585 bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
586  const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
587  if (FileNumber == 0)
588  return getDwarfVersion() >= 5 && LineTable.hasRootFile();
589  if (FileNumber >= LineTable.getMCDwarfFiles().size())
590  return false;
591 
592  return !LineTable.getMCDwarfFiles()[FileNumber].Name.empty();
593 }
594 
595 /// Remove empty sections from SectionsForRanges, to avoid generating
596 /// useless debug info for them.
598  SectionsForRanges.remove_if(
599  [&](MCSection *Sec) { return !MCOS.mayHaveInstructions(*Sec); });
600 }
601 
603  if (!CVContext.get())
604  CVContext.reset(new CodeViewContext);
605  return *CVContext.get();
606 }
607 
608 //===----------------------------------------------------------------------===//
609 // Error Reporting
610 //===----------------------------------------------------------------------===//
611 
612 void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
613  HadError = true;
614 
615  // If we have a source manager use it. Otherwise, try using the inline source
616  // manager.
617  // If that fails, use the generic report_fatal_error().
618  if (SrcMgr)
619  SrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
620  else if (InlineSrcMgr)
621  InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Error, Msg);
622  else
623  report_fatal_error(Msg, false);
624 }
625 
626 void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) {
627  reportError(Loc, Msg);
628 
629  // If we reached here, we are failing ungracefully. Run the interrupt handlers
630  // to make sure any special cleanups get done, in particular that we remove
631  // files registered with RemoveFileOnSignal.
633  exit(1);
634 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
MCSymbol * getDirectionalLocalSymbol(unsigned LocalLabelVal, bool Before)
Create and return a directional local symbol for numbered label (used for "1b" or 1f" references)...
Definition: MCContext.cpp:248
SectionKind getKind() const
Definition: MCSection.h:106
This represents a section on a Mach-O system (used by Mac OS X).
MCSymbol * lookupSymbol(const Twine &Name) const
Get the symbol for Name, or null.
Definition: MCContext.cpp:256
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:24
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:126
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
unsigned getNumBuffers() const
Definition: SourceMgr.h:136
StringRef getLinkerPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:498
void push_back(const T &Elt)
Definition: SmallVector.h:218
MCSymbol * getOrCreateFrameAllocSymbol(StringRef FuncName, unsigned Idx)
Gets a symbol that will be defined to the final stack offset of a local variable after codegen...
Definition: MCContext.cpp:136
void reset()
reset - return object to right after construction state to prepare to process a new module ...
Definition: MCContext.cpp:83
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
Definition: StringRef.h:138
SourceMgr SrcMgr
Definition: Error.cpp:24
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
Definition: Twine.h:398
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:453
MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K)
Definition: MCContext.h:454
MCSymbol * createDirectionalLocalSymbol(unsigned LocalLabelVal)
Create the definition of a directional local symbol for numbered label (used for "1:" definitions)...
Definition: MCContext.cpp:243
MCSymbol * getOrCreateParentFrameOffsetSymbol(StringRef FuncName)
Definition: MCContext.cpp:142
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:510
F(f)
uint16_t getDwarfVersion() const
Definition: MCContext.h:628
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:491
MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI, const MCObjectFileInfo *MOFI, const SourceMgr *Mgr=nullptr, bool DoAutoReset=true)
Definition: MCContext.cpp:57
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:422
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym...
Definition: MCContext.cpp:470
This represents a section on Windows.
Definition: MCSectionCOFF.h:27
void setComdat(bool isComdat)
Definition: MCSymbolWasm.h:57
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Definition: SourceMgr.cpp:248
#define DWARF2_FLAG_IS_STMT
Definition: MCDwarf.h:80
amdgpu Simplify well known AMD library false Value Value const Twine & Name
MCSymbol * createLinkerPrivateTempSymbol()
Create and return a new linker temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:211
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
void Reset()
Deallocate all but the current slab and reset the current pointer to the beginning of it...
Definition: Allocator.h:195
void renameELFSection(MCSectionELF *Section, StringRef Name)
Definition: MCContext.cpp:301
void finalizeDwarfSections(MCStreamer &MCOS)
Remove empty sections from SectionsForRanges, to avoid generating useless debug info for them...
Definition: MCContext.cpp:597
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Definition: MCSymbol.h:252
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:273
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:524
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:912
static cl::opt< char * > AsSecureLogFileName("as-secure-log-file-name", cl::desc("As secure log file name (initialized from " "AS_SECURE_LOG_FILE env variable)"), cl::init(getenv("AS_SECURE_LOG_FILE")), cl::Hidden)
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:267
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:267
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:131
MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)
Return the MCSection for the specified mach-o section.
Definition: MCContext.cpp:273
void RemapDebugPaths()
Definition: MCContext.cpp:543
Instances of this class represent the information from a dwarf .loc directive.
Definition: MCDwarf.h:68
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:73
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
LLVM_ATTRIBUTE_NORETURN void reportFatalError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:626
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned getMainFileID() const
Definition: SourceMgr.h:140
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
unsigned getUniqueID() const
Definition: MCSectionELF.h:87
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:423
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
Definition: MCDwarf.h:343
Streaming machine code generation interface.
Definition: MCStreamer.h:189
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
unsigned const MachineRegisterInfo * MRI
const MCSymbolELF * getGroup() const
Definition: MCSectionELF.h:78
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This represents a section on wasm.
Definition: MCSectionWasm.h:28
void RunInterruptHandlers()
This function runs all the registered interrupt handlers, including the removal of files registered b...
virtual bool mayHaveInstructions(MCSection &Sec) const
Definition: MCStreamer.h:984
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:612
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:23
MCSectionELF * getELFNamedSection(const Twine &Prefix, const Twine &Suffix, unsigned Type, unsigned Flags, unsigned EntrySize=0)
Get a section with the provided group identifier.
Definition: MCContext.cpp:366
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: StringMap.h:347
Environment getObjectFileType() const
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
StringRef getSectionName() const
Definition: MCSectionCOFF.h:72
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
bool isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID=0)
isValidDwarfFileNumber - takes a dwarf file number and returns true if it currently is assigned and f...
Definition: MCContext.cpp:585
void setType(unsigned Type) const
Definition: MCSymbolELF.cpp:95
bool hasRootFile() const
Definition: MCDwarf.h:322
MCSectionELF * createELFRelSection(const Twine &Name, unsigned Type, unsigned Flags, unsigned EntrySize, const MCSymbolELF *Group, const MCSectionELF *RelInfoSection)
Definition: MCContext.cpp:352
unsigned incInstance()
Increment the current instance of this Directional Local Label.
Definition: MCLabel.h:41
Basic Register Allocator
BlockVerifier::State From
MCSymbol * getOrCreateLSDASymbol(StringRef FuncName)
Definition: MCContext.cpp:147
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:257
Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned FileNumber=0)
Definition: MCDwarf.cpp:534
void setBinding(unsigned Binding) const
Definition: MCSymbolELF.cpp:42
MCSymbol * getBeginSymbol()
Definition: MCSection.h:110
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:366
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:248
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:267
void setSymbolValue(MCStreamer &Streamer, StringRef Sym, uint64_t Val)
Set value for a symbol.
Definition: MCContext.cpp:262
iterator insert(iterator where, pointer New)
Definition: ilist.h:228
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
unsigned getInstance() const
Get the current instance of this Directional Local Label.
Definition: MCLabel.h:38
void addDebugPrefixMapEntry(const std::string &From, const std::string &To)
Add an entry to the debug prefix map.
Definition: MCContext.cpp:538
#define I(x, y, z)
Definition: MD5.cpp:58
COFFYAML::WeakExternalCharacteristics Characteristics
Definition: COFFYAML.cpp:323
Generic base class for all target subtargets.
This represents a section on linux, lots of unix variants and some bare metal systems.
Definition: MCSectionELF.h:28
MCSectionELF * createELFGroupSection(const MCSymbolELF *Group)
Definition: MCContext.cpp:416
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:18
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:203
CodeViewContext & getCVContext()
Definition: MCContext.cpp:602
const unsigned Kind
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
Definition: MCContext.cpp:573
Instances of this class represent a label name in the MC file, and MCLabel are created and uniqued by...
Definition: MCLabel.h:24
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:389
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
Represents a location in source code.
Definition: SMLoc.h:24
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:150
static SectionKind getReadOnly()
Definition: SectionKind.h:182
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:164
StringRef getSectionName() const
Definition: MCSectionELF.h:73
iterator begin()
Definition: MCSection.h:163
static SectionKind getExecuteOnly()
Definition: SectionKind.h:181
Pass this value as the UniqueID during section creation to get the generic section with the given nam...
Definition: MCContext.h:372
static SectionKind getText()
Definition: SectionKind.h:180
void resize(size_type N)
Definition: SmallVector.h:351
MCSubtargetInfo & getSubtargetCopy(const MCSubtargetInfo &STI)
Definition: MCContext.cpp:534
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:138