llvm.org GIT mirror llvm / e867bfc
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 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_40@303746 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 2 years ago
4 changed file(s) with 42 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
5959
6060 // Return true if the constant pool is empty
6161 bool empty();
62
63 void clearCache();
6264 };
6365
6466 class AssemblerConstantPools {
8284 public:
8385 void emitAll(MCStreamer &Streamer);
8486 void emitForCurrentSection(MCStreamer &Streamer);
87 void clearCacheForCurrentSection(MCStreamer &Streamer);
8588 const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Expr,
8689 unsigned Size, SMLoc Loc);
8790
5353
5454 bool ConstantPool::empty() { return Entries.empty(); }
5555
56 void ConstantPool::clearCache() {
57 CachedEntries.clear();
58 }
59
5660 //
5761 // AssemblerConstantPools implementation
5862 //
9498 }
9599 }
96100
101 void AssemblerConstantPools::clearCacheForCurrentSection(MCStreamer &Streamer) {
102 MCSection *Section = Streamer.getCurrentSectionOnly();
103 if (ConstantPool *CP = getConstantPool(Section)) {
104 CP->clearCache();
105 }
106 }
107
97108 const MCExpr *AssemblerConstantPools::addEntry(MCStreamer &Streamer,
98109 const MCExpr *Expr,
99110 unsigned Size, SMLoc Loc) {
3232
3333 void ARMTargetStreamer::emitCurrentConstantPool() {
3434 ConstantPools->emitForCurrentSection(Streamer);
35 ConstantPools->clearCacheForCurrentSection(Streamer);
3536 }
3637
3738 // finish() - write out any non-empty assembler constant pools.
0 @ RUN: llvm-mc -triple armv7-unknown-linux-gnueabi -filetype obj -o - %s \
1 @ RUN: | llvm-objdump -d - | FileCheck %s
2
3 ldr r0, =0x01020304
4 @ CHECK: ldr
5 .ltorg
6 @ CHECK: 0x01020304
7 ldr r0, =0x01020304
8 ldr r0, =0x01020304
9 ldr r0, =0x01020304
10 @ CHECK: ldr
11 @ CHECK: ldr
12 @ CHECK: ldr
13 .ltorg
14 @ CHECK: 0x01020304
15 .rep 1028
16 .word 0
17 .endr
18 @ CHECK: 0x00000000
19
20 ldr r0, =0x01020304
21 @ CHECK: ldr
22 .ltorg
23 @ CHECK: 0x01020304
24 .rep 1028
25 .word 0
26 .endr