16#ifndef FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
17#define FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
19#include "flang/Optimizer/Dialect/FIROps.h"
20#include "flang/Optimizer/Dialect/FIROpsSupport.h"
21#include "flang/Optimizer/Dialect/FIRType.h"
22#include "flang/Optimizer/Dialect/Support/FIRContext.h"
23#include "flang/Optimizer/Dialect/Support/KindMapping.h"
25#include "mlir/IR/Builders.h"
26#include "mlir/IR/BuiltinOps.h"
27#include "llvm/ADT/DenseMap.h"
46 return builder.getI64Type();
55class FirOpBuilder :
public mlir::OpBuilder,
public mlir::OpBuilder::Listener {
58 mlir::SymbolTable *symbolTable =
nullptr)
59 : OpBuilder{op,
this}, kindMap{std::move(kindMap)},
60 symbolTable{symbolTable} {
61 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
68 mlir::SymbolTable *symbolTable =
nullptr)
69 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)},
70 symbolTable{symbolTable} {
73 explicit FirOpBuilder(mlir::OpBuilder &builder, mlir::ModuleOp mod)
74 : OpBuilder(builder), OpBuilder::Listener(),
80 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)} {
82 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
88 FirOpBuilder(mlir::OpBuilder &builder, mlir::Operation *op)
92 FirOpBuilder(
const FirOpBuilder &other)
93 : OpBuilder(other), OpBuilder::Listener(), kindMap{other.kindMap},
94 fastMathFlags{other.fastMathFlags},
95 integerOverflowFlags{other.integerOverflowFlags},
96 symbolTable{other.symbolTable} {
100 FirOpBuilder(FirOpBuilder &&other)
101 : OpBuilder(other), OpBuilder::Listener(),
102 kindMap{std::move(other.kindMap)}, fastMathFlags{other.fastMathFlags},
103 integerOverflowFlags{other.integerOverflowFlags},
104 symbolTable{other.symbolTable} {
109 mlir::Region &
getRegion() {
return *getBlock()->getParent(); }
113 return getRegion().getParentOfType<mlir::ModuleOp>();
118 return getRegion().getParentOfType<mlir::func::FuncOp>();
129 return getIntegerType(
141 bool allowCharacterConversion =
false,
142 bool allowRebox =
false);
153 mlir::Type
getRefType(mlir::Type eleTy,
bool isVolatile =
false);
167 return mlir::SymbolRefAttr::get(getContext(), str);
173 fir::BoxProcType getBoxProcType(mlir::FunctionType funcTy) {
174 return fir::BoxProcType::get(getContext(), funcTy);
194 mlir::Type integerType) {
200 llvm::APFloat::integerPart val);
204 const llvm::APFloat &val);
214 llvm::StringRef uniqName, llvm::StringRef name,
217 bool asTarget =
false);
219 llvm::StringRef uniqName, llvm::StringRef name,
222 bool asTarget =
false);
233 mlir::Location loc, mlir::Type type, llvm::StringRef name,
234 mlir::ValueRange lenParams = {}, mlir::ValueRange shape = {},
235 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
236 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
242 mlir::Location loc, mlir::Type type, llvm::StringRef name = {},
243 mlir::ValueRange shape = {}, mlir::ValueRange lenParams = {},
244 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
245 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
249 mlir::ValueRange shape) {
259 llvm::StringRef name,
260 llvm::ArrayRef<mlir::NamedAttribute> attrs) {
267 llvm::StringRef name = {}, mlir::ValueRange shape = {},
268 mlir::ValueRange lenParams = {},
269 llvm::ArrayRef<mlir::NamedAttribute> attrs = {});
276 mlir::Location loc, mlir::Value memref,
277 llvm::StringRef name, mlir::Value shape,
278 llvm::ArrayRef<mlir::Value> typeParams,
279 fir::FortranVariableFlagsAttr attrs);
298 mlir::Location loc, mlir::Type baseType, mlir::Value shape,
299 llvm::ArrayRef<mlir::Value> extents,
300 llvm::ArrayRef<mlir::Value> typeParams,
302 mlir::Value polymorphicMold,
bool useStack, llvm::StringRef tmpName);
304 std::pair<mlir::Value, bool>
309 mlir::Value polymorphicMold,
bool useStack =
false,
310 llvm::StringRef tmpName =
".tmp.array") {
312 genDeclare, polymorphicMold, useStack, tmpName);
325 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
326 llvm::StringRef name,
327 mlir::StringAttr linkage = {},
328 mlir::Attribute value = {},
bool isConst =
false,
329 bool isTarget =
false,
330 cuf::DataAttributeAttr dataAttr = {});
332 fir::GlobalOp
createGlobal(mlir::Location loc, mlir::Type type,
333 llvm::StringRef name,
bool isConst,
bool isTarget,
334 std::function<
void(FirOpBuilder &)> bodyBuilder,
335 mlir::StringAttr linkage = {},
336 cuf::DataAttributeAttr dataAttr = {});
340 llvm::StringRef name,
341 mlir::StringAttr linkage = {},
342 mlir::Attribute value = {}) {
343 return createGlobal(loc, type, name, linkage, value,
true,
349 llvm::StringRef name,
350 std::function<
void(FirOpBuilder &)> bodyBuilder,
351 mlir::StringAttr linkage = {}) {
353 bodyBuilder, linkage);
358 llvm::StringRef
string);
360 std::pair<fir::TypeInfoOp, mlir::OpBuilder::InsertPoint>
361 createTypeInfoOp(mlir::Location loc, fir::RecordType recordType,
362 fir::RecordType parentType);
368 static mlir::StringAttr createCommonLinkage(mlir::MLIRContext *context) {
369 return mlir::StringAttr::get(context,
"common");
371 mlir::StringAttr createCommonLinkage() {
372 return createCommonLinkage(getContext());
375 mlir::StringAttr createInternalLinkage() {
return getStringAttr(
"internal"); }
377 mlir::StringAttr createLinkOnceLinkage() {
return getStringAttr(
"linkonce"); }
379 mlir::StringAttr createLinkOnceODRLinkage() {
380 return getStringAttr(
"linkonce_odr");
383 mlir::StringAttr createWeakLinkage() {
return getStringAttr(
"weak"); }
390 static mlir::func::FuncOp
391 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
392 llvm::StringRef name);
399 static mlir::func::FuncOp
400 getNamedFunction(mlir::ModuleOp module,
const mlir::SymbolTable *symbolTable,
401 mlir::SymbolRefAttr symbol);
403 fir::GlobalOp getNamedGlobal(llvm::StringRef name) {
407 static fir::GlobalOp getNamedGlobal(mlir::ModuleOp module,
408 const mlir::SymbolTable *symbolTable,
409 llvm::StringRef name);
412 mlir::Value
createConvert(mlir::Location loc, mlir::Type toTy,
431 mlir::Value
loadIfRef(mlir::Location loc, mlir::Value val);
436 mlir::FunctionType ty) {
441 mlir::ModuleOp module,
442 llvm::StringRef name,
443 mlir::FunctionType ty,
444 mlir::SymbolTable *);
451 llvm::StringRef name,
452 mlir::FunctionType ty,
474 mlir::ValueRange triples, mlir::ValueRange path);
485 mlir::Value
createBox(mlir::Location loc, mlir::Type boxType,
486 mlir::Value addr, mlir::Value shape, mlir::Value slice,
504 IfBuilder(fir::IfOp ifOp, FirOpBuilder &builder)
505 : ifOp{ifOp}, builder{builder} {}
506 template <
typename CC>
507 IfBuilder &genThen(CC func) {
508 builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
512 template <
typename CC>
513 IfBuilder &genElse(CC func) {
514 assert(!ifOp.getElseRegion().empty() &&
"must have else region");
515 builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
519 void end() { builder.setInsertionPointAfter(ifOp); }
524 return ifOp.getResults();
527 fir::IfOp &getIfOp() {
return ifOp; };
537 mlir::Value cdt,
bool withElseRegion) {
538 auto op = fir::IfOp::create(*
this, loc, results, cdt, withElseRegion);
545 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
false);
552 auto op = fir::IfOp::create(*
this, loc, mlir::TypeRange(), cdt,
true);
556 mlir::Value genNot(mlir::Location loc, mlir::Value
boolean) {
557 return mlir::arith::CmpIOp::create(*
this, loc,
558 mlir::arith::CmpIPredicate::eq,
boolean,
566 mlir::Value
genIsNullAddr(mlir::Location loc, mlir::Value addr);
571 mlir::Value ub, mlir::Value step,
576 mlir::Value
genAbsentOp(mlir::Location loc, mlir::Type argTy);
582 fastMathFlags = flags;
598 if (flags == mlir::arith::FastMathFlags::none)
601 std::string fmfString{mlir::arith::stringifyFastMathFlags(flags)};
602 std::replace(fmfString.begin(), fmfString.end(),
',',
'_');
610 integerOverflowFlags = flags;
615 return integerOverflowFlags;
621 complexDivisionToRuntimeFlag = flag;
626 return complexDivisionToRuntimeFlag;
634 mlir::OpBuilder::InsertPoint previous)
override {
636 if (previous.isSet())
638 setCommonAttributes(op);
646 template <
typename OpTy>
648 mlir::Value left, mlir::Value right) {
649 if (!resultType.isIntOrFloat())
650 return OpTy::create(*
this, loc, resultType, left, right);
651 mlir::Type signlessType = mlir::IntegerType::get(
652 getContext(), resultType.getIntOrFloatBitWidth(),
653 mlir::IntegerType::SignednessSemantics::Signless);
654 mlir::Type opResType = resultType;
655 if (left.getType().isUnsignedInteger()) {
657 opResType = signlessType;
659 if (right.getType().isUnsignedInteger()) {
661 opResType = signlessType;
663 mlir::Value result = OpTy::create(*
this, loc, opResType, left, right);
664 if (resultType.isUnsignedInteger())
671 mlir::arith::CmpIPredicate predicate,
672 mlir::Value ptr1, mlir::Value ptr2) {
675 return mlir::arith::CmpIOp::create(*
this, loc, predicate, ptr1, ptr2);
681 void setCommonAttributes(mlir::Operation *op)
const;
687 mlir::arith::FastMathFlags fastMathFlags{};
691 mlir::arith::IntegerOverflowFlags integerOverflowFlags{};
695 bool complexDivisionToRuntimeFlag =
true;
699 mlir::SymbolTable *symbolTable =
nullptr;
704 std::unique_ptr<mlir::DataLayout> dataLayout =
nullptr;
719mlir::Value
readCharLen(fir::FirOpBuilder &builder, mlir::Location loc,
720 const fir::ExtendedValue &box);
723mlir::Value
readExtent(fir::FirOpBuilder &builder, mlir::Location loc,
724 const fir::ExtendedValue &box,
unsigned dim);
729mlir::Value
readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc,
730 const fir::ExtendedValue &box,
unsigned dim,
731 mlir::Value defaultValue);
734llvm::SmallVector<mlir::Value>
readExtents(fir::FirOpBuilder &builder,
736 const fir::BoxValue &box);
743fir::ExtendedValue
readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
744 const fir::BoxValue &box);
748llvm::SmallVector<mlir::Value>
750 const fir::ExtendedValue &exv);
755llvm::SmallVector<mlir::Value>
765 llvm::StringRef
string);
769std::string
uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name);
773llvm::SmallVector<mlir::Value>
createExtents(fir::FirOpBuilder &builder,
775 fir::SequenceType seqTy);
784mlir::Value
locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type);
794 mlir::Value component);
804 const fir::ExtendedValue &array,
805 mlir::Value element);
812 fir::FirOpBuilder &builder, mlir::Location loc,
813 const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice);
818 const fir::ExtendedValue &lhs,
819 const fir::ExtendedValue &rhs,
820 bool needFinalization =
false,
821 bool isTemporaryLHS =
false);
827 const fir::ExtendedValue &lhs,
828 const fir::ExtendedValue &rhs,
829 bool needFinalization =
false,
830 bool isTemporaryLHS =
false);
842 fir::ArrayLoadOp arrLoad,
843 llvm::ArrayRef<mlir::Value> path,
844 llvm::ArrayRef<mlir::Value> substring);
846 fir::SequenceType seqTy, mlir::Value memref,
847 llvm::ArrayRef<mlir::Value> typeParams,
848 llvm::ArrayRef<mlir::Value> path,
849 llvm::ArrayRef<mlir::Value> substring);
853mlir::Value
createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
862mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
863 mlir::Value lb, mlir::Value ub);
864mlir::Value
computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
865 mlir::Value lb, mlir::Value ub, mlir::Value zero,
869mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
871mlir::Value
genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
872 mlir::Value value, mlir::Value zero);
878 mlir::Value cPtr, mlir::Type ty);
882mlir::Value
genCDevPtrAddr(fir::FirOpBuilder &builder, mlir::Location loc,
883 mlir::Value cDevPtr, mlir::Type ty);
887 mlir::Location loc, mlir::Value cPtr);
891fir::BoxValue
createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
892 const fir::ExtendedValue &exv);
900mlir::Value
createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type,
906llvm::SmallVector<mlir::Value>
907elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
909llvm::SmallVector<mlir::Value>
910elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
922 mlir::ValueRange extents2);
924uint64_t getGlobalAddressSpace(mlir::DataLayout *dataLayout);
926uint64_t getProgramAddressSpace(mlir::DataLayout *dataLayout);
939 fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents);
947 llvm::SmallVectorImpl<mlir::Value> *lbounds,
948 llvm::SmallVectorImpl<mlir::Value> *extents,
949 llvm::SmallVectorImpl<mlir::Value> *strides);
955 fir::AllocaOp alloc,
const mlir::DataLayout *dl);
Definition MathOptionsBase.h:22
Definition BoxValue.h:125
Definition BoxValue.h:291
Definition BoxValue.h:478
Definition FIRBuilder.h:502
mlir::Operation::result_range getResults()
End the IfOp and return the results if any.
Definition FIRBuilder.h:522
Definition FIRBuilder.h:55
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:551
fir::StringLitOp createStringLitOp(mlir::Location loc, llvm::StringRef string)
Convert a StringRef string into a fir::StringLitOp.
Definition FIRBuilder.cpp:631
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={})
Create a global value.
Definition FIRBuilder.cpp:446
void genStackRestore(mlir::Location loc, mlir::Value stackPointer)
Definition FIRBuilder.cpp:439
mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str)
Wrap str to a SymbolRefAttr.
Definition FIRBuilder.h:166
mlir::Value createRealZeroConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with a value zero.
Definition FIRBuilder.h:207
mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path)
Definition FIRBuilder.cpp:697
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition FIRBuilder.cpp:611
IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion)
Definition FIRBuilder.h:536
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is a null address.
Definition FIRBuilder.cpp:855
mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol)
Definition FIRBuilder.h:396
mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType, llvm::APFloat::integerPart val)
Create a real constant from an integer value.
Definition FIRBuilder.cpp:177
mlir::Type getCharacterLengthType()
Get character length type.
Definition FIRBuilder.h:159
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:329
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:544
mlir::Value genStackSave(mlir::Location loc)
Definition FIRBuilder.cpp:433
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:663
const fir::KindMapping & getKindMap()
Get a reference to the kind map.
Definition FIRBuilder.h:122
mlir::Type getRefType(mlir::Type eleTy, bool isVolatile=false)
Safely create a reference type to the type eleTy.
Definition FIRBuilder.cpp:108
mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.cpp:166
mlir::ModuleOp getModule()
Get the current Module.
Definition FIRBuilder.h:112
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:392
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:339
mlir::Value createMinusOneInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.h:193
mlir::Value createVolatileCast(mlir::Location loc, bool isVolatile, mlir::Value value)
Cast value to have isVolatile volatility.
Definition FIRBuilder.cpp:581
void setComplexDivisionToRuntimeFlag(bool flag)
Definition FIRBuilder.h:620
mlir::IntegerType getDefaultIntegerType()
Get the default integer type.
Definition FIRBuilder.h:128
mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType={})
Definition FIRBuilder.cpp:138
void setFastMathFlags(mlir::arith::FastMathFlags flags)
Definition FIRBuilder.h:581
LLVM_DUMP_METHOD void dumpFunc()
Dump the current function. (debug)
Definition FIRBuilder.cpp:837
mlir::ArrayAttr create2DI64ArrayAttr(llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData)
Definition FIRBuilder.cpp:319
mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false)
Definition FIRBuilder.cpp:508
mlir::SymbolTable * getMLIRSymbolTable()
Get func.func/fir.global symbol table attached to this builder if any.
Definition FIRBuilder.h:125
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:305
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:670
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is not a null address.
Definition FIRBuilder.cpp:849
mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val)
Cast the input value to IndexType.
Definition FIRBuilder.h:456
void createStoreWithConvert(mlir::Location loc, mlir::Value val, mlir::Value addr)
Definition FIRBuilder.cpp:616
void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags)
Definition FIRBuilder.h:609
mlir::func::FuncOp createRuntimeFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty, bool isIO=false)
Definition FIRBuilder.cpp:52
mlir::Region & getRegion()
Get the current Region of the insertion point.
Definition FIRBuilder.h:109
void notifyOperationInserted(mlir::Operation *op, mlir::OpBuilder::InsertPoint previous) override
FirOpBuilder hook for creating new operation.
Definition FIRBuilder.h:633
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:420
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition FIRBuilder.h:387
mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type)
Definition FIRBuilder.cpp:861
std::string getFastMathFlagsString()
Definition FIRBuilder.h:596
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right)
Definition FIRBuilder.h:647
bool getComplexDivisionToRuntimeFlag() const
Get current ComplexDivisionToRuntimeFlag value.
Definition FIRBuilder.h:625
mlir::Value createBool(mlir::Location loc, bool b)
Create constant i1 with value 1. if b is true or 0. otherwise.
Definition FIRBuilder.h:490
mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const
Get current IntegerOverflowFlags value.
Definition FIRBuilder.h:614
mlir::func::FuncOp getFunction()
Get the current Function.
Definition FIRBuilder.h:117
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:353
mlir::Type getRealType(int kind)
Get the mlir float type that implements Fortran REAL(kind).
Definition FIRBuilder.cpp:118
mlir::Block * getAllocaBlock()
Get the block for adding Allocas.
Definition FIRBuilder.cpp:277
mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank=1)
Create a sequence of eleTy with rank dimensions of unknown size.
Definition FIRBuilder.cpp:113
mlir::Value loadIfRef(mlir::Location loc, mlir::Value val)
Definition FIRBuilder.cpp:625
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:377
mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Definition FIRBuilder.cpp:591
mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:676
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:237
mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy)
Definition FIRBuilder.cpp:878
mlir::arith::FastMathFlags getFastMathFlags() const
Get current FastMathFlags value.
Definition FIRBuilder.h:590
mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType, std::int64_t i)
Definition FIRBuilder.cpp:144
mlir::Value createBox(mlir::Location loc, const fir::ExtendedValue &exv, bool isPolymorphic=false, bool isAssumedType=false)
Definition FIRBuilder.cpp:748
mlir::Block * getEntryBlock()
Get the entry block of the current Function.
Definition FIRBuilder.h:145
mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty)
Definition FIRBuilder.h:435
mlir::DataLayout & getDataLayout()
Construct a data layout on demand and return it.
Definition FIRBuilder.cpp:941
mlir::Value createTemporary(mlir::Location loc, mlir::Type type, mlir::ValueRange shape)
Create an unnamed and untracked temporary on the stack.
Definition FIRBuilder.h:248
mlir::Type getIntPtrType()
Definition FIRBuilder.h:163
Definition KindMapping.h:48
Definition BoxValue.h:360
Definition BoxValue.h:445
fir::ExtendedValue componentToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value component)
Definition FIRBuilder.cpp:1296
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:1714
mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1654
llvm::SmallVector< mlir::Value > deduceOptimalExtents(mlir::ValueRange extents1, mlir::ValueRange extents2)
Definition FIRBuilder.cpp:1882
mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim, mlir::Value defaultValue)
Definition FIRBuilder.cpp:1008
std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name)
Definition FIRBuilder.cpp:1210
mlir::Value genCDevPtrAddr(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cDevPtr, mlir::Type ty)
Definition FIRBuilder.cpp:1764
llvm::SmallVector< mlir::Value > updateRuntimeExtentsForEmptyArrays(fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents)
Definition FIRBuilder.cpp:1909
void genScalarAssignment(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &lhs, const fir::ExtendedValue &rhs, bool needFinalization=false, bool isTemporaryLHS=false)
Definition FIRBuilder.cpp:1395
llvm::SmallVector< mlir::Value > getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1106
fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location, llvm::StringRef string)
Definition FIRBuilder.cpp:1248
mlir::TupleType getRaggedArrayHeaderType(fir::FirOpBuilder &builder)
Definition FIRBuilder.cpp:1587
mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location)
Generate a string literal containing the file name and return its address.
Definition FIRBuilder.cpp:1230
mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type)
Generate a constant of the given type with the location line number.
Definition FIRBuilder.cpp:1240
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:977
mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box)
Definition FIRBuilder.cpp:952
void genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value mem)
Definition FIRBuilder.cpp:1973
mlir::Value genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr, mlir::Type ty)
Definition FIRBuilder.cpp:1754
llvm::SmallVector< mlir::Value > readExtents(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Read extents from box.
Definition FIRBuilder.cpp:1038
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:1674
mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr)
Get the C address value.
Definition FIRBuilder.cpp:1783
uint64_t getAllocaAddressSpace(const mlir::DataLayout *dataLayout)
Get the address space which should be used for allocas.
Definition FIRBuilder.cpp:1874
void setInternalLinkage(mlir::func::FuncOp)
Set internal linkage attribute on a function.
Definition FIRBuilder.cpp:1866
mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType)
Generate Null BoxProc for procedure pointer null initialization.
Definition FIRBuilder.cpp:1855
fir::ExtendedValue arraySectionElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice)
Definition FIRBuilder.cpp:1380
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:1596
fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1817
void genDimInfoFromBox(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box, llvm::SmallVectorImpl< mlir::Value > *lbounds, llvm::SmallVectorImpl< mlir::Value > *extents, llvm::SmallVectorImpl< mlir::Value > *strides)
Definition FIRBuilder.cpp:1935
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:1540
mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type, mlir::Value)
Definition FIRBuilder.cpp:598
fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Definition FIRBuilder.cpp:1077
mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value lb, mlir::Value ub)
Definition FIRBuilder.cpp:1731
fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element)
Definition FIRBuilder.cpp:1350
llvm::SmallVector< mlir::Value > getNonDeferredLenParams(const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1128
llvm::SmallVector< mlir::Value > createExtents(fir::FirOpBuilder &builder, mlir::Location loc, fir::SequenceType seqTy)
Definition FIRBuilder.cpp:1270
mlir::Value genLifetimeStart(mlir::OpBuilder &builder, mlir::Location loc, fir::AllocaOp alloc, const mlir::DataLayout *dl)
Definition FIRBuilder.cpp:1961
Definition AbstractConverter.h:34
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:43
bool isAssumedType(mlir::Type ty)
Definition FIRType.cpp:353
Definition AbstractConverter.h:29