Subzero: Shorten and normalize strings in non-DUMP builds.
Jump table labels change from ".Lxxxxx_yy" to "$Jxxxxx_yy".
Pooled float labels change from ".L$float$xxxxyyyy" to "$Fxxxxyyyy".
Pooled double labels change from ".L$double$xxxxxxxxyyyyyyyy" to "$Dxxxxxxxxyyyyyyyy".
All these should in theory not conflict with C/C++ user symbols.
Float labels now likely fit into short strings and don't require extra memory allocation.
Double labels may exceed the limit - encoding in base64 instead of hex would fix that. Or, directly use the binary bytes as the string value.
BUG= none
R=jpp@chromium.org
Review URL: https://codereview.chromium.org/1868113002 .
diff --git a/src/IceInst.cpp b/src/IceInst.cpp
index 8412b05..1265d58 100644
--- a/src/IceInst.cpp
+++ b/src/IceInst.cpp
@@ -579,7 +579,7 @@
return GlobalString::createWithString(
Ctx, ".L" + FuncName.toString() + "$jumptable$__" + std::to_string(Id));
return GlobalString::createWithString(
- Ctx, ".L" + std::to_string(FuncName.getID()) + "_" + std::to_string(Id));
+ Ctx, "$J" + std::to_string(FuncName.getID()) + "_" + std::to_string(Id));
}
} // end of anonymous namespace
diff --git a/src/IceOperand.h b/src/IceOperand.h
index 06b11e6..26630df 100644
--- a/src/IceOperand.h
+++ b/src/IceOperand.h
@@ -209,7 +209,23 @@
void initName(GlobalContext *Ctx) {
std::string Buffer;
llvm::raw_string_ostream Str(Buffer);
- Str << ".L$" << getType() << "$";
+ constexpr bool IsCompact = !BuildDefs::dump();
+ if (IsCompact) {
+ switch (getType()) {
+ case IceType_f32:
+ Str << "$F";
+ break;
+ case IceType_f64:
+ Str << "$D";
+ break;
+ default:
+ // For constant pooling diversification
+ Str << ".L$" << getType() << "$";
+ break;
+ }
+ } else {
+ Str << ".L$" << getType() << "$";
+ }
// Print hex characters byte by byte, starting from the most significant
// byte. NOTE: This ordering assumes Subzero runs on a little-endian
// platform. That means the possibility of different label names depending
@@ -223,7 +239,7 @@
// For a floating-point value in DecorateAsm mode, also append the value in
// human-readable sprintf form, changing '+' to 'p' and '-' to 'm' to
// maintain valid asm labels.
- if (std::is_floating_point<PrimType>::value && !BuildDefs::minimal() &&
+ if (BuildDefs::dump() && std::is_floating_point<PrimType>::value &&
getFlags().getDecorateAsm()) {
char Buf[30];
snprintf(Buf, llvm::array_lengthof(Buf), "$%g", (double)Value);
diff --git a/tests_lit/llvm2ice_tests/bitcast.ll b/tests_lit/llvm2ice_tests/bitcast.ll
index e61a165..b5e9066 100644
--- a/tests_lit/llvm2ice_tests/bitcast.ll
+++ b/tests_lit/llvm2ice_tests/bitcast.ll
@@ -49,8 +49,8 @@
ret i64 %v0
}
; CHECK-LABEL: cast_d2ll_const
-; CHECK: mov e{{..}},{{(DWORD PTR )?}}ds:0x0 {{.*}} .L$double$0012345678901234
-; CHECK: mov e{{..}},{{(DWORD PTR )?}}ds:0x4 {{.*}} .L$double$0012345678901234
+; CHECK: mov e{{..}},{{(DWORD PTR )?}}ds:0x0 {{.*}} {{.*}}0012345678901234
+; CHECK: mov e{{..}},{{(DWORD PTR )?}}ds:0x4 {{.*}} {{.*}}0012345678901234
; ARM32-LABEL: cast_d2ll_const
; ARM32-DAG: movw [[ADDR:r[0-9]+]], #:lower16:.L$
; ARM32-DAG: movt [[ADDR]], #:upper16:.L$
diff --git a/tests_lit/llvm2ice_tests/elf_container.ll b/tests_lit/llvm2ice_tests/elf_container.ll
index 6ab0f4d..bee9002 100644
--- a/tests_lit/llvm2ice_tests/elf_container.ll
+++ b/tests_lit/llvm2ice_tests/elf_container.ll
@@ -57,8 +57,8 @@
ret float %f
}
; TEXT-RELOCS-LABEL: returnFloatConst
-; TEXT-RELOCS: movss {{.*}} R_386_32 .L$float$80000000
-; TEXT-RELOCS: addss {{.*}} R_386_32 .L$float$3f9d70a0
+; TEXT-RELOCS: movss {{.*}} R_386_32 {{.*}}80000000
+; TEXT-RELOCS: addss {{.*}} R_386_32 {{.*}}3f9d70a0
define internal double @returnDoubleConst() {
entry:
@@ -67,9 +67,9 @@
ret double %d2
}
; TEXT-RELOCS-LABEL: returnDoubleConst
-; TEXT-RELOCS: movsd {{.*}} R_386_32 .L$double$ffffffffffffffff
-; TEXT-RELOCS: addsd {{.*}} R_386_32 .L$double$fff7ffffffffffff
-; TEXT-RELOCS: addsd {{.*}} R_386_32 .L$double$fff8000000000003
+; TEXT-RELOCS: movsd {{.*}} R_386_32 {{.*}}ffffffffffffffff
+; TEXT-RELOCS: addsd {{.*}} R_386_32 {{.*}}fff7ffffffffffff
+; TEXT-RELOCS: addsd {{.*}} R_386_32 {{.*}}fff8000000000003
; Test intrinsics that call out to external functions.
define internal void @test_memcpy(i32 %iptr_dst, i32 %len) {
@@ -385,11 +385,11 @@
; CHECK: Relocations [
; CHECK: Section ({{[0-9]+}}) .rel.text {
-; CHECK: 0x7 R_386_32 .L$float$80000000 0x0
-; CHECK: 0xF R_386_32 .L$float$3f9d70a0 0x0
-; CHECK: 0x27 R_386_32 .L$double$ffffffffffffffff 0x0
-; CHECK: 0x2F R_386_32 .L$double$fff7ffffffffffff 0x0
-; CHECK: 0x37 R_386_32 .L$double$fff8000000000003 0x0
+; CHECK: 0x7 R_386_32 {{.*}}80000000 0x0
+; CHECK: 0xF R_386_32 {{.*}}3f9d70a0 0x0
+; CHECK: 0x27 R_386_32 {{.*}}ffffffffffffffff 0x0
+; CHECK: 0x2F R_386_32 {{.*}}fff7ffffffffffff 0x0
+; CHECK: 0x37 R_386_32 {{.*}}fff8000000000003 0x0
; CHECK: 0x{{.*}} R_386_PC32 memcpy
; CHECK: 0x{{.*}} R_386_PC32 memset
; CHECK: 0x{{.*}} R_386_PC32 external_foo
@@ -421,7 +421,7 @@
; CHECK-NEXT: Section: Undefined (0x0)
; CHECK-NEXT: }
; CHECK: Symbol {
-; CHECK: Name: .L$double$fff8000000000003
+; CHECK: Name: {{.*}}fff8000000000003
; CHECK-NEXT: Value: 0x8
; CHECK-NEXT: Size: 0
; CHECK-NEXT: Binding: Local (0x0)
@@ -430,7 +430,7 @@
; CHECK-NEXT: Section: .rodata.cst8
; CHECK-NEXT: }
; CHECK: Symbol {
-; CHECK: Name: .L$double$ffffffffffffffff
+; CHECK: Name: {{.*}}ffffffffffffffff
; CHECK-NEXT: Value: 0x10
; CHECK-NEXT: Size: 0
; CHECK-NEXT: Binding: Local (0x0)
@@ -439,7 +439,7 @@
; CHECK-NEXT: Section: .rodata.cst8
; CHECK-NEXT: }
; CHECK: Symbol {
-; CHECK: Name: .L$float$3f9d70a0
+; CHECK: Name: {{.*}}3f9d70a0
; CHECK-NEXT: Value: 0x0
; CHECK-NEXT: Size: 0
; CHECK-NEXT: Binding: Local (0x0)
@@ -448,7 +448,7 @@
; CHECK-NEXT: Section: .rodata.cst4
; CHECK-NEXT: }
; CHECK: Symbol {
-; CHECK: Name: .L$float$80000000
+; CHECK: Name: {{.*}}80000000
; CHECK-NEXT: Value: 0x4
; CHECK-NEXT: Size: 0
; CHECK-NEXT: Binding: Local (0x0)