[llvm-branch-commits] [llvm-branch] r303746 - Merging r302416:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed May 24 07:08:01 PDT 2017


Author: tstellar
Date: Wed May 24 09:08:01 2017
New Revision: 303746

URL: http://llvm.org/viewvc/llvm-project?rev=303746&view=rev
Log:
Merging r302416:

------------------------------------------------------------------------
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
------------------------------------------------------------------------

Added:
    llvm/branches/release_40/test/MC/ARM/ltorg-range.s
Modified:
    llvm/branches/release_40/include/llvm/MC/ConstantPools.h
    llvm/branches/release_40/lib/MC/ConstantPools.cpp
    llvm/branches/release_40/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp

Modified: llvm/branches/release_40/include/llvm/MC/ConstantPools.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/include/llvm/MC/ConstantPools.h?rev=303746&r1=303745&r2=303746&view=diff
==============================================================================
--- llvm/branches/release_40/include/llvm/MC/ConstantPools.h (original)
+++ llvm/branches/release_40/include/llvm/MC/ConstantPools.h Wed May 24 09:08:01 2017
@@ -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);
 

Modified: llvm/branches/release_40/lib/MC/ConstantPools.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/lib/MC/ConstantPools.cpp?rev=303746&r1=303745&r2=303746&view=diff
==============================================================================
--- llvm/branches/release_40/lib/MC/ConstantPools.cpp (original)
+++ llvm/branches/release_40/lib/MC/ConstantPools.cpp Wed May 24 09:08:01 2017
@@ -54,6 +54,10 @@ const MCExpr *ConstantPool::addEntry(con
 
 bool ConstantPool::empty() { return Entries.empty(); }
 
+void ConstantPool::clearCache() {
+  CachedEntries.clear();
+}
+
 //
 // AssemblerConstantPools implementation
 //
@@ -95,6 +99,13 @@ void AssemblerConstantPools::emitForCurr
   }
 }
 
+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) {

Modified: llvm/branches/release_40/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp?rev=303746&r1=303745&r2=303746&view=diff
==============================================================================
--- llvm/branches/release_40/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp (original)
+++ llvm/branches/release_40/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp Wed May 24 09:08:01 2017
@@ -33,6 +33,7 @@ const MCExpr *ARMTargetStreamer::addCons
 
 void ARMTargetStreamer::emitCurrentConstantPool() {
   ConstantPools->emitForCurrentSection(Streamer);
+  ConstantPools->clearCacheForCurrentSection(Streamer);
 }
 
 // finish() - write out any non-empty assembler constant pools.

Added: llvm/branches/release_40/test/MC/ARM/ltorg-range.s
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_40/test/MC/ARM/ltorg-range.s?rev=303746&view=auto
==============================================================================
--- llvm/branches/release_40/test/MC/ARM/ltorg-range.s (added)
+++ llvm/branches/release_40/test/MC/ARM/ltorg-range.s Wed May 24 09:08:01 2017
@@ -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




More information about the llvm-branch-commits mailing list