Skip to content

Commit d8382ab

Browse files
committed
Adopt preserve_none attribute for MUST_TAIL optimization
Despite using __attribute__((musttail)), the compiler may still emit full stack frames and spill callee-saved registers in complex handlers (e.g., do_lw), undermining the benefits of the threaded interpreter. Integrate Clang's __attribute__((preserve_none)) (available since Clang 19.1.0) into the MUST_TAIL macro. This attribute modifies the calling convention to avoid preserving registers, thereby minimizing stack setup and register pressure during instruction dispatch. This ensures more consistent tail call optimization and reduces overhead in the interpreter loop. Closes: #601
1 parent 0358490 commit d8382ab

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ static inline uint8_t ilog2(uint32_t x)
191191
* even without optimizations enabled.
192192
*/
193193
#if defined(__has_attribute) && __has_attribute(musttail)
194+
#if __has_attribute(preserve_none)
195+
#define MUST_TAIL __attribute__((musttail)) __attribute__((preserve_none))
196+
#else
194197
#define MUST_TAIL __attribute__((musttail))
198+
#endif
195199
#else
196200
#define MUST_TAIL
197201
#endif

0 commit comments

Comments
 (0)