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>();
140 return getIntegerType(
152 bool allowCharacterConversion =
false,
153 bool allowRebox =
false);
164 mlir::Type
getRefType(mlir::Type eleTy,
bool isVolatile =
false);
178 return mlir::SymbolRefAttr::get(getContext(), str);
184 fir::BoxProcType getBoxProcType(mlir::FunctionType funcTy) {
185 return fir::BoxProcType::get(getContext(), funcTy);
205 mlir::Type integerType) {
211 llvm::APFloat::integerPart val);
215 const llvm::APFloat &val);
230 llvm::StringRef uniqName, llvm::StringRef name,
233 bool asTarget =
false);
235 llvm::StringRef uniqName, llvm::StringRef name,
238 bool asTarget =
false);
249 mlir::Location loc, mlir::Type type, llvm::StringRef name,
250 mlir::ValueRange lenParams = {}, mlir::ValueRange shape = {},
251 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
252 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
258 mlir::Location loc, mlir::Type type, llvm::StringRef name = {},
259 mlir::ValueRange shape = {}, mlir::ValueRange lenParams = {},
260 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
261 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
265 mlir::ValueRange shape) {
275 llvm::StringRef name,
276 llvm::ArrayRef<mlir::NamedAttribute> attrs) {
283 llvm::StringRef name = {}, mlir::ValueRange shape = {},
284 mlir::ValueRange lenParams = {},
285 llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
292 mlir::Location loc, mlir::Value memref,
293 llvm::StringRef name, mlir::Value shape,
294 llvm::ArrayRef<mlir::Value> typeParams,
295 fir::FortranVariableFlagsAttr attrs);
314 mlir::Location loc, mlir::Type baseType, mlir::Value shape,
315 llvm::ArrayRef<mlir::Value> extents,
316 llvm::ArrayRef<mlir::Value> typeParams,
318 mlir::Value polymorphicMold,
bool useStack, llvm::StringRef tmpName);
320 std::pair<mlir::Value, bool>
325 mlir::Value polymorphicMold,
bool useStack =
false,
326 llvm::StringRef tmpName =
".tmp.array") {
328 genDeclare, polymorphicMold, useStack, tmpName);
341 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
342 llvm::StringRef name,
343 fir::LinkageAttr linkage = {},
344 mlir::Attribute value = {},
bool isConst =
false,
345 bool isTarget =
false,
346 cuf::DataAttributeAttr dataAttr = {},
347 bool setDefaultAlignment =
true);
349 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
350 llvm::StringRef name,
bool isConst,
bool isTarget,
351 std::function<
void(FirOpBuilder &)> bodyBuilder,
352 fir::LinkageAttr linkage = {},
353 cuf::DataAttributeAttr dataAttr = {},
354 bool setDefaultAlignment =
true);
358 llvm::StringRef name,
359 fir::LinkageAttr linkage = {},
360 mlir::Attribute value = {}) {
361 return createGlobal(loc, type, name, linkage, value,
true,
367 llvm::StringRef name,
368 std::function<
void(FirOpBuilder &)> bodyBuilder,
369 fir::LinkageAttr linkage = {}) {
371 bodyBuilder, linkage);
376 llvm::StringRef
string);
378 std::pair<fir::TypeInfoOp, mlir::OpBuilder::InsertPoint>
379 createTypeInfoOp(mlir::Location loc, fir::RecordType recordType,
380 fir::RecordType parentType);
386 static fir::LinkageAttr createCommonLinkage(mlir::MLIRContext *context) {
387 return fir::LinkageAttr::get(context, fir::LinkageEnum::Common);
389 fir::LinkageAttr createCommonLinkage() {
390 return createCommonLinkage(getContext());
393 fir::LinkageAttr createExternalLinkage() {
394 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::External);
397 fir::LinkageAttr createInternalLinkage() {
398 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Internal);
401 fir::LinkageAttr createLinkOnceLinkage() {
402 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Linkonce);
405 fir::LinkageAttr createLinkOnceODRLinkage() {
406 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::LinkonceODR);
409 fir::LinkageAttr createWeakLinkage() {
410 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Weak);
418 static mlir::func::FuncOp
419 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
420 llvm::StringRef name);
427 static mlir::func::FuncOp
428 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
429 mlir::SymbolRefAttr symbol);
431 fir::GlobalOp getNamedGlobal(llvm::StringRef name) {
435 static fir::GlobalOp getNamedGlobal(mlir::ModuleOp module,
436 const mlir::SymbolTable *symbolTable,
437 llvm::StringRef name);
440 mlir::Value
createConvert(mlir::Location loc, mlir::Type toTy,
459 mlir::Value
loadIfRef(mlir::Location loc, mlir::Value val);
464 mlir::FunctionType ty) {
469 mlir::ModuleOp module,
470 llvm::StringRef name,
471 mlir::FunctionType ty,
472 mlir::SymbolTable *);
479 llvm::StringRef name,
480 mlir::FunctionType ty,
502 mlir::ValueRange triples, mlir::ValueRange path);
512 unsigned corank = 0);
514 mlir::Value
createBox(mlir::Location loc, mlir::Type boxType,
515 mlir::Value addr, mlir::Value shape, mlir::Value slice,
533 IfBuilder(fir::IfOp ifOp, FirOpBuilder &builder)
534 : ifOp{ifOp}, builder{builder} {}
535 template <
typename CC>
536 IfBuilder &genThen(CC func) {
537 builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
541 template <
typename CC>
542 IfBuilder &genElse(CC func) {
543 assert(!ifOp.getElseRegion().empty() &&
"must have else region");
544 builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
548 void end() { builder.setInsertionPointAfter(ifOp); }
553 return ifOp.getResults();
556 fir::IfOp &getIfOp() {
return ifOp; };
566 mlir::Value cdt,
bool withElseRegion) {
567 auto op = fir::IfOp::create(*
this, loc, results, cdt, withElseRegion);
574 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
false);
581 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
true);
585 mlir::Value genNot(mlir::Location loc, mlir::Value
boolean) {
586 return mlir::arith::CmpIOp::create(*
this, loc,
587 mlir::arith::CmpIPredicate::eq,
boolean,
595 mlir::Value
genIsNullAddr(mlir::Location loc, mlir::Value addr);
600 mlir::Value ub, mlir::Value step,
601 mlir::Type type,
bool fold =
false);
605 mlir::Value
genAbsentOp(mlir::Location loc, mlir::Type argTy);
611 fastMathFlags = flags;
627 if (flags == mlir::arith::FastMathFlags::none)
630 std::string fmfString{mlir::arith::stringifyFastMathFlags(flags)};
631 std::replace(fmfString.begin(), fmfString.end(),
',',
'_');
637 class FastMathFlagGuard {
639 FastMathFlagGuard(FirOpBuilder &builder, mlir::arith::FastMathFlags flags)
640 : builder{builder}, savedFlags{builder.getFastMathFlags()} {
641 builder.setFastMathFlags(flags);
643 FastMathFlagGuard(
const FastMathFlagGuard &) =
delete;
644 FastMathFlagGuard &operator=(
const FastMathFlagGuard &) =
delete;
645 ~FastMathFlagGuard() { builder.setFastMathFlags(savedFlags); }
648 FirOpBuilder &builder;
649 mlir::arith::FastMathFlags savedFlags;
656 integerOverflowFlags = flags;
661 return integerOverflowFlags;
667 complexDivisionToRuntimeFlag = flag;
672 return complexDivisionToRuntimeFlag;
677 fpMaxminBehavior = mode;
680 return fpMaxminBehavior;
688 mlir::OpBuilder::InsertPoint previous)
override {
690 if (previous.isSet())
692 setCommonAttributes(op);
700 template <
typename OpTy>
702 mlir::Value left, mlir::Value right) {
703 if (!resultType.isIntOrFloat())
704 return OpTy::create(*
this, loc, resultType, left, right);
705 mlir::Type signlessType = mlir::IntegerType::get(
706 getContext(), resultType.getIntOrFloatBitWidth(),
707 mlir::IntegerType::SignednessSemantics::Signless);
708 mlir::Type opResType = resultType;
709 if (left.getType().isUnsignedInteger()) {
711 opResType = signlessType;
713 if (right.getType().isUnsignedInteger()) {
715 opResType = signlessType;
717 mlir::Value result = OpTy::create(*
this, loc, opResType, left, right);
718 if (resultType.isUnsignedInteger())
725 mlir::arith::CmpIPredicate predicate,
726 mlir::Value ptr1, mlir::Value ptr2) {
729 return mlir::arith::CmpIOp::create(*
this, loc, predicate, ptr1, ptr2);
735 void setCommonAttributes(mlir::Operation *op)
const;
741 mlir::arith::FastMathFlags fastMathFlags{};
749 Fortran::common::FPMaxminBehavior::Legacy};
753 mlir::arith::IntegerOverflowFlags integerOverflowFlags{};
757 bool complexDivisionToRuntimeFlag =
true;
761 mlir::SymbolTable *symbolTable =
nullptr;
766 std::unique_ptr<mlir::DataLayout> dataLayout =
nullptr;
783mlir::Value
readCharLen(fir::FirOpBuilder &builder, mlir::Location loc,
784 const fir::ExtendedValue &box);
787mlir::Value
readExtent(fir::FirOpBuilder &builder, mlir::Location loc,
788 const fir::ExtendedValue &box,
unsigned dim);
793mlir::Value
readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc,
794 const fir::ExtendedValue &box,
unsigned dim,
795 mlir::Value defaultValue);
798llvm::SmallVector<mlir::Value>
readExtents(fir::FirOpBuilder &builder,
800 const fir::BoxValue &box);
807fir::ExtendedValue
readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
808 const fir::BoxValue &box);
812llvm::SmallVector<mlir::Value>
814 const fir::ExtendedValue &exv);
823 llvm::StringRef
string);
827std::string
uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name);
831llvm::SmallVector<mlir::Value>
createExtents(fir::FirOpBuilder &builder,
833 fir::SequenceType seqTy);
842mlir::Value
locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type);
852 mlir::Value component);
862 const fir::ExtendedValue &array,
863 mlir::Value element);
870 fir::FirOpBuilder &builder, mlir::Location loc,
871 const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice);
876 const fir::ExtendedValue &lhs,
877 const fir::ExtendedValue &rhs,
878 bool needFinalization =
false,
879 bool isTemporaryLHS =
false,
880 mlir::ArrayAttr accessGroups = {});
886 const fir::ExtendedValue &lhs,
887 const fir::ExtendedValue &rhs,
888 bool needFinalization =
false,
889 bool isTemporaryLHS =
false);
893mlir::Value
createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
898mlir::Value
createOneValue(fir::FirOpBuilder &builder, mlir::Location loc,
903mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
904 mlir::Value lb, mlir::Value ub);
905mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
906 mlir::Value lb, mlir::Value ub, mlir::Value zero,
910mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
912mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
913 mlir::Value value, mlir::Value zero);
917 mlir::Value cPtr, mlir::Type ty);
921 mlir::Location loc, mlir::Value cPtr);
925fir::BoxValue
createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
926 const fir::ExtendedValue &exv,
927 unsigned corank = 0);
935mlir::Value
createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type,
941llvm::SmallVector<mlir::Value>
942elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
944llvm::SmallVector<mlir::Value>
945elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
957 mlir::ValueRange extents2);
959uint64_t getGlobalAddressSpace(mlir::DataLayout *dataLayout);
961uint64_t getProgramAddressSpace(mlir::DataLayout *dataLayout);
974 fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents);
980 fir::AllocaOp alloc,
const mlir::DataLayout *dl);
993 mlir::Location loc, mlir::Value box,
994 mlir::Value newAddr);
997std::optional<mlir::Value>
999 mlir::Value lhsRef, mlir::Value rhsRef);
1002std::optional<mlir::Value>
1004 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:531
mlir::Operation::result_range getResults()
End the IfOp and return the results if any.
Definition FIRBuilder.h:551
Definition FIRBuilder.h:66
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:580
fir::StringLitOp createStringLitOp(mlir::Location loc, llvm::StringRef string)
Convert a StringRef string into a fir::StringLitOp.
Definition FIRBuilder.cpp:650
mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type, bool fold=false)
Definition FIRBuilder.cpp:889
void genStackRestore(mlir::Location loc, mlir::Value stackPointer)
Definition FIRBuilder.cpp:451
mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str)
Wrap str to a SymbolRefAttr.
Definition FIRBuilder.h:177
mlir::Value createRealZeroConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with a value zero.
Definition FIRBuilder.h:218
void setFPMaxminBehavior(Fortran::common::FPMaxminBehavior mode)
Setter/getter for fpMaxminBehavior.
Definition FIRBuilder.h:676
mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path)
Definition FIRBuilder.cpp:716
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition FIRBuilder.cpp:630
IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion)
Definition FIRBuilder.h:565
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is a null address.
Definition FIRBuilder.cpp:874
mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol)
Definition FIRBuilder.h:424
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:170
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:340
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:573
mlir::Value genStackSave(mlir::Location loc)
Definition FIRBuilder.cpp:445
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:682
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:112
mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.cpp:170
mlir::ModuleOp getModule()
Get the current Module.
Definition FIRBuilder.h:123
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:403
mlir::Value createMinusOneInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.h:204
mlir::Value createVolatileCast(mlir::Location loc, bool isVolatile, mlir::Value value)
Cast value to have isVolatile volatility.
Definition FIRBuilder.cpp:600
void setComplexDivisionToRuntimeFlag(bool flag)
Definition FIRBuilder.h:666
mlir::IntegerType getDefaultIntegerType()
Get the default integer type.
Definition FIRBuilder.h:139
mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType={})
Definition FIRBuilder.cpp:142
void setFastMathFlags(mlir::arith::FastMathFlags flags)
Definition FIRBuilder.h:610
LLVM_DUMP_METHOD void dumpFunc()
Dump the current function. (debug)
Definition FIRBuilder.cpp:856
mlir::ArrayAttr create2DI64ArrayAttr(llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData)
Definition FIRBuilder.cpp:330
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:458
mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false)
Definition FIRBuilder.cpp:527
mlir::SymbolTable * getMLIRSymbolTable()
Get func.func/fir.global symbol table attached to this builder if any.
Definition FIRBuilder.h:136
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:321
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:724
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is not a null address.
Definition FIRBuilder.cpp:868
mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val)
Cast the input value to IndexType.
Definition FIRBuilder.h:484
void createStoreWithConvert(mlir::Location loc, mlir::Value val, mlir::Value addr)
Definition FIRBuilder.cpp:635
void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags)
Definition FIRBuilder.h:655
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:767
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:687
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:431
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition FIRBuilder.h:415
std::string getFastMathFlagsString()
Definition FIRBuilder.h:625
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right)
Definition FIRBuilder.h:701
bool getComplexDivisionToRuntimeFlag() const
Get current ComplexDivisionToRuntimeFlag value.
Definition FIRBuilder.h:671
mlir::Value createBool(mlir::Location loc, bool b)
Create constant i1 with value 1. if b is true or 0. otherwise.
Definition FIRBuilder.h:519
mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const
Get current IntegerOverflowFlags value.
Definition FIRBuilder.h:660
mlir::func::FuncOp getFunction()
Get the current Function.
Definition FIRBuilder.h:128
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:364
mlir::Type getRealType(int kind)
Get the mlir float type that implements Fortran REAL(kind).
Definition FIRBuilder.cpp:122
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:357
mlir::Block * getAllocaBlock()
Definition FIRBuilder.cpp:316
mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank=1)
Create a sequence of eleTy with rank dimensions of unknown size.
Definition FIRBuilder.cpp:117
mlir::Value loadIfRef(mlir::Location loc, mlir::Value val)
Definition FIRBuilder.cpp:644
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:388
mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Definition FIRBuilder.cpp:610
mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:695
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:908
mlir::arith::FastMathFlags getFastMathFlags() const
Get current FastMathFlags value.
Definition FIRBuilder.h:619
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:223
mlir::Block * getEntryBlock()
Get the entry block of the current Function.
Definition FIRBuilder.h:156
mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty)
Definition FIRBuilder.h:463
mlir::DataLayout & getDataLayout()
Construct a data layout on demand and return it.
Definition FIRBuilder.cpp:971
mlir::Value createTemporary(mlir::Location loc, mlir::Type type, mlir::ValueRange shape)
Create an unnamed and untracked temporary on the stack.
Definition FIRBuilder.h:264
mlir::Type getIntPtrType()
Definition FIRBuilder.h:174
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:1269
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:1618
mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1566
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:1368
llvm::SmallVector< mlir::Value > deduceOptimalExtents(mlir::ValueRange extents1, mlir::ValueRange extents2)
Definition FIRBuilder.cpp:1776
fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv, unsigned corank=0)
Definition FIRBuilder.cpp:1710
mlir::Value getDescriptorWithNewBaseAddress(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box, mlir::Value newAddr)
Definition FIRBuilder.cpp:1846
mlir::Value createOneValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1585
mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim, mlir::Value defaultValue)
Definition FIRBuilder.cpp:1038
std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name)
Definition FIRBuilder.cpp:1183
llvm::SmallVector< mlir::Value > updateRuntimeExtentsForEmptyArrays(fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents)
Definition FIRBuilder.cpp:1803
llvm::SmallVector< mlir::Value > getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1136
fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location, llvm::StringRef string)
Definition FIRBuilder.cpp:1221
mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location)
Generate a string literal containing the file name and return its address.
Definition FIRBuilder.cpp:1203
mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type)
Generate a constant of the given type with the location line number.
Definition FIRBuilder.cpp:1213
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:1868
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:1007
mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box)
Definition FIRBuilder.cpp:982
void genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value mem)
Definition FIRBuilder.cpp:1841
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:1921
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:1658
llvm::SmallVector< mlir::Value > readExtents(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Read extents from box.
Definition FIRBuilder.cpp:1068
mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr)
Get the C address value.
Definition FIRBuilder.cpp:1676
uint64_t getAllocaAddressSpace(const mlir::DataLayout *dataLayout)
Get the address space which should be used for allocas.
Definition FIRBuilder.cpp:1768
void setInternalLinkage(mlir::func::FuncOp)
Set internal linkage attribute on a function.
Definition FIRBuilder.cpp:1760
mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType)
Generate Null BoxProc for procedure pointer null initialization.
Definition FIRBuilder.cpp:1749
fir::ExtendedValue arraySectionElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice)
Definition FIRBuilder.cpp:1353
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:1513
mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type, mlir::Value)
Definition FIRBuilder.cpp:617
fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Definition FIRBuilder.cpp:1107
mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value lb, mlir::Value ub)
Definition FIRBuilder.cpp:1635
fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element)
Definition FIRBuilder.cpp:1323
llvm::SmallVector< mlir::Value > createExtents(fir::FirOpBuilder &builder, mlir::Location loc, fir::SequenceType seqTy)
Definition FIRBuilder.cpp:1243
mlir::Value genLifetimeStart(mlir::OpBuilder &builder, mlir::Location loc, fir::AllocaOp alloc, const mlir::DataLayout *dl)
Definition FIRBuilder.cpp:1829
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:281
bool isAssumedType(mlir::Type ty)
Definition FIRType.cpp:372
Definition AbstractConverter.h:32