LLVM Discussion Forums

Instrument regular llvm IR to another subset of LLVM IR

I am facing a problem that I want to convert a regular LLVM IR (say A) to a subset of LLVM IR (say B), based on B’s specification. What is the process of doing such a task? Any pointer of information would help.

I don’t think there is anything generic that allows to do this, it heavily depends on how B is defined. It would involved a bunch of conversion rules that operates from A->A and a framework to define B and apply these rules. This is somehow what SelectionDAG and GlobalISel are doing when lowering to machine instruction (you’re out of LLVM IR though).
MLIR conversion framework is a generalization of this, it would be possible to use MLIR and the LLVM dialect to build what you want, but it won’t come readily available for free though: all the rules must be added to the system (at least the minimal amount of rules to go from “unsupported IR in A” -> “equivalent in B”).

Thanks a lot !

I was looking at the LLIR, and I actually saw the possible solution. As my target LLVM IR B is actually the NVVRM IR, I am wondering if I can somehow convert my original IR A into GPUDialect or NVVMDialect with MLIR. Any suggestions? Sorry that I am new into this area.