Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / MC / MCObjectWriter.cpp
blob818e703514d61e082927504b948fe8c77e53f0ee
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 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCObjectWriter.h"
10 #include "llvm/MC/MCAssembler.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCFragment.h"
13 #include "llvm/MC/MCSymbol.h"
14 namespace llvm {
15 class MCSection;
18 using namespace llvm;
20 MCObjectWriter::~MCObjectWriter() = default;
22 void MCObjectWriter::reset() {
23 FileNames.clear();
24 AddrsigSyms.clear();
25 EmitAddrsigSection = false;
26 SubsectionsViaSymbols = false;
27 CGProfile.clear();
30 bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
31 const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
32 bool InSet) const {
33 // Modified symbol references cannot be resolved.
34 if (A->getKind() != MCSymbolRefExpr::VK_None ||
35 B->getKind() != MCSymbolRefExpr::VK_None)
36 return false;
38 const MCSymbol &SA = A->getSymbol();
39 const MCSymbol &SB = B->getSymbol();
40 assert(!SA.isUndefined() && !SB.isUndefined());
41 MCFragment *FB = SB.getFragment();
42 if (!FB || !SA.getFragment())
43 return false;
45 return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, *FB, InSet, /*IsPCRel=*/false);
48 bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
49 const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
50 bool InSet, bool IsPCRel) const {
51 const MCSection &SecA = SymA.getSection();
52 const MCSection &SecB = *FB.getParent();
53 // On ELF and COFF A - B is absolute if A and B are in the same section.
54 return &SecA == &SecB;
57 void MCObjectWriter::addFileName(MCAssembler &Asm, StringRef FileName) {
58 FileNames.emplace_back(std::string(FileName), Asm.Symbols.size());