[llvm-dev] How to add a barrier pseudo instruction?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Mon Sep 17 03:13:33 PDT 2018


Hi,

On Sun, 16 Sep 2018 at 22:02, Son Tuan VU via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> I want to add a custom intrinsic to the LLVM IR which would be lowered into a pseudo instruction since it doesn't correspond to any real instruction defined by the architecture. The speciality of this intrinsic/pseudo instruction that it should behave like a scheduling barrier: every instruction before the intrinsic has to be emitted before the intrinsic, the same goes for all instructions after the intrinsic, and this should hold after any optimization in opt and llc.

That's going to be very difficult. LLVM allows intrinsics to have
unmodelled side-effects that prevent reordering with instructions that
might also have side-effects (including loads and stores). But it
assumes that simple arithmetic instructions (like "add") have no
effect other than what's in the IR so they can be freely moved past
anything.

The difference occasionally comes up when people want begin-benchmark
and end-benchmark intrinsics, but really the whole concept of what's
calculated between two points is pretty fuzzy.

> Which bit should be set to 1? isBarrier or hasSideEffects or both?

hasSideEffects is the closest, with the caveats above.

isBarrier has nothing to do with fences. It's applied to unconditional
branches so that LLVM knows that a basic-block ending with that
instruction won't fall-through.

Cheers.

Tim.


More information about the llvm-dev mailing list