Skip to content

Commit e867bfc

Browse files
committed
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
1 parent a2735ea commit e867bfc

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

include/llvm/MC/ConstantPools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class ConstantPool {
6060

6161
// Return true if the constant pool is empty
6262
bool empty();
63+
64+
void clearCache();
6365
};
6466

6567
class AssemblerConstantPools {
@@ -83,6 +85,7 @@ class AssemblerConstantPools {
8385
public:
8486
void emitAll(MCStreamer &Streamer);
8587
void emitForCurrentSection(MCStreamer &Streamer);
88+
void clearCacheForCurrentSection(MCStreamer &Streamer);
8689
const MCExpr *addEntry(MCStreamer &Streamer, const MCExpr *Expr,
8790
unsigned Size, SMLoc Loc);
8891

lib/MC/ConstantPools.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context,
5454

5555
bool ConstantPool::empty() { return Entries.empty(); }
5656

57+
void ConstantPool::clearCache() {
58+
CachedEntries.clear();
59+
}
60+
5761
//
5862
// AssemblerConstantPools implementation
5963
//
@@ -95,6 +99,13 @@ void AssemblerConstantPools::emitForCurrentSection(MCStreamer &Streamer) {
9599
}
96100
}
97101

102+
void AssemblerConstantPools::clearCacheForCurrentSection(MCStreamer &Streamer) {
103+
MCSection *Section = Streamer.getCurrentSectionOnly();
104+
if (ConstantPool *CP = getConstantPool(Section)) {
105+
CP->clearCache();
106+
}
107+
}
108+
98109
const MCExpr *AssemblerConstantPools::addEntry(MCStreamer &Streamer,
99110
const MCExpr *Expr,
100111
unsigned Size, SMLoc Loc) {

lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const MCExpr *ARMTargetStreamer::addConstantPoolEntry(const MCExpr *Expr, SMLoc
3333

3434
void ARMTargetStreamer::emitCurrentConstantPool() {
3535
ConstantPools->emitForCurrentSection(Streamer);
36+
ConstantPools->clearCacheForCurrentSection(Streamer);
3637
}
3738

3839
// finish() - write out any non-empty assembler constant pools.

test/MC/ARM/ltorg-range.s

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@ RUN: llvm-mc -triple armv7-unknown-linux-gnueabi -filetype obj -o - %s \
2+
@ RUN: | llvm-objdump -d - | FileCheck %s
3+
4+
ldr r0, =0x01020304
5+
@ CHECK: ldr
6+
.ltorg
7+
@ CHECK: 0x01020304
8+
ldr r0, =0x01020304
9+
ldr r0, =0x01020304
10+
ldr r0, =0x01020304
11+
@ CHECK: ldr
12+
@ CHECK: ldr
13+
@ CHECK: ldr
14+
.ltorg
15+
@ CHECK: 0x01020304
16+
.rep 1028
17+
.word 0
18+
.endr
19+
@ CHECK: 0x00000000
20+
21+
ldr r0, =0x01020304
22+
@ CHECK: ldr
23+
.ltorg
24+
@ CHECK: 0x01020304
25+
.rep 1028
26+
.word 0
27+
.endr

0 commit comments

Comments
 (0)