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);
203 const llvm::APInt &value);
212 mlir::Type integerType) {
218 llvm::APFloat::integerPart val);
222 const llvm::APFloat &val);
237 llvm::StringRef uniqName, llvm::StringRef name,
240 bool asTarget =
false);
242 llvm::StringRef uniqName, llvm::StringRef name,
245 bool asTarget =
false);
256 mlir::Location loc, mlir::Type type, llvm::StringRef name,
257 mlir::ValueRange lenParams = {}, mlir::ValueRange shape = {},
258 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
259 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
265 mlir::Location loc, mlir::Type type, llvm::StringRef name = {},
266 mlir::ValueRange shape = {}, mlir::ValueRange lenParams = {},
267 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
268 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
272 mlir::ValueRange shape) {
282 llvm::StringRef name,
283 llvm::ArrayRef<mlir::NamedAttribute> attrs) {
290 llvm::StringRef name = {}, mlir::ValueRange shape = {},
291 mlir::ValueRange lenParams = {},
292 llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
299 mlir::Location loc, mlir::Value memref,
300 llvm::StringRef name, mlir::Value shape,
301 llvm::ArrayRef<mlir::Value> typeParams,
302 fir::FortranVariableFlagsAttr attrs);
321 mlir::Location loc, mlir::Type baseType, mlir::Value shape,
322 llvm::ArrayRef<mlir::Value> extents,
323 llvm::ArrayRef<mlir::Value> typeParams,
325 mlir::Value polymorphicMold,
bool useStack, llvm::StringRef tmpName);
327 std::pair<mlir::Value, bool>
332 mlir::Value polymorphicMold,
bool useStack =
false,
333 llvm::StringRef tmpName =
".tmp.array") {
335 genDeclare, polymorphicMold, useStack, tmpName);
348 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
349 llvm::StringRef name,
350 fir::LinkageAttr linkage = {},
351 mlir::Attribute value = {},
bool isConst =
false,
352 bool isTarget =
false,
353 cuf::DataAttributeAttr dataAttr = {},
354 bool setDefaultAlignment =
true);
356 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
357 llvm::StringRef name,
bool isConst,
bool isTarget,
358 std::function<
void(FirOpBuilder &)> bodyBuilder,
359 fir::LinkageAttr linkage = {},
360 cuf::DataAttributeAttr dataAttr = {},
361 bool setDefaultAlignment =
true);
365 llvm::StringRef name,
366 fir::LinkageAttr linkage = {},
367 mlir::Attribute value = {}) {
368 return createGlobal(loc, type, name, linkage, value,
true,
374 llvm::StringRef name,
375 std::function<
void(FirOpBuilder &)> bodyBuilder,
376 fir::LinkageAttr linkage = {}) {
378 bodyBuilder, linkage);
383 llvm::StringRef
string);
385 std::pair<fir::TypeInfoOp, mlir::OpBuilder::InsertPoint>
386 createTypeInfoOp(mlir::Location loc, fir::RecordType recordType,
387 fir::RecordType parentType);
393 static fir::LinkageAttr createCommonLinkage(mlir::MLIRContext *context) {
394 return fir::LinkageAttr::get(context, fir::LinkageEnum::Common);
396 fir::LinkageAttr createCommonLinkage() {
397 return createCommonLinkage(getContext());
400 fir::LinkageAttr createExternalLinkage() {
401 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::External);
404 fir::LinkageAttr createInternalLinkage() {
405 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Internal);
408 fir::LinkageAttr createLinkOnceLinkage() {
409 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Linkonce);
412 fir::LinkageAttr createLinkOnceODRLinkage() {
413 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::LinkonceODR);
416 fir::LinkageAttr createWeakLinkage() {
417 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Weak);
425 static mlir::func::FuncOp
426 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
427 llvm::StringRef name);
434 static mlir::func::FuncOp
435 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
436 mlir::SymbolRefAttr symbol);
438 fir::GlobalOp getNamedGlobal(llvm::StringRef name) {
442 static fir::GlobalOp getNamedGlobal(mlir::ModuleOp module,
443 const mlir::SymbolTable *symbolTable,
444 llvm::StringRef name);
447 mlir::Value
createConvert(mlir::Location loc, mlir::Type toTy,
466 mlir::Value
loadIfRef(mlir::Location loc, mlir::Value val);
471 mlir::FunctionType ty) {
476 mlir::ModuleOp module,
477 llvm::StringRef name,
478 mlir::FunctionType ty,
479 mlir::SymbolTable *);
486 llvm::StringRef name,
487 mlir::FunctionType ty,
509 mlir::ValueRange triples, mlir::ValueRange path);
519 unsigned corank = 0);
521 mlir::Value
createBox(mlir::Location loc, mlir::Type boxType,
522 mlir::Value addr, mlir::Value shape, mlir::Value slice,
540 IfBuilder(fir::IfOp ifOp, FirOpBuilder &builder)
541 : ifOp{ifOp}, builder{builder} {}
542 template <
typename CC>
543 IfBuilder &genThen(CC func) {
544 builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
548 template <
typename CC>
549 IfBuilder &genElse(CC func) {
550 assert(!ifOp.getElseRegion().empty() &&
"must have else region");
551 builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
555 void end() { builder.setInsertionPointAfter(ifOp); }
560 return ifOp.getResults();
563 fir::IfOp &getIfOp() {
return ifOp; };
573 mlir::Value cdt,
bool withElseRegion) {
574 auto op = fir::IfOp::create(*
this, loc, results, cdt, withElseRegion);
581 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
false);
588 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
true);
592 mlir::Value genNot(mlir::Location loc, mlir::Value
boolean) {
593 return mlir::arith::CmpIOp::create(*
this, loc,
594 mlir::arith::CmpIPredicate::eq,
boolean,
602 mlir::Value
genIsNullAddr(mlir::Location loc, mlir::Value addr);
607 mlir::Value ub, mlir::Value step,
608 mlir::Type type,
bool fold =
false);
612 mlir::Value
genAbsentOp(mlir::Location loc, mlir::Type argTy);
618 fastMathFlags = flags;
634 if (flags == mlir::arith::FastMathFlags::none)
637 std::string fmfString{mlir::arith::stringifyFastMathFlags(flags)};
638 std::replace(fmfString.begin(), fmfString.end(),
',',
'_');
644 class FastMathFlagGuard {
646 FastMathFlagGuard(FirOpBuilder &builder, mlir::arith::FastMathFlags flags)
647 : builder{builder}, savedFlags{builder.getFastMathFlags()} {
648 builder.setFastMathFlags(flags);
650 FastMathFlagGuard(
const FastMathFlagGuard &) =
delete;
651 FastMathFlagGuard &operator=(
const FastMathFlagGuard &) =
delete;
652 ~FastMathFlagGuard() { builder.setFastMathFlags(savedFlags); }
655 FirOpBuilder &builder;
656 mlir::arith::FastMathFlags savedFlags;
663 integerOverflowFlags = flags;
668 return integerOverflowFlags;
674 complexDivisionToRuntimeFlag = flag;
679 return complexDivisionToRuntimeFlag;
684 fpMaxminBehavior = mode;
687 return fpMaxminBehavior;
695 mlir::OpBuilder::InsertPoint previous)
override {
697 if (previous.isSet())
699 setCommonAttributes(op);
707 template <
typename OpTy>
709 mlir::Value left, mlir::Value right) {
710 if (!resultType.isIntOrFloat())
711 return OpTy::create(*
this, loc, resultType, left, right);
712 mlir::Type signlessType = mlir::IntegerType::get(
713 getContext(), resultType.getIntOrFloatBitWidth(),
714 mlir::IntegerType::SignednessSemantics::Signless);
715 mlir::Type opResType = resultType;
716 if (left.getType().isUnsignedInteger()) {
718 opResType = signlessType;
720 if (right.getType().isUnsignedInteger()) {
722 opResType = signlessType;
724 mlir::Value result = OpTy::create(*
this, loc, opResType, left, right);
725 if (resultType.isUnsignedInteger())
732 mlir::arith::CmpIPredicate predicate,
733 mlir::Value ptr1, mlir::Value ptr2) {
736 return mlir::arith::CmpIOp::create(*
this, loc, predicate, ptr1, ptr2);
742 void setCommonAttributes(mlir::Operation *op)
const;
748 mlir::arith::FastMathFlags fastMathFlags{};
756 Fortran::common::FPMaxminBehavior::Legacy};
760 mlir::arith::IntegerOverflowFlags integerOverflowFlags{};
764 bool complexDivisionToRuntimeFlag =
true;
768 mlir::SymbolTable *symbolTable =
nullptr;
773 std::unique_ptr<mlir::DataLayout> dataLayout =
nullptr;
790mlir::Value
readCharLen(fir::FirOpBuilder &builder, mlir::Location loc,
791 const fir::ExtendedValue &box);
794mlir::Value
readExtent(fir::FirOpBuilder &builder, mlir::Location loc,
795 const fir::ExtendedValue &box,
unsigned dim);
800mlir::Value
readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc,
801 const fir::ExtendedValue &box,
unsigned dim,
802 mlir::Value defaultValue);
805llvm::SmallVector<mlir::Value>
readExtents(fir::FirOpBuilder &builder,
807 const fir::BoxValue &box);
814fir::ExtendedValue
readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
815 const fir::BoxValue &box);
819llvm::SmallVector<mlir::Value>
821 const fir::ExtendedValue &exv);
830 llvm::StringRef
string);
834std::string
uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name);
838llvm::SmallVector<mlir::Value>
createExtents(fir::FirOpBuilder &builder,
840 fir::SequenceType seqTy);
849mlir::Value
locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type);
859 mlir::Value component);
869 const fir::ExtendedValue &array,
870 mlir::Value element);
877 fir::FirOpBuilder &builder, mlir::Location loc,
878 const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice);
883 const fir::ExtendedValue &lhs,
884 const fir::ExtendedValue &rhs,
885 bool needFinalization =
false,
886 bool isTemporaryLHS =
false,
887 mlir::ArrayAttr accessGroups = {});
893 const fir::ExtendedValue &lhs,
894 const fir::ExtendedValue &rhs,
895 bool needFinalization =
false,
896 bool isTemporaryLHS =
false);
900mlir::Value
createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
905mlir::Value
createOneValue(fir::FirOpBuilder &builder, mlir::Location loc,
910mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
911 mlir::Value lb, mlir::Value ub);
912mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
913 mlir::Value lb, mlir::Value ub, mlir::Value zero,
917mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
919mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
920 mlir::Value value, mlir::Value zero);
924 mlir::Value cPtr, mlir::Type ty);
928 mlir::Location loc, mlir::Value cPtr);
932fir::BoxValue
createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
933 const fir::ExtendedValue &exv,
934 unsigned corank = 0);
942mlir::Value
createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type,
948llvm::SmallVector<mlir::Value>
949elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
951llvm::SmallVector<mlir::Value>
952elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
964 mlir::ValueRange extents2);
966uint64_t getGlobalAddressSpace(mlir::DataLayout *dataLayout);
968uint64_t getProgramAddressSpace(mlir::DataLayout *dataLayout);
981 fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents);
987 fir::AllocaOp alloc,
const mlir::DataLayout *dl);
1000 mlir::Location loc, mlir::Value box,
1001 mlir::Value newAddr);
1004std::optional<mlir::Value>
1006 mlir::Value lhsRef, mlir::Value rhsRef);
1009std::optional<mlir::Value>
1011 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:538
mlir::Operation::result_range getResults()
End the IfOp and return the results if any.
Definition FIRBuilder.h:558
Definition FIRBuilder.h:66
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:587
fir::StringLitOp createStringLitOp(mlir::Location loc, llvm::StringRef string)
Convert a StringRef string into a fir::StringLitOp.
Definition FIRBuilder.cpp:674
mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type, bool fold=false)
Definition FIRBuilder.cpp:913
void genStackRestore(mlir::Location loc, mlir::Value stackPointer)
Definition FIRBuilder.cpp:475
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:225
void setFPMaxminBehavior(Fortran::common::FPMaxminBehavior mode)
Setter/getter for fpMaxminBehavior.
Definition FIRBuilder.h:683
mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path)
Definition FIRBuilder.cpp:740
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition FIRBuilder.cpp:654
IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion)
Definition FIRBuilder.h:572
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is a null address.
Definition FIRBuilder.cpp:898
mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol)
Definition FIRBuilder.h:431
mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType, llvm::APFloat::integerPart val)
Create a real constant from an integer value.
Definition FIRBuilder.cpp:199
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:364
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:580
mlir::Value genStackSave(mlir::Location loc)
Definition FIRBuilder.cpp:469
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:706
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:188
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:427
mlir::Value createMinusOneInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.h:211
mlir::Value createVolatileCast(mlir::Location loc, bool isVolatile, mlir::Value value)
Cast value to have isVolatile volatility.
Definition FIRBuilder.cpp:624
void setComplexDivisionToRuntimeFlag(bool flag)
Definition FIRBuilder.h:673
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:617
LLVM_DUMP_METHOD void dumpFunc()
Dump the current function. (debug)
Definition FIRBuilder.cpp:880
mlir::ArrayAttr create2DI64ArrayAttr(llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData)
Definition FIRBuilder.cpp:354
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:482
mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false)
Definition FIRBuilder.cpp:551
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:328
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:731
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is not a null address.
Definition FIRBuilder.cpp:892
mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val)
Cast the input value to IndexType.
Definition FIRBuilder.h:491
void createStoreWithConvert(mlir::Location loc, mlir::Value val, mlir::Value addr)
Definition FIRBuilder.cpp:659
void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags)
Definition FIRBuilder.h:662
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:791
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:694
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:455
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition FIRBuilder.h:422
std::string getFastMathFlagsString()
Definition FIRBuilder.h:632
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right)
Definition FIRBuilder.h:708
bool getComplexDivisionToRuntimeFlag() const
Get current ComplexDivisionToRuntimeFlag value.
Definition FIRBuilder.h:678
mlir::Value createBool(mlir::Location loc, bool b)
Create constant i1 with value 1. if b is true or 0. otherwise.
Definition FIRBuilder.h:526
mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const
Get current IntegerOverflowFlags value.
Definition FIRBuilder.h:667
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:388
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:364
mlir::Block * getAllocaBlock()
Definition FIRBuilder.cpp:340
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:668
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:412
mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Definition FIRBuilder.cpp:634
mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:719
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:259
mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy)
Definition FIRBuilder.cpp:932
mlir::arith::FastMathFlags getFastMathFlags() const
Get current FastMathFlags value.
Definition FIRBuilder.h:626
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:230
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:470
mlir::DataLayout & getDataLayout()
Construct a data layout on demand and return it.
Definition FIRBuilder.cpp:995
mlir::Value createTemporary(mlir::Location loc, mlir::Type type, mlir::ValueRange shape)
Create an unnamed and untracked temporary on the stack.
Definition FIRBuilder.h:271
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:1293
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:1593
mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1541
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:1392
llvm::SmallVector< mlir::Value > deduceOptimalExtents(mlir::ValueRange extents1, mlir::ValueRange extents2)
Definition FIRBuilder.cpp:1751
fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv, unsigned corank=0)
Definition FIRBuilder.cpp:1685
mlir::Value getDescriptorWithNewBaseAddress(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box, mlir::Value newAddr)
Definition FIRBuilder.cpp:1821
mlir::Value createOneValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1560
mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim, mlir::Value defaultValue)
Definition FIRBuilder.cpp:1062
std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name)
Definition FIRBuilder.cpp:1207
llvm::SmallVector< mlir::Value > updateRuntimeExtentsForEmptyArrays(fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents)
Definition FIRBuilder.cpp:1778
llvm::SmallVector< mlir::Value > getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1160
fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location, llvm::StringRef string)
Definition FIRBuilder.cpp:1245
mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location)
Generate a string literal containing the file name and return its address.
Definition FIRBuilder.cpp:1227
mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type)
Generate a constant of the given type with the location line number.
Definition FIRBuilder.cpp:1237
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:1843
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:1031
mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box)
Definition FIRBuilder.cpp:1006
void genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value mem)
Definition FIRBuilder.cpp:1816
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:1896
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:1633
llvm::SmallVector< mlir::Value > readExtents(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Read extents from box.
Definition FIRBuilder.cpp:1092
mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr)
Get the C address value.
Definition FIRBuilder.cpp:1651
uint64_t getAllocaAddressSpace(const mlir::DataLayout *dataLayout)
Get the address space which should be used for allocas.
Definition FIRBuilder.cpp:1743
void setInternalLinkage(mlir::func::FuncOp)
Set internal linkage attribute on a function.
Definition FIRBuilder.cpp:1735
mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType)
Generate Null BoxProc for procedure pointer null initialization.
Definition FIRBuilder.cpp:1724
fir::ExtendedValue arraySectionElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice)
Definition FIRBuilder.cpp:1377
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:1457
mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type, mlir::Value)
Definition FIRBuilder.cpp:641
fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Definition FIRBuilder.cpp:1131
mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value lb, mlir::Value ub)
Definition FIRBuilder.cpp:1610
fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element)
Definition FIRBuilder.cpp:1347
llvm::SmallVector< mlir::Value > createExtents(fir::FirOpBuilder &builder, mlir::Location loc, fir::SequenceType seqTy)
Definition FIRBuilder.cpp:1267
mlir::Value genLifetimeStart(mlir::OpBuilder &builder, mlir::Location loc, fir::AllocaOp alloc, const mlir::DataLayout *dl)
Definition FIRBuilder.cpp:1804
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:299
bool isAssumedType(mlir::Type ty)
Definition FIRType.cpp:373
Definition AbstractConverter.h:32