Lines Matching defs:fir

24 namespace fir {
27 } // namespace fir
33 namespace fir {
62 mlir::isa<fir::RecordType>(funTy.getResult(0)) &&
63 !fir::isa_builtin_cptr_type(funTy.getResult(0));
69 .Case<fir::SequenceType, fir::RecordType>(
72 return fir::BoxType::get(type);
73 return fir::ReferenceType::get(type);
75 .Case<fir::BaseBoxType>([](mlir::Type type) -> mlir::Type {
76 return fir::ReferenceType::get(type);
94 return fir::ReferenceType::get(mlir::NoneType::get(context));
100 assert(fir::isa_builtin_cptr_type(funcTy.getResult(0)));
108 return mlir::isa<fir::SequenceType, fir::RecordType>(resultType) &&
130 mlir::dyn_cast<fir::SaveResultOp>(result.use_begin().getUser());
133 loc, "calls with abstract result must be used in fir.save_result");
140 arg = rewriter.create<fir::EmboxOp>(
145 bool isResultBuiltinCPtr = fir::isa_builtin_cptr_type(result.getType());
150 // fir::CallOp specific handling.
151 if constexpr (std::is_same_v<Op, fir::CallOp>) {
157 newOp = rewriter.create<fir::CallOp>(loc, *op.getCallee(),
171 rewriter.create<fir::ConvertOp>(loc, newFuncTy, op.getOperand(0)));
176 newOp = rewriter.create<fir::CallOp>(loc, mlir::SymbolRefAttr{},
181 // fir::DispatchOp specific handling.
182 if constexpr (std::is_same_v<Op, fir::DispatchOp>) {
192 newOp = rewriter.create<fir::DispatchOp>(
202 mlir::Value saveAddr = fir::factory::genCPtrOrCFunptrAddr(
216 : public mlir::OpRewritePattern<fir::SaveResultOp> {
222 matchAndRewrite(fir::SaveResultOp op,
226 if (mlir::isa<fir::RecordType>(type) && call && fir::hasBindcAttr(call) &&
227 !fir::isa_builtin_cptr_type(type)) {
228 rewriter.replaceOpWithNewOp<fir::StoreOp>(op, op.getValue(),
244 fir::LoadOp resultLoad;
247 if (auto load = resultValue.getDefiningOp<fir::LoadOp>()) {
250 // The result alloca may be behind a fir.declare, if any.
251 if (auto declare = resultStorage.getDefiningOp<fir::DeclareOp>())
257 if (fir::isa_builtin_cptr_type(resultValue.getType())) {
267 fir::factory::genCPtrOrCFunptrValue(builder, loc, cptr);
277 // register pass, this is possible for fir.box results, or fir.record
280 rewriter.create<fir::StoreOp>(loc, resultValue, newArg);
285 if (auto alloc = resultStorage.getDefiningOp<fir::AllocaOp>())
322 class AddrOfOpConversion : public mlir::OpRewritePattern<fir::AddrOfOp> {
328 matchAndRewrite(fir::AddrOfOp addrOf,
333 fir::isa_builtin_cptr_type(oldFuncTy.getResult(0)))
337 auto newAddrOf = rewriter.create<fir::AddrOfOp>(addrOf.getLoc(), newFuncTy,
343 rewriter.replaceOpWithNewOp<fir::ConvertOp>(addrOf, oldFuncTy, newAddrOf);
352 : public fir::impl::AbstractResultOptBase<AbstractResultOpt> {
354 using fir::impl::AbstractResultOptBase<
369 fir::hasBindcAttr(func.getOperation()))
372 if (fir::isa_builtin_cptr_type(funcTy.getResult(0))) {
378 return !fir::isa_builtin_cptr_type(retTy);
391 auto bufferType = fir::ReferenceType::get(resultType);
393 newArg = rewriter.create<fir::BoxAddrOp>(loc, bufferType, newArg);
428 .Case([](fir::BoxProcType boxProc) {
429 return fir::hasAbstractResult(
432 .Case([](fir::PointerType pointer) {
433 return fir::hasAbstractResult(
439 void runOnSpecificOperation(fir::GlobalOp global, bool,
447 /// Run the pass on a ModuleOp. This makes fir-opt --abstract-result work.
459 // fir.global
488 .Case<mlir::func::FuncOp, fir::GlobalOp, mlir::gpu::GPUFuncOp>(
494 target.addLegalDialect<fir::FIROpsDialect, mlir::arith::ArithDialect,
496 target.addIllegalOp<fir::SaveResultOp>();
497 target.addDynamicallyLegalOp<fir::CallOp>([](fir::CallOp call) {
500 fir::hasBindcAttr(call.getOperation()))
504 target.addDynamicallyLegalOp<fir::AddrOfOp>([&symbolTable](
505 fir::AddrOfOp addrOf) {
510 return func && fir::hasBindcAttr(func.getOperation());
516 target.addDynamicallyLegalOp<fir::DispatchOp>([](fir::DispatchOp dispatch) {
519 fir::hasBindcAttr(dispatch.getOperation()))
524 patterns.insert<CallConversion<fir::CallOp>>(context, shouldBoxResult);
525 patterns.insert<CallConversion<fir::DispatchOp>>(context, shouldBoxResult);
537 } // namespace fir