FLANG
FIRBuilder.h
1//===-- FirBuilder.h -- FIR operation builder -------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Builder routines for constructing the FIR dialect of MLIR. As FIR is a
10// dialect of MLIR, it makes extensive use of MLIR interfaces and MLIR's coding
11// style (https://mlir.llvm.org/getting_started/DeveloperGuide/) is used in this
12// module.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
17#define FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
18
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"
30#include <optional>
31#include <utility>
32
33namespace mlir {
34class DataLayout;
35class SymbolTable;
36}
37
38namespace fir {
40class ExtendedValue;
41class MutableBoxValue;
42class BoxValue;
43
45constexpr unsigned defaultArrayGlobalAlignment = 64;
47inline mlir::Type getIntPtrType(mlir::OpBuilder &builder) {
48 // TODO: Delay the need of such type until codegen or find a way to use
49 // llvm::DataLayout::getPointerSizeInBits here.
50 return builder.getI64Type();
51}
52
58mlir::Block *getAllocaBlock(mlir::Region &region);
59
60//===----------------------------------------------------------------------===//
61// FirOpBuilder
62//===----------------------------------------------------------------------===//
63
66class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
67public:
68 explicit FirOpBuilder(mlir::Operation *op, fir::KindMapping kindMap,
69 mlir::SymbolTable *symbolTable = nullptr)
70 : OpBuilder{op, /*listener=*/this}, kindMap{std::move(kindMap)},
71 symbolTable{symbolTable} {
72 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
73 if (fmi) {
74 // Set the builder with FastMathFlags attached to the operation.
75 setFastMathFlags(fmi.getFastMathFlagsAttr().getValue());
76 }
77 }
78 explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap,
79 mlir::SymbolTable *symbolTable = nullptr)
80 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)},
81 symbolTable{symbolTable} {
82 setListener(this);
83 }
84 explicit FirOpBuilder(mlir::OpBuilder &builder, mlir::ModuleOp mod)
85 : OpBuilder(builder), OpBuilder::Listener(),
86 kindMap{getKindMapping(mod)} {
87 setListener(this);
88 }
89 explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap,
90 mlir::Operation *op)
91 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)} {
92 setListener(this);
93 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
94 if (fmi) {
95 // Set the builder with FastMathFlags attached to the operation.
96 setFastMathFlags(fmi.getFastMathFlagsAttr().getValue());
97 }
98 }
99 FirOpBuilder(mlir::OpBuilder &builder, mlir::Operation *op)
100 : FirOpBuilder(builder, fir::getKindMapping(op), op) {}
101
102 // The listener self-reference has to be updated in case of copy-construction.
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} {
108 setListener(this);
109 }
110
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} {
116 setListener(this);
117 }
118
120 mlir::Region &getRegion() { return *getBlock()->getParent(); }
121
123 mlir::ModuleOp getModule() {
124 return getRegion().getParentOfType<mlir::ModuleOp>();
125 }
126
128 mlir::func::FuncOp getFunction() {
129 return getRegion().getParentOfType<mlir::func::FuncOp>();
130 }
131
133 const fir::KindMapping &getKindMap() { return kindMap; }
134
140 mlir::SymbolTable *getMLIRSymbolTable() { return symbolTable; }
141
143 [[maybe_unused]] mlir::IntegerType getDefaultIntegerType() {
144 return getIntegerType(
145 getKindMap().getIntegerBitsize(getKindMap().defaultIntegerKind()));
146 }
147
154 mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy,
155 mlir::Value val,
156 bool allowCharacterConversion = false,
157 bool allowRebox = false);
158
160 mlir::Block *getEntryBlock() { return &getFunction().front(); }
161
165 mlir::Block *getAllocaBlock();
166
168 mlir::Type getRefType(mlir::Type eleTy, bool isVolatile = false);
169
171 mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank = 1);
172
174 mlir::Type getCharacterLengthType() { return getIndexType(); }
175
178 mlir::Type getIntPtrType() { return fir::getIntPtrType(*this); }
179
181 mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str) {
182 return mlir::SymbolRefAttr::get(getContext(), str);
183 }
184
186 mlir::Type getRealType(int kind);
187
188 fir::BoxProcType getBoxProcType(mlir::FunctionType funcTy) {
189 return fir::BoxProcType::get(getContext(), funcTy);
190 }
191
194 mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType = {});
195
199 mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType,
200 std::int64_t i);
201
206 mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType,
207 const llvm::APInt &value);
208
211 mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType);
212
215 mlir::Value createMinusOneInteger(mlir::Location loc,
216 mlir::Type integerType) {
217 return createAllOnesInteger(loc, integerType);
218 }
219
221 mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType,
222 llvm::APFloat::integerPart val);
223
225 mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType,
226 const llvm::APFloat &val);
227
229 mlir::Value createRealZeroConstant(mlir::Location loc, mlir::Type realType) {
230 return createRealConstant(loc, realType, 0u);
231 }
232
234 mlir::Value createRealOneConstant(mlir::Location loc, mlir::Type realType) {
235 return createRealConstant(loc, realType, 1u);
236 }
237
240 mlir::Value allocateLocal(mlir::Location loc, mlir::Type ty,
241 llvm::StringRef uniqName, llvm::StringRef name,
242 bool pinned, llvm::ArrayRef<mlir::Value> shape,
244 bool asTarget = false);
245 mlir::Value allocateLocal(mlir::Location loc, mlir::Type ty,
246 llvm::StringRef uniqName, llvm::StringRef name,
249 bool asTarget = false);
250
253 mlir::ArrayAttr create2DI64ArrayAttr(
255
260 mlir::Value createTemporaryAlloc(
261 mlir::Location loc, mlir::Type type, llvm::StringRef name,
262 mlir::ValueRange lenParams = {}, mlir::ValueRange shape = {},
263 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
264 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt,
265 std::optional<std::int64_t> alignment = std::nullopt);
266
271 mlir::Value createTemporary(
272 mlir::Location loc, mlir::Type type, llvm::StringRef name = {},
273 mlir::ValueRange shape = {}, mlir::ValueRange lenParams = {},
274 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
275 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt,
276 std::optional<std::int64_t> alignment = std::nullopt);
277
279 mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
280 mlir::ValueRange shape) {
281 return createTemporary(loc, type, llvm::StringRef{}, shape);
282 }
283
284 mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
286 return createTemporary(loc, type, llvm::StringRef{}, {}, {}, attrs);
287 }
288
289 mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
290 llvm::StringRef name,
291 llvm::ArrayRef<mlir::NamedAttribute> attrs) {
292 return createTemporary(loc, type, name, {}, {}, attrs);
293 }
294
297 mlir::Value
298 createHeapTemporary(mlir::Location loc, mlir::Type type,
299 llvm::StringRef name = {}, mlir::ValueRange shape = {},
300 mlir::ValueRange lenParams = {},
301 llvm::ArrayRef<mlir::NamedAttribute> attrs = {},
302 std::optional<std::int64_t> alignment = std::nullopt);
303
308 static mlir::Value genTempDeclareOp(fir::FirOpBuilder &builder,
309 mlir::Location loc, mlir::Value memref,
310 llvm::StringRef name, mlir::Value shape,
311 llvm::ArrayRef<mlir::Value> typeParams,
312 fir::FortranVariableFlagsAttr attrs);
313
333 std::pair<mlir::Value, bool> createAndDeclareTemp(
334 mlir::Location loc, mlir::Type baseType, mlir::Value shape,
335 llvm::ArrayRef<mlir::Value> extents,
336 llvm::ArrayRef<mlir::Value> typeParams,
337 const std::function<decltype(genTempDeclareOp)> &genDeclare,
338 mlir::Value polymorphicMold, bool useStack, llvm::StringRef tmpName,
339 std::optional<std::int64_t> alignment = std::nullopt);
341 std::pair<mlir::Value, bool>
342 createArrayTemp(mlir::Location loc, fir::SequenceType arrayType,
343 mlir::Value shape, llvm::ArrayRef<mlir::Value> extents,
345 const std::function<decltype(genTempDeclareOp)> &genDeclare,
346 mlir::Value polymorphicMold, bool useStack = false,
347 llvm::StringRef tmpName = ".tmp.array",
348 std::optional<std::int64_t> alignment = std::nullopt) {
349 return createAndDeclareTemp(loc, arrayType, shape, extents, typeParams,
350 genDeclare, polymorphicMold, useStack, tmpName,
351 alignment);
352 }
353
357 mlir::Value genStackSave(mlir::Location loc);
358
361 void genStackRestore(mlir::Location loc, mlir::Value stackPointer);
362
364 fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type,
365 llvm::StringRef name,
366 fir::LinkageAttr linkage = {},
367 mlir::Attribute value = {}, bool isConst = false,
368 bool isTarget = false,
369 cuf::DataAttributeAttr dataAttr = {},
370 bool setDefaultAlignment = true);
371
372 fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type,
373 llvm::StringRef name, bool isConst, bool isTarget,
374 std::function<void(FirOpBuilder &)> bodyBuilder,
375 fir::LinkageAttr linkage = {},
376 cuf::DataAttributeAttr dataAttr = {},
377 bool setDefaultAlignment = true);
378
380 fir::GlobalOp createGlobalConstant(mlir::Location loc, mlir::Type type,
381 llvm::StringRef name,
382 fir::LinkageAttr linkage = {},
383 mlir::Attribute value = {}) {
384 return createGlobal(loc, type, name, linkage, value, /*isConst=*/true,
385 /*isTarget=*/false);
386 }
387
388 fir::GlobalOp
389 createGlobalConstant(mlir::Location loc, mlir::Type type,
390 llvm::StringRef name,
391 std::function<void(FirOpBuilder &)> bodyBuilder,
392 fir::LinkageAttr linkage = {}) {
393 return createGlobal(loc, type, name, /*isConst=*/true, /*isTarget=*/false,
394 bodyBuilder, linkage);
395 }
396
398 fir::StringLitOp createStringLitOp(mlir::Location loc,
399 llvm::StringRef string);
400
401 std::pair<fir::TypeInfoOp, mlir::OpBuilder::InsertPoint>
402 createTypeInfoOp(mlir::Location loc, fir::RecordType recordType,
403 fir::RecordType parentType);
404
405 //===--------------------------------------------------------------------===//
406 // Linkage helpers (inline). The default linkage is external.
407 //===--------------------------------------------------------------------===//
408
409 static fir::LinkageAttr createCommonLinkage(mlir::MLIRContext *context) {
410 return fir::LinkageAttr::get(context, fir::LinkageEnum::Common);
411 }
412 fir::LinkageAttr createCommonLinkage() {
413 return createCommonLinkage(getContext());
414 }
415
416 fir::LinkageAttr createExternalLinkage() {
417 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::External);
418 }
419
420 fir::LinkageAttr createInternalLinkage() {
421 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Internal);
422 }
423
424 fir::LinkageAttr createLinkOnceLinkage() {
425 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Linkonce);
426 }
427
428 fir::LinkageAttr createLinkOnceODRLinkage() {
429 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::LinkonceODR);
430 }
431
432 fir::LinkageAttr createWeakLinkage() {
433 return fir::LinkageAttr::get(getContext(), fir::LinkageEnum::Weak);
434 }
435
439 mlir::func::FuncOp getNamedFunction(llvm::StringRef name) {
441 }
442 static mlir::func::FuncOp
443 getNamedFunction(mlir::ModuleOp module, const mlir::SymbolTable *symbolTable,
444 llvm::StringRef name);
445
448 mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol) {
449 return getNamedFunction(getModule(), getMLIRSymbolTable(), symbol);
450 }
451 static mlir::func::FuncOp
452 getNamedFunction(mlir::ModuleOp module, const mlir::SymbolTable *symbolTable,
453 mlir::SymbolRefAttr symbol);
454
455 fir::GlobalOp getNamedGlobal(llvm::StringRef name) {
456 return getNamedGlobal(getModule(), getMLIRSymbolTable(), name);
457 }
458
459 static fir::GlobalOp getNamedGlobal(mlir::ModuleOp module,
460 const mlir::SymbolTable *symbolTable,
461 llvm::StringRef name);
462
464 mlir::Value createConvert(mlir::Location loc, mlir::Type toTy,
465 mlir::Value val);
466
469 mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy,
470 mlir::Value val);
471
473 mlir::Value createVolatileCast(mlir::Location loc, bool isVolatile,
474 mlir::Value value);
475
478 void createStoreWithConvert(mlir::Location loc, mlir::Value val,
479 mlir::Value addr);
480
483 mlir::Value loadIfRef(mlir::Location loc, mlir::Value val);
484
487 mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name,
488 mlir::FunctionType ty) {
489 return createFunction(loc, getModule(), name, ty, getMLIRSymbolTable());
490 }
491
492 static mlir::func::FuncOp createFunction(mlir::Location loc,
493 mlir::ModuleOp module,
494 llvm::StringRef name,
495 mlir::FunctionType ty,
496 mlir::SymbolTable *);
497
502 mlir::func::FuncOp createRuntimeFunction(mlir::Location loc,
503 llvm::StringRef name,
504 mlir::FunctionType ty,
505 bool isIO = false);
506
508 mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val) {
509 return createConvert(loc, getIndexType(), val);
510 }
511
513 mlir::Value genShape(mlir::Location loc, const fir::AbstractArrayBox &arr);
514 mlir::Value genShape(mlir::Location loc, llvm::ArrayRef<mlir::Value> shift,
516 mlir::Value genShape(mlir::Location loc, llvm::ArrayRef<mlir::Value> exts);
517 mlir::Value genShift(mlir::Location loc, llvm::ArrayRef<mlir::Value> shift);
518
521 mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv);
522
525 mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv,
526 mlir::ValueRange triples, mlir::ValueRange path);
527
534 mlir::Value createBox(mlir::Location loc, const fir::ExtendedValue &exv,
535 bool isPolymorphic = false, bool isAssumedType = false,
536 unsigned corank = 0);
537
538 mlir::Value createBox(mlir::Location loc, mlir::Type boxType,
539 mlir::Value addr, mlir::Value shape, mlir::Value slice,
540 llvm::ArrayRef<mlir::Value> lengths, mlir::Value tdesc);
541
543 mlir::Value createBool(mlir::Location loc, bool b) {
544 return createIntegerConstant(loc, getIntegerType(1), b ? 1 : 0);
545 }
546
547 //===--------------------------------------------------------------------===//
548 // If-Then-Else generation helper
549 //===--------------------------------------------------------------------===//
550
555 class IfBuilder {
556 public:
557 IfBuilder(fir::IfOp ifOp, FirOpBuilder &builder)
558 : ifOp{ifOp}, builder{builder} {}
559 template <typename CC>
560 IfBuilder &genThen(CC func) {
561 builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
562 func();
563 return *this;
564 }
565 template <typename CC>
566 IfBuilder &genElse(CC func) {
567 assert(!ifOp.getElseRegion().empty() && "must have else region");
568 builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
569 func();
570 return *this;
571 }
572 void end() { builder.setInsertionPointAfter(ifOp); }
573
575 mlir::Operation::result_range getResults() {
576 end();
577 return ifOp.getResults();
578 }
579
580 fir::IfOp &getIfOp() { return ifOp; };
581
582 private:
583 fir::IfOp ifOp;
584 FirOpBuilder &builder;
585 };
586
589 IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results,
590 mlir::Value cdt, bool withElseRegion) {
591 auto op = fir::IfOp::create(*this, loc, results, cdt, withElseRegion);
592 return IfBuilder(op, *this);
593 }
594
597 IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt) {
598 auto op = fir::IfOp::create(*this, loc, mlir::TypeRange(), cdt, false);
599 return IfBuilder(op, *this);
600 }
601
604 IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt) {
605 auto op = fir::IfOp::create(*this, loc, mlir::TypeRange(), cdt, true);
606 return IfBuilder(op, *this);
607 }
608
609 mlir::Value genNot(mlir::Location loc, mlir::Value boolean) {
610 return mlir::arith::CmpIOp::create(*this, loc,
611 mlir::arith::CmpIPredicate::eq, boolean,
612 createBool(loc, false));
613 }
614
616 mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr);
617
619 mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr);
620
623 mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb,
624 mlir::Value ub, mlir::Value step,
625 mlir::Type type, bool fold = false);
626
629 mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy);
630
634 void setFastMathFlags(mlir::arith::FastMathFlags flags) {
635 fastMathFlags = flags;
636 }
637
641
643 mlir::arith::FastMathFlags getFastMathFlags() const { return fastMathFlags; }
644
650 mlir::arith::FastMathFlags flags = getFastMathFlags();
651 if (flags == mlir::arith::FastMathFlags::none)
652 return {};
653
654 std::string fmfString{mlir::arith::stringifyFastMathFlags(flags)};
655 std::replace(fmfString.begin(), fmfString.end(), ',', '_');
656 return fmfString;
657 }
658
661 class FastMathFlagGuard {
662 public:
663 FastMathFlagGuard(FirOpBuilder &builder, mlir::arith::FastMathFlags flags)
664 : builder{builder}, savedFlags{builder.getFastMathFlags()} {
665 builder.setFastMathFlags(flags);
666 }
667 FastMathFlagGuard(const FastMathFlagGuard &) = delete;
668 FastMathFlagGuard &operator=(const FastMathFlagGuard &) = delete;
669 ~FastMathFlagGuard() { builder.setFastMathFlags(savedFlags); }
670
671 private:
672 FirOpBuilder &builder;
673 mlir::arith::FastMathFlags savedFlags;
674 };
675
679 void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags) {
680 integerOverflowFlags = flags;
681 }
682
684 mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const {
685 return integerOverflowFlags;
686 }
687
691 complexDivisionToRuntimeFlag = flag;
692 }
693
696 return complexDivisionToRuntimeFlag;
697 }
698
701 fpMaxminBehavior = mode;
702 }
703 Fortran::common::FPMaxminBehavior getFPMaxminBehavior() const {
704 return fpMaxminBehavior;
705 }
706
707#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
709 LLVM_DUMP_METHOD void dumpFunc();
710#endif
711
713 void notifyOperationInserted(mlir::Operation *op,
714 mlir::OpBuilder::InsertPoint previous) override {
715 // We only care about newly created operations.
716 if (previous.isSet())
717 return;
718 setCommonAttributes(op);
719 }
720
722 mlir::DataLayout &getDataLayout();
723
726 template <typename OpTy>
727 mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType,
728 mlir::Value left, mlir::Value right) {
729 if (!resultType.isIntOrFloat())
730 return OpTy::create(*this, loc, resultType, left, right);
731 mlir::Type signlessType = mlir::IntegerType::get(
732 getContext(), resultType.getIntOrFloatBitWidth(),
733 mlir::IntegerType::SignednessSemantics::Signless);
734 mlir::Type opResType = resultType;
735 if (left.getType().isUnsignedInteger()) {
736 left = createConvert(loc, signlessType, left);
737 opResType = signlessType;
738 }
739 if (right.getType().isUnsignedInteger()) {
740 right = createConvert(loc, signlessType, right);
741 opResType = signlessType;
742 }
743 mlir::Value result = OpTy::create(*this, loc, opResType, left, right);
744 if (resultType.isUnsignedInteger())
745 result = createConvert(loc, resultType, result);
746 return result;
747 }
748
750 mlir::Value genPtrCompare(mlir::Location loc,
751 mlir::arith::CmpIPredicate predicate,
752 mlir::Value ptr1, mlir::Value ptr2) {
753 ptr1 = createConvert(loc, getIndexType(), ptr1);
754 ptr2 = createConvert(loc, getIndexType(), ptr2);
755 return mlir::arith::CmpIOp::create(*this, loc, predicate, ptr1, ptr2);
756 }
757
758private:
761 void setCommonAttributes(mlir::Operation *op) const;
762
763 KindMapping kindMap;
764
767 mlir::arith::FastMathFlags fastMathFlags{};
768
774 Fortran::common::FPMaxminBehavior fpMaxminBehavior{
775 Fortran::common::FPMaxminBehavior::Legacy};
776
779 mlir::arith::IntegerOverflowFlags integerOverflowFlags{};
780
783 bool complexDivisionToRuntimeFlag = true;
784
787 mlir::SymbolTable *symbolTable = nullptr;
788
792 std::unique_ptr<mlir::DataLayout> dataLayout = nullptr;
793};
794
795} // namespace fir
796
797namespace fir::factory {
798
800
801//===----------------------------------------------------------------------===//
802// ExtendedValue inquiry helpers
803//===----------------------------------------------------------------------===//
804
809mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc,
810 const fir::ExtendedValue &box);
811
813mlir::Value readExtent(fir::FirOpBuilder &builder, mlir::Location loc,
814 const fir::ExtendedValue &box, unsigned dim);
815
819mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc,
820 const fir::ExtendedValue &box, unsigned dim,
821 mlir::Value defaultValue);
822
824llvm::SmallVector<mlir::Value> readExtents(fir::FirOpBuilder &builder,
825 mlir::Location loc,
826 const fir::BoxValue &box);
827
833fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
834 const fir::BoxValue &box);
835
838llvm::SmallVector<mlir::Value>
839getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc,
840 const fir::ExtendedValue &exv);
841
842//===----------------------------------------------------------------------===//
843// String literal helper helpers
844//===----------------------------------------------------------------------===//
845
848fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location,
849 llvm::StringRef string);
850
853std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name);
854
857llvm::SmallVector<mlir::Value> createExtents(fir::FirOpBuilder &builder,
858 mlir::Location loc,
859 fir::SequenceType seqTy);
860
861//===--------------------------------------------------------------------===//
862// Location helpers
863//===--------------------------------------------------------------------===//
864
866mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location);
868mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type);
869
870//===--------------------------------------------------------------------===//
871// ExtendedValue helpers
872//===--------------------------------------------------------------------===//
873
876fir::ExtendedValue componentToExtendedValue(fir::FirOpBuilder &builder,
877 mlir::Location loc,
878 mlir::Value component);
879
886fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder,
887 mlir::Location loc,
888 const fir::ExtendedValue &array,
889 mlir::Value element);
890
895fir::ExtendedValue arraySectionElementToExtendedValue(
896 fir::FirOpBuilder &builder, mlir::Location loc,
897 const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice);
898
901void genScalarAssignment(fir::FirOpBuilder &builder, mlir::Location loc,
902 const fir::ExtendedValue &lhs,
903 const fir::ExtendedValue &rhs,
904 bool needFinalization = false,
905 bool isTemporaryLHS = false,
906 mlir::ArrayAttr accessGroups = {});
907
911void genRecordAssignment(fir::FirOpBuilder &builder, mlir::Location loc,
912 const fir::ExtendedValue &lhs,
913 const fir::ExtendedValue &rhs,
914 bool needFinalization = false,
915 bool isTemporaryLHS = false);
916
919mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
920 mlir::Type type);
921
924mlir::Value createOneValue(fir::FirOpBuilder &builder, mlir::Location loc,
925 mlir::Type type);
926
929mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
930 mlir::Value lb, mlir::Value ub);
931mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc,
932 mlir::Value lb, mlir::Value ub, mlir::Value zero,
933 mlir::Value one);
934
936mlir::Value genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
937 mlir::Value value);
938mlir::Value genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
939 mlir::Value value, mlir::Value zero);
940
942mlir::Value genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder, mlir::Location loc,
943 mlir::Value cPtr, mlir::Type ty);
944
946mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder,
947 mlir::Location loc, mlir::Value cPtr);
948
951fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
952 const fir::ExtendedValue &exv,
953 unsigned corank = 0);
954
956mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc,
957 mlir::Type boxType);
958
961mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type,
962 mlir::Value);
963
965void setInternalLinkage(mlir::func::FuncOp);
966
967llvm::SmallVector<mlir::Value>
968elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
969
970llvm::SmallVector<mlir::Value>
971elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
972
974uint64_t getAllocaAddressSpace(const mlir::DataLayout *dataLayout);
975
982llvm::SmallVector<mlir::Value> deduceOptimalExtents(mlir::ValueRange extents1,
983 mlir::ValueRange extents2);
984
985uint64_t getGlobalAddressSpace(mlir::DataLayout *dataLayout);
986
987uint64_t getProgramAddressSpace(mlir::DataLayout *dataLayout);
988
999llvm::SmallVector<mlir::Value> updateRuntimeExtentsForEmptyArrays(
1000 fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents);
1001
1005mlir::Value genLifetimeStart(mlir::OpBuilder &builder, mlir::Location loc,
1006 fir::AllocaOp alloc, const mlir::DataLayout *dl);
1007
1010void genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc,
1011 mlir::Value mem);
1012
1018mlir::Value getDescriptorWithNewBaseAddress(fir::FirOpBuilder &builder,
1019 mlir::Location loc, mlir::Value box,
1020 mlir::Value newAddr);
1021
1023std::optional<mlir::Value>
1024genIndexBasedDisjointnessCheck(mlir::Location loc, fir::FirOpBuilder &builder,
1025 mlir::Value lhsRef, mlir::Value rhsRef);
1026
1028std::optional<mlir::Value>
1029genAddressBasedDisjointnessCheck(mlir::Location loc, fir::FirOpBuilder &builder,
1030 mlir::Value lhsRef, mlir::Value rhsRef);
1031
1032} // namespace fir::factory
1033
1034#endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
Definition MathOptionsBase.h:22
Definition BoxValue.h:124
Definition BoxValue.h:292
Definition BoxValue.h:469
Definition FIRBuilder.h:555
mlir::Operation::result_range getResults()
End the IfOp and return the results if any.
Definition FIRBuilder.h:575
Definition FIRBuilder.h:66
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:604
fir::StringLitOp createStringLitOp(mlir::Location loc, llvm::StringRef string)
Convert a StringRef string into a fir::StringLitOp.
Definition FIRBuilder.cpp:688
mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type, bool fold=false)
Definition FIRBuilder.cpp:929
mlir::Value createTemporary(mlir::Location loc, mlir::Type type, llvm::StringRef name={}, mlir::ValueRange shape={}, mlir::ValueRange lenParams={}, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, std::optional< Fortran::common::CUDADataAttr > cudaAttr=std::nullopt, std::optional< std::int64_t > alignment=std::nullopt)
Definition FIRBuilder.cpp:394
void genStackRestore(mlir::Location loc, mlir::Value stackPointer)
Definition FIRBuilder.cpp:490
mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str)
Wrap str to a SymbolRefAttr.
Definition FIRBuilder.h:181
mlir::Value createRealZeroConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with a value zero.
Definition FIRBuilder.h:229
void setFPMaxminBehavior(Fortran::common::FPMaxminBehavior mode)
Setter/getter for fpMaxminBehavior.
Definition FIRBuilder.h:700
mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path)
Definition FIRBuilder.cpp:754
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition FIRBuilder.cpp:668
IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion)
Definition FIRBuilder.h:589
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is a null address.
Definition FIRBuilder.cpp:914
mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol)
Definition FIRBuilder.h:448
mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType, llvm::APFloat::integerPart val)
Create a real constant from an integer value.
Definition FIRBuilder.cpp:201
mlir::Type getCharacterLengthType()
Get character length type.
Definition FIRBuilder.h:174
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt)
Definition FIRBuilder.h:597
mlir::Value genStackSave(mlir::Location loc)
Definition FIRBuilder.cpp:484
mlir::Value genShape(mlir::Location loc, const fir::AbstractArrayBox &arr)
Construct one of the two forms of shape op from an array box.
Definition FIRBuilder.cpp:720
const fir::KindMapping & getKindMap()
Get a reference to the kind map.
Definition FIRBuilder.h:133
mlir::Type getRefType(mlir::Type eleTy, bool isVolatile=false)
Safely create a reference type to the type eleTy.
Definition FIRBuilder.cpp:114
mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.cpp:190
mlir::ModuleOp getModule()
Get the current Module.
Definition FIRBuilder.h:123
mlir::Value createMinusOneInteger(mlir::Location loc, mlir::Type integerType)
Definition FIRBuilder.h:215
mlir::Value createVolatileCast(mlir::Location loc, bool isVolatile, mlir::Value value)
Cast value to have isVolatile volatility.
Definition FIRBuilder.cpp:638
void setComplexDivisionToRuntimeFlag(bool flag)
Definition FIRBuilder.h:690
mlir::IntegerType getDefaultIntegerType()
Get the default integer type.
Definition FIRBuilder.h:143
mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType={})
Definition FIRBuilder.cpp:144
void setFastMathFlags(mlir::arith::FastMathFlags flags)
Definition FIRBuilder.h:634
LLVM_DUMP_METHOD void dumpFunc()
Dump the current function. (debug)
Definition FIRBuilder.cpp:895
mlir::ArrayAttr create2DI64ArrayAttr(llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData)
Definition FIRBuilder.cpp:356
fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type, llvm::StringRef name, fir::LinkageAttr linkage={}, mlir::Attribute value={}, bool isConst=false, bool isTarget=false, cuf::DataAttributeAttr dataAttr={}, bool setDefaultAlignment=true)
Create a global value.
Definition FIRBuilder.cpp:497
mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false)
Definition FIRBuilder.cpp:565
mlir::SymbolTable * getMLIRSymbolTable()
Definition FIRBuilder.h:140
mlir::Value genPtrCompare(mlir::Location loc, mlir::arith::CmpIPredicate predicate, mlir::Value ptr1, mlir::Value ptr2)
Compare two pointer-like values using the given predicate.
Definition FIRBuilder.h:750
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is not a null address.
Definition FIRBuilder.cpp:908
mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val)
Cast the input value to IndexType.
Definition FIRBuilder.h:508
void createStoreWithConvert(mlir::Location loc, mlir::Value val, mlir::Value addr)
Definition FIRBuilder.cpp:673
void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags)
Definition FIRBuilder.h:679
mlir::func::FuncOp createRuntimeFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty, bool isIO=false)
Definition FIRBuilder.cpp:56
mlir::Value createBox(mlir::Location loc, const fir::ExtendedValue &exv, bool isPolymorphic=false, bool isAssumedType=false, unsigned corank=0)
Definition FIRBuilder.cpp:805
std::pair< mlir::Value, bool > createAndDeclareTemp(mlir::Location loc, mlir::Type baseType, mlir::Value shape, llvm::ArrayRef< mlir::Value > extents, llvm::ArrayRef< mlir::Value > typeParams, const std::function< decltype(genTempDeclareOp)> &genDeclare, mlir::Value polymorphicMold, bool useStack, llvm::StringRef tmpName, std::optional< std::int64_t > alignment=std::nullopt)
Definition FIRBuilder.cpp:438
std::pair< mlir::Value, bool > createArrayTemp(mlir::Location loc, fir::SequenceType arrayType, mlir::Value shape, llvm::ArrayRef< mlir::Value > extents, llvm::ArrayRef< mlir::Value > typeParams, const std::function< decltype(genTempDeclareOp)> &genDeclare, mlir::Value polymorphicMold, bool useStack=false, llvm::StringRef tmpName=".tmp.array", std::optional< std::int64_t > alignment=std::nullopt)
Create and declare an array temporary.
Definition FIRBuilder.h:342
mlir::Region & getRegion()
Get the current Region of the insertion point.
Definition FIRBuilder.h:120
void notifyOperationInserted(mlir::Operation *op, mlir::OpBuilder::InsertPoint previous) override
FirOpBuilder hook for creating new operation.
Definition FIRBuilder.h:713
static mlir::Value genTempDeclareOp(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value memref, llvm::StringRef name, mlir::Value shape, llvm::ArrayRef< mlir::Value > typeParams, fir::FortranVariableFlagsAttr attrs)
Definition FIRBuilder.cpp:470
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition FIRBuilder.h:439
std::string getFastMathFlagsString()
Definition FIRBuilder.h:649
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right)
Definition FIRBuilder.h:727
bool getComplexDivisionToRuntimeFlag() const
Get current ComplexDivisionToRuntimeFlag value.
Definition FIRBuilder.h:695
mlir::Value createBool(mlir::Location loc, bool b)
Create constant i1 with value 1. if b is true or 0. otherwise.
Definition FIRBuilder.h:543
mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const
Get current IntegerOverflowFlags value.
Definition FIRBuilder.h:684
mlir::func::FuncOp getFunction()
Get the current Function.
Definition FIRBuilder.h:128
mlir::Type getRealType(int kind)
Get the mlir float type that implements Fortran REAL(kind).
Definition FIRBuilder.cpp:124
fir::GlobalOp createGlobalConstant(mlir::Location loc, mlir::Type type, llvm::StringRef name, fir::LinkageAttr linkage={}, mlir::Attribute value={})
Create a global constant (read-only) value.
Definition FIRBuilder.h:380
mlir::Block * getAllocaBlock()
Definition FIRBuilder.cpp:342
mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank=1)
Create a sequence of eleTy with rank dimensions of unknown size.
Definition FIRBuilder.cpp:119
mlir::Value loadIfRef(mlir::Location loc, mlir::Value val)
Definition FIRBuilder.cpp:682
mlir::Value createConvertWithVolatileCast(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Definition FIRBuilder.cpp:648
mlir::Value createTemporaryAlloc(mlir::Location loc, mlir::Type type, llvm::StringRef name, mlir::ValueRange lenParams={}, mlir::ValueRange shape={}, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, std::optional< Fortran::common::CUDADataAttr > cudaAttr=std::nullopt, std::optional< std::int64_t > alignment=std::nullopt)
Definition FIRBuilder.cpp:366
mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:733
mlir::Value allocateLocal(mlir::Location loc, mlir::Type ty, llvm::StringRef uniqName, llvm::StringRef name, bool pinned, llvm::ArrayRef< mlir::Value > shape, llvm::ArrayRef< mlir::Value > lenParams, bool asTarget=false)
Definition FIRBuilder.cpp:261
mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy)
Definition FIRBuilder.cpp:948
mlir::arith::FastMathFlags getFastMathFlags() const
Get current FastMathFlags value.
Definition FIRBuilder.h:643
mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType, std::int64_t i)
Definition FIRBuilder.cpp:150
mlir::Value createRealOneConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with value one.
Definition FIRBuilder.h:234
mlir::Block * getEntryBlock()
Get the entry block of the current Function.
Definition FIRBuilder.h:160
mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty)
Definition FIRBuilder.h:487
mlir::DataLayout & getDataLayout()
Construct a data layout on demand and return it.
Definition FIRBuilder.cpp:1011
mlir::Value createTemporary(mlir::Location loc, mlir::Type type, mlir::ValueRange shape)
Create an unnamed and untracked temporary on the stack.
Definition FIRBuilder.h:279
mlir::Type getIntPtrType()
Definition FIRBuilder.h:178
mlir::Value createHeapTemporary(mlir::Location loc, mlir::Type type, llvm::StringRef name={}, mlir::ValueRange shape={}, mlir::ValueRange lenParams={}, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, std::optional< std::int64_t > alignment=std::nullopt)
Definition FIRBuilder.cpp:419
Definition KindMapping.h:48
Definition BoxValue.h:361
Definition FIRType.h:106
Definition OpenACC.h:22
Definition OpenACC.h:20
FPMaxminBehavior
Definition FPMaxminBehavior.h:29
Definition BoxValue.h:446
fir::ExtendedValue componentToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value component)
Definition FIRBuilder.cpp:1309
mlir::Value genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value value)
Generate max(value, 0) where value is a scalar integer.
Definition FIRBuilder.cpp:1609
mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1557
void genScalarAssignment(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &lhs, const fir::ExtendedValue &rhs, bool needFinalization=false, bool isTemporaryLHS=false, mlir::ArrayAttr accessGroups={})
Definition FIRBuilder.cpp:1408
llvm::SmallVector< mlir::Value > deduceOptimalExtents(mlir::ValueRange extents1, mlir::ValueRange extents2)
Definition FIRBuilder.cpp:1767
fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv, unsigned corank=0)
Definition FIRBuilder.cpp:1701
mlir::Value getDescriptorWithNewBaseAddress(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value box, mlir::Value newAddr)
Definition FIRBuilder.cpp:1837
mlir::Value createOneValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type)
Definition FIRBuilder.cpp:1576
mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim, mlir::Value defaultValue)
Definition FIRBuilder.cpp:1078
std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name)
Definition FIRBuilder.cpp:1223
llvm::SmallVector< mlir::Value > updateRuntimeExtentsForEmptyArrays(fir::FirOpBuilder &builder, mlir::Location loc, mlir::ValueRange extents)
Definition FIRBuilder.cpp:1794
llvm::SmallVector< mlir::Value > getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &exv)
Definition FIRBuilder.cpp:1176
fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location, llvm::StringRef string)
Definition FIRBuilder.cpp:1261
mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location)
Generate a string literal containing the file name and return its address.
Definition FIRBuilder.cpp:1243
mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type)
Generate a constant of the given type with the location line number.
Definition FIRBuilder.cpp:1253
std::optional< mlir::Value > genIndexBasedDisjointnessCheck(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value lhsRef, mlir::Value rhsRef)
Generate a index-based disjointness check.
Definition FIRBuilder.cpp:1859
mlir::Value readExtent(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box, unsigned dim)
Read or get the extent in dimension dim of the array described by box.
Definition FIRBuilder.cpp:1047
mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &box)
Definition FIRBuilder.cpp:1022
void genLifetimeEnd(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value mem)
Definition FIRBuilder.cpp:1832
std::optional< mlir::Value > genAddressBasedDisjointnessCheck(mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value lhsRef, mlir::Value rhsRef)
Generate a address-based disjointness check.
Definition FIRBuilder.cpp:1912
mlir::Value genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr, mlir::Type ty)
Get the C address from a type(C_PTR/C_FUNPTR/C_DEVPTR) entity.
Definition FIRBuilder.cpp:1649
llvm::SmallVector< mlir::Value > readExtents(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Read extents from box.
Definition FIRBuilder.cpp:1108
mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value cPtr)
Get the C address value.
Definition FIRBuilder.cpp:1667
uint64_t getAllocaAddressSpace(const mlir::DataLayout *dataLayout)
Get the address space which should be used for allocas.
Definition FIRBuilder.cpp:1759
void setInternalLinkage(mlir::func::FuncOp)
Set internal linkage attribute on a function.
Definition FIRBuilder.cpp:1751
mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type boxType)
Generate Null BoxProc for procedure pointer null initialization.
Definition FIRBuilder.cpp:1740
fir::ExtendedValue arraySectionElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice)
Definition FIRBuilder.cpp:1393
void genRecordAssignment(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &lhs, const fir::ExtendedValue &rhs, bool needFinalization=false, bool isTemporaryLHS=false)
Definition FIRBuilder.cpp:1473
mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type, mlir::Value)
Definition FIRBuilder.cpp:655
fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::BoxValue &box)
Definition FIRBuilder.cpp:1147
mlir::Value computeExtent(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Value lb, mlir::Value ub)
Definition FIRBuilder.cpp:1626
fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder, mlir::Location loc, const fir::ExtendedValue &array, mlir::Value element)
Definition FIRBuilder.cpp:1363
llvm::SmallVector< mlir::Value > createExtents(fir::FirOpBuilder &builder, mlir::Location loc, fir::SequenceType seqTy)
Definition FIRBuilder.cpp:1283
mlir::Value genLifetimeStart(mlir::OpBuilder &builder, mlir::Location loc, fir::AllocaOp alloc, const mlir::DataLayout *dl)
Definition FIRBuilder.cpp:1820
Definition AbstractConverter.h:37
KindMapping getKindMapping(mlir::ModuleOp mod)
Definition FIRContext.cpp:43
mlir::Type getIntPtrType(mlir::OpBuilder &builder)
Get the integer type with a pointer size.
Definition FIRBuilder.h:47
void genDimInfoFromBox(mlir::OpBuilder &builder, mlir::Location loc, mlir::Value box, llvm::SmallVectorImpl< mlir::Value > *lbounds, llvm::SmallVectorImpl< mlir::Value > *extents, llvm::SmallVectorImpl< mlir::Value > *strides)
Definition FIRBoxUtils.cpp:16
constexpr unsigned defaultArrayGlobalAlignment
Default alignment (in bytes) applied to array globals.
Definition FIRBuilder.h:45
mlir::Block * getAllocaBlock(mlir::Region &region)
Get the block for adding Allocas.
Definition FIRBuilder.cpp:301
bool isAssumedType(mlir::Type ty)
Definition FIRType.cpp:372
Definition AbstractConverter.h:32