]> granicus.if.org Git - llvm/commitdiff
Merging r302416:
authorTom Stellard <tstellar@redhat.com>
Wed, 24 May 2017 14:08:01 +0000 (14:08 +0000)
committerTom Stellard <tstellar@redhat.com>
Wed, 24 May 2017 14:08:01 +0000 (14:08 +0000)
------------------------------------------------------------------------
r302416 | mstorsjo | 2017-05-08 06:26:24 -0400 (Mon, 08 May 2017) | 19 lines

[ARM] Clear the constant pool cache on explicit .ltorg directives

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/branches/release_40@303746 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 f0c445dbe59fd97af9d3c931329f3e9ed430e0fc..39258003b3b3109b492293578043bba9733d725c 100644 (file)
@@ -60,6 +60,8 @@ public:
 
   // Return true if the constant pool is empty
   bool empty();
+
+  void clearCache();
 };
 
 class AssemblerConstantPools {
@@ -83,6 +85,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 9608c2c656b7c0a8162fa0f1235c7044792473da..bf2c39ef71288daa5349480aea1a585efa3ca45d 100644 (file)
@@ -54,6 +54,10 @@ const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context,
 
 bool ConstantPool::empty() { return Entries.empty(); }
 
+void ConstantPool::clearCache() {
+  CachedEntries.clear();
+}
+
 //
 // AssemblerConstantPools implementation
 //
@@ -95,6 +99,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 c0d10c896354bf56d2aa7cc222f10e215605ec36..e49f1a30674f86a086ceab5eb15654eb803b82f1 100644 (file)
@@ -33,6 +33,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