0

In LLVM is it necessary that if we insert some instruction in LLVM IR through LLVM Pass ,than also we have to insert an instruction which will use the result of our previous inserted instruction or we have to store result of our inserted instruction into some variable already present in LLVM IR that is not useless.

for example cant i insert instruction

%result = add i32 4 3

and %result is not used in subsequent instructions.

techcomp
  • 370
  • 3
  • 16

2 Answers2

0

You should be able to insert it but if an optimization pass runs after your pass it might be eliminated because it's unused and doesn't have side effects.

Colin LeMahieu
  • 610
  • 5
  • 7
  • May be you are right but according to my previous questions{IR insertion} i was getting errors like use still stuck around when def is destroyed , but now when i am also using their values, i am not getting those errors but getting some other errors which are most likely my programming faults. – techcomp Nov 02 '14 at 18:47
0

No, it's absolutely not necessary. If you insert the instruction properly (i.e. use the API correctly), it can be left unused.

As a matter of fact, unused values can be left around by various optimization passes as well. LLVM has other passes like DCE (dead code elimination) that will remove unused instructions.

Eli Bendersky
  • 263,248
  • 89
  • 350
  • 412