Search code examples
c++llvmllvm-c++-api

How are fast-math flags added int the LLVM C++ API during code generation?


I have a builder that builds an operaion:

return BuilderBinop.CreateFMul(L, R, "multmp");

This generates

%multmp23 = fmul float %d22, %e21

Now I want to add fast-math flags to this. Specifically, I want to add the fast flag. How do I go about doing this?


Solution

  • FastMathFlags fmf;
    fmf.setFast(true);
    BuilderBinop.setFastMathFlags(fmf);
    

    The FastMathFlags class has helper methods to set flags. Since the interest here is to set the fast flag to true, the .setFast() comes in handy.

    To clear the flags, the .clear() can be used.