Diable auto fallthrough of MBB (original) (raw)
Hey, Im trying to develop a custom backend.
I saw in the LLVM documentation that the defualt behaviour of MBB is to fall through the next MBB. This is not the case in my backend, as one must specify which label to jump to.
Is there a simple way to change those settings?
I want this solution to be robust, and handle things like LTO and any other optimization that may alter the labels in the code.
yshaneh June 2, 2025, 4:32pm 2
I’ll clarify, the target works somewhat like WASM.
it’s assembly is not native but bytecode, and it is based around labels, treated as blocks.
When executing a block the program does not fall through to the next block, if no explicit branch is taken the program exits.
That implicit rule has code relying on it all over the place; I wouldn’t suggest trying to change it.
You can probably just run a late pass that adds a branch at the end of each block that doesn’t already have one.
yshaneh June 2, 2025, 6:03pm 4
Don’t you think it would be overwritten by any optimization that runs later on?
I’m not familiar with compiler optimizations and don’t know how to handle someone altering the code after I’ve set it the way I want it.
If you’re writing a backend, you control exactly where your passes run. TargetPassConfig has a bunch of virtual methods you override for this. In this case, you can use addPreEmitPass2().