FLANG
Classes | Public Member Functions | Static Public Member Functions | List of all members
fir::FirOpBuilder Class Reference

#include <flang/Optimizer/Builder/FIRBuilder.h>

Inheritance diagram for fir::FirOpBuilder:

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::KindMappinggetKindMap ()
 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)
 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.
 
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.
 
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::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.
 
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)
 

Static Public Member Functions

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 *)
 

Detailed Description

Extends the MLIR OpBuilder to provide methods for building common FIR patterns.

Member Function Documentation

◆ allocateLocal()

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.

◆ convertWithSemantics()

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.

◆ create2DI64ArrayAttr()

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>>>.

◆ createAllOnesInteger()

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.

◆ createBox()

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.

◆ createFunction()

mlir::func::FuncOp fir::FirOpBuilder::createFunction ( mlir::Location  loc,
llvm::StringRef  name,
mlir::FunctionType  ty 
)
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.

◆ createGlobal()

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.

◆ createIntegerConstant()

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.

◆ createMinusOneInteger()

mlir::Value fir::FirOpBuilder::createMinusOneInteger ( mlir::Location  loc,
mlir::Type  integerType 
)
inline

Create -1 constant of integerType. Safe to use regardless of integerType bitwidth.

◆ createNullConstant()

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.

◆ createShape()

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.

◆ createSlice()

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.

◆ createStoreWithConvert()

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.

◆ createTemporary()

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.

◆ createTemporaryAlloc()

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.

◆ createUnsigned()

template<typename OpTy >
mlir::Value fir::FirOpBuilder::createUnsigned ( mlir::Location  loc,
mlir::Type  resultType,
mlir::Value  left,
mlir::Value  right 
)
inline

Convert operands &/or result from/to unsigned so that the operation only receives/produces signless operands.

◆ genAbsentOp()

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.

◆ genExtentFromTriplet()

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.

◆ genIfOp()

IfBuilder fir::FirOpBuilder::genIfOp ( mlir::Location  loc,
mlir::TypeRange  results,
mlir::Value  cdt,
bool  withElseRegion 
)
inline

Create an IfOp and returns an IfBuilder that can generate the else/then bodies.

◆ genIfThen()

IfBuilder fir::FirOpBuilder::genIfThen ( mlir::Location  loc,
mlir::Value  cdt 
)
inline

Create an IfOp with no "else" region, and no result values. Usage: genIfThen(loc, cdt).genThen(lambda).end();

◆ genIfThenElse()

IfBuilder fir::FirOpBuilder::genIfThenElse ( mlir::Location  loc,
mlir::Value  cdt 
)
inline

Create an IfOp with an "else" region, and no result values. Usage: genIfThenElse(loc, cdt).genThen(lambda).genElse(lambda).end();

◆ genStackRestore()

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.

◆ 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.

◆ getAllocaBlock()

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

◆ getFastMathFlagsString()

std::string fir::FirOpBuilder::getFastMathFlagsString ( )
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.

◆ getIntPtrType()

mlir::Type fir::FirOpBuilder::getIntPtrType ( )
inline

Get the integer type whose bit width corresponds to the width of pointer types, or is bigger.

◆ getNamedFunction() [1/2]

mlir::func::FuncOp fir::FirOpBuilder::getNamedFunction ( llvm::StringRef  name)
inline

Get a function by name. If the function exists in the current module, it is returned. Otherwise, a null FuncOp is returned.

◆ getNamedFunction() [2/2]

mlir::func::FuncOp fir::FirOpBuilder::getNamedFunction ( mlir::SymbolRefAttr  symbol)
inline

Get a function by symbol name. The result will be null if there is no function with the given symbol in the module.

◆ loadIfRef()

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

◆ setFastMathFlags() [1/2]

void fir::FirOpBuilder::setFastMathFlags ( Fortran::common::MathOptionsBase  options)

Set default FastMathFlags value from the passed MathOptionsBase config.

◆ setFastMathFlags() [2/2]

void fir::FirOpBuilder::setFastMathFlags ( mlir::arith::FastMathFlags  flags)
inline

Set default FastMathFlags value for all operations supporting mlir::arith::FastMathAttr that will be created by this builder.

◆ setIntegerOverflowFlags()

void fir::FirOpBuilder::setIntegerOverflowFlags ( mlir::arith::IntegerOverflowFlags  flags)
inline

Set default IntegerOverflowFlags value for all operations supporting mlir::arith::IntegerOverflowFlagsAttr that will be created by this builder.


The documentation for this class was generated from the following files: