LLVM Discussion Forums

LLVM pass at the basic block level

Hello Everyone,
Is it possible to apply LLVM transformation pass to a specific basic block, instead of the whole IR?

No you can’t, what is your use-case though? It is fairly trivial to loop over the blocks and apply your “pseudo pass” to every block.

Thanks for your reply. I want to create a functionally equivalent obfuscated version of a specific basic block in the IR.
Just to clarify, in the first part you mentioned we cannot apply the transformation to a specific block. But in the second part you mentioned we can, by looping over the each block, and apply my pass to them separately to each block.

I wrote “pseudo pass”: a “Pass” is a specific concept in LLVM, it is the unit of scheduling for the pass manager and the unit of computation and invalidation for analysis. It operates on Function, SCCs, and Module.
So you cannot write a pass that operates on a “per block” basis, but this is because it isn’t needed in practice.
You can write a function pass (or a module pass) that will walk the IR, and do something for each of the blocks.

1 Like