selfpatch-slr/docs/plan.txt
2025-10-17 17:27:13 +02:00

34 lines
2.2 KiB
Plaintext

General:
- Use custom __builtin_offsetof definition to preserve the call until lower gimple
Approach:
- Use gcc 16 callback in build_component_ref to replace relevant offfsetofs with __spslr_offsetof(uid) calls
- Maintain mapping from uid to type and member information
- At early RTL, find calls and replace them with UNSPEC RTL mov instructions of constants
- Doing it late would most certainly litter rax (return of call)
- Doing it late would also cause surrounding code to deal with clobbering caused by call!
- At very late RTL, find UNSPECs, replace them with constants and add asm labels
- To begin with, this causes one move per offsetof
- Later, add DIY constant folding -> patcher executes byte code program produced by postprocessor
- Patcher program also handles instructions like SET_PERM(RWX, base, page count)
- Current operand values and arbitrary number of member offsets can be used in new operand value compuation
- Patcher is just a byte code interpreter
OLD Approach 1:
- At the very last point of gimple (after gimple optimizations), recognize accesses
- Build a mapping of statement location (multiple statements share) to a semantic graph (or tree)
- Right after expansion to RTL, pattern match set of RTL instructions with same location to graph
- Add notes (persistent over RTL transformations) to any RTL instruction that is relevant
- After all RTL optimizations, add assembly labels before relevant RTL instructions (identified by notes)
- Might need an additional early pass to prevent COMPONENT_REFs to constant/static stuff from being folded early
OLD Approach 2:
- At the very first point of gimple (before optimizations), replace COMPONENT_REFs of relevant structs
- Turn them into calls of __spslr_component_ref(base (new ssa stmt), type uid, member uid)
- Make sure the return type is matching that of the COMPONENT_REF (member type)
- Let those calls get lowered all the way into UNOPTIMIZED RTL
- Replace calls by inserting original constants and attaching notes
- Let RTL optimizations do their job with those many separate constants
- At the very end of RTL, recognize member offsets by notes and add assembly labels
- MIGHT require some logic to trace notes through RTL optimizations (which operand?, combined how?)