From 1ce54d6be2bfba92c82372186a22aad6b0e09fbc Mon Sep 17 00:00:00 2001 From: James Molloy Date: Fri, 23 Sep 2016 12:15:58 +0000 Subject: [ARM] Promote small global constants to constant pools If a constant is unamed_addr and is only used within one function, we can save on the code size and runtime cost of an indirection by changing the global's storage to inside the constant pool. For example, instead of: ldr r0, .CPI0 bl printf bx lr .CPI0: &format_string format_string: .asciz "hello, world!\n" We can emit: adr r0, .CPI0 bl printf bx lr .CPI0: .asciz "hello, world!\n" This can cause significant code size savings when many small strings are used in one function (4 bytes per string). This recommit contains fixes for a nasty bug related to fast-isel fallback - because fast-isel doesn't know about this optimization, if it runs and emits references to a string that we inline (because fast-isel fell back to SDAG) we will end up with an inlined string and also an out-of-line string, and we won't emit the out-of-line string, causing backend failures. It also contains fixes for emitting .text relocations which made the sanitizer bots unhappy. llvm-svn: 282241 --- llvm/lib/Target/ARM/ARMConstantPoolValue.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/Target/ARM/ARMConstantPoolValue.cpp') diff --git a/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp b/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp index f13ae481bdb..05d1b84b328 100644 --- a/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp @@ -131,12 +131,24 @@ ARMConstantPoolConstant::ARMConstantPoolConstant(const Constant *C, AddCurrentAddress), CVal(C) {} +ARMConstantPoolConstant::ARMConstantPoolConstant(const GlobalVariable *GV, + const Constant *C) + : ARMConstantPoolValue((Type *)C->getType(), 0, ARMCP::CPPromotedGlobal, 0, + ARMCP::no_modifier, false), + CVal(C), GVar(GV) {} + ARMConstantPoolConstant * ARMConstantPoolConstant::Create(const Constant *C, unsigned ID) { return new ARMConstantPoolConstant(C, ID, ARMCP::CPValue, 0, ARMCP::no_modifier, false); } +ARMConstantPoolConstant * +ARMConstantPoolConstant::Create(const GlobalVariable *GVar, + const Constant *Initializer) { + return new ARMConstantPoolConstant(GVar, Initializer); +} + ARMConstantPoolConstant * ARMConstantPoolConstant::Create(const GlobalValue *GV, ARMCP::ARMCPModifier Modifier) { -- cgit v1.2.3