llvm::ConstantFoldInstOperands

ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands. If successful, the constant result is returned, if not, null is returned. Note that this function can fail when attempting to fold instructions like loads and stores, which have no constant expression form.

Synopsis

Declared in <llvm/Analysis/ConstantFolding.h>

Constant*
ConstantFoldInstOperands(
    Instruction const* I,
    ArrayRef<Constant*> Ops,
    DataLayout const& DL,
    TargetLibraryInfo const* TLI = nullptr,
    bool AllowNonDeterministic = true);

Description

In some cases, constant folding may return one value chosen from a set of multiple legal return values. For example, the exact bit pattern of NaN results is not guaranteed. Using such a result is usually only valid if all uses of the original operation are replaced by the constant-folded result. The AllowNonDeterministic parameter controls whether this is allowed.

Return Value

This is an important base class in LLVM. It provides the common facilities of all constant values in an LLVM program. A constant is a value that is immutable at runtime. Functions are constants because their address is immutable. Same with global variables.

Parameters

NameDescription
OpsRepresent a constant reference to an array (0 or more elements consecutively in memory), i.e. a start pointer and a length. It allows various APIs to take consecutive elements easily and conveniently.
DLA parsed version of the target data layout string in and methods for querying it.
TLIProvides information about what library functions are available for the current target.