Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LLVM no-op instruction?

I am writing a compiler for an assignment for a language that has empty statements. For structures like if-then-else it could be convenient if I could use a no-op statement in llvm but I didnt find any "official" nop. I have some ideas but ideally I would like to have llvm to optimize that part of the code and remove the instruction; any advice?

like image 391
Thanos Tintinidis Avatar asked Nov 18 '11 19:11

Thanos Tintinidis


People also ask

How to implement institerators in LLVM?

You'll need to include llvm/Support/InstIterator.h, and then instantiate InstIterators explicitly in your code. Here's a small example that shows how to dump all instructions in a function to stderr (Note:Dereferencing an InstIteratoryields an Instruction*, notan Instruction&!):

What is and and or in LLVM?

References llvm::And, and llvm::Or. Return true if the specified instruction is exactly identical to the current one. This means that all operands match and any extra information (e.g. load is volatile) agree. Definition at line 499 of file Instruction.cpp.

What are some ways to improve the performance of LLVM?

Deleting Instructions Replacing an Instruction with another Value Replacing individual instructions Deleting Instructions Replacing multiple uses of Users and Values Deleting GlobalVariables Threads and LLVM Ending Execution with llvm_shutdown() Lazy Initialization with ManagedStatic Achieving Isolation with LLVMContext Threads and the JIT

How do I check if an instruction is idempotent in LLVM?

Determine if the OpCode is one of the FuncletPadInst instructions. Definition at line 228 of file Instruction.h. Return true if the instruction is idempotent: In LLVM, the And and Or operators are idempotent. Definition at line 574 of file Instruction.h. References getOpcode (), and isIdempotent ().


2 Answers

There is no no-op opcode in the IR. But you can safely use any side-effects-free dead instruction as a replacement (that is, if you really need to emit a no-op) because the optimizers will delete them easily enough. E.g. %nop = add i1 0, 0 or %nop = alloca i1, i1 0 could work.

like image 119
CAFxX Avatar answered Oct 12 '22 22:10

CAFxX


Look at this intrinsic:

declare void @llvm.donothing() nounwind readnone

from LLVM Language Reference Manual:

The llvm.donothing intrinsic doesn’t perform any operation. It’s one of only two intrinsics (besides llvm.experimental.patchpoint) that can be called with an invoke instruction.

like image 26
Maxim Reznik Avatar answered Oct 12 '22 23:10

Maxim Reznik