From 25cbe525ef1b18855d1ec67a1724f965c62b3e9c Mon Sep 17 00:00:00 2001 From: Serge Guelton Date: Mon, 13 Nov 2017 20:57:40 +0000 Subject: [PATCH] Reorder Value.def to optimize code size If the first values in Value.def is the range of constant, then the code generated by `isa` is smaller by one operation (basically, an add is removed). It turns out this small optimization reduces the size of the statically linked clang binary by 400ko on my laptop. The theoritical performance gain is non visible from my benchmarks, but the size dropdown is. Differential Revision: https://reviews.llvm.org/D39373 llvm-svn: 318083 --- llvm/include/llvm/IR/Value.def | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/llvm/include/llvm/IR/Value.def b/llvm/include/llvm/IR/Value.def index cebd7f7..e2ddba0 100644 --- a/llvm/include/llvm/IR/Value.def +++ b/llvm/include/llvm/IR/Value.def @@ -56,16 +56,10 @@ #define HANDLE_CONSTANT_MARKER(MarkerName, ValueName) #endif -HANDLE_VALUE(Argument) -HANDLE_VALUE(BasicBlock) - -// FIXME: It's awkward that Value.def knows about classes in Analysis. While -// this doesn't introduce a strict link or include dependency, we should remove -// the circular dependency eventually. -HANDLE_MEMORY_VALUE(MemoryUse) -HANDLE_MEMORY_VALUE(MemoryDef) -HANDLE_MEMORY_VALUE(MemoryPhi) +// Having constant first makes the range check for isa faster +// and smaller by one operation. +// Constant HANDLE_GLOBAL_VALUE(Function) HANDLE_GLOBAL_VALUE(GlobalAlias) HANDLE_GLOBAL_VALUE(GlobalIFunc) @@ -88,13 +82,6 @@ HANDLE_CONSTANT(ConstantFP) HANDLE_CONSTANT(ConstantPointerNull) HANDLE_CONSTANT(ConstantTokenNone) -HANDLE_METADATA_VALUE(MetadataAsValue) -HANDLE_INLINE_ASM_VALUE(InlineAsm) - -HANDLE_INSTRUCTION(Instruction) -// Enum values starting at InstructionVal are used for Instructions; -// don't add new values here! - HANDLE_CONSTANT_MARKER(ConstantFirstVal, Function) HANDLE_CONSTANT_MARKER(ConstantLastVal, ConstantTokenNone) HANDLE_CONSTANT_MARKER(ConstantDataFirstVal, UndefValue) @@ -102,6 +89,24 @@ HANDLE_CONSTANT_MARKER(ConstantDataLastVal, ConstantTokenNone) HANDLE_CONSTANT_MARKER(ConstantAggregateFirstVal, ConstantArray) HANDLE_CONSTANT_MARKER(ConstantAggregateLastVal, ConstantVector) +HANDLE_VALUE(Argument) +HANDLE_VALUE(BasicBlock) + + +HANDLE_METADATA_VALUE(MetadataAsValue) +HANDLE_INLINE_ASM_VALUE(InlineAsm) + +// FIXME: It's awkward that Value.def knows about classes in Analysis. While +// this doesn't introduce a strict link or include dependency, we should remove +// the circular dependency eventually. +HANDLE_MEMORY_VALUE(MemoryUse) +HANDLE_MEMORY_VALUE(MemoryDef) +HANDLE_MEMORY_VALUE(MemoryPhi) + +HANDLE_INSTRUCTION(Instruction) +// Enum values starting at InstructionVal are used for Instructions; +// don't add new values here! + #undef HANDLE_MEMORY_VALUE #undef HANDLE_GLOBAL_VALUE #undef HANDLE_CONSTANT -- 2.7.4