summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC
diff options
context:
space:
mode:
authorWeiming Zhao <weimingz@codeaurora.org>2016-11-04 19:17:32 +0000
committerWeiming Zhao <weimingz@codeaurora.org>2016-11-04 19:17:32 +0000
commit6100118a52828c0a824aea5492e4e5f9ec3ce5c5 (patch)
tree47ea01d6f8f62f8d05b80ad5357f1398311ff8a1 /llvm/lib/MC
parentb4eef1fa4ae8e51f2008b372fb2529b06f537755 (diff)
downloadbcm5719-llvm-6100118a52828c0a824aea5492e4e5f9ec3ce5c5.tar.gz
bcm5719-llvm-6100118a52828c0a824aea5492e4e5f9ec3ce5c5.zip
Fix 24560: assembler does not share constant pool for same constants
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: 286006
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 c52eec38090..9608c2c656b 100644
--- a/llvm/lib/MC/ConstantPools.cpp
+++ b/llvm/lib/MC/ConstantPools.cpp
@@ -36,10 +36,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