summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorJames Molloy <james.molloy@arm.com>2017-05-22 09:42:01 +0000
committerJames Molloy <james.molloy@arm.com>2017-05-22 09:42:01 +0000
commit5193c80830995d951049db7bcf510e38b0b1521e (patch)
tree902c03c815e85bc6e95256847e370e464f92196d /llvm/lib/MC
parentab9573f37cd0ede2f53d47f0abd72625d1603ea9 (diff)
downloadbcm5719-llvm-5193c80830995d951049db7bcf510e38b0b1521e.tar.gz
bcm5719-llvm-5193c80830995d951049db7bcf510e38b0b1521e.zip
Re-apply r286006: Fix 24560: assembler does not share constant pool for same constants
Re-applying now that the open bug on this commit, PR32825, is known to be fixed. Original commit message: Summary: This patch returns the same label if the CP entry with the same value has been created. Reviewers: eli.friedman, rengolin, jmolloy Subscribers: majnemer, jmolloy, llvm-commits Differential Revision: https://reviews.llvm.org/D25804 llvm-svn: 303539
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r--llvm/lib/MC/ConstantPools.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/MC/ConstantPools.cpp b/llvm/lib/MC/ConstantPools.cpp
index 1763d099115..8c94e278099 100644
--- a/llvm/lib/MC/ConstantPools.cpp
+++ b/llvm/lib/MC/ConstantPools.cpp
@@ -39,10 +39,20 @@ void ConstantPool::emitEntries(MCStreamer &Streamer) {
const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context,
unsigned Size, SMLoc Loc) {
+ const MCConstantExpr *C = dyn_cast<MCConstantExpr>(Value);
+
+ // Check if there is existing entry for the same constant. If so, reuse it.
+ auto Itr = C ? CachedEntries.find(C->getValue()) : CachedEntries.end();
+ if (Itr != CachedEntries.end())
+ return Itr->second;
+
MCSymbol *CPEntryLabel = Context.createTempSymbol();
Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size, Loc));
- return MCSymbolRefExpr::create(CPEntryLabel, Context);
+ const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context);
+ if (C)
+ CachedEntries[C->getValue()] = SymRef;
+ return SymRef;
}
bool ConstantPool::empty() { return Entries.empty(); }
OpenPOWER on IntegriCloud