LLVM Discussion Forums

How to specify that a function has no side-effects?

Hello all,

I’d like to specify that a function does not have side effects.
Ideally, I’d like to be able to do this for an external function (that is only declared).
How can I do this?

Best,
Dumitru

I don’t think side-effect modeling on MLIR FuncOps or on FunctionLike trait has been designed.

While looking into the code (LoopInvariantCodeMotion.cpp) I’ve seen:

  • the HasRecursiveSideEffects trait
  • the MemoryEffectOpInterface interface, which introduces a method hasNoEffect

Can’t these be used in some way to specify which functions (or function calls) have or have not side effects, thereby enabling some optimizations?