[llvm] r331412 - [MC] Factor MCObjectStreamer::addFragmentAtoms out of MachO streamer.
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed May 2 16:01:11 PDT 2018
Author: sbc
Date: Wed May 2 16:01:10 2018
New Revision: 331412
URL: http://llvm.org/viewvc/llvm-project?rev=331412&view=rev
Log:
[MC] Factor MCObjectStreamer::addFragmentAtoms out of MachO streamer.
This code previously existed only in MCMachOStreamer but is
useful for WebAssembly too. See: D46335
Differential Revision: https://reviews.llvm.org/D46297
Modified:
llvm/trunk/include/llvm/MC/MCObjectStreamer.h
llvm/trunk/lib/MC/MCMachOStreamer.cpp
llvm/trunk/lib/MC/MCObjectStreamer.cpp
llvm/trunk/lib/MC/MCWasmStreamer.cpp
Modified: llvm/trunk/include/llvm/MC/MCObjectStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectStreamer.h?rev=331412&r1=331411&r2=331412&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectStreamer.h Wed May 2 16:01:10 2018
@@ -85,6 +85,8 @@ protected:
/// will be used as a symbol offset within the fragment.
void flushPendingLabels(MCFragment *F, uint64_t FOffset = 0);
+ void addFragmentAtoms();
+
public:
void visitUsedSymbol(const MCSymbol &Sym) override;
Modified: llvm/trunk/lib/MC/MCMachOStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCMachOStreamer.cpp?rev=331412&r1=331411&r2=331412&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCMachOStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCMachOStreamer.cpp Wed May 2 16:01:10 2018
@@ -455,30 +455,7 @@ void MCMachOStreamer::FinishImpl() {
// We have to set the fragment atom associations so we can relax properly for
// Mach-O.
-
- // First, scan the symbol table to build a lookup table from fragments to
- // defining symbols.
- DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
- for (const MCSymbol &Symbol : getAssembler().symbols()) {
- if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() &&
- !Symbol.isVariable()) {
- // An atom defining symbol should never be internal to a fragment.
- assert(Symbol.getOffset() == 0 &&
- "Invalid offset in atom defining symbol!");
- DefiningSymbolMap[Symbol.getFragment()] = &Symbol;
- }
- }
-
- // Set the fragment atom associations by tracking the last seen atom defining
- // symbol.
- for (MCSection &Sec : getAssembler()) {
- const MCSymbol *CurrentAtom = nullptr;
- for (MCFragment &Frag : Sec) {
- if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(&Frag))
- CurrentAtom = Symbol;
- Frag.setAtom(CurrentAtom);
- }
- }
+ addFragmentAtoms();
this->MCObjectStreamer::FinishImpl();
}
Modified: llvm/trunk/lib/MC/MCObjectStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCObjectStreamer.cpp?rev=331412&r1=331411&r2=331412&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCObjectStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCObjectStreamer.cpp Wed May 2 16:01:10 2018
@@ -60,6 +60,32 @@ void MCObjectStreamer::flushPendingLabel
PendingLabels.clear();
}
+void MCObjectStreamer::addFragmentAtoms() {
+ // First, scan the symbol table to build a lookup table from fragments to
+ // defining symbols.
+ DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap;
+ for (const MCSymbol &Symbol : getAssembler().symbols()) {
+ if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() &&
+ !Symbol.isVariable()) {
+ // An atom defining symbol should never be internal to a fragment.
+ assert(Symbol.getOffset() == 0 &&
+ "Invalid offset in atom defining symbol!");
+ DefiningSymbolMap[Symbol.getFragment()] = &Symbol;
+ }
+ }
+
+ // Set the fragment atom associations by tracking the last seen atom defining
+ // symbol.
+ for (MCSection &Sec : getAssembler()) {
+ const MCSymbol *CurrentAtom = nullptr;
+ for (MCFragment &Frag : Sec) {
+ if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(&Frag))
+ CurrentAtom = Symbol;
+ Frag.setAtom(CurrentAtom);
+ }
+ }
+}
+
// As a compile-time optimization, avoid allocating and evaluating an MCExpr
// tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
static Optional<uint64_t> absoluteSymbolDiff(const MCSymbol *Hi,
Modified: llvm/trunk/lib/MC/MCWasmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCWasmStreamer.cpp?rev=331412&r1=331411&r2=331412&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCWasmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCWasmStreamer.cpp Wed May 2 16:01:10 2018
@@ -198,6 +198,9 @@ void MCWasmStreamer::EmitInstToData(cons
void MCWasmStreamer::FinishImpl() {
EmitFrames(nullptr);
+ // Set fragment atoms so we can map from code fragment to defining symbol
+ addFragmentAtoms();
+
this->MCObjectStreamer::FinishImpl();
}
More information about the llvm-commits
mailing list