Skip to content

Commit e3bd672

Browse files
committed
[rebase] update SystemClock lowering to pass the integer kind for the result (new runtime argument)
1 parent df3987c commit e3bd672

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

flang/lib/Lower/Runtime.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,15 @@ void Fortran::lower::genSystemClock(fir::FirOpBuilder &builder,
340340
mlir::Location loc, mlir::Value count,
341341
mlir::Value rate, mlir::Value max) {
342342
auto makeCall = [&](mlir::FuncOp func, mlir::Value arg) {
343-
mlir::Value res = builder.create<fir::CallOp>(loc, func).getResult(0);
343+
auto kindTy = func.getType().getInput(0);
344+
int integerKind = 8;
345+
if (auto intType =
346+
fir::unwrapRefType(arg.getType()).dyn_cast<mlir::IntegerType>())
347+
integerKind = intType.getWidth() / 8;
348+
auto kind = builder.createIntegerConstant(loc, kindTy, integerKind);
349+
mlir::Value res =
350+
builder.create<fir::CallOp>(loc, func, mlir::ValueRange{kind})
351+
.getResult(0);
344352
mlir::Value castRes =
345353
builder.createConvert(loc, fir::dyn_cast_ptrEleTy(arg.getType()), res);
346354
builder.create<fir::StoreOp>(loc, castRes, arg);

flang/test/Lower/intrinsic-procedures/system_clock.f90

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,22 @@ subroutine system_clock_test()
88
! CHECK-DAG: %[[c:.*]] = fir.alloca i32 {bindc_name = "c"
99
! CHECK-DAG: %[[m:.*]] = fir.alloca i64 {bindc_name = "m"
1010
! CHECK-DAG: %[[r:.*]] = fir.alloca f32 {bindc_name = "r"
11-
! CHECK: %[[Count:.*]] = fir.call @_FortranASystemClockCount() : () -> i64
11+
! CHECK: %[[c4:.*]] = arith.constant 4 : i32
12+
! CHECK: %[[Count:.*]] = fir.call @_FortranASystemClockCount(%[[c4]]) : (i32) -> i64
1213
! CHECK: %[[Count1:.*]] = fir.convert %[[Count]] : (i64) -> i32
1314
! CHECK: fir.store %[[Count1]] to %[[c]] : !fir.ref<i32>
14-
! CHECK: %[[Rate:.*]] = fir.call @_FortranASystemClockCountRate() : () -> i64
15+
! CHECK: %[[c8:.*]] = arith.constant 8 : i32
16+
! CHECK: %[[Rate:.*]] = fir.call @_FortranASystemClockCountRate(%[[c8]]) : (i32) -> i64
1517
! CHECK: %[[Rate1:.*]] = fir.convert %[[Rate]] : (i64) -> f32
1618
! CHECK: fir.store %[[Rate1]] to %[[r]] : !fir.ref<f32>
17-
! CHECK: %[[Max:.*]] = fir.call @_FortranASystemClockCountMax() : () -> i64
19+
! CHECK: %[[c8_2:.*]] = arith.constant 8 : i32
20+
! CHECK: %[[Max:.*]] = fir.call @_FortranASystemClockCountMax(%[[c8_2]]) : (i32) -> i64
1821
! CHECK: fir.store %[[Max]] to %[[m]] : !fir.ref<i64>
1922
call system_clock(c, r, m)
2023
! print*, c, r, m
2124
! CHECK-NOT: fir.call
22-
! CHECK: %[[Rate:.*]] = fir.call @_FortranASystemClockCountRate() : () -> i64
25+
! CHECK: %[[c8_3:.*]] = arith.constant 8 : i32
26+
! CHECK: %[[Rate:.*]] = fir.call @_FortranASystemClockCountRate(%[[c8_3]]) : (i32) -> i64
2327
! CHECK: fir.store %[[Rate]] to %[[m]] : !fir.ref<i64>
2428
call system_clock(count_rate=m)
2529
! CHECK-NOT: fir.call

0 commit comments

Comments
 (0)