LLVM  16.0.0git
MCObjectWriter.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/MC/MCExpr.h"
11 #include "llvm/MC/MCFragment.h"
12 #include "llvm/MC/MCSymbol.h"
13 namespace llvm {
14 class MCSection;
15 }
16 
17 using namespace llvm;
18 
20 
22  const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
23  bool InSet) const {
24  // Modified symbol references cannot be resolved.
25  if (A->getKind() != MCSymbolRefExpr::VK_None ||
26  B->getKind() != MCSymbolRefExpr::VK_None)
27  return false;
28 
29  const MCSymbol &SA = A->getSymbol();
30  const MCSymbol &SB = B->getSymbol();
31  if (SA.isUndefined() || SB.isUndefined())
32  return false;
33 
34  if (!SA.getFragment() || !SB.getFragment())
35  return false;
36 
37  return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, SB, InSet);
38 }
39 
41  const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B,
42  bool InSet) const {
43  return isSymbolRefDifferenceFullyResolvedImpl(Asm, A, *B.getFragment(), InSet,
44  false);
45 }
46 
48  const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
49  bool InSet, bool IsPCRel) const {
50  const MCSection &SecA = SymA.getSection();
51  const MCSection &SecB = *FB.getParent();
52  // On ELF and COFF A - B is absolute if A and B are in the same section.
53  return &SecA == &SecB;
54 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCObjectWriter::~MCObjectWriter
virtual ~MCObjectWriter()
MCFragment.h
llvm::MCSymbol::isUndefined
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:252
llvm::MCSymbol::getFragment
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:392
llvm::MCFragment::getParent
MCSection * getParent() const
Definition: MCFragment.h:95
llvm::MCFragment
Definition: MCFragment.h:30
llvm::MCSymbol::getSection
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:262
MCSymbol.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MCAssembler
Definition: MCAssembler.h:73
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
A
* A
Definition: README_ALTIVEC.txt:89
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
MCObjectWriter.h
llvm::MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, bool InSet) const
Definition: MCObjectWriter.cpp:40
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
MCExpr.h
llvm::MCObjectWriter::isSymbolRefDifferenceFullyResolved
bool isSymbolRefDifferenceFullyResolved(const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B, bool InSet) const
Check whether the difference (A - B) between two symbol references is fully resolved.
Definition: MCObjectWriter.cpp:21