16#ifndef FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
17#define FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
19#include "flang/Optimizer/Dialect/FIRBoxUtils.h"
20#include "flang/Optimizer/Dialect/FIROps.h"
21#include "flang/Optimizer/Dialect/FIROpsSupport.h"
22#include "flang/Optimizer/Dialect/FIRType.h"
23#include "flang/Optimizer/Dialect/Support/FIRContext.h"
24#include "flang/Optimizer/Dialect/Support/KindMapping.h"
27#include "mlir/IR/Builders.h"
28#include "mlir/IR/BuiltinOps.h"
29#include "llvm/ADT/DenseMap.h"
50 return builder.getI64Type();
59class FirOpBuilder :
public mlir::OpBuilder,
public mlir::OpBuilder::Listener {
62 mlir::SymbolTable *symbolTable =
nullptr)
63 : OpBuilder{op,
this}, kindMap{std::move(kindMap)},
64 symbolTable{symbolTable} {
65 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
72 mlir::SymbolTable *symbolTable =
nullptr)
73 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)},
74 symbolTable{symbolTable} {
77 explicit FirOpBuilder(mlir::OpBuilder &builder, mlir::ModuleOp mod)
78 : OpBuilder(builder), OpBuilder::Listener(),
84 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)} {
86 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
92 FirOpBuilder(mlir::OpBuilder &builder, mlir::Operation *op)
96 FirOpBuilder(
const FirOpBuilder &other)
97 : OpBuilder(other), OpBuilder::Listener(), kindMap{other.kindMap},
98 fastMathFlags{other.fastMathFlags},
99 integerOverflowFlags{other.integerOverflowFlags},
100 symbolTable{other.symbolTable} {
104 FirOpBuilder(FirOpBuilder &&other)
105 : OpBuilder(other), OpBuilder::Listener(),
106 kindMap{std::move(other.kindMap)}, fastMathFlags{other.fastMathFlags},
107 integerOverflowFlags{other.integerOverflowFlags},
108 symbolTable{other.symbolTable} {
113 mlir::Region &
getRegion() {
return *getBlock()->getParent(); }
117 return getRegion().getParentOfType<mlir::ModuleOp>();
122 return getRegion().getParentOfType<mlir::func::FuncOp>();
133 return getIntegerType(
145 bool allowCharacterConversion =
false,
146 bool allowRebox =
false);
157 mlir::Type
getRefType(mlir::Type eleTy,
bool isVolatile =
false);
171 return mlir::SymbolRefAttr::get(getContext(), str);
177 fir::BoxProcType getBoxProcType(mlir::FunctionType funcTy) {
178 return fir::BoxProcType::get(getContext(), funcTy);
198 mlir::Type integerType) {
204 llvm::APFloat::integerPart val);
208 const llvm::APFloat &val);
223 llvm::StringRef uniqName, llvm::StringRef name,
226 bool asTarget =
false);
228 llvm::StringRef uniqName, llvm::StringRef name,
231 bool asTarget =
false);
242 mlir::Location loc, mlir::Type type, llvm::StringRef name,
243 mlir::ValueRange lenParams = {}, mlir::ValueRange shape = {},
244 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
245 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
251 mlir::Location loc, mlir::Type type, llvm::StringRef name = {},
252 mlir::ValueRange shape = {}, mlir::ValueRange lenParams = {},
253 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
254 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
258 mlir::ValueRange shape) {
268 llvm::StringRef name,
269 llvm::ArrayRef<mlir::NamedAttribute> attrs) {
276 llvm::StringRef name = {}, mlir::ValueRange shape = {},
277 mlir::ValueRange lenParams = {},
278 llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
285 mlir::Location loc, mlir::Value memref,
286 llvm::StringRef name, mlir::Value shape,
287 llvm::ArrayRef<mlir::Value> typeParams,
288 fir::FortranVariableFlagsAttr attrs);
307 mlir::Location loc, mlir::Type baseType, mlir::Value shape,
308 llvm::ArrayRef<mlir::Value> extents,
309 llvm::ArrayRef<mlir::Value> typeParams,
311 mlir::Value polymorphicMold,
bool useStack, llvm::StringRef tmpName);
313 std::pair<mlir::Value, bool>
318 mlir::Value polymorphicMold,
bool useStack =
false,
319 llvm::StringRef tmpName =
".tmp.array") {
321 genDeclare, polymorphicMold, useStack, tmpName);
334 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
335 llvm::StringRef name,
336 mlir::StringAttr linkage = {},
337 mlir::Attribute value = {},
bool isConst =
false,
338 bool isTarget =
false,
339 cuf::DataAttributeAttr dataAttr = {},
340 bool setDefaultAlignment =
true);
342 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
343 llvm::StringRef name,
bool isConst,
bool isTarget,
344 std::function<
void(FirOpBuilder &)> bodyBuilder,
345 mlir::StringAttr linkage = {},
346 cuf::DataAttributeAttr dataAttr = {},
347 bool setDefaultAlignment =
true);
351 llvm::StringRef name,
352 mlir::StringAttr linkage = {},
353 mlir::Attribute value = {}) {
354 return createGlobal(loc, type, name, linkage, value,
true,
360 llvm::StringRef name,
361 std::function<
void(FirOpBuilder &)> bodyBuilder,
362 mlir::StringAttr linkage = {}) {
364 bodyBuilder, linkage);
369 llvm::StringRef
string);
371 std::pair<fir::TypeInfoOp, mlir::OpBuilder::InsertPoint>
372 createTypeInfoOp(mlir::Location loc, fir::RecordType recordType,
373 fir::RecordType parentType);
379 static mlir::StringAttr createCommonLinkage(mlir::MLIRContext *context) {
380 return mlir::StringAttr::get(context,
"common");
382 mlir::StringAttr createCommonLinkage() {
383 return createCommonLinkage(getContext());
386 mlir::StringAttr createExternalLinkage() {
return getStringAttr(
"external"); }
388 mlir::StringAttr createInternalLinkage() {
return getStringAttr(
"internal"); }
390 mlir::StringAttr createLinkOnceLinkage() {
return getStringAttr(
"linkonce"); }
392 mlir::StringAttr createLinkOnceODRLinkage() {
393 return getStringAttr(
"linkonce_odr");
396 mlir::StringAttr createWeakLinkage() {
return getStringAttr(
"weak"); }
403 static mlir::func::FuncOp
404 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
405 llvm::StringRef name);
412 static mlir::func::FuncOp
413 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
414 mlir::SymbolRefAttr symbol);
416 fir::GlobalOp getNamedGlobal(llvm::StringRef name) {
420 static fir::GlobalOp getNamedGlobal(mlir::ModuleOp module,
421 const mlir::SymbolTable *symbolTable,
422 llvm::StringRef name);
425 mlir::Value
createConvert(mlir::Location loc, mlir::Type toTy,
444 mlir::Value
loadIfRef(mlir::Location loc, mlir::Value val);
449 mlir::FunctionType ty) {
454 mlir::ModuleOp module,
455 llvm::StringRef name,
456 mlir::FunctionType ty,
457 mlir::SymbolTable *);
464 llvm::StringRef name,
465 mlir::FunctionType ty,
487 mlir::ValueRange triples, mlir::ValueRange path);
497 unsigned corank = 0);
499 mlir::Value
createBox(mlir::Location loc, mlir::Type boxType,
500 mlir::Value addr, mlir::Value shape, mlir::Value slice,
518 IfBuilder(fir::IfOp ifOp, FirOpBuilder &builder)
519 : ifOp{ifOp}, builder{builder} {}
520 template <
typename CC>
521 IfBuilder &genThen(CC func) {
522 builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
526 template <
typename CC>
527 IfBuilder &genElse(CC func) {
528 assert(!ifOp.getElseRegion().empty() &&
"must have else region");
529 builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
533 void end() { builder.setInsertionPointAfter(ifOp); }
538 return ifOp.getResults();
541 fir::IfOp &getIfOp() {
return ifOp; };
551 mlir::Value cdt,
bool withElseRegion) {
552 auto op = fir::IfOp::create(*
this, loc, results, cdt, withElseRegion);
559 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
false);
566 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
true);
570 mlir::Value genNot(mlir::Location loc, mlir::Value
boolean) {
571 return mlir::arith::CmpIOp::create(*
this, loc,
572 mlir::arith::CmpIPredicate::eq,
boolean,
580 mlir::Value
genIsNullAddr(mlir::Location loc, mlir::Value addr);
585 mlir::Value ub, mlir::Value step,
586 mlir::Type type,
bool fold =
false);
590 mlir::Value
genAbsentOp(mlir::Location loc, mlir::Type argTy);
596 fastMathFlags = flags;
612 if (flags == mlir::arith::FastMathFlags::none)
615 std::string fmfString{mlir::arith::stringifyFastMathFlags(flags)};
616 std::replace(fmfString.begin(), fmfString.end(),
',',
'_');
624 integerOverflowFlags = flags;
629 return integerOverflowFlags;
635 complexDivisionToRuntimeFlag = flag;
640 return complexDivisionToRuntimeFlag;
645 fpMaxminBehavior = mode;
648 return fpMaxminBehavior;
656 mlir::OpBuilder::InsertPoint previous)
override {
658 if (previous.isSet())
660 setCommonAttributes(op);
668 template <
typename OpTy>
670 mlir::Value left, mlir::Value right) {
671 if (!resultType.isIntOrFloat())
672 return OpTy::create(*
this, loc, resultType, left, right);
673 mlir::Type signlessType = mlir::IntegerType::get(
674 getContext(), resultType.getIntOrFloatBitWidth(),
675 mlir::IntegerType::SignednessSemantics::Signless);
676 mlir::Type opResType = resultType;
677 if (left.getType().isUnsignedInteger()) {
679 opResType = signlessType;
681 if (right.getType().isUnsignedInteger()) {
683 opResType = signlessType;
685 mlir::Value result = OpTy::create(*
this, loc, opResType, left, right);
686 if (resultType.isUnsignedInteger())
693 mlir::arith::CmpIPredicate predicate,
694 mlir::Value ptr1, mlir::Value ptr2) {
697 return mlir::arith::CmpIOp::create(*
this, loc, predicate, ptr1, ptr2);
703 void setCommonAttributes(mlir::Operation *op)
const;
709 mlir::arith::FastMathFlags fastMathFlags{};
717 Fortran::common::FPMaxminBehavior::Legacy};
721 mlir::arith::IntegerOverflowFlags integerOverflowFlags{};
725 bool complexDivisionToRuntimeFlag =
true;
729 mlir::SymbolTable *symbolTable =
nullptr;
734 std::unique_ptr<mlir::DataLayout> dataLayout =
nullptr;
751mlir::Value
readCharLen(fir::FirOpBuilder &builder, mlir::Location loc,
752 const fir::ExtendedValue &box);
755mlir::Value
readExtent(fir::FirOpBuilder &builder, mlir::Location loc,
756 const fir::ExtendedValue &box,
unsigned dim);
761mlir::Value
readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc,
762 const fir::ExtendedValue &box,
unsigned dim,
763 mlir::Value defaultValue);
766llvm::SmallVector<mlir::Value>
readExtents(fir::FirOpBuilder &builder,
768 const fir::BoxValue &box);
775fir::ExtendedValue
readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
776 const fir::BoxValue &box);
780llvm::SmallVector<mlir::Value>
782 const fir::ExtendedValue &exv);
787llvm::SmallVector<mlir::Value>
797 llvm::StringRef
string);
801std::string
uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name);
805llvm::SmallVector<mlir::Value>
createExtents(fir::FirOpBuilder &builder,
807 fir::SequenceType seqTy);
816mlir::Value
locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type);
826 mlir::Value component);
836 const fir::ExtendedValue &array,
837 mlir::Value element);
844 fir::FirOpBuilder &builder, mlir::Location loc,
845 const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice);
850 const fir::ExtendedValue &lhs,
851 const fir::ExtendedValue &rhs,
852 bool needFinalization =
false,
853 bool isTemporaryLHS =
false,
854 mlir::ArrayAttr accessGroups = {});
860 const fir::ExtendedValue &lhs,
861 const fir::ExtendedValue &rhs,
862 bool needFinalization =
false,
863 bool isTemporaryLHS =
false);
875 fir::ArrayLoadOp arrLoad,
876 llvm::ArrayRef<mlir::Value> path,
877 llvm::ArrayRef<mlir::Value> substring);
879 fir::SequenceType seqTy, mlir::Value memref,
880 llvm::ArrayRef<mlir::Value> typeParams,
881 llvm::ArrayRef<mlir::Value> path,
882 llvm::ArrayRef<mlir::Value> substring);
886mlir::Value
createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
891mlir::Value
createOneValue(fir::FirOpBuilder &builder, mlir::Location loc,
900mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
901 mlir::Value lb, mlir::Value ub);
902mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
903 mlir::Value lb, mlir::Value ub, mlir::Value zero,
907mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
909mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
910 mlir::Value value, mlir::Value zero);
914 mlir::Value cPtr, mlir::Type ty);
918 mlir::Location loc, mlir::Value cPtr);
922fir::BoxValue
createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
923 const fir::ExtendedValue &exv,
924 unsigned corank = 0);
932mlir::Value
createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type,
938llvm::SmallVector<mlir::Value>
939elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
941llvm::SmallVector<mlir::Value>
942elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
954 mlir::ValueRange extents2);
956uint64_t getGlobalAddressSpace(mlir::DataLayout *dataLayout);
958uint64_t getProgramAddressSpace(mlir::DataLayout *dataLayout);
971 fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents);
977 fir::AllocaOp alloc,
const mlir::DataLayout *dl);
990 mlir::Location loc, mlir::Value box,
991 mlir::Value newAddr);
994std::optional<mlir::Value>
996 mlir::Value lhsRef, mlir::Value rhsRef);
999std::optional<mlir::Value>
1001 mlir::Value lhsRef, mlir::Value rhsRef);
Definition MathOptionsBase.h:22
Definition BoxValue.h:125
Definition BoxValue.h:293
Definition BoxValue.h:480
Definition FIRBuilder.h:516
mlir::Operation::result_range getResults()
End the IfOp and return the results if any.
Definition FIRBuilder.h:536
Definition FIRBuilder.h:59
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:565
fir::StringLitOp createStringLitOp(mlir::Location loc, llvm::StringRef string)
Convert a StringRef string into a fir::StringLitOp.
Definition FIRBuilder.cpp:643
mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type, bool fold=false)
Definition FIRBuilder.cpp:882
void genStackRestore(mlir::Location loc, mlir::Value stackPointer)
Definition FIRBuilder.cpp:444
mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str)
Wrap str to a SymbolRefAttr.
Definition FIRBuilder.h:170
mlir::Value createRealZeroConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with a value zero.
Definition FIRBuilder.h:211
void setFPMaxminBehavior(Fortran::common::FPMaxminBehavior mode)
Setter/getter for fpMaxminBehavior.
Definition FIRBuilder.h:644
mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path)
Definition FIRBuilder.cpp:709
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition FIRBuilder.cpp:623
IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion)
Definition FIRBuilder.h:550
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is a null address.
Definition FIRBuilder.cpp:867
mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol)
Definition FIRBuilder.h:409
mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType, llvm::APFloat::integerPart val)
Create a real constant from an integer value.
Definition FIRBuilder.cpp:181
mlir::Type getCharacterLengthType()
Get character length type.
Definition FIRBuilder.h:163
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)
Definition FIRBuilder.cpp:333
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:558
mlir::Value genStackSave(mlir::Location loc)
Definition FIRBuilder.cpp:438
mlir::Value genShape(mlir::Location loc, const fir::AbstractArrayBox &arr)
Construct one of the two forms of shape op from an array box.
Definition FIRBuilder.cpp:675
const fir::KindMapping & getKindMap()
Get a reference to the kind map.
Definition FIRBuilder.h:126
mlir::Type getRefType(mlir::Type eleTy, bool isVolatile=false)
Safely create a reference type to the type eleTy.
Definition FIRBuilder.cpp:112
mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.cpp:170
mlir::ModuleOp getModule()
Get the current Module.
Definition FIRBuilder.h:116
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)
Definition FIRBuilder.cpp:396
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.
Definition FIRBuilder.h:350
mlir::Value createMinusOneInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.h:197
mlir::Value createVolatileCast(mlir::Location loc, bool isVolatile, mlir::Value value)
Cast value to have isVolatile volatility.
Definition FIRBuilder.cpp:593
void setComplexDivisionToRuntimeFlag(bool flag)
Definition FIRBuilder.h:634
mlir::IntegerType getDefaultIntegerType()
Get the default integer type.
Definition FIRBuilder.h:132
mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType={})
Definition FIRBuilder.cpp:142
void setFastMathFlags(mlir::arith::FastMathFlags flags)
Definition FIRBuilder.h:595
LLVM_DUMP_METHOD void dumpFunc()
Dump the current function. (debug)
Definition FIRBuilder.cpp:849
mlir::ArrayAttr create2DI64ArrayAttr(llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData)
Definition FIRBuilder.cpp:323
mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false)
Definition FIRBuilder.cpp:520
mlir::SymbolTable * getMLIRSymbolTable()
Get func.func/fir.global symbol table attached to this builder if any.
Definition FIRBuilder.h:129
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.
Definition FIRBuilder.h:314
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.
Definition FIRBuilder.h:692
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is not a null address.
Definition FIRBuilder.cpp:861
mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val)
Cast the input value to IndexType.
Definition FIRBuilder.h:469
void createStoreWithConvert(mlir::Location loc, mlir::Value val, mlir::Value addr)
Definition FIRBuilder.cpp:628
void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags)
Definition FIRBuilder.h:623
mlir::func::FuncOp createRuntimeFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty, bool isIO=false)
Definition FIRBuilder.cpp:56
mlir::Value createBox(mlir::Location loc, const fir::ExtendedValue &exv, bool isPolymorphic=false, bool isAssumedType=false, unsigned corank=0)
Definition FIRBuilder.cpp:760
mlir::Region & getRegion()
Get the current Region of the insertion point.
Definition FIRBuilder.h:113
void notifyOperationInserted(mlir::Operation *op, mlir::OpBuilder::InsertPoint previous) override
FirOpBuilder hook for creating new operation.
Definition FIRBuilder.h:655
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)
Definition FIRBuilder.cpp:424
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition FIRBuilder.h:400
std::string getFastMathFlagsString()
Definition FIRBuilder.h:610
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right)
Definition FIRBuilder.h:669
bool getComplexDivisionToRuntimeFlag() const
Get current ComplexDivisionToRuntimeFlag value.
Definition FIRBuilder.h:639
mlir::Value createBool(mlir::Location loc, bool b)
Create constant i1 with value 1. if b is true or 0. otherwise.
Definition FIRBuilder.h:504
mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const
Get current IntegerOverflowFlags value.
Definition FIRBuilder.h:628
mlir::func::FuncOp getFunction()
Get the current Function.
Definition FIRBuilder.h:121
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)
Definition FIRBuilder.cpp:357
mlir::Type getRealType(int kind)
Get the mlir float type that implements Fortran REAL(kind).
Definition FIRBuilder.cpp:122
mlir::Block * getAllocaBlock()
Get the block for adding Allocas.
Definition FIRBuilder.cpp:281
mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank=1)
Create a sequence of eleTy with rank dimensions of unknown size.
Definition FIRBuilder.cpp:117
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={}, bool setDefaultAlignment=true)
Create a global value.
Definition FIRBuilder.cpp:451
mlir::Value loadIfRef(mlir::Location loc, mlir::Value val)
Definition FIRBuilder.cpp:637
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.
Definition FIRBuilder.cpp:381
mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Definition FIRBuilder.cpp:603
mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:688
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)
Definition FIRBuilder.cpp:241
mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy)
Definition FIRBuilder.cpp:901
mlir::arith::FastMathFlags getFastMathFlags() const
Get current FastMathFlags value.
Definition FIRBuilder.h:604
mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType, std::int64_t i)
Definition FIRBuilder.cpp:148
mlir::Value createRealOneConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with value one.
Definition FIRBuilder.h:216
mlir::Block * getEntryBlock()
Get the entry block of the current Function.
Definition FIRBuilder.h:149
mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty)
Definition FIRBuilder.h:448
mlir::DataLayout & getDataLayout()
Construct a data layout on demand and return it.
Definition FIRBuilder.cpp:964
mlir::Value createTemporary(mlir::Location loc, mlir::Type type, mlir::ValueRange shape)
Create an unnamed and untracked temporary on the stack.
Definition FIRBuilder.h:257
mlir::Type getIntPtrType()
Definition FIRBuilder.h:167
Definition KindMapping.h:48
Definition BoxValue.h:362
FPMaxminBehavior
Definition FPMaxminBehavior.h:29
Definition BoxValue.h:447
fir::ExtendedValue componentToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value component)
Definition FIRBuilder.cpp:1319
mlir::Value genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value value)
Generate max(value, 0) where value is a scalar integer.
Definition FIRBuilder.cpp:1764
mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1684
void genScalarAssignment(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &lhs, const fir::ExtendedValue &rhs, bool needFinalization=false, bool isTemporaryLHS=false, mlir::ArrayAttr accessGroups={})
Definition FIRBuilder.cpp:1418
llvm::SmallVector< mlir::Value > deduceOptimalExtents(mlir::ValueRange extents1, mlir::ValueRange extents2)
Definition FIRBuilder.cpp:1922
fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv, unsigned corank=0)
Definition FIRBuilder.cpp:1856
mlir::Value getDescriptorWithNewBaseAddress(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box, mlir::Value newAddr)
Definition FIRBuilder.cpp:1992
mlir::Value createOneValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1703
mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim, mlir::Value defaultValue)
Definition FIRBuilder.cpp:1031
std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name)
Definition FIRBuilder.cpp:1233
llvm::SmallVector< mlir::Value > updateRuntimeExtentsForEmptyArrays(fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents)
Definition FIRBuilder.cpp:1949
llvm::SmallVector< mlir::Value > getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1129
fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location, llvm::StringRef string)
Definition FIRBuilder.cpp:1271
mlir::TupleType getRaggedArrayHeaderType(fir::FirOpBuilder &builder)
Definition FIRBuilder.cpp:1617
mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location)
Generate a string literal containing the file name and return its address.
Definition FIRBuilder.cpp:1253
mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type)
Generate a constant of the given type with the location line number.
Definition FIRBuilder.cpp:1263
std::optional< mlir::Value > genIndexBasedDisjointnessCheck(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value lhsRef, mlir::Value rhsRef)
Generate a index-based disjointness check.
Definition FIRBuilder.cpp:2014
mlir::Value readExtent(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim)
Read or get the extent in dimension dim of the array described by box.
Definition FIRBuilder.cpp:1000
mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box)
Definition FIRBuilder.cpp:975
void genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value mem)
Definition FIRBuilder.cpp:1987
std::optional< mlir::Value > genAddressBasedDisjointnessCheck(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value lhsRef, mlir::Value rhsRef)
Generate a address-based disjointness check.
Definition FIRBuilder.cpp:2067
mlir::Value genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr, mlir::Type ty)
Get the C address from a type(C_PTR/C_FUNPTR/C_DEVPTR) entity.
Definition FIRBuilder.cpp:1804
llvm::SmallVector< mlir::Value > readExtents(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Read extents from box.
Definition FIRBuilder.cpp:1061
std::optional< std::int64_t > getExtentFromTriplet(mlir::Value lb, mlir::Value ub, mlir::Value stride)
Get the integer constants of triplet and compute the extent.
Definition FIRBuilder.cpp:1724
mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr)
Get the C address value.
Definition FIRBuilder.cpp:1822
uint64_t getAllocaAddressSpace(const mlir::DataLayout *dataLayout)
Get the address space which should be used for allocas.
Definition FIRBuilder.cpp:1914
void setInternalLinkage(mlir::func::FuncOp)
Set internal linkage attribute on a function.
Definition FIRBuilder.cpp:1906
mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType)
Generate Null BoxProc for procedure pointer null initialization.
Definition FIRBuilder.cpp:1895
fir::ExtendedValue arraySectionElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice)
Definition FIRBuilder.cpp:1403
mlir::Value genLenOfCharacter(fir::FirOpBuilder &builder, mlir::Location loc, fir::ArrayLoadOp arrLoad, llvm::ArrayRef< mlir::Value > path, llvm::ArrayRef< mlir::Value > substring)
Definition FIRBuilder.cpp:1626
void genRecordAssignment(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &lhs, const fir::ExtendedValue &rhs, bool needFinalization=false, bool isTemporaryLHS=false)
Definition FIRBuilder.cpp:1563
mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type, mlir::Value)
Definition FIRBuilder.cpp:610
fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Definition FIRBuilder.cpp:1100
mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value lb, mlir::Value ub)
Definition FIRBuilder.cpp:1781
fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element)
Definition FIRBuilder.cpp:1373
llvm::SmallVector< mlir::Value > getNonDeferredLenParams(const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1151
llvm::SmallVector< mlir::Value > createExtents(fir::FirOpBuilder &builder, mlir::Location loc, fir::SequenceType seqTy)
Definition FIRBuilder.cpp:1293
mlir::Value genLifetimeStart(mlir::OpBuilder &builder, mlir::Location loc, fir::AllocaOp alloc, const mlir::DataLayout *dl)
Definition FIRBuilder.cpp:1975
Definition AbstractConverter.h:37
KindMapping getKindMapping(mlir::ModuleOp mod)
Definition FIRContext.cpp:43
mlir::Type getIntPtrType(mlir::OpBuilder &builder)
Get the integer type with a pointer size.
Definition FIRBuilder.h:47
void genDimInfoFromBox(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value box, llvm::SmallVectorImpl< mlir::Value > *lbounds, llvm::SmallVectorImpl< mlir::Value > *extents, llvm::SmallVectorImpl< mlir::Value > *strides)
Definition FIRBoxUtils.cpp:16
constexpr unsigned defaultArrayGlobalAlignment
Default alignment (in bytes) applied to array globals.
Definition FIRBuilder.h:45
bool isAssumedType(mlir::Type ty)
Definition FIRType.cpp:372
Definition AbstractConverter.h:32