[PATCH] D127113: [MC][ARM] Reuse symbol value in constant pool

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 22:40:37 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa7b154aa1770: [MC][ARM] Reuse symbol value in constant pool (authored by StephenFan).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127113/new/

https://reviews.llvm.org/D127113

Files:
  llvm/include/llvm/MC/ConstantPools.h
  llvm/lib/MC/ConstantPools.cpp
  llvm/test/MC/ARM/ldr-pseudo-wide.s


Index: llvm/test/MC/ARM/ldr-pseudo-wide.s
===================================================================
--- llvm/test/MC/ARM/ldr-pseudo-wide.s
+++ llvm/test/MC/ARM/ldr-pseudo-wide.s
@@ -36,9 +36,9 @@
 
   ldr.w r0, =foo
 @ CHECK-ARM: ldr r0, .Ltmp[[TMP2:[0-9]+]]
-@ CHECK-DARWIN-ARM: ldr r0, Ltmp2
+@ CHECK-DARWIN-ARM: ldr r0, Ltmp1
 @ CHECK-THUMB2: ldr.w r0, .Ltmp[[TMP2:[0-9]+]]
-@ CHECK-DARWIN-THUMB2: ldr.w r0, Ltmp2
+@ CHECK-DARWIN-THUMB2: ldr.w r0, Ltmp1
 @ CHECK-THUMB: error: instruction requires: thumb2
 @ CHECK-THUMB-NEXT:  ldr.w r0, =foo
 
@@ -56,12 +56,8 @@
 @ CHECK-NEXT: .long   65538
 @ CHECK: .Ltmp1:
 @ CHECK-NEXT: .long   foo
-@ CHECK: .Ltmp2:
-@ CHECK-NEXT: .long   foo
 
 @ CHECK-DARWIN: Ltmp0:
 @ CHECK-DARWIN-NEXT: .long   65538
 @ CHECK-DARWIN: Ltmp1:
 @ CHECK-DARWIN-NEXT: .long   foo
-@ CHECK-DARWIN: Ltmp2:
-@ CHECK-DARWIN-NEXT: .long   foo
Index: llvm/lib/MC/ConstantPools.cpp
===================================================================
--- llvm/lib/MC/ConstantPools.cpp
+++ llvm/lib/MC/ConstantPools.cpp
@@ -39,25 +39,38 @@
 const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context,
                                      unsigned Size, SMLoc Loc) {
   const MCConstantExpr *C = dyn_cast<MCConstantExpr>(Value);
+  const MCSymbolRefExpr *S = dyn_cast<MCSymbolRefExpr>(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;
+  if (C) {
+    auto CItr = CachedConstantEntries.find(C->getValue());
+    if (CItr != CachedConstantEntries.end())
+      return CItr->second;
+  }
+
+  // Check if there is existing entry for the same symbol. If so, reuse it.
+  if (S) {
+    auto SItr = CachedSymbolEntries.find(&(S->getSymbol()));
+    if (SItr != CachedSymbolEntries.end())
+      return SItr->second;
+  }
 
   MCSymbol *CPEntryLabel = Context.createTempSymbol();
 
   Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size, Loc));
   const auto SymRef = MCSymbolRefExpr::create(CPEntryLabel, Context);
   if (C)
-    CachedEntries[C->getValue()] = SymRef;
+    CachedConstantEntries[C->getValue()] = SymRef;
+  if (S)
+    CachedSymbolEntries[&(S->getSymbol())] = SymRef;
   return SymRef;
 }
 
 bool ConstantPool::empty() { return Entries.empty(); }
 
 void ConstantPool::clearCache() {
-  CachedEntries.clear();
+  CachedConstantEntries.clear();
+  CachedSymbolEntries.clear();
 }
 
 //
Index: llvm/include/llvm/MC/ConstantPools.h
===================================================================
--- llvm/include/llvm/MC/ConstantPools.h
+++ llvm/include/llvm/MC/ConstantPools.h
@@ -43,7 +43,8 @@
 class ConstantPool {
   using EntryVecTy = SmallVector<ConstantPoolEntry, 4>;
   EntryVecTy Entries;
-  std::map<int64_t, const MCSymbolRefExpr *> CachedEntries;
+  std::map<int64_t, const MCSymbolRefExpr *> CachedConstantEntries;
+  DenseMap<const MCSymbol *, const MCSymbolRefExpr *> CachedSymbolEntries;
 
 public:
   // Initialize a new empty constant pool


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127113.434693.patch
Type: text/x-patch
Size: 3100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220607/8ec1af25/attachment.bin>


More information about the llvm-commits mailing list