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
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"
25#include "mlir/IR/Builders.h"
26#include "mlir/IR/BuiltinOps.h"
27#include "llvm/ADT/DenseMap.h"
28#include <optional>
29#include <utility>
30
31namespace mlir {
32class DataLayout;
33class SymbolTable;
34}
35
36namespace fir {
37class AbstractArrayBox;
38class ExtendedValue;
39class MutableBoxValue;
40class BoxValue;
41
43inline mlir::Type getIntPtrType(mlir::OpBuilder &builder) {
44 // TODO: Delay the need of such type until codegen or find a way to use
45 // llvm::DataLayout::getPointerSizeInBits here.
46 return builder.getI64Type();
47}
48
49//===----------------------------------------------------------------------===//
50// FirOpBuilder
51//===----------------------------------------------------------------------===//
52
55class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
56public:
57 explicit FirOpBuilder(mlir::Operation *op, fir::KindMapping kindMap,
58 mlir::SymbolTable *symbolTable = nullptr)
59 : OpBuilder{op, /*listener=*/this}, kindMap{std::move(kindMap)},
60 symbolTable{symbolTable} {}
61 explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap,
62 mlir::SymbolTable *symbolTable = nullptr)
63 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)},
64 symbolTable{symbolTable} {
65 setListener(this);
66 }
67 explicit FirOpBuilder(mlir::OpBuilder &builder, mlir::ModuleOp mod)
68 : OpBuilder(builder), OpBuilder::Listener(),
69 kindMap{getKindMapping(mod)} {
70 setListener(this);
71 }
72 explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap,
73 mlir::Operation *op)
74 : OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)} {
75 setListener(this);
76 auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
77 if (fmi) {
78 // Set the builder with FastMathFlags attached to the operation.
79 setFastMathFlags(fmi.getFastMathFlagsAttr().getValue());
80 }
81 }
82 FirOpBuilder(mlir::OpBuilder &builder, mlir::Operation *op)
83 : FirOpBuilder(builder, fir::getKindMapping(op), op) {}
84
85 // The listener self-reference has to be updated in case of copy-construction.
86 FirOpBuilder(const FirOpBuilder &other)
87 : OpBuilder(other), OpBuilder::Listener(), kindMap{other.kindMap},
88 fastMathFlags{other.fastMathFlags},
89 integerOverflowFlags{other.integerOverflowFlags},
90 symbolTable{other.symbolTable} {
91 setListener(this);
92 }
93
95 : OpBuilder(other), OpBuilder::Listener(),
96 kindMap{std::move(other.kindMap)}, fastMathFlags{other.fastMathFlags},
97 integerOverflowFlags{other.integerOverflowFlags},
98 symbolTable{other.symbolTable} {
99 setListener(this);
100 }
101
103 mlir::Region &getRegion() { return *getBlock()->getParent(); }
104
106 mlir::ModuleOp getModule() {
107 return getRegion().getParentOfType<mlir::ModuleOp>();
108 }
109
111 mlir::func::FuncOp getFunction() {
112 return getRegion().getParentOfType<mlir::func::FuncOp>();
113 }
114
116 const fir::KindMapping &getKindMap() { return kindMap; }
117
119 mlir::SymbolTable *getMLIRSymbolTable() { return symbolTable; }
120
122 [[maybe_unused]] mlir::IntegerType getDefaultIntegerType() {
123 return getIntegerType(
124 getKindMap().getIntegerBitsize(getKindMap().defaultIntegerKind()));
125 }
126
133 mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy,
134 mlir::Value val,
135 bool allowCharacterConversion = false,
136 bool allowRebox = false);
137
139 mlir::Block *getEntryBlock() { return &getFunction().front(); }
140
144 mlir::Block *getAllocaBlock();
145
147 mlir::Type getRefType(mlir::Type eleTy);
148
150 mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank = 1);
151
153 mlir::Type getCharacterLengthType() { return getIndexType(); }
154
157 mlir::Type getIntPtrType() { return fir::getIntPtrType(*this); }
158
160 mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str) {
161 return mlir::SymbolRefAttr::get(getContext(), str);
162 }
163
165 mlir::Type getRealType(int kind);
166
167 fir::BoxProcType getBoxProcType(mlir::FunctionType funcTy) {
168 return fir::BoxProcType::get(getContext(), funcTy);
169 }
170
173 mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType = {});
174
178 mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType,
179 std::int64_t i);
180
183 mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType);
184
187 mlir::Value createMinusOneInteger(mlir::Location loc,
188 mlir::Type integerType) {
189 return createAllOnesInteger(loc, integerType);
190 }
191
193 mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType,
194 llvm::APFloat::integerPart val);
195
197 mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType,
198 const llvm::APFloat &val);
199
201 mlir::Value createRealZeroConstant(mlir::Location loc, mlir::Type realType) {
202 return createRealConstant(loc, realType, 0u);
203 }
204
207 mlir::Value allocateLocal(mlir::Location loc, mlir::Type ty,
208 llvm::StringRef uniqName, llvm::StringRef name,
209 bool pinned, llvm::ArrayRef<mlir::Value> shape,
211 bool asTarget = false);
212 mlir::Value allocateLocal(mlir::Location loc, mlir::Type ty,
213 llvm::StringRef uniqName, llvm::StringRef name,
216 bool asTarget = false);
217
220 mlir::ArrayAttr create2DI64ArrayAttr(
221 llvm::SmallVectorImpl<llvm::SmallVector<int64_t>> &intData);
222
226 mlir::Value createTemporaryAlloc(
227 mlir::Location loc, mlir::Type type, llvm::StringRef name,
228 mlir::ValueRange lenParams = {}, mlir::ValueRange shape = {},
230 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
231
235 mlir::Value createTemporary(
236 mlir::Location loc, mlir::Type type, llvm::StringRef name = {},
237 mlir::ValueRange shape = {}, mlir::ValueRange lenParams = {},
239 std::optional<Fortran::common::CUDADataAttr> cudaAttr = std::nullopt);
240
242 mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
243 mlir::ValueRange shape) {
244 return createTemporary(loc, type, llvm::StringRef{}, shape);
245 }
246
247 mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
249 return createTemporary(loc, type, llvm::StringRef{}, {}, {}, attrs);
250 }
251
252 mlir::Value createTemporary(mlir::Location loc, mlir::Type type,
253 llvm::StringRef name,
255 return createTemporary(loc, type, name, {}, {}, attrs);
256 }
257
259 mlir::Value
260 createHeapTemporary(mlir::Location loc, mlir::Type type,
261 llvm::StringRef name = {}, mlir::ValueRange shape = {},
262 mlir::ValueRange lenParams = {},
264
268 mlir::Value genStackSave(mlir::Location loc);
269
272 void genStackRestore(mlir::Location loc, mlir::Value stackPointer);
273
275 fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type,
276 llvm::StringRef name,
277 mlir::StringAttr linkage = {},
278 mlir::Attribute value = {}, bool isConst = false,
279 bool isTarget = false,
280 cuf::DataAttributeAttr dataAttr = {});
281
282 fir::GlobalOp createGlobal(mlir::Location loc, mlir::Type type,
283 llvm::StringRef name, bool isConst, bool isTarget,
284 std::function<void(FirOpBuilder &)> bodyBuilder,
285 mlir::StringAttr linkage = {},
286 cuf::DataAttributeAttr dataAttr = {});
287
289 fir::GlobalOp createGlobalConstant(mlir::Location loc, mlir::Type type,
290 llvm::StringRef name,
291 mlir::StringAttr linkage = {},
292 mlir::Attribute value = {}) {
293 return createGlobal(loc, type, name, linkage, value, /*isConst=*/true,
294 /*isTarget=*/false);
295 }
296
297 fir::GlobalOp
298 createGlobalConstant(mlir::Location loc, mlir::Type type,
299 llvm::StringRef name,
300 std::function<void(FirOpBuilder &)> bodyBuilder,
301 mlir::StringAttr linkage = {}) {
302 return createGlobal(loc, type, name, /*isConst=*/true, /*isTarget=*/false,
303 bodyBuilder, linkage);
304 }
305
307 fir::StringLitOp createStringLitOp(mlir::Location loc,
308 llvm::StringRef string);
309
310 std::pair<fir::TypeInfoOp, mlir::OpBuilder::InsertPoint>
311 createTypeInfoOp(mlir::Location loc, fir::RecordType recordType,
312 fir::RecordType parentType);
313
314 //===--------------------------------------------------------------------===//
315 // Linkage helpers (inline). The default linkage is external.
316 //===--------------------------------------------------------------------===//
317
318 mlir::StringAttr createCommonLinkage() { return getStringAttr("common"); }
319
320 mlir::StringAttr createInternalLinkage() { return getStringAttr("internal"); }
321
322 mlir::StringAttr createLinkOnceLinkage() { return getStringAttr("linkonce"); }
323
324 mlir::StringAttr createLinkOnceODRLinkage() {
325 return getStringAttr("linkonce_odr");
326 }
327
328 mlir::StringAttr createWeakLinkage() { return getStringAttr("weak"); }
329
332 mlir::func::FuncOp getNamedFunction(llvm::StringRef name) {
334 }
335 static mlir::func::FuncOp
336 getNamedFunction(mlir::ModuleOp module, const mlir::SymbolTable *symbolTable,
337 llvm::StringRef name);
338
341 mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol) {
342 return getNamedFunction(getModule(), getMLIRSymbolTable(), symbol);
343 }
344 static mlir::func::FuncOp
345 getNamedFunction(mlir::ModuleOp module, const mlir::SymbolTable *symbolTable,
346 mlir::SymbolRefAttr symbol);
347
348 fir::GlobalOp getNamedGlobal(llvm::StringRef name) {
349 return getNamedGlobal(getModule(), getMLIRSymbolTable(), name);
350 }
351
352 static fir::GlobalOp getNamedGlobal(mlir::ModuleOp module,
353 const mlir::SymbolTable *symbolTable,
354 llvm::StringRef name);
355
357 mlir::Value createConvert(mlir::Location loc, mlir::Type toTy,
358 mlir::Value val);
359
362 void createStoreWithConvert(mlir::Location loc, mlir::Value val,
363 mlir::Value addr);
364
367 mlir::Value loadIfRef(mlir::Location loc, mlir::Value val);
368
371 mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name,
372 mlir::FunctionType ty) {
373 return createFunction(loc, getModule(), name, ty, getMLIRSymbolTable());
374 }
375
376 static mlir::func::FuncOp createFunction(mlir::Location loc,
377 mlir::ModuleOp module,
378 llvm::StringRef name,
379 mlir::FunctionType ty,
380 mlir::SymbolTable *);
381
383 mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val) {
384 return createConvert(loc, getIndexType(), val);
385 }
386
388 mlir::Value genShape(mlir::Location loc, const fir::AbstractArrayBox &arr);
389 mlir::Value genShape(mlir::Location loc, llvm::ArrayRef<mlir::Value> shift,
391 mlir::Value genShape(mlir::Location loc, llvm::ArrayRef<mlir::Value> exts);
392 mlir::Value genShift(mlir::Location loc, llvm::ArrayRef<mlir::Value> shift);
393
396 mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv);
397
400 mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv,
401 mlir::ValueRange triples, mlir::ValueRange path);
402
409 mlir::Value createBox(mlir::Location loc, const fir::ExtendedValue &exv,
410 bool isPolymorphic = false, bool isAssumedType = false);
411
412 mlir::Value createBox(mlir::Location loc, mlir::Type boxType,
413 mlir::Value addr, mlir::Value shape, mlir::Value slice,
414 llvm::ArrayRef<mlir::Value> lengths, mlir::Value tdesc);
415
417 mlir::Value createBool(mlir::Location loc, bool b) {
418 return createIntegerConstant(loc, getIntegerType(1), b ? 1 : 0);
419 }
420
421 //===--------------------------------------------------------------------===//
422 // If-Then-Else generation helper
423 //===--------------------------------------------------------------------===//
424
429 class IfBuilder {
430 public:
431 IfBuilder(fir::IfOp ifOp, FirOpBuilder &builder)
432 : ifOp{ifOp}, builder{builder} {}
433 template <typename CC>
434 IfBuilder &genThen(CC func) {
435 builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
436 func();
437 return *this;
438 }
439 template <typename CC>
440 IfBuilder &genElse(CC func) {
441 assert(!ifOp.getElseRegion().empty() && "must have else region");
442 builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
443 func();
444 return *this;
445 }
446 void end() { builder.setInsertionPointAfter(ifOp); }
447
449 mlir::Operation::result_range getResults() {
450 end();
451 return ifOp.getResults();
452 }
453
454 fir::IfOp &getIfOp() { return ifOp; };
455
456 private:
457 fir::IfOp ifOp;
458 FirOpBuilder &builder;
459 };
460
463 IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results,
464 mlir::Value cdt, bool withElseRegion) {
465 auto op = create<fir::IfOp>(loc, results, cdt, withElseRegion);
466 return IfBuilder(op, *this);
467 }
468
471 IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt) {
472 auto op = create<fir::IfOp>(loc, std::nullopt, cdt, false);
473 return IfBuilder(op, *this);
474 }
475
478 IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt) {
479 auto op = create<fir::IfOp>(loc, std::nullopt, cdt, true);
480 return IfBuilder(op, *this);
481 }
482
483 mlir::Value genNot(mlir::Location loc, mlir::Value boolean) {
484 return create<mlir::arith::CmpIOp>(loc, mlir::arith::CmpIPredicate::eq,
485 boolean, createBool(loc, false));
486 }
487
489 mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr);
490
492 mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr);
493
496 mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb,
497 mlir::Value ub, mlir::Value step,
498 mlir::Type type);
499
502 mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy);
503
507 void setFastMathFlags(mlir::arith::FastMathFlags flags) {
508 fastMathFlags = flags;
509 }
510
514
516 mlir::arith::FastMathFlags getFastMathFlags() const { return fastMathFlags; }
517
523 mlir::arith::FastMathFlags flags = getFastMathFlags();
524 if (flags == mlir::arith::FastMathFlags::none)
525 return {};
526
527 std::string fmfString{mlir::arith::stringifyFastMathFlags(flags)};
528 std::replace(fmfString.begin(), fmfString.end(), ',', '_');
529 return fmfString;
530 }
531
535 void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags) {
536 integerOverflowFlags = flags;
537 }
538
540 mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const {
541 return integerOverflowFlags;
542 }
543
545 LLVM_DUMP_METHOD void dumpFunc();
546
548 void notifyOperationInserted(mlir::Operation *op,
549 mlir::OpBuilder::InsertPoint previous) override {
550 // We only care about newly created operations.
551 if (previous.isSet())
552 return;
553 setCommonAttributes(op);
554 }
555
557 mlir::DataLayout &getDataLayout();
558
561 template <typename OpTy>
562 mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType,
563 mlir::Value left, mlir::Value right) {
564 if (!resultType.isIntOrFloat())
565 return create<OpTy>(loc, resultType, left, right);
566 mlir::Type signlessType = mlir::IntegerType::get(
567 getContext(), resultType.getIntOrFloatBitWidth(),
568 mlir::IntegerType::SignednessSemantics::Signless);
569 mlir::Type opResType = resultType;
570 if (left.getType().isUnsignedInteger()) {
571 left = createConvert(loc, signlessType, left);
572 opResType = signlessType;
573 }
574 if (right.getType().isUnsignedInteger()) {
575 right = createConvert(loc, signlessType, right);
576 opResType = signlessType;
577 }
578 mlir::Value result = create<OpTy>(loc, opResType, left, right);
579 if (resultType.isUnsignedInteger())
580 result = createConvert(loc, resultType, result);
581 return result;
582 }
583
584private:
587 void setCommonAttributes(mlir::Operation *op) const;
588
589 KindMapping kindMap;
590
593 mlir::arith::FastMathFlags fastMathFlags{};
594
597 mlir::arith::IntegerOverflowFlags integerOverflowFlags{};
598
601 mlir::SymbolTable *symbolTable = nullptr;
602
606 std::unique_ptr<mlir::DataLayout> dataLayout = nullptr;
607};
608
609} // namespace fir
610
611namespace fir::factory {
612
613//===----------------------------------------------------------------------===//
614// ExtendedValue inquiry helpers
615//===----------------------------------------------------------------------===//
616
621mlir::Value readCharLen(fir::FirOpBuilder &builder, mlir::Location loc,
622 const fir::ExtendedValue &box);
623
625mlir::Value readExtent(fir::FirOpBuilder &builder, mlir::Location loc,
626 const fir::ExtendedValue &box, unsigned dim);
627
631mlir::Value readLowerBound(fir::FirOpBuilder &builder, mlir::Location loc,
632 const fir::ExtendedValue &box, unsigned dim,
633 mlir::Value defaultValue);
634
637 mlir::Location loc,
638 const fir::BoxValue &box);
639
645fir::ExtendedValue readBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
646 const fir::BoxValue &box);
647
651getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc,
652 const fir::ExtendedValue &exv);
653
658getNonDeferredLenParams(const fir::ExtendedValue &exv);
659
660//===----------------------------------------------------------------------===//
661// String literal helper helpers
662//===----------------------------------------------------------------------===//
663
666fir::ExtendedValue createStringLiteral(fir::FirOpBuilder &, mlir::Location,
667 llvm::StringRef string);
668
671std::string uniqueCGIdent(llvm::StringRef prefix, llvm::StringRef name);
672
676 mlir::Location loc,
677 fir::SequenceType seqTy);
678
679//===--------------------------------------------------------------------===//
680// Location helpers
681//===--------------------------------------------------------------------===//
682
684mlir::Value locationToFilename(fir::FirOpBuilder &, mlir::Location);
686mlir::Value locationToLineNo(fir::FirOpBuilder &, mlir::Location, mlir::Type);
687
688//===--------------------------------------------------------------------===//
689// ExtendedValue helpers
690//===--------------------------------------------------------------------===//
691
694fir::ExtendedValue componentToExtendedValue(fir::FirOpBuilder &builder,
695 mlir::Location loc,
696 mlir::Value component);
697
704fir::ExtendedValue arrayElementToExtendedValue(fir::FirOpBuilder &builder,
705 mlir::Location loc,
706 const fir::ExtendedValue &array,
707 mlir::Value element);
708
713fir::ExtendedValue arraySectionElementToExtendedValue(
714 fir::FirOpBuilder &builder, mlir::Location loc,
715 const fir::ExtendedValue &array, mlir::Value element, mlir::Value slice);
716
719void genScalarAssignment(fir::FirOpBuilder &builder, mlir::Location loc,
720 const fir::ExtendedValue &lhs,
721 const fir::ExtendedValue &rhs,
722 bool needFinalization = false,
723 bool isTemporaryLHS = false);
724
728void genRecordAssignment(fir::FirOpBuilder &builder, mlir::Location loc,
729 const fir::ExtendedValue &lhs,
730 const fir::ExtendedValue &rhs,
731 bool needFinalization = false,
732 bool isTemporaryLHS = false);
733
737mlir::TupleType getRaggedArrayHeaderType(fir::FirOpBuilder &builder);
738
743mlir::Value genLenOfCharacter(fir::FirOpBuilder &builder, mlir::Location loc,
744 fir::ArrayLoadOp arrLoad,
747mlir::Value genLenOfCharacter(fir::FirOpBuilder &builder, mlir::Location loc,
748 fir::SequenceType seqTy, mlir::Value memref,
752
755mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
756 mlir::Type type);
757
759std::optional<std::int64_t> getExtentFromTriplet(mlir::Value lb, mlir::Value ub,
760 mlir::Value stride);
761
763mlir::Value genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,
764 mlir::Value value);
765
769mlir::Value genCPtrOrCFunptrAddr(fir::FirOpBuilder &builder, mlir::Location loc,
770 mlir::Value cPtr, mlir::Type ty);
771
774mlir::Value genCDevPtrAddr(fir::FirOpBuilder &builder, mlir::Location loc,
775 mlir::Value cDevPtr, mlir::Type ty);
776
778mlir::Value genCPtrOrCFunptrValue(fir::FirOpBuilder &builder,
779 mlir::Location loc, mlir::Value cPtr);
780
783fir::BoxValue createBoxValue(fir::FirOpBuilder &builder, mlir::Location loc,
784 const fir::ExtendedValue &exv);
785
787mlir::Value createNullBoxProc(fir::FirOpBuilder &builder, mlir::Location loc,
788 mlir::Type boxType);
789
792mlir::Value createConvert(mlir::OpBuilder &, mlir::Location, mlir::Type,
793 mlir::Value);
794
796void setInternalLinkage(mlir::func::FuncOp);
797
799elideExtentsAlreadyInType(mlir::Type type, mlir::ValueRange shape);
800
802elideLengthsAlreadyInType(mlir::Type type, mlir::ValueRange lenParams);
803
805uint64_t getAllocaAddressSpace(mlir::DataLayout *dataLayout);
806
813llvm::SmallVector<mlir::Value> deduceOptimalExtents(mlir::ValueRange extents1,
814 mlir::ValueRange extents2);
815
816} // namespace fir::factory
817
818#endif // FORTRAN_OPTIMIZER_BUILDER_FIRBUILDER_H
Definition: MathOptionsBase.h:22
Definition: BoxValue.h:125
Definition: BoxValue.h:291
Definition: BoxValue.h:478
Definition: FIRBuilder.h:429
mlir::Operation::result_range getResults()
End the IfOp and return the results if any.
Definition: FIRBuilder.h:449
Definition: FIRBuilder.h:55
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt)
Definition: FIRBuilder.h:478
fir::StringLitOp createStringLitOp(mlir::Location loc, llvm::StringRef string)
Convert a StringRef string into a fir::StringLitOp.
Definition: FIRBuilder.cpp:530
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:363
mlir::Type getRefType(mlir::Type eleTy)
Safely create a reference type to the type eleTy.
Definition: FIRBuilder.cpp:95
void genStackRestore(mlir::Location loc, mlir::Value stackPointer)
Definition: FIRBuilder.cpp:356
mlir::SymbolRefAttr getSymbolRefAttr(llvm::StringRef str)
Wrap str to a SymbolRefAttr.
Definition: FIRBuilder.h:160
mlir::Value createRealZeroConstant(mlir::Location loc, mlir::Type realType)
Create a real constant of type realType with a value zero.
Definition: FIRBuilder.h:201
mlir::Value createSlice(mlir::Location loc, const fir::ExtendedValue &exv, mlir::ValueRange triples, mlir::ValueRange path)
Definition: FIRBuilder.cpp:596
mlir::Value createConvert(mlir::Location loc, mlir::Type toTy, mlir::Value val)
Lazy creation of fir.convert op.
Definition: FIRBuilder.cpp:511
IfBuilder genIfOp(mlir::Location loc, mlir::TypeRange results, mlir::Value cdt, bool withElseRegion)
Definition: FIRBuilder.h:463
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is a null address.
Definition: FIRBuilder.cpp:752
mlir::func::FuncOp getNamedFunction(mlir::SymbolRefAttr symbol)
Definition: FIRBuilder.h:341
mlir::Value createRealConstant(mlir::Location loc, mlir::Type realType, llvm::APFloat::integerPart val)
Create a real constant from an integer value.
Definition: FIRBuilder.cpp:150
mlir::Type getCharacterLengthType()
Get character length type.
Definition: FIRBuilder.h:153
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:290
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt)
Definition: FIRBuilder.h:471
mlir::Value genStackSave(mlir::Location loc)
Definition: FIRBuilder.cpp:350
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:562
const fir::KindMapping & getKindMap()
Get a reference to the kind map.
Definition: FIRBuilder.h:116
mlir::Value createAllOnesInteger(mlir::Location loc, mlir::Type integerType)
Definition: FIRBuilder.cpp:140
mlir::ModuleOp getModule()
Get the current Module.
Definition: FIRBuilder.h:106
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:289
mlir::Value createMinusOneInteger(mlir::Location loc, mlir::Type integerType)
Definition: FIRBuilder.h:187
mlir::IntegerType getDefaultIntegerType()
Get the default integer type.
Definition: FIRBuilder.h:122
mlir::Value createNullConstant(mlir::Location loc, mlir::Type ptrType={})
Definition: FIRBuilder.cpp:125
void setFastMathFlags(mlir::arith::FastMathFlags flags)
Definition: FIRBuilder.h:507
LLVM_DUMP_METHOD void dumpFunc()
Dump the current function. (debug)
Definition: FIRBuilder.cpp:734
mlir::ArrayAttr create2DI64ArrayAttr(llvm::SmallVectorImpl< llvm::SmallVector< int64_t > > &intData)
Definition: FIRBuilder.cpp:280
mlir::Value convertWithSemantics(mlir::Location loc, mlir::Type toTy, mlir::Value val, bool allowCharacterConversion=false, bool allowRebox=false)
Definition: FIRBuilder.cpp:425
mlir::SymbolTable * getMLIRSymbolTable()
Get func.func/fir.global symbol table attached to this builder if any.
Definition: FIRBuilder.h:119
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr)
Generate code testing addr is not a null address.
Definition: FIRBuilder.cpp:746
mlir::Value convertToIndexType(mlir::Location loc, mlir::Value val)
Cast the input value to IndexType.
Definition: FIRBuilder.h:383
void createStoreWithConvert(mlir::Location loc, mlir::Value val, mlir::Value addr)
Definition: FIRBuilder.cpp:516
void setIntegerOverflowFlags(mlir::arith::IntegerOverflowFlags flags)
Definition: FIRBuilder.h:535
mlir::Region & getRegion()
Get the current Region of the insertion point.
Definition: FIRBuilder.h:103
void notifyOperationInserted(mlir::Operation *op, mlir::OpBuilder::InsertPoint previous) override
FirOpBuilder hook for creating new operation.
Definition: FIRBuilder.h:548
mlir::func::FuncOp getNamedFunction(llvm::StringRef name)
Definition: FIRBuilder.h:332
mlir::Value genExtentFromTriplet(mlir::Location loc, mlir::Value lb, mlir::Value ub, mlir::Value step, mlir::Type type)
Definition: FIRBuilder.cpp:758
std::string getFastMathFlagsString()
Definition: FIRBuilder.h:522
mlir::Value createUnsigned(mlir::Location loc, mlir::Type resultType, mlir::Value left, mlir::Value right)
Definition: FIRBuilder.h:562
mlir::Value createBool(mlir::Location loc, bool b)
Create constant i1 with value 1. if b is true or 0. otherwise.
Definition: FIRBuilder.h:417
mlir::arith::IntegerOverflowFlags getIntegerOverflowFlags() const
Get current IntegerOverflowFlags value.
Definition: FIRBuilder.h:540
mlir::func::FuncOp getFunction()
Get the current Function.
Definition: FIRBuilder.h:111
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:312
mlir::Type getRealType(int kind)
Get the mlir float type that implements Fortran REAL(kind).
Definition: FIRBuilder.cpp:105
mlir::Block * getAllocaBlock()
Get the block for adding Allocas.
Definition: FIRBuilder.cpp:250
mlir::Type getVarLenSeqTy(mlir::Type eleTy, unsigned rank=1)
Create a sequence of eleTy with rank dimensions of unknown size.
Definition: FIRBuilder.cpp:100
mlir::Value loadIfRef(mlir::Location loc, mlir::Value val)
Definition: FIRBuilder.cpp:524
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:336
mlir::Value createShape(mlir::Location loc, const fir::ExtendedValue &exv)
Definition: FIRBuilder.cpp:575
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:210
mlir::Value genAbsentOp(mlir::Location loc, mlir::Type argTy)
Definition: FIRBuilder.cpp:775
mlir::arith::FastMathFlags getFastMathFlags() const
Get current FastMathFlags value.
Definition: FIRBuilder.h:516
mlir::Value createIntegerConstant(mlir::Location loc, mlir::Type integerType, std::int64_t i)
Definition: FIRBuilder.cpp:131
mlir::Value createBox(mlir::Location loc, const fir::ExtendedValue &exv, bool isPolymorphic=false, bool isAssumedType=false)
Definition: FIRBuilder.cpp:647
mlir::Block * getEntryBlock()
Get the entry block of the current Function.
Definition: FIRBuilder.h:139
mlir::func::FuncOp createFunction(mlir::Location loc, llvm::StringRef name, mlir::FunctionType ty)
Definition: FIRBuilder.h:371
mlir::DataLayout & getDataLayout()
Construct a data layout on demand and return it.
Definition: FIRBuilder.cpp:837
mlir::Value createTemporary(mlir::Location loc, mlir::Type type, mlir::ValueRange shape)
Create an unnamed and untracked temporary on the stack.
Definition: FIRBuilder.h:242
mlir::Type getIntPtrType()
Definition: FIRBuilder.h:157
Definition: KindMapping.h:48
Definition: FIRType.h:77
Definition: OpenACC.h:20
fir::ExtendedValue createBoxValue(mlir::Location loc, AbstractConverter &converter, const SomeExpr &expr, SymMap &symMap, StatementContext &stmtCtx)
Definition: ConvertExpr.cpp:7562
Definition: AbstractConverter.h:31
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:320
Definition: AbstractConverter.h:27