summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lib/MC/ConstantPools.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2017-01-24 08:32:59 +0000
committerpatrick <patrick@openbsd.org>2017-01-24 08:32:59 +0000
commit53d771aafdbe5b919f264f53cba3788e2c4cffd2 (patch)
tree7eca39498be0ff1e3a6daf583cd9ca5886bb2636 /gnu/llvm/lib/MC/ConstantPools.cpp
parentIn preparation of compiling our kernels with -ffreestanding, explicitly map (diff)
downloadwireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.tar.xz
wireguard-openbsd-53d771aafdbe5b919f264f53cba3788e2c4cffd2.zip
Import LLVM 4.0.0 rc1 including clang and lld to help the current
development effort on OpenBSD/arm64.
Diffstat (limited to 'gnu/llvm/lib/MC/ConstantPools.cpp')
-rw-r--r--gnu/llvm/lib/MC/ConstantPools.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/gnu/llvm/lib/MC/ConstantPools.cpp b/gnu/llvm/lib/MC/ConstantPools.cpp
index 17a23d063b7..9608c2c656b 100644
--- a/gnu/llvm/lib/MC/ConstantPools.cpp
+++ b/gnu/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(); }
@@ -79,7 +89,7 @@ void AssemblerConstantPools::emitAll(MCStreamer &Streamer) {
}
void AssemblerConstantPools::emitForCurrentSection(MCStreamer &Streamer) {
- MCSection *Section = Streamer.getCurrentSection().first;
+ MCSection *Section = Streamer.getCurrentSectionOnly();
if (ConstantPool *CP = getConstantPool(Section)) {
emitConstantPool(Streamer, Section, *CP);
}
@@ -88,7 +98,7 @@ void AssemblerConstantPools::emitForCurrentSection(MCStreamer &Streamer) {
const MCExpr *AssemblerConstantPools::addEntry(MCStreamer &Streamer,
const MCExpr *Expr,
unsigned Size, SMLoc Loc) {
- MCSection *Section = Streamer.getCurrentSection().first;
+ MCSection *Section = Streamer.getCurrentSectionOnly();
return getOrCreateConstantPool(Section).addEntry(Expr, Streamer.getContext(),
Size, Loc);
}