]> granicus.if.org Git - llvm/commitdiff
Re-apply r302416: [ARM] Clear the constant pool cache on explicit .ltorg directives
authorJames Molloy <james.molloy@arm.com>
Mon, 22 May 2017 09:42:07 +0000 (09:42 +0000)
committerJames Molloy <james.molloy@arm.com>
Mon, 22 May 2017 09:42:07 +0000 (09:42 +0000)
Re-applying now that PR32825 which was raised on the commit this fixed up is now known to have also been fixed by this commit.

Original commit message:
    Multiple ldr pseudoinstructions with the same constant value will
    reuse the same constant pool entry. However, if the constant pool
    is explicitly flushed with a .ltorg directive, we should not try
    to reference constants in the previous pool any longer, since they
    may be out of range.

    This fixes assembling hand-written assembler source which repeatedly
    loads the same constant value, across a binary size larger than the
    pc-relative fixup range for ldr instructions (4096 bytes). Such
    assembler source already uses explicit .ltorg instructions to emit
    constant pools with regular intervals. However if we try to reuse
    constants emitted in earlier pools, they end up out of range.

    This makes the output of the testcase match what binutils gas does
    (prior to this patch, it would fail to assemble).

    Differential Revision: https://reviews.llvm.org/D32847

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303540 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/ConstantPools.h
lib/MC/ConstantPools.cpp
lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
test/MC/ARM/ltorg-range.s [new file with mode: 0644]

index c34211c2bd12689a61a35dcd64ca3892ed4d33c0..5d4e32a672ddd6e6115b3a6498ce0a64aba37c94 100644 (file)
@@ -63,6 +63,8 @@ public:
 
   // Return true if the constant pool is empty
   bool empty();
+
+  void clearCache();
 };
 
 class AssemblerConstantPools {
@@ -86,6 +88,7 @@ class AssemblerConstantPools {
 public:
   void emitAll(MCStreamer &Streamer);
   void emitForCurrentSection(MCStreamer &Streamer);
+  void clearCacheForCurrentSection(MCStreamer &Streamer);
   const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Expr,
                          unsigned Size, SMLoc Loc);
 
index 8c94e2780998f1851048b1f9bf620669e6a802de..ca5440237e49817b11c069355660d2d14a0da8d5 100644 (file)
@@ -57,6 +57,10 @@ const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context,
 
 bool ConstantPool::empty() { return Entries.empty(); }
 
+void ConstantPool::clearCache() {
+  CachedEntries.clear();
+}
+
 //
 // AssemblerConstantPools implementation
 //
@@ -98,6 +102,13 @@ void AssemblerConstantPools::emitForCurrentSection(MCStreamer &Streamer) {
   }
 }
 
+void AssemblerConstantPools::clearCacheForCurrentSection(MCStreamer &Streamer) {
+  MCSection *Section = Streamer.getCurrentSectionOnly();
+  if (ConstantPool *CP = getConstantPool(Section)) {
+    CP->clearCache();
+  }
+}
+
 const MCExpr *AssemblerConstantPools::addEntry(MCStreamer &Streamer,
                                                const MCExpr *Expr,
                                                unsigned Size, SMLoc Loc) {
index 2b0cd461df7af8174d25659073cc347cedb46a66..4a943187ab6da611825e796c569ae18e2bd5ce59 100644 (file)
@@ -38,6 +38,7 @@ const MCExpr *ARMTargetStreamer::addConstantPoolEntry(const MCExpr *Expr, SMLoc
 
 void ARMTargetStreamer::emitCurrentConstantPool() {
   ConstantPools->emitForCurrentSection(Streamer);
+  ConstantPools->clearCacheForCurrentSection(Streamer);
 }
 
 // finish() - write out any non-empty assembler constant pools.
diff --git a/test/MC/ARM/ltorg-range.s b/test/MC/ARM/ltorg-range.s
new file mode 100644 (file)
index 0000000..5c27d4c
--- /dev/null
@@ -0,0 +1,27 @@
+@ RUN: llvm-mc -triple armv7-unknown-linux-gnueabi -filetype obj -o - %s \
+@ RUN:   | llvm-objdump -d - | FileCheck %s
+
+        ldr r0, =0x01020304
+@ CHECK: ldr
+        .ltorg
+@ CHECK: 0x01020304
+        ldr r0, =0x01020304
+        ldr r0, =0x01020304
+        ldr r0, =0x01020304
+@ CHECK: ldr
+@ CHECK: ldr
+@ CHECK: ldr
+        .ltorg
+@ CHECK: 0x01020304
+    .rep 1028
+        .word 0
+    .endr
+@ CHECK: 0x00000000
+
+        ldr r0, =0x01020304
+@ CHECK: ldr
+        .ltorg
+@ CHECK: 0x01020304
+    .rep 1028
+        .word 0
+    .endr