Llvm pass to remove temporaries

Hi.

I’m just starting to dig into the many existing llvm passes, and so far I didn’t find what I’m looking for.

I generate llvm IR code in debug. I’d just like to go through this code and remove as many temporaries as possible. Those variables look generated for debug purposes.
They often look like synonyms of variables declared in the input source and don’t seem to have a real meaning.

IR looks like:
Load a
Store b
Use b (instead of a)

I don’t want to run something like mem2reg or simpilfycfg, because the generated IR is too different from the input source.

Could someone please give me a hint?

Hi,

mem2reg is what you want. Why are you worried about the generated IR looking different from the input source? don’t you have to modify the IR to remove such temporaries?

Cheers,

James

Hi James.

Thanks for the answer.

After the opt pass, I want to parse the generated IR. But when I run mem2reg, I’m getting values with valueTy set to 32, which is not in the ValuTy enum. I deduced those are instruction values. But I didn’t find that much doc on those. That’s why I’d like to stay in the “safe” zone and avoiding those vals.

Thanks again.

Regis