FLANG
|
#include <flang/Optimizer/Builder/FIRBuilder.h>
Classes | |
class | IfBuilder |
Public Member Functions | |
FirOpBuilder (mlir::Operation *op, fir::KindMapping kindMap, mlir::SymbolTable *symbolTable=nullptr) | |
FirOpBuilder (mlir::OpBuilder &builder, fir::KindMapping kindMap, mlir::SymbolTable *symbolTable=nullptr) | |
FirOpBuilder (mlir::OpBuilder &builder, mlir::ModuleOp mod) | |
FirOpBuilder (mlir::OpBuilder &builder, fir::KindMapping kindMap, mlir::Operation *op) | |
FirOpBuilder (mlir::OpBuilder &builder, mlir::Operation *op) | |
FirOpBuilder (const FirOpBuilder &other) | |
FirOpBuilder (FirOpBuilder &&other) | |
mlir::Region & | getRegion () |
Get the current Region of the insertion point. | |
mlir::ModuleOp | getModule () |
Get the current Module. | |
mlir::func::FuncOp | getFunction () |
Get the current Function. | |
const fir::KindMapping & | getKindMap () |
Get a reference to the kind map. | |
mlir::SymbolTable * | getMLIRSymbolTable () |
Get func.func/fir.global symbol table attached to this builder if any. | |
mlir::IntegerType | getDefaultIntegerType () |
Get the default integer type. | |
mlir::Value | convertWithSemantics (mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false) |
mlir::Block * | getEntryBlock () |
Get the entry block of the current Function. | |
mlir::Block * | getAllocaBlock () |
Get the block for adding Allocas. | |
mlir::Type | getRefType (mlir::Type eleTy, bool isVolatile=false) |
Safely create a reference type to the type eleTy . | |
mlir::Type | getVarLenSeqTy (mlir::Type eleTy, unsigned rank=1) |
Create a sequence of eleTy with rank dimensions of unknown size. | |
mlir::Type | getCharacterLengthType () |
Get character length type. | |
mlir::Type | getIntPtrType () |
mlir::SymbolRefAttr | getSymbolRefAttr (llvm::StringRef str) |
Wrap str to a SymbolRefAttr. | |
mlir::Type | getRealType (int kind) |
Get the mlir float type that implements Fortran REAL(kind). | |
fir::BoxProcType | getBoxProcType (mlir::FunctionType funcTy) |
mlir::Value | createNullConstant (mlir::Location loc, mlir::Type ptrType={}) |
mlir::Value | createIntegerConstant (mlir::Location loc, mlir::Type integerType, std::int64_t i) |
mlir::Value | createAllOnesInteger (mlir::Location loc, mlir::Type integerType) |
mlir::Value | createMinusOneInteger (mlir::Location loc, mlir::Type integerType) |
mlir::Value | createRealConstant (mlir::Location loc, mlir::Type realType, llvm::APFloat::integerPart val) |
Create a real constant from an integer value. | |
mlir::Value | createRealConstant (mlir::Location loc, mlir::Type realType, const llvm::APFloat &val) |
Create a real constant from an APFloat value. | |
mlir::Value | createRealZeroConstant (mlir::Location loc, mlir::Type realType) |
Create a real constant of type realType with a value zero. | |
mlir::Value | allocateLocal (mlir::Location loc, mlir::Type ty, llvm::StringRef uniqName, llvm::StringRef name, bool pinned, llvm::ArrayRef< mlir::Value > shape, llvm::ArrayRef< mlir::Value > lenParams, bool asTarget=false) |
mlir::Value | allocateLocal (mlir::Location loc, mlir::Type ty, llvm::StringRef uniqName, llvm::StringRef name, llvm::ArrayRef< mlir::Value > shape, llvm::ArrayRef< mlir::Value > lenParams, bool asTarget=false) |
mlir::ArrayAttr | create2DI64ArrayAttr (llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData) |
mlir::Value | createTemporaryAlloc (mlir::Location loc, mlir::Type type, llvm::StringRef name, mlir::ValueRange lenParams={}, mlir::ValueRange shape={}, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, std::optional< Fortran::common::CUDADataAttr > cudaAttr=std::nullopt) |
mlir::Value | createTemporary (mlir::Location loc, mlir::Type type, llvm::StringRef name={}, mlir::ValueRange shape={}, mlir::ValueRange lenParams={}, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, std::optional< Fortran::common::CUDADataAttr > cudaAttr=std::nullopt) |
mlir::Value | createTemporary (mlir::Location loc, mlir::Type type, mlir::ValueRange shape) |
Create an unnamed and untracked temporary on the stack. | |
mlir::Value | createTemporary (mlir::Location loc, mlir::Type type, llvm::ArrayRef< mlir::NamedAttribute > attrs) |
mlir::Value | createTemporary (mlir::Location loc, mlir::Type type, llvm::StringRef name, llvm::ArrayRef< mlir::NamedAttribute > attrs) |
mlir::Value | createHeapTemporary (mlir::Location loc, mlir::Type type, llvm::StringRef name={}, mlir::ValueRange shape={}, mlir::ValueRange lenParams={}, llvm::ArrayRef< mlir::NamedAttribute > attrs={}) |
Create a temporary on the heap. | |
std::pair< mlir::Value, bool > | createAndDeclareTemp (mlir::Location loc, mlir::Type baseType, mlir::Value shape, llvm::ArrayRef< mlir::Value > extents, llvm::ArrayRef< mlir::Value > typeParams, const std::function< decltype(genTempDeclareOp)> &genDeclare, mlir::Value polymorphicMold, bool useStack, llvm::StringRef tmpName) |
std::pair< mlir::Value, bool > | createArrayTemp (mlir::Location loc, fir::SequenceType arrayType, mlir::Value shape, llvm::ArrayRef< mlir::Value > extents, llvm::ArrayRef< mlir::Value > typeParams, const std::function< decltype(genTempDeclareOp)> &genDeclare, mlir::Value polymorphicMold, bool useStack=false, llvm::StringRef tmpName=".tmp.array") |
Create and declare an array temporary. | |
mlir::Value | genStackSave (mlir::Location loc) |
void | genStackRestore (mlir::Location loc, mlir::Value stackPointer) |
fir::GlobalOp | createGlobal (mlir::Location loc, mlir::Type type, llvm::StringRef name, mlir::StringAttr linkage={}, mlir::Attribute value={}, bool isConst=false, bool isTarget=false, cuf::DataAttributeAttr dataAttr={}) |
Create a global value. | |
fir::GlobalOp | createGlobal (mlir::Location loc, mlir::Type type, llvm::StringRef name, bool isConst, bool isTarget, std::function< void(FirOpBuilder &)> bodyBuilder, mlir::StringAttr linkage={}, cuf::DataAttributeAttr dataAttr={}) |
fir::GlobalOp | createGlobalConstant (mlir::Location loc, mlir::Type type, llvm::StringRef name, mlir::StringAttr linkage={}, mlir::Attribute value={}) |
Create a global constant (read-only) value. | |
fir::GlobalOp | createGlobalConstant (mlir::Location loc, mlir::Type type, llvm::StringRef name, std::function< void(FirOpBuilder &)> bodyBuilder, mlir::StringAttr linkage={}) |
fir::StringLitOp | createStringLitOp (mlir::Location loc, llvm::StringRef string) |
Convert a StringRef string into a fir::StringLitOp. | |
std::pair< fir::TypeInfoOp, mlir::OpBuilder::InsertPoint > | createTypeInfoOp (mlir::Location loc, fir::RecordType recordType, fir::RecordType parentType) |
mlir::StringAttr | createCommonLinkage () |
mlir::StringAttr | createInternalLinkage () |
mlir::StringAttr | createLinkOnceLinkage () |
mlir::StringAttr | createLinkOnceODRLinkage () |
mlir::StringAttr | createWeakLinkage () |
mlir::func::FuncOp | getNamedFunction (llvm::StringRef name) |
mlir::func::FuncOp | getNamedFunction (mlir::SymbolRefAttr symbol) |
fir::GlobalOp | getNamedGlobal (llvm::StringRef name) |
mlir::Value | createConvert (mlir::Location loc, mlir::Type toTy, mlir::Value val) |
Lazy creation of fir.convert op. | |
mlir::Value | createConvertWithVolatileCast (mlir::Location loc, mlir::Type toTy, mlir::Value val) |
mlir::Value | createVolatileCast (mlir::Location loc, bool isVolatile, mlir::Value value) |
Cast value to have isVolatile volatility. | |
void | createStoreWithConvert (mlir::Location loc, mlir::Value val, mlir::Value addr) |
mlir::Value | loadIfRef (mlir::Location loc, mlir::Value val) |
mlir::func::FuncOp | createFunction (mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty) |
mlir::func::FuncOp | createRuntimeFunction (mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty, bool isIO=false) |
mlir::Value | convertToIndexType (mlir::Location loc, mlir::Value val) |
Cast the input value to IndexType. | |
mlir::Value | genShape (mlir::Location loc, const fir::AbstractArrayBox &arr) |
Construct one of the two forms of shape op from an array box. | |
mlir::Value | genShape (mlir::Location loc, llvm::ArrayRef< mlir::Value > shift, llvm::ArrayRef< mlir::Value > exts) |
mlir::Value | genShape (mlir::Location loc, llvm::ArrayRef< mlir::Value > exts) |
mlir::Value | genShift (mlir::Location loc, llvm::ArrayRef< mlir::Value > shift) |
mlir::Value | createShape (mlir::Location loc, const fir::ExtendedValue &exv) |
mlir::Value | createSlice (mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path) |
mlir::Value | createBox (mlir::Location loc, const fir::ExtendedValue &exv, bool isPolymorphic=false, bool isAssumedType=false) |
mlir::Value | createBox (mlir::Location loc, mlir::Type boxType, mlir::Value addr, mlir::Value shape, mlir::Value slice, llvm::ArrayRef< mlir::Value > lengths, mlir::Value tdesc) |
mlir::Value | createBool (mlir::Location loc, bool b) |
Create constant i1 with value 1. if b is true or 0. otherwise. | |
IfBuilder | genIfOp (mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion) |
IfBuilder | genIfThen (mlir::Location loc, mlir::Value cdt) |
IfBuilder | genIfThenElse (mlir::Location loc, mlir::Value cdt) |
mlir::Value | genNot (mlir::Location loc, mlir::Value boolean) |
mlir::Value | genIsNotNullAddr (mlir::Location loc, mlir::Value addr) |
Generate code testing addr is not a null address. | |
mlir::Value | genIsNullAddr (mlir::Location loc, mlir::Value addr) |
Generate code testing addr is a null address. | |
mlir::Value | genExtentFromTriplet (mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type) |
mlir::Value | genAbsentOp (mlir::Location loc, mlir::Type argTy) |
void | setFastMathFlags (mlir::arith::FastMathFlags flags) |
void | setFastMathFlags (Fortran::common::MathOptionsBase options) |
mlir::arith::FastMathFlags | getFastMathFlags () const |
Get current FastMathFlags value. | |
std::string | getFastMathFlagsString () |
void | setIntegerOverflowFlags (mlir::arith::IntegerOverflowFlags flags) |
mlir::arith::IntegerOverflowFlags | getIntegerOverflowFlags () const |
Get current IntegerOverflowFlags value. | |
void | setComplexDivisionToRuntimeFlag (bool flag) |
bool | getComplexDivisionToRuntimeFlag () const |
Get current ComplexDivisionToRuntimeFlag value. | |
LLVM_DUMP_METHOD void | dumpFunc () |
Dump the current function. (debug) | |
void | notifyOperationInserted (mlir::Operation *op, mlir::OpBuilder::InsertPoint previous) override |
FirOpBuilder hook for creating new operation. | |
mlir::DataLayout & | getDataLayout () |
Construct a data layout on demand and return it. | |
template<typename OpTy > | |
mlir::Value | createUnsigned (mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right) |
mlir::Value | genPtrCompare (mlir::Location loc, mlir::arith::CmpIPredicate predicate, mlir::Value ptr1, mlir::Value ptr2) |
Compare two pointer-like values using the given predicate. | |
Static Public Member Functions | |
static mlir::Value | genTempDeclareOp (fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value memref, llvm::StringRef name, mlir::Value shape, llvm::ArrayRef< mlir::Value > typeParams, fir::FortranVariableFlagsAttr attrs) |
static mlir::func::FuncOp | getNamedFunction (mlir::ModuleOp module, const mlir::SymbolTable *symbolTable, llvm::StringRef name) |
static mlir::func::FuncOp | getNamedFunction (mlir::ModuleOp module, const mlir::SymbolTable *symbolTable, mlir::SymbolRefAttr symbol) |
static fir::GlobalOp | getNamedGlobal (mlir::ModuleOp module, const mlir::SymbolTable *symbolTable, llvm::StringRef name) |
static mlir::func::FuncOp | createFunction (mlir::Location loc, mlir::ModuleOp module, llvm::StringRef name, mlir::FunctionType ty, mlir::SymbolTable *) |
Extends the MLIR OpBuilder to provide methods for building common FIR patterns.
mlir::Value fir::FirOpBuilder::allocateLocal | ( | mlir::Location | loc, |
mlir::Type | ty, | ||
llvm::StringRef | uniqName, | ||
llvm::StringRef | name, | ||
bool | pinned, | ||
llvm::ArrayRef< mlir::Value > | shape, | ||
llvm::ArrayRef< mlir::Value > | lenParams, | ||
bool | asTarget = false |
||
) |
Create a slot for a local on the stack. Besides the variable's type and shape, it may be given name, pinned, or target attributes.
Allocate a local variable. A local variable ought to have a name in the source code.
mlir::Value fir::FirOpBuilder::convertWithSemantics | ( | mlir::Location | loc, |
mlir::Type | toTy, | ||
mlir::Value | val, | ||
bool | allowCharacterConversion = false , |
||
bool | allowRebox = false |
||
) |
The LHS and RHS are not always in agreement in terms of type. In some cases, the disagreement is between COMPLEX and other scalar types. In that case, the conversion must insert (extract) out of a COMPLEX value to have the proper semantics and be strongly typed. E.g., converting an integer (real) to a complex, the real part is filled using the integer (real) after type conversion and the imaginary part is zero.
mlir::ArrayAttr fir::FirOpBuilder::create2DI64ArrayAttr | ( | llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > & | intData | ) |
Create a two dimensional ArrayAttr containing integer data as IntegerAttrs, effectively: ArrayAttr<ArrayAttr<IntegerAttr>>>.
mlir::Value fir::FirOpBuilder::createAllOnesInteger | ( | mlir::Location | loc, |
mlir::Type | integerType | ||
) |
Create an integer of integerType
where all the bits have been set to ones. Safe to use regardless of integerType bitwidth.
std::pair< mlir::Value, bool > fir::FirOpBuilder::createAndDeclareTemp | ( | mlir::Location | loc, |
mlir::Type | baseType, | ||
mlir::Value | shape, | ||
llvm::ArrayRef< mlir::Value > | extents, | ||
llvm::ArrayRef< mlir::Value > | typeParams, | ||
const std::function< decltype(genTempDeclareOp)> & | genDeclare, | ||
mlir::Value | polymorphicMold, | ||
bool | useStack, | ||
llvm::StringRef | tmpName | ||
) |
Create a temporary with the given baseType
, shape
, extents
and typeParams
. An optional polymorphicMold
specifies the entity which dynamic type has to be used for the allocation. genDeclare
callback generates a declare operation for the created temporary. FIR passes may use genTempDeclareOp() function above that creates fir.declare. HLFIR passes may provide their own callback that generates hlfir.declare. Some passes may provide a callback that just passes through the base of the temporary. If useStack
is true, the function will try to do the allocation in stack memory (which is not always possible currently). The first return value is the base of the temporary object, which may be !fir.ref<!fir.array<>> or !fir.box/class<>. The second return value is true, if the actual allocation was done in heap memory.
mlir::Value fir::FirOpBuilder::createBox | ( | mlir::Location | loc, |
const fir::ExtendedValue & | exv, | ||
bool | isPolymorphic = false , |
||
bool | isAssumedType = false |
||
) |
Create a boxed value (Fortran descriptor) to be passed to the runtime. exv
is an extended value holding a memory reference to the object that must be boxed. This function will crash if provided something that is not a memory reference type. Array entities are boxed with a shape and possibly a shift. Character entities are boxed with a LEN parameter.
mlir::Value fir::FirOpBuilder::createConvertWithVolatileCast | ( | mlir::Location | loc, |
mlir::Type | toTy, | ||
mlir::Value | val | ||
) |
Create a fir.convert op with a volatile cast if the source value's type does not match the target type's volatility.
|
inline |
Determine if the named function is already in the module. Return the instance if found, otherwise add a new named function to the module.
fir::GlobalOp fir::FirOpBuilder::createGlobal | ( | mlir::Location | loc, |
mlir::Type | type, | ||
llvm::StringRef | name, | ||
mlir::StringAttr | linkage = {} , |
||
mlir::Attribute | value = {} , |
||
bool | isConst = false , |
||
bool | isTarget = false , |
||
cuf::DataAttributeAttr | dataAttr = {} |
||
) |
Create a global value.
Create a global variable in the (read-only) data section. A global variable must have a unique name to identify and reference it.
mlir::Value fir::FirOpBuilder::createIntegerConstant | ( | mlir::Location | loc, |
mlir::Type | integerType, | ||
std::int64_t | i | ||
) |
Create an integer constant of type type
and value i
. Should not be used with negative values with integer types of more than 64 bits.
|
inline |
Create -1 constant of integerType
. Safe to use regardless of integerType bitwidth.
mlir::Value fir::FirOpBuilder::createNullConstant | ( | mlir::Location | loc, |
mlir::Type | ptrType = {} |
||
) |
Create a null constant memory reference of type ptrType
. If ptrType
is not provided, !fir.ref<none> type will be used.
mlir::func::FuncOp fir::FirOpBuilder::createRuntimeFunction | ( | mlir::Location | loc, |
llvm::StringRef | name, | ||
mlir::FunctionType | ty, | ||
bool | isIO = false |
||
) |
mlir::Value fir::FirOpBuilder::createShape | ( | mlir::Location | loc, |
const fir::ExtendedValue & | exv | ||
) |
Create one of the shape ops given an extended value. For a boxed value, this may create a fir.shift
op.
mlir::Value fir::FirOpBuilder::createSlice | ( | mlir::Location | loc, |
const fir::ExtendedValue & | exv, | ||
mlir::ValueRange | triples, | ||
mlir::ValueRange | path | ||
) |
Create a slice op extended value. The value to be sliced, exv
, must be an array.
void fir::FirOpBuilder::createStoreWithConvert | ( | mlir::Location | loc, |
mlir::Value | val, | ||
mlir::Value | addr | ||
) |
Create a fir.store of val
into addr
. A lazy conversion of val
to the element type of addr
is created if needed.
mlir::Value fir::FirOpBuilder::createTemporary | ( | mlir::Location | loc, |
mlir::Type | type, | ||
llvm::StringRef | name = {} , |
||
mlir::ValueRange | shape = {} , |
||
mlir::ValueRange | lenParams = {} , |
||
llvm::ArrayRef< mlir::NamedAttribute > | attrs = {} , |
||
std::optional< Fortran::common::CUDADataAttr > | cudaAttr = std::nullopt |
||
) |
Create a temporary. A temp is allocated using fir.alloca
and can be read and written using fir.load
and fir.store
, resp. The temporary can be given a name via a front-end Symbol
or a StringRef
.
Create a temporary variable on the stack. Anonymous temporaries have no name
value. Temporaries do not require a uniqued name.
mlir::Value fir::FirOpBuilder::createTemporaryAlloc | ( | mlir::Location | loc, |
mlir::Type | type, | ||
llvm::StringRef | name, | ||
mlir::ValueRange | lenParams = {} , |
||
mlir::ValueRange | shape = {} , |
||
llvm::ArrayRef< mlir::NamedAttribute > | attrs = {} , |
||
std::optional< Fortran::common::CUDADataAttr > | cudaAttr = std::nullopt |
||
) |
Create a temporary using fir.alloca
. This function does not hoist. It is the callers responsibility to set the insertion point if hoisting is required.
|
inline |
Convert operands &/or result from/to unsigned so that the operation only receives/produces signless operands.
mlir::Value fir::FirOpBuilder::genAbsentOp | ( | mlir::Location | loc, |
mlir::Type | argTy | ||
) |
Create an AbsentOp of argTy
type and handle special cases, such as Character Procedure Tuple arguments.
mlir::Value fir::FirOpBuilder::genExtentFromTriplet | ( | mlir::Location | loc, |
mlir::Value | lb, | ||
mlir::Value | ub, | ||
mlir::Value | step, | ||
mlir::Type | type | ||
) |
Compute the extent of (lb:ub:step) as max((ub-lb+step)/step, 0). See Fortran 2018 9.5.3.3.2 section for more details.
|
inline |
Create an IfOp and returns an IfBuilder that can generate the else/then bodies.
|
inline |
Create an IfOp with no "else" region, and no result values. Usage: genIfThen(loc, cdt).genThen(lambda).end();
|
inline |
Create an IfOp with an "else" region, and no result values. Usage: genIfThenElse(loc, cdt).genThen(lambda).genElse(lambda).end();
void fir::FirOpBuilder::genStackRestore | ( | mlir::Location | loc, |
mlir::Value | stackPointer | ||
) |
Create an LLVM stack restore intrinsic op. stackPointer should be a value previously returned from genStackSave.
mlir::Value fir::FirOpBuilder::genStackSave | ( | mlir::Location | loc | ) |
Create an LLVM stack save intrinsic op. Returns the saved stack pointer. The stack address space is fetched from the data layout of the current module.
|
static |
Sample genDeclare callback for createArrayTemp() below. It creates fir.declare operation using the given operands. memref
is the base of the allocated temporary, which may be !fir.ref<!fir.array<>> or !fir.box/class<>.
mlir::Block * fir::FirOpBuilder::getAllocaBlock | ( | ) |
Get the block for adding Allocas.
Get the block for adding Allocas. If OpenMP is enabled then get the the alloca block from an Operation which can be Outlined. Otherwise use the entry block of the current Function
|
inline |
Stringify FastMathFlags set in a way that the string may be used for mangling a function name. If FastMathFlags are set to 'none', then the result is an empty string.
|
inline |
Get the integer type whose bit width corresponds to the width of pointer types, or is bigger.
|
inline |
Get a function by name. If the function exists in the current module, it is returned. Otherwise, a null FuncOp is returned.
|
inline |
Get a function by symbol name. The result will be null if there is no function with the given symbol in the module.
mlir::Value fir::FirOpBuilder::loadIfRef | ( | mlir::Location | loc, |
mlir::Value | val | ||
) |
Create a fir.load if val
is a reference or pointer type. Return the result of the load if it was created, otherwise return val
|
inline |
Set ComplexDivisionToRuntimeFlag value. If set to true, complex number division is lowered to a runtime function by this builder.
void fir::FirOpBuilder::setFastMathFlags | ( | Fortran::common::MathOptionsBase | options | ) |
Set default FastMathFlags value from the passed MathOptionsBase config.
|
inline |
Set default FastMathFlags value for all operations supporting mlir::arith::FastMathAttr that will be created by this builder.
|
inline |
Set default IntegerOverflowFlags value for all operations supporting mlir::arith::IntegerOverflowFlagsAttr that will be created by this builder.