@@ -100,14 +100,14 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
100
100
// Convert ops in target-specific patterns.
101
101
mod.walk ([&](mlir::Operation *op) {
102
102
if (auto call = mlir::dyn_cast<fir::CallOp>(op)) {
103
- if (!hasPortableSignature (call.getFunctionType (), op ))
103
+ if (!hasPortableSignature (call.getFunctionType ()))
104
104
convertCallOp (call);
105
105
} else if (auto dispatch = mlir::dyn_cast<fir::DispatchOp>(op)) {
106
- if (!hasPortableSignature (dispatch.getFunctionType (), op ))
106
+ if (!hasPortableSignature (dispatch.getFunctionType ()))
107
107
convertCallOp (dispatch);
108
108
} else if (auto addr = mlir::dyn_cast<fir::AddrOfOp>(op)) {
109
109
if (addr.getType ().isa <mlir::FunctionType>() &&
110
- !hasPortableSignature (addr.getType (), op ))
110
+ !hasPortableSignature (addr.getType ()))
111
111
convertAddrOp (addr);
112
112
}
113
113
});
@@ -443,23 +443,19 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
443
443
// / then it is considered portable for any target, and this function will
444
444
// / return `true`. Otherwise, the signature is not portable and `false` is
445
445
// / returned.
446
- bool hasPortableSignature (mlir::Type signature, mlir::Operation *op ) {
446
+ bool hasPortableSignature (mlir::Type signature) {
447
447
assert (signature.isa <mlir::FunctionType>());
448
448
auto func = signature.dyn_cast <mlir::FunctionType>();
449
- bool hasFirRuntime = op->hasAttrOfType <mlir::UnitAttr>(
450
- fir::FIROpsDialect::getFirRuntimeAttrName ());
451
449
for (auto ty : func.getResults ())
452
450
if ((ty.isa <fir::BoxCharType>() && !noCharacterConversion) ||
453
- (fir::isa_complex (ty) && !noComplexConversion) ||
454
- (ty.isa <mlir::IntegerType>() && hasFirRuntime)) {
451
+ (fir::isa_complex (ty) && !noComplexConversion)) {
455
452
LLVM_DEBUG (llvm::dbgs () << " rewrite " << signature << " for target\n " );
456
453
return false ;
457
454
}
458
455
for (auto ty : func.getInputs ())
459
456
if (((ty.isa <fir::BoxCharType>() || fir::isCharacterProcedureTuple (ty)) &&
460
457
!noCharacterConversion) ||
461
- (fir::isa_complex (ty) && !noComplexConversion) ||
462
- (ty.isa <mlir::IntegerType>() && hasFirRuntime)) {
458
+ (fir::isa_complex (ty) && !noComplexConversion)) {
463
459
LLVM_DEBUG (llvm::dbgs () << " rewrite " << signature << " for target\n " );
464
460
return false ;
465
461
}
@@ -480,14 +476,13 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
480
476
// / the immediately subsequent target code gen.
481
477
void convertSignature (mlir::func::FuncOp func) {
482
478
auto funcTy = func.getFunctionType ().cast <mlir::FunctionType>();
483
- if (hasPortableSignature (funcTy, func ) && !hasHostAssociations (func))
479
+ if (hasPortableSignature (funcTy) && !hasHostAssociations (func))
484
480
return ;
485
481
llvm::SmallVector<mlir::Type> newResTys;
486
482
llvm::SmallVector<mlir::Type> newInTys;
487
483
llvm::SmallVector<std::pair<unsigned , mlir::NamedAttribute>> savedAttrs;
488
484
llvm::SmallVector<std::pair<unsigned , mlir::NamedAttribute>> extraAttrs;
489
485
llvm::SmallVector<FixupTy> fixups;
490
- llvm::SmallVector<std::pair<unsigned , mlir::NamedAttrList>, 1 > resultAttrs;
491
486
492
487
// Save argument attributes in case there is a shift so we can replace them
493
488
// correctly.
@@ -514,22 +509,6 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
514
509
else
515
510
doComplexReturn (func, cmplx, newResTys, newInTys, fixups);
516
511
})
517
- .Case <mlir::IntegerType>([&](mlir::IntegerType intTy) {
518
- auto m = specifics->integerArgumentType (func.getLoc (), intTy);
519
- assert (m.size () == 1 );
520
- auto attr = std::get<fir::CodeGenSpecifics::Attributes>(m[0 ]);
521
- auto retTy = std::get<mlir::Type>(m[0 ]);
522
- std::size_t resId = newResTys.size ();
523
- llvm::StringRef extensionAttrName = attr.getIntExtensionAttrName ();
524
- if (!extensionAttrName.empty () &&
525
- // TODO: we have to do the same for BIND(C) routines.
526
- func->hasAttrOfType <mlir::UnitAttr>(
527
- fir::FIROpsDialect::getFirRuntimeAttrName ()))
528
- resultAttrs.emplace_back (
529
- resId, rewriter->getNamedAttr (extensionAttrName,
530
- rewriter->getUnitAttr ()));
531
- newResTys.push_back (retTy);
532
- })
533
512
.Default ([&](mlir::Type ty) { newResTys.push_back (ty); });
534
513
535
514
// Saved potential shift in argument. Handling of result can add arguments
@@ -593,26 +572,6 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
593
572
newInTys.push_back (ty);
594
573
}
595
574
})
596
- .Case <mlir::IntegerType>([&](mlir::IntegerType intTy) {
597
- auto m = specifics->integerArgumentType (func.getLoc (), intTy);
598
- assert (m.size () == 1 );
599
- auto attr = std::get<fir::CodeGenSpecifics::Attributes>(m[0 ]);
600
- auto argTy = std::get<mlir::Type>(m[0 ]);
601
- auto argNo = newInTys.size ();
602
- llvm::StringRef extensionAttrName = attr.getIntExtensionAttrName ();
603
- if (!extensionAttrName.empty () &&
604
- // TODO: we have to do the same for BIND(C) routines.
605
- func->hasAttrOfType <mlir::UnitAttr>(
606
- fir::FIROpsDialect::getFirRuntimeAttrName ())) {
607
- fixups.emplace_back (FixupTy::Codes::ArgumentType, argNo,
608
- [=](mlir::func::FuncOp func) {
609
- func.setArgAttr (
610
- argNo, extensionAttrName,
611
- mlir::UnitAttr::get (func.getContext ()));
612
- });
613
- }
614
- newInTys.push_back (argTy);
615
- })
616
575
.Default ([&](mlir::Type ty) { newInTys.push_back (ty); });
617
576
618
577
if (func.getArgAttrOfType <mlir::UnitAttr>(index,
@@ -649,18 +608,14 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
649
608
case FixupTy::Codes::ArgumentType: {
650
609
// Argument is pass-by-value, but its type has likely been modified to
651
610
// suit the target ABI convention.
652
- auto oldArgTy =
653
- fir::ReferenceType::get (oldArgTys[fixup.index - offset]);
654
- // If type did not change, keep the original argument.
655
- if (newInTys[fixup.index ] == oldArgTy)
656
- break ;
657
-
658
611
auto newArg = func.front ().insertArgument (fixup.index ,
659
612
newInTys[fixup.index ], loc);
660
613
rewriter->setInsertionPointToStart (&func.front ());
661
614
auto mem =
662
615
rewriter->create <fir::AllocaOp>(loc, newInTys[fixup.index ]);
663
616
rewriter->create <fir::StoreOp>(loc, newArg, mem);
617
+ auto oldArgTy =
618
+ fir::ReferenceType::get (oldArgTys[fixup.index - offset]);
664
619
auto cast = rewriter->create <fir::ConvertOp>(loc, oldArgTy, mem);
665
620
mlir::Value load = rewriter->create <fir::LoadOp>(loc, cast);
666
621
func.getArgument (fixup.index + 1 ).replaceAllUsesWith (load);
@@ -789,10 +744,6 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
789
744
func.setArgAttr (extraAttr.first , extraAttr.second .getName (),
790
745
extraAttr.second .getValue ());
791
746
792
- for (auto [resId, resAttrList] : resultAttrs)
793
- for (mlir::NamedAttribute resAttr : resAttrList)
794
- func.setResultAttr (resId, resAttr.getName (), resAttr.getValue ());
795
-
796
747
// Replace attributes to the correct argument if there was an argument shift
797
748
// to the right.
798
749
if (argumentShift > 0 ) {
0 commit comments