@@ -427,6 +427,10 @@ struct IntrinsicLibrary {
427
427
// / if the argument is an integer, into llvm intrinsics if the argument is
428
428
// / real and to the `hypot` math routine if the argument is of complex type.
429
429
mlir::Value genAbs (mlir::Type, llvm::ArrayRef<mlir::Value>);
430
+ template <void (*CallRuntime)(fir::FirOpBuilder &, mlir::Location loc,
431
+ mlir::Value, mlir::Value)>
432
+ fir::ExtendedValue genAdjustRtCall (mlir::Type,
433
+ llvm::ArrayRef<fir::ExtendedValue>);
430
434
mlir::Value genAimag (mlir::Type, llvm::ArrayRef<mlir::Value>);
431
435
fir::ExtendedValue genAll (mlir::Type, llvm::ArrayRef<fir::ExtendedValue>);
432
436
fir::ExtendedValue genAllocated (mlir::Type,
@@ -562,6 +566,14 @@ static constexpr bool handleDynamicOptional = true;
562
566
// / should be provided for all the intrinsic arguments for completeness.
563
567
static constexpr IntrinsicHandler handlers[]{
564
568
{" abs" , &I::genAbs},
569
+ {" adjustl" ,
570
+ &I::genAdjustRtCall<fir::runtime::genAdjustL>,
571
+ {{{" string" , asAddr}}},
572
+ /* isElemental=*/ true },
573
+ {" adjustr" ,
574
+ &I::genAdjustRtCall<fir::runtime::genAdjustR>,
575
+ {{{" string" , asAddr}}},
576
+ /* isElemental=*/ true },
565
577
{" aimag" , &I::genAimag},
566
578
{" all" ,
567
579
&I::genAll,
@@ -1430,6 +1442,37 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType,
1430
1442
llvm_unreachable (" unexpected type in ABS argument" );
1431
1443
}
1432
1444
1445
+ // ADJUSTL & ADJUSTR
1446
+ template <void (*CallRuntime)(fir::FirOpBuilder &, mlir::Location loc,
1447
+ mlir::Value, mlir::Value)>
1448
+ fir::ExtendedValue
1449
+ IntrinsicLibrary::genAdjustRtCall (mlir::Type resultType,
1450
+ llvm::ArrayRef<fir::ExtendedValue> args) {
1451
+ assert (args.size () == 1 );
1452
+ mlir::Value string = builder.createBox (loc, args[0 ]);
1453
+ // Create a mutable fir.box to be passed to the runtime for the result.
1454
+ fir::MutableBoxValue resultMutableBox =
1455
+ fir::factory::createTempMutableBox (builder, loc, resultType);
1456
+ mlir::Value resultIrBox =
1457
+ fir::factory::getMutableIRBox (builder, loc, resultMutableBox);
1458
+
1459
+ // Call the runtime -- the runtime will allocate the result.
1460
+ CallRuntime (builder, loc, resultIrBox, string);
1461
+
1462
+ // Read result from mutable fir.box and add it to the list of temps to be
1463
+ // finalized by the StatementContext.
1464
+ fir::ExtendedValue res =
1465
+ fir::factory::genMutableBoxRead (builder, loc, resultMutableBox);
1466
+ return res.match (
1467
+ [&](const fir::CharBoxValue &box) -> fir::ExtendedValue {
1468
+ addCleanUpForTemp (loc, fir::getBase (box));
1469
+ return box;
1470
+ },
1471
+ [&](const auto &) -> fir::ExtendedValue {
1472
+ fir::emitFatalError (loc, " result of ADJUSTL is not a scalar character" );
1473
+ });
1474
+ }
1475
+
1433
1476
// AIMAG
1434
1477
mlir::Value IntrinsicLibrary::genAimag (mlir::Type resultType,
1435
1478
llvm::ArrayRef<mlir::Value> args) {
0 commit comments