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);
498 mlir::Value
createBox(mlir::Location loc, mlir::Type boxType,
499 mlir::Value addr, mlir::Value shape, mlir::Value slice,
517 IfBuilder(fir::IfOp ifOp, FirOpBuilder &builder)
518 : ifOp{ifOp}, builder{builder} {}
519 template <
typename CC>
520 IfBuilder &genThen(CC func) {
521 builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
525 template <
typename CC>
526 IfBuilder &genElse(CC func) {
527 assert(!ifOp.getElseRegion().empty() &&
"must have else region");
528 builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
532 void end() { builder.setInsertionPointAfter(ifOp); }
537 return ifOp.getResults();
540 fir::IfOp &getIfOp() {
return ifOp; };
550 mlir::Value cdt,
bool withElseRegion) {
551 auto op = fir::IfOp::create(*
this, loc, results, cdt, withElseRegion);
558 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
false);
565 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
true);
569 mlir::Value genNot(mlir::Location loc, mlir::Value
boolean) {
570 return mlir::arith::CmpIOp::create(*
this, loc,
571 mlir::arith::CmpIPredicate::eq,
boolean,
579 mlir::Value
genIsNullAddr(mlir::Location loc, mlir::Value addr);
584 mlir::Value ub, mlir::Value step,
585 mlir::Type type,
bool fold =
false);
589 mlir::Value
genAbsentOp(mlir::Location loc, mlir::Type argTy);
595 fastMathFlags = flags;
611 if (flags == mlir::arith::FastMathFlags::none)
614 std::string fmfString{mlir::arith::stringifyFastMathFlags(flags)};
615 std::replace(fmfString.begin(), fmfString.end(),
',',
'_');
623 integerOverflowFlags = flags;
628 return integerOverflowFlags;
634 complexDivisionToRuntimeFlag = flag;
639 return complexDivisionToRuntimeFlag;
644 fpMaxminBehavior = mode;
647 return fpMaxminBehavior;
655 mlir::OpBuilder::InsertPoint previous)
override {
657 if (previous.isSet())
659 setCommonAttributes(op);
667 template <
typename OpTy>
669 mlir::Value left, mlir::Value right) {
670 if (!resultType.isIntOrFloat())
671 return OpTy::create(*
this, loc, resultType, left, right);
672 mlir::Type signlessType = mlir::IntegerType::get(
673 getContext(), resultType.getIntOrFloatBitWidth(),
674 mlir::IntegerType::SignednessSemantics::Signless);
675 mlir::Type opResType = resultType;
676 if (left.getType().isUnsignedInteger()) {
678 opResType = signlessType;
680 if (right.getType().isUnsignedInteger()) {
682 opResType = signlessType;
684 mlir::Value result = OpTy::create(*
this, loc, opResType, left, right);
685 if (resultType.isUnsignedInteger())
692 mlir::arith::CmpIPredicate predicate,
693 mlir::Value ptr1, mlir::Value ptr2) {
696 return mlir::arith::CmpIOp::create(*
this, loc, predicate, ptr1, ptr2);
702 void setCommonAttributes(mlir::Operation *op)
const;
708 mlir::arith::FastMathFlags fastMathFlags{};
716 Fortran::common::FPMaxminBehavior::Legacy};
720 mlir::arith::IntegerOverflowFlags integerOverflowFlags{};
724 bool complexDivisionToRuntimeFlag =
true;
728 mlir::SymbolTable *symbolTable =
nullptr;
733 std::unique_ptr<mlir::DataLayout> dataLayout =
nullptr;
750mlir::Value
readCharLen(fir::FirOpBuilder &builder, mlir::Location loc,
751 const fir::ExtendedValue &box);
754mlir::Value
readExtent(fir::FirOpBuilder &builder, mlir::Location loc,
755 const fir::ExtendedValue &box,
unsigned dim);
760mlir::Value
readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc,
761 const fir::ExtendedValue &box,
unsigned dim,
762 mlir::Value defaultValue);
765llvm::SmallVector<mlir::Value>
readExtents(fir::FirOpBuilder &builder,
767 const fir::BoxValue &box);
774fir::ExtendedValue
readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
775 const fir::BoxValue &box);
779llvm::SmallVector<mlir::Value>
781 const fir::ExtendedValue &exv);
786llvm::SmallVector<mlir::Value>
796 llvm::StringRef
string);
800std::string
uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name);
804llvm::SmallVector<mlir::Value>
createExtents(fir::FirOpBuilder &builder,
806 fir::SequenceType seqTy);
815mlir::Value
locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type);
825 mlir::Value component);
835 const fir::ExtendedValue &array,
836 mlir::Value element);
843 fir::FirOpBuilder &builder, mlir::Location loc,
844 const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice);
849 const fir::ExtendedValue &lhs,
850 const fir::ExtendedValue &rhs,
851 bool needFinalization =
false,
852 bool isTemporaryLHS =
false,
853 mlir::ArrayAttr accessGroups = {});
859 const fir::ExtendedValue &lhs,
860 const fir::ExtendedValue &rhs,
861 bool needFinalization =
false,
862 bool isTemporaryLHS =
false);
874 fir::ArrayLoadOp arrLoad,
875 llvm::ArrayRef<mlir::Value> path,
876 llvm::ArrayRef<mlir::Value> substring);
878 fir::SequenceType seqTy, mlir::Value memref,
879 llvm::ArrayRef<mlir::Value> typeParams,
880 llvm::ArrayRef<mlir::Value> path,
881 llvm::ArrayRef<mlir::Value> substring);
885mlir::Value
createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
890mlir::Value
createOneValue(fir::FirOpBuilder &builder, mlir::Location loc,
899mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
900 mlir::Value lb, mlir::Value ub);
901mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
902 mlir::Value lb, mlir::Value ub, mlir::Value zero,
906mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
908mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
909 mlir::Value value, mlir::Value zero);
913 mlir::Value cPtr, mlir::Type ty);
917 mlir::Location loc, mlir::Value cPtr);
921fir::BoxValue
createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
922 const fir::ExtendedValue &exv);
930mlir::Value
createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type,
936llvm::SmallVector<mlir::Value>
937elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
939llvm::SmallVector<mlir::Value>
940elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
952 mlir::ValueRange extents2);
954uint64_t getGlobalAddressSpace(mlir::DataLayout *dataLayout);
956uint64_t getProgramAddressSpace(mlir::DataLayout *dataLayout);
969 fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents);
975 fir::AllocaOp alloc,
const mlir::DataLayout *dl);
988 mlir::Location loc, mlir::Value box,
989 mlir::Value newAddr);
Definition MathOptionsBase.h:22
Definition BoxValue.h:125
Definition BoxValue.h:291
Definition BoxValue.h:478
Definition FIRBuilder.h:515
mlir::Operation::result_range getResults()
End the IfOp and return the results if any.
Definition FIRBuilder.h:535
Definition FIRBuilder.h:59
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:564
fir::StringLitOp createStringLitOp(mlir::Location loc, llvm::StringRef string)
Convert a StringRef string into a fir::StringLitOp.
Definition FIRBuilder.cpp:640
mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type, bool fold=false)
Definition FIRBuilder.cpp:879
void genStackRestore(mlir::Location loc, mlir::Value stackPointer)
Definition FIRBuilder.cpp:441
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:643
mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path)
Definition FIRBuilder.cpp:706
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition FIRBuilder.cpp:620
IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion)
Definition FIRBuilder.h:549
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is a null address.
Definition FIRBuilder.cpp:864
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:178
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:330
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:557
mlir::Value genStackSave(mlir::Location loc)
Definition FIRBuilder.cpp:435
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:672
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:109
mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.cpp:167
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:393
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:590
void setComplexDivisionToRuntimeFlag(bool flag)
Definition FIRBuilder.h:633
mlir::IntegerType getDefaultIntegerType()
Get the default integer type.
Definition FIRBuilder.h:132
mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType={})
Definition FIRBuilder.cpp:139
void setFastMathFlags(mlir::arith::FastMathFlags flags)
Definition FIRBuilder.h:594
LLVM_DUMP_METHOD void dumpFunc()
Dump the current function. (debug)
Definition FIRBuilder.cpp:846
mlir::ArrayAttr create2DI64ArrayAttr(llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData)
Definition FIRBuilder.cpp:320
mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false)
Definition FIRBuilder.cpp:517
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:691
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is not a null address.
Definition FIRBuilder.cpp:858
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:625
void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags)
Definition FIRBuilder.h:622
mlir::func::FuncOp createRuntimeFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty, bool isIO=false)
Definition FIRBuilder.cpp:53
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:654
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:421
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition FIRBuilder.h:400
std::string getFastMathFlagsString()
Definition FIRBuilder.h:609
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right)
Definition FIRBuilder.h:668
bool getComplexDivisionToRuntimeFlag() const
Get current ComplexDivisionToRuntimeFlag value.
Definition FIRBuilder.h:638
mlir::Value createBool(mlir::Location loc, bool b)
Create constant i1 with value 1. if b is true or 0. otherwise.
Definition FIRBuilder.h:503
mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const
Get current IntegerOverflowFlags value.
Definition FIRBuilder.h:627
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:354
mlir::Type getRealType(int kind)
Get the mlir float type that implements Fortran REAL(kind).
Definition FIRBuilder.cpp:119
mlir::Block * getAllocaBlock()
Get the block for adding Allocas.
Definition FIRBuilder.cpp:278
mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank=1)
Create a sequence of eleTy with rank dimensions of unknown size.
Definition FIRBuilder.cpp:114
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:448
mlir::Value loadIfRef(mlir::Location loc, mlir::Value val)
Definition FIRBuilder.cpp:634
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:378
mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Definition FIRBuilder.cpp:600
mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:685
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:238
mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy)
Definition FIRBuilder.cpp:898
mlir::arith::FastMathFlags getFastMathFlags() const
Get current FastMathFlags value.
Definition FIRBuilder.h:603
mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType, std::int64_t i)
Definition FIRBuilder.cpp:145
mlir::Value createBox(mlir::Location loc, const fir::ExtendedValue &exv, bool isPolymorphic=false, bool isAssumedType=false)
Definition FIRBuilder.cpp:757
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:961
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:360
FPMaxminBehavior
Definition FPMaxminBehavior.h:29
Definition BoxValue.h:445
fir::ExtendedValue componentToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value component)
Definition FIRBuilder.cpp:1316
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:1761
mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1681
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:1415
llvm::SmallVector< mlir::Value > deduceOptimalExtents(mlir::ValueRange extents1, mlir::ValueRange extents2)
Definition FIRBuilder.cpp:1918
mlir::Value getDescriptorWithNewBaseAddress(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box, mlir::Value newAddr)
Definition FIRBuilder.cpp:1988
mlir::Value createOneValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1700
mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim, mlir::Value defaultValue)
Definition FIRBuilder.cpp:1028
std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name)
Definition FIRBuilder.cpp:1230
llvm::SmallVector< mlir::Value > updateRuntimeExtentsForEmptyArrays(fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents)
Definition FIRBuilder.cpp:1945
llvm::SmallVector< mlir::Value > getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1126
fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location, llvm::StringRef string)
Definition FIRBuilder.cpp:1268
mlir::TupleType getRaggedArrayHeaderType(fir::FirOpBuilder &builder)
Definition FIRBuilder.cpp:1614
mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location)
Generate a string literal containing the file name and return its address.
Definition FIRBuilder.cpp:1250
mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type)
Generate a constant of the given type with the location line number.
Definition FIRBuilder.cpp:1260
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:997
mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box)
Definition FIRBuilder.cpp:972
void genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value mem)
Definition FIRBuilder.cpp:1983
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:1801
llvm::SmallVector< mlir::Value > readExtents(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Read extents from box.
Definition FIRBuilder.cpp:1058
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:1721
mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr)
Get the C address value.
Definition FIRBuilder.cpp:1819
uint64_t getAllocaAddressSpace(const mlir::DataLayout *dataLayout)
Get the address space which should be used for allocas.
Definition FIRBuilder.cpp:1910
void setInternalLinkage(mlir::func::FuncOp)
Set internal linkage attribute on a function.
Definition FIRBuilder.cpp:1902
mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType)
Generate Null BoxProc for procedure pointer null initialization.
Definition FIRBuilder.cpp:1891
fir::ExtendedValue arraySectionElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice)
Definition FIRBuilder.cpp:1400
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:1623
fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1853
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:1560
mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type, mlir::Value)
Definition FIRBuilder.cpp:607
fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Definition FIRBuilder.cpp:1097
mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value lb, mlir::Value ub)
Definition FIRBuilder.cpp:1778
fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element)
Definition FIRBuilder.cpp:1370
llvm::SmallVector< mlir::Value > getNonDeferredLenParams(const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1148
llvm::SmallVector< mlir::Value > createExtents(fir::FirOpBuilder &builder, mlir::Location loc, fir::SequenceType seqTy)
Definition FIRBuilder.cpp:1290
mlir::Value genLifetimeStart(mlir::OpBuilder &builder, mlir::Location loc, fir::AllocaOp alloc, const mlir::DataLayout *dl)
Definition FIRBuilder.cpp:1971
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:364
Definition AbstractConverter.h:32