[PATCH] D27145: Add "RPRED" mechanism for relocation predicates. (5% speedup for `ld.lld -O0`)
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 28 07:00:28 PST 2016
ruiu added a comment.
It is unfortunate that we cannot write like that. I wish we had the C99 desginated initializer in C++.
================
Comment at: ELF/Relocations.h:42-43
enum RelExpr {
- R_ABS,
- R_GOT,
- R_GOTONLY_PC,
- R_GOTONLY_PC_FROM_END,
- R_GOTREL,
- R_GOTREL_FROM_END,
- R_GOT_FROM_END,
- R_GOT_OFF,
- R_GOT_PAGE_PC,
- R_GOT_PC,
- R_HINT,
- R_MIPS_GOT_LOCAL_PAGE,
- R_MIPS_GOT_OFF,
- R_MIPS_GOT_OFF32,
- R_MIPS_GOTREL,
- R_MIPS_TLSGD,
- R_MIPS_TLSLD,
- R_NEG_TLS,
- R_PAGE_PC,
- R_PC,
- R_PLT,
- R_PLT_PC,
- R_PLT_PAGE_PC,
- R_PPC_OPD,
- R_PPC_PLT_OPD,
- R_PPC_TOC,
- R_RELAX_GOT_PC,
- R_RELAX_GOT_PC_NOPIC,
- R_RELAX_TLS_GD_TO_IE,
- R_RELAX_TLS_GD_TO_IE_END,
- R_RELAX_TLS_GD_TO_IE_ABS,
- R_RELAX_TLS_GD_TO_IE_PAGE_PC,
- R_RELAX_TLS_GD_TO_LE,
- R_RELAX_TLS_GD_TO_LE_NEG,
- R_RELAX_TLS_IE_TO_LE,
- R_RELAX_TLS_LD_TO_LE,
- R_SIZE,
- R_THUNK_ABS,
- R_THUNK_PC,
- R_THUNK_PLT_PC,
- R_TLS,
- R_TLSDESC,
- R_TLSDESC_PAGE,
- R_TLSDESC_CALL,
- R_TLSGD,
- R_TLSGD_PC,
- R_TLSLD,
- R_TLSLD_PC,
+#define RELOCATION(Name, Index, PredicateBits) Name = (Index | PredicateBits),
+#include "Relocations.def"
};
----------------
I think I prefer writing the definitions inline here in a macro-expanded form rather than in an included file. The file is not included more than once (except for static_assert), so the #include hack does not make much sense. I also want to make code less exciting by writing constants inline.
This code
enum RelExprPredicateBit {
RPRED_NEEDS_PLT = 1 << 31,
RPRED_ALWAYS_CONSTANT = 1 << 30,
RPRED_REFERS_TO_GOT = 1 << 29,
RPRED_RELAX_MARKER = 1 << 28,
RPRED_RELATIVE = 1 << 27,
};
is boring but I believe it's easier to read. Likewise, I prefer a style like this because it is obvious what it is doing without looking at other places.
enum RelExpr {
R_ABS = 1,
R_GOT = 2 | RPRED_REFERS_TO_GOT,
R_GOTONLY_PC = 3,
R_GOTONLY_PC_FROM_END = 4,
R_GOTREL = 5 | RPRED_RELATIVE,
R_GOTREL_FROM_END = 6 | RPRED_RELATIVE,
R_GOT_FROM_END = 7 | RPRED_ALWAYS_CONSTANT | RPRED_REFERS_TO_GOT,
...
};
https://reviews.llvm.org/D27145
More information about the llvm-commits
mailing list