mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-23 09:41:10 +00:00
[ELF] Optimize basic block section bytesDropped/jumpInstrMods
and make them more space efficient. This decreases sizeof(InputSection) from 176 to 160, and decreases peak memory usage by 0.3% when linking Chrome.
This commit is contained in:
parent
ec501f15a8
commit
e90c8c0422
@ -304,7 +304,8 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is, InputFile *file,
|
||||
JmpInsnOpcode jInvert = invertJmpOpcode(jmpOpcodeB);
|
||||
if (jInvert == J_UNKNOWN)
|
||||
return false;
|
||||
is.jumpInstrMods.push_back({jInvert, (rB.offset - 1), 4});
|
||||
is.jumpInstrMod = make<JumpInstrMod>();
|
||||
*is.jumpInstrMod = {rB.offset - 1, jInvert, 4};
|
||||
// Move R's values to rB except the offset.
|
||||
rB = {r.expr, r.type, rB.offset, r.addend, r.sym};
|
||||
// Cancel R
|
||||
|
@ -1106,12 +1106,9 @@ void InputSectionBase::relocateAlloc(uint8_t *buf, uint8_t *bufEnd) {
|
||||
// a jmp insn must be modified to shrink the jmp insn or to flip the jmp
|
||||
// insn. This is primarily used to relax and optimize jumps created with
|
||||
// basic block sections.
|
||||
if (isa<InputSection>(this)) {
|
||||
for (const JumpInstrMod &jumpMod : jumpInstrMods) {
|
||||
uint64_t offset = jumpMod.offset;
|
||||
uint8_t *bufLoc = buf + offset;
|
||||
target.applyJumpInstrMod(bufLoc, jumpMod.original, jumpMod.size);
|
||||
}
|
||||
if (jumpInstrMod) {
|
||||
target.applyJumpInstrMod(buf + jumpInstrMod->offset, jumpInstrMod->original,
|
||||
jumpInstrMod->size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,13 +130,16 @@ public:
|
||||
// one or two jump instructions at the end that could be relaxed to a smaller
|
||||
// instruction. The members below help trimming the trailing jump instruction
|
||||
// and shrinking a section.
|
||||
unsigned bytesDropped = 0;
|
||||
uint8_t bytesDropped = 0;
|
||||
|
||||
// Whether the section needs to be padded with a NOP filler due to
|
||||
// deleteFallThruJmpInsn.
|
||||
bool nopFiller = false;
|
||||
|
||||
void drop_back(uint64_t num) { bytesDropped += num; }
|
||||
void drop_back(unsigned num) {
|
||||
assert(bytesDropped + num < 256);
|
||||
bytesDropped += num;
|
||||
}
|
||||
|
||||
void push_back(uint64_t num) {
|
||||
assert(bytesDropped >= num);
|
||||
@ -203,7 +206,7 @@ public:
|
||||
// block sections are enabled. Basic block sections creates opportunities to
|
||||
// relax jump instructions at basic block boundaries after reordering the
|
||||
// basic blocks.
|
||||
SmallVector<JumpInstrMod, 0> jumpInstrMods;
|
||||
JumpInstrMod *jumpInstrMod = nullptr;
|
||||
|
||||
// A function compiled with -fsplit-stack calling a function
|
||||
// compiled without -fsplit-stack needs its prologue adjusted. Find
|
||||
@ -377,9 +380,9 @@ private:
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
static_assert(sizeof(InputSection) <= 184, "InputSection is too big");
|
||||
static_assert(sizeof(InputSection) <= 168, "InputSection is too big");
|
||||
#else
|
||||
static_assert(sizeof(InputSection) <= 176, "InputSection is too big");
|
||||
static_assert(sizeof(InputSection) <= 160, "InputSection is too big");
|
||||
#endif
|
||||
|
||||
inline bool isDebugSection(const InputSectionBase &sec) {
|
||||
|
@ -117,8 +117,8 @@ struct Relocation {
|
||||
// jump instruction opcodes at basic block boundaries and are particularly
|
||||
// useful when basic block sections are enabled.
|
||||
struct JumpInstrMod {
|
||||
JumpModType original;
|
||||
uint64_t offset;
|
||||
JumpModType original;
|
||||
unsigned size;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user