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();
66class FirOpBuilder :
public mlir::OpBuilder,
public mlir::OpBuilder::Listener {
69 mlir::SymbolTable *symbolTable =
nullptr)
70 : OpBuilder{op,
this}, kindMap{std::move(kindMap)},
71 symbolTable{symbolTable} {
72 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
79 mlir::SymbolTable *symbolTable =
nullptr)
80 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)},
81 symbolTable{symbolTable} {
84 explicit FirOpBuilder(mlir::OpBuilder &builder, mlir::ModuleOp mod)
85 : OpBuilder(builder), OpBuilder::Listener(),
91 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)} {
93 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
99 FirOpBuilder(mlir::OpBuilder &builder, mlir::Operation *op)
103 FirOpBuilder(
const FirOpBuilder &other)
104 : OpBuilder(other), OpBuilder::Listener(), kindMap{other.kindMap},
105 fastMathFlags{other.fastMathFlags},
106 integerOverflowFlags{other.integerOverflowFlags},
107 symbolTable{other.symbolTable} {
111 FirOpBuilder(FirOpBuilder &&other)
112 : OpBuilder(other), OpBuilder::Listener(),
113 kindMap{std::move(other.kindMap)}, fastMathFlags{other.fastMathFlags},
114 integerOverflowFlags{other.integerOverflowFlags},
115 symbolTable{other.symbolTable} {
120 mlir::Region &
getRegion() {
return *getBlock()->getParent(); }
124 return getRegion().getParentOfType<mlir::ModuleOp>();
129 return getRegion().getParentOfType<mlir::func::FuncOp>();
144 return getIntegerType(
156 bool allowCharacterConversion =
false,
157 bool allowRebox =
false);
168 mlir::Type
getRefType(mlir::Type eleTy,
bool isVolatile =
false);
182 return mlir::SymbolRefAttr::get(getContext(), str);
188 fir::BoxProcType getBoxProcType(mlir::FunctionType funcTy) {
189 return fir::BoxProcType::get(getContext(), funcTy);
207 const llvm::APInt &value);
216 mlir::Type integerType) {
222 llvm::APFloat::integerPart val);
226 const llvm::APFloat &val);
241 llvm::StringRef uniqName, llvm::StringRef name,
244 bool asTarget =
false);
246 llvm::StringRef uniqName, llvm::StringRef name,
249 bool asTarget =
false);
261 mlir::Location loc, mlir::Type type, llvm::StringRef name,
262 mlir::ValueRange lenParams = {}, mlir::ValueRange shape = {},
263 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
264 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt,
265 std::optional<std::int64_t> alignment = std::nullopt);
272 mlir::Location loc, mlir::Type type, llvm::StringRef name = {},
273 mlir::ValueRange shape = {}, mlir::ValueRange lenParams = {},
274 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
275 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt,
276 std::optional<std::int64_t> alignment = std::nullopt);
280 mlir::ValueRange shape) {
290 llvm::StringRef name,
291 llvm::ArrayRef<mlir::NamedAttribute> attrs) {
299 llvm::StringRef name = {}, mlir::ValueRange shape = {},
300 mlir::ValueRange lenParams = {},
301 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
302 std::optional<std::int64_t> alignment = std::nullopt);
309 mlir::Location loc, mlir::Value memref,
310 llvm::StringRef name, mlir::Value shape,
311 llvm::ArrayRef<mlir::Value> typeParams,
312 fir::FortranVariableFlagsAttr attrs);
334 mlir::Location loc, mlir::Type baseType, mlir::Value shape,
335 llvm::ArrayRef<mlir::Value> extents,
336 llvm::ArrayRef<mlir::Value> typeParams,
338 mlir::Value polymorphicMold,
bool useStack, llvm::StringRef tmpName,
339 std::optional<std::int64_t> alignment = std::nullopt);
341 std::pair<mlir::Value, bool>
346 mlir::Value polymorphicMold,
bool useStack =
false,
347 llvm::StringRef tmpName =
".tmp.array",
348 std::optional<std::int64_t> alignment = std::nullopt) {
350 genDeclare, polymorphicMold, useStack, tmpName,
364 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
365 llvm::StringRef name,
366 fir::LinkageAttr linkage = {},
367 mlir::Attribute value = {},
bool isConst =
false,
368 bool isTarget =
false,
369 cuf::DataAttributeAttr dataAttr = {},
370 bool setDefaultAlignment =
true);
372 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
373 llvm::StringRef name,
bool isConst,
bool isTarget,
374 std::function<
void(FirOpBuilder &)> bodyBuilder,
375 fir::LinkageAttr linkage = {},
376 cuf::DataAttributeAttr dataAttr = {},
377 bool setDefaultAlignment =
true);
381 llvm::StringRef name,
382 fir::LinkageAttr linkage = {},
383 mlir::Attribute value = {}) {
384 return createGlobal(loc, type, name, linkage, value,
true,
390 llvm::StringRef name,
391 std::function<
void(FirOpBuilder &)> bodyBuilder,
392 fir::LinkageAttr linkage = {}) {
394 bodyBuilder, linkage);
399 llvm::StringRef
string);
401 std::pair<fir::TypeInfoOp, mlir::OpBuilder::InsertPoint>
402 createTypeInfoOp(mlir::Location loc, fir::RecordType recordType,
403 fir::RecordType parentType);
409 static fir::LinkageAttr createCommonLinkage(mlir::MLIRContext *context) {
410 return fir::LinkageAttr::get(context, fir::LinkageEnum::Common);
412 fir::LinkageAttr createCommonLinkage() {
413 return createCommonLinkage(getContext());
416 fir::LinkageAttr createExternalLinkage() {
417 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::External);
420 fir::LinkageAttr createInternalLinkage() {
421 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Internal);
424 fir::LinkageAttr createLinkOnceLinkage() {
425 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Linkonce);
428 fir::LinkageAttr createLinkOnceODRLinkage() {
429 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::LinkonceODR);
432 fir::LinkageAttr createWeakLinkage() {
433 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Weak);
442 static mlir::func::FuncOp
443 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
444 llvm::StringRef name);
451 static mlir::func::FuncOp
452 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
453 mlir::SymbolRefAttr symbol);
455 fir::GlobalOp getNamedGlobal(llvm::StringRef name) {
459 static fir::GlobalOp getNamedGlobal(mlir::ModuleOp module,
460 const mlir::SymbolTable *symbolTable,
461 llvm::StringRef name);
464 mlir::Value
createConvert(mlir::Location loc, mlir::Type toTy,
483 mlir::Value
loadIfRef(mlir::Location loc, mlir::Value val);
488 mlir::FunctionType ty) {
493 mlir::ModuleOp module,
494 llvm::StringRef name,
495 mlir::FunctionType ty,
496 mlir::SymbolTable *);
503 llvm::StringRef name,
504 mlir::FunctionType ty,
526 mlir::ValueRange triples, mlir::ValueRange path);
536 unsigned corank = 0);
538 mlir::Value
createBox(mlir::Location loc, mlir::Type boxType,
539 mlir::Value addr, mlir::Value shape, mlir::Value slice,
557 IfBuilder(fir::IfOp ifOp, FirOpBuilder &builder)
558 : ifOp{ifOp}, builder{builder} {}
559 template <
typename CC>
560 IfBuilder &genThen(CC func) {
561 builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
565 template <
typename CC>
566 IfBuilder &genElse(CC func) {
567 assert(!ifOp.getElseRegion().empty() &&
"must have else region");
568 builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
572 void end() { builder.setInsertionPointAfter(ifOp); }
577 return ifOp.getResults();
580 fir::IfOp &getIfOp() {
return ifOp; };
590 mlir::Value cdt,
bool withElseRegion) {
591 auto op = fir::IfOp::create(*
this, loc, results, cdt, withElseRegion);
598 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
false);
605 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
true);
609 mlir::Value genNot(mlir::Location loc, mlir::Value
boolean) {
610 return mlir::arith::CmpIOp::create(*
this, loc,
611 mlir::arith::CmpIPredicate::eq,
boolean,
619 mlir::Value
genIsNullAddr(mlir::Location loc, mlir::Value addr);
624 mlir::Value ub, mlir::Value step,
625 mlir::Type type,
bool fold =
false);
629 mlir::Value
genAbsentOp(mlir::Location loc, mlir::Type argTy);
635 fastMathFlags = flags;
651 if (flags == mlir::arith::FastMathFlags::none)
654 std::string fmfString{mlir::arith::stringifyFastMathFlags(flags)};
655 std::replace(fmfString.begin(), fmfString.end(),
',',
'_');
661 class FastMathFlagGuard {
663 FastMathFlagGuard(FirOpBuilder &builder, mlir::arith::FastMathFlags flags)
664 : builder{builder}, savedFlags{builder.getFastMathFlags()} {
665 builder.setFastMathFlags(flags);
667 FastMathFlagGuard(
const FastMathFlagGuard &) =
delete;
668 FastMathFlagGuard &operator=(
const FastMathFlagGuard &) =
delete;
669 ~FastMathFlagGuard() { builder.setFastMathFlags(savedFlags); }
672 FirOpBuilder &builder;
673 mlir::arith::FastMathFlags savedFlags;
680 integerOverflowFlags = flags;
685 return integerOverflowFlags;
691 complexDivisionToRuntimeFlag = flag;
696 return complexDivisionToRuntimeFlag;
701 fpMaxminBehavior = mode;
704 return fpMaxminBehavior;
707#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
714 mlir::OpBuilder::InsertPoint previous)
override {
716 if (previous.isSet())
718 setCommonAttributes(op);
726 template <
typename OpTy>
728 mlir::Value left, mlir::Value right) {
729 if (!resultType.isIntOrFloat())
730 return OpTy::create(*
this, loc, resultType, left, right);
731 mlir::Type signlessType = mlir::IntegerType::get(
732 getContext(), resultType.getIntOrFloatBitWidth(),
733 mlir::IntegerType::SignednessSemantics::Signless);
734 mlir::Type opResType = resultType;
735 if (left.getType().isUnsignedInteger()) {
737 opResType = signlessType;
739 if (right.getType().isUnsignedInteger()) {
741 opResType = signlessType;
743 mlir::Value result = OpTy::create(*
this, loc, opResType, left, right);
744 if (resultType.isUnsignedInteger())
751 mlir::arith::CmpIPredicate predicate,
752 mlir::Value ptr1, mlir::Value ptr2) {
755 return mlir::arith::CmpIOp::create(*
this, loc, predicate, ptr1, ptr2);
761 void setCommonAttributes(mlir::Operation *op)
const;
767 mlir::arith::FastMathFlags fastMathFlags{};
775 Fortran::common::FPMaxminBehavior::Legacy};
779 mlir::arith::IntegerOverflowFlags integerOverflowFlags{};
783 bool complexDivisionToRuntimeFlag =
true;
787 mlir::SymbolTable *symbolTable =
nullptr;
792 std::unique_ptr<mlir::DataLayout> dataLayout =
nullptr;
809mlir::Value
readCharLen(fir::FirOpBuilder &builder, mlir::Location loc,
810 const fir::ExtendedValue &box);
813mlir::Value
readExtent(fir::FirOpBuilder &builder, mlir::Location loc,
814 const fir::ExtendedValue &box,
unsigned dim);
819mlir::Value
readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc,
820 const fir::ExtendedValue &box,
unsigned dim,
821 mlir::Value defaultValue);
824llvm::SmallVector<mlir::Value>
readExtents(fir::FirOpBuilder &builder,
826 const fir::BoxValue &box);
833fir::ExtendedValue
readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
834 const fir::BoxValue &box);
838llvm::SmallVector<mlir::Value>
840 const fir::ExtendedValue &exv);
849 llvm::StringRef
string);
853std::string
uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name);
857llvm::SmallVector<mlir::Value>
createExtents(fir::FirOpBuilder &builder,
859 fir::SequenceType seqTy);
868mlir::Value
locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type);
878 mlir::Value component);
888 const fir::ExtendedValue &array,
889 mlir::Value element);
896 fir::FirOpBuilder &builder, mlir::Location loc,
897 const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice);
902 const fir::ExtendedValue &lhs,
903 const fir::ExtendedValue &rhs,
904 bool needFinalization =
false,
905 bool isTemporaryLHS =
false,
906 mlir::ArrayAttr accessGroups = {});
912 const fir::ExtendedValue &lhs,
913 const fir::ExtendedValue &rhs,
914 bool needFinalization =
false,
915 bool isTemporaryLHS =
false);
919mlir::Value
createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
924mlir::Value
createOneValue(fir::FirOpBuilder &builder, mlir::Location loc,
929mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
930 mlir::Value lb, mlir::Value ub);
931mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
932 mlir::Value lb, mlir::Value ub, mlir::Value zero,
936mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
938mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
939 mlir::Value value, mlir::Value zero);
943 mlir::Value cPtr, mlir::Type ty);
947 mlir::Location loc, mlir::Value cPtr);
951fir::BoxValue
createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
952 const fir::ExtendedValue &exv,
953 unsigned corank = 0);
961mlir::Value
createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type,
967llvm::SmallVector<mlir::Value>
968elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
970llvm::SmallVector<mlir::Value>
971elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
983 mlir::ValueRange extents2);
985uint64_t getGlobalAddressSpace(mlir::DataLayout *dataLayout);
987uint64_t getProgramAddressSpace(mlir::DataLayout *dataLayout);
1000 fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents);
1006 fir::AllocaOp alloc,
const mlir::DataLayout *dl);
1019 mlir::Location loc, mlir::Value box,
1020 mlir::Value newAddr);
1023std::optional<mlir::Value>
1025 mlir::Value lhsRef, mlir::Value rhsRef);
1028std::optional<mlir::Value>
1030 mlir::Value lhsRef, mlir::Value rhsRef);
Definition MathOptionsBase.h:22
Definition BoxValue.h:124
Definition BoxValue.h:292
Definition BoxValue.h:469
Definition FIRBuilder.h:555
mlir::Operation::result_range getResults()
End the IfOp and return the results if any.
Definition FIRBuilder.h:575
Definition FIRBuilder.h:66
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:604
fir::StringLitOp createStringLitOp(mlir::Location loc, llvm::StringRef string)
Convert a StringRef string into a fir::StringLitOp.
Definition FIRBuilder.cpp:688
mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type, bool fold=false)
Definition FIRBuilder.cpp:929
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, std::optional< std::int64_t > alignment=std::nullopt)
Definition FIRBuilder.cpp:394
void genStackRestore(mlir::Location loc, mlir::Value stackPointer)
Definition FIRBuilder.cpp:490
mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str)
Wrap str to a SymbolRefAttr.
Definition FIRBuilder.h:181
mlir::Value createRealZeroConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with a value zero.
Definition FIRBuilder.h:229
void setFPMaxminBehavior(Fortran::common::FPMaxminBehavior mode)
Setter/getter for fpMaxminBehavior.
Definition FIRBuilder.h:700
mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path)
Definition FIRBuilder.cpp:754
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition FIRBuilder.cpp:668
IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion)
Definition FIRBuilder.h:589
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is a null address.
Definition FIRBuilder.cpp:914
mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol)
Definition FIRBuilder.h:448
mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType, llvm::APFloat::integerPart val)
Create a real constant from an integer value.
Definition FIRBuilder.cpp:201
mlir::Type getCharacterLengthType()
Get character length type.
Definition FIRBuilder.h:174
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:597
mlir::Value genStackSave(mlir::Location loc)
Definition FIRBuilder.cpp:484
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:720
const fir::KindMapping & getKindMap()
Get a reference to the kind map.
Definition FIRBuilder.h:133
mlir::Type getRefType(mlir::Type eleTy, bool isVolatile=false)
Safely create a reference type to the type eleTy.
Definition FIRBuilder.cpp:114
mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.cpp:190
mlir::ModuleOp getModule()
Get the current Module.
Definition FIRBuilder.h:123
mlir::Value createMinusOneInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.h:215
mlir::Value createVolatileCast(mlir::Location loc, bool isVolatile, mlir::Value value)
Cast value to have isVolatile volatility.
Definition FIRBuilder.cpp:638
void setComplexDivisionToRuntimeFlag(bool flag)
Definition FIRBuilder.h:690
mlir::IntegerType getDefaultIntegerType()
Get the default integer type.
Definition FIRBuilder.h:143
mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType={})
Definition FIRBuilder.cpp:144
void setFastMathFlags(mlir::arith::FastMathFlags flags)
Definition FIRBuilder.h:634
LLVM_DUMP_METHOD void dumpFunc()
Dump the current function. (debug)
Definition FIRBuilder.cpp:895
mlir::ArrayAttr create2DI64ArrayAttr(llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData)
Definition FIRBuilder.cpp:356
fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type, llvm::StringRef name, fir::LinkageAttr linkage={}, mlir::Attribute value={}, bool isConst=false, bool isTarget=false, cuf::DataAttributeAttr dataAttr={}, bool setDefaultAlignment=true)
Create a global value.
Definition FIRBuilder.cpp:497
mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false)
Definition FIRBuilder.cpp:565
mlir::SymbolTable * getMLIRSymbolTable()
Definition FIRBuilder.h:140
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:750
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is not a null address.
Definition FIRBuilder.cpp:908
mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val)
Cast the input value to IndexType.
Definition FIRBuilder.h:508
void createStoreWithConvert(mlir::Location loc, mlir::Value val, mlir::Value addr)
Definition FIRBuilder.cpp:673
void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags)
Definition FIRBuilder.h:679
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:805
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::optional< std::int64_t > alignment=std::nullopt)
Definition FIRBuilder.cpp:438
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", std::optional< std::int64_t > alignment=std::nullopt)
Create and declare an array temporary.
Definition FIRBuilder.h:342
mlir::Region & getRegion()
Get the current Region of the insertion point.
Definition FIRBuilder.h:120
void notifyOperationInserted(mlir::Operation *op, mlir::OpBuilder::InsertPoint previous) override
FirOpBuilder hook for creating new operation.
Definition FIRBuilder.h:713
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:470
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition FIRBuilder.h:439
std::string getFastMathFlagsString()
Definition FIRBuilder.h:649
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right)
Definition FIRBuilder.h:727
bool getComplexDivisionToRuntimeFlag() const
Get current ComplexDivisionToRuntimeFlag value.
Definition FIRBuilder.h:695
mlir::Value createBool(mlir::Location loc, bool b)
Create constant i1 with value 1. if b is true or 0. otherwise.
Definition FIRBuilder.h:543
mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const
Get current IntegerOverflowFlags value.
Definition FIRBuilder.h:684
mlir::func::FuncOp getFunction()
Get the current Function.
Definition FIRBuilder.h:128
mlir::Type getRealType(int kind)
Get the mlir float type that implements Fortran REAL(kind).
Definition FIRBuilder.cpp:124
fir::GlobalOp createGlobalConstant(mlir::Location loc, mlir::Type type, llvm::StringRef name, fir::LinkageAttr linkage={}, mlir::Attribute value={})
Create a global constant (read-only) value.
Definition FIRBuilder.h:380
mlir::Block * getAllocaBlock()
Definition FIRBuilder.cpp:342
mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank=1)
Create a sequence of eleTy with rank dimensions of unknown size.
Definition FIRBuilder.cpp:119
mlir::Value loadIfRef(mlir::Location loc, mlir::Value val)
Definition FIRBuilder.cpp:682
mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Definition FIRBuilder.cpp:648
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, std::optional< std::int64_t > alignment=std::nullopt)
Definition FIRBuilder.cpp:366
mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:733
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:261
mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy)
Definition FIRBuilder.cpp:948
mlir::arith::FastMathFlags getFastMathFlags() const
Get current FastMathFlags value.
Definition FIRBuilder.h:643
mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType, std::int64_t i)
Definition FIRBuilder.cpp:150
mlir::Value createRealOneConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with value one.
Definition FIRBuilder.h:234
mlir::Block * getEntryBlock()
Get the entry block of the current Function.
Definition FIRBuilder.h:160
mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty)
Definition FIRBuilder.h:487
mlir::DataLayout & getDataLayout()
Construct a data layout on demand and return it.
Definition FIRBuilder.cpp:1011
mlir::Value createTemporary(mlir::Location loc, mlir::Type type, mlir::ValueRange shape)
Create an unnamed and untracked temporary on the stack.
Definition FIRBuilder.h:279
mlir::Type getIntPtrType()
Definition FIRBuilder.h:178
mlir::Value createHeapTemporary(mlir::Location loc, mlir::Type type, llvm::StringRef name={}, mlir::ValueRange shape={}, mlir::ValueRange lenParams={}, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, std::optional< std::int64_t > alignment=std::nullopt)
Definition FIRBuilder.cpp:419
Definition KindMapping.h:48
Definition BoxValue.h:361
FPMaxminBehavior
Definition FPMaxminBehavior.h:29
Definition BoxValue.h:446
fir::ExtendedValue componentToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value component)
Definition FIRBuilder.cpp:1309
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:1609
mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1557
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:1408
llvm::SmallVector< mlir::Value > deduceOptimalExtents(mlir::ValueRange extents1, mlir::ValueRange extents2)
Definition FIRBuilder.cpp:1767
fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv, unsigned corank=0)
Definition FIRBuilder.cpp:1701
mlir::Value getDescriptorWithNewBaseAddress(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box, mlir::Value newAddr)
Definition FIRBuilder.cpp:1837
mlir::Value createOneValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1576
mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim, mlir::Value defaultValue)
Definition FIRBuilder.cpp:1078
std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name)
Definition FIRBuilder.cpp:1223
llvm::SmallVector< mlir::Value > updateRuntimeExtentsForEmptyArrays(fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents)
Definition FIRBuilder.cpp:1794
llvm::SmallVector< mlir::Value > getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1176
fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location, llvm::StringRef string)
Definition FIRBuilder.cpp:1261
mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location)
Generate a string literal containing the file name and return its address.
Definition FIRBuilder.cpp:1243
mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type)
Generate a constant of the given type with the location line number.
Definition FIRBuilder.cpp:1253
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:1859
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:1047
mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box)
Definition FIRBuilder.cpp:1022
void genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value mem)
Definition FIRBuilder.cpp:1832
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:1912
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:1649
llvm::SmallVector< mlir::Value > readExtents(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Read extents from box.
Definition FIRBuilder.cpp:1108
mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr)
Get the C address value.
Definition FIRBuilder.cpp:1667
uint64_t getAllocaAddressSpace(const mlir::DataLayout *dataLayout)
Get the address space which should be used for allocas.
Definition FIRBuilder.cpp:1759
void setInternalLinkage(mlir::func::FuncOp)
Set internal linkage attribute on a function.
Definition FIRBuilder.cpp:1751
mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType)
Generate Null BoxProc for procedure pointer null initialization.
Definition FIRBuilder.cpp:1740
fir::ExtendedValue arraySectionElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice)
Definition FIRBuilder.cpp:1393
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:1473
mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type, mlir::Value)
Definition FIRBuilder.cpp:655
fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Definition FIRBuilder.cpp:1147
mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value lb, mlir::Value ub)
Definition FIRBuilder.cpp:1626
fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element)
Definition FIRBuilder.cpp:1363
llvm::SmallVector< mlir::Value > createExtents(fir::FirOpBuilder &builder, mlir::Location loc, fir::SequenceType seqTy)
Definition FIRBuilder.cpp:1283
mlir::Value genLifetimeStart(mlir::OpBuilder &builder, mlir::Location loc, fir::AllocaOp alloc, const mlir::DataLayout *dl)
Definition FIRBuilder.cpp:1820
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
mlir::Block * getAllocaBlock(mlir::Region ®ion)
Get the block for adding Allocas.
Definition FIRBuilder.cpp:301
bool isAssumedType(mlir::Type ty)
Definition FIRType.cpp:372
Definition AbstractConverter.h:32