[flang] system_clock intrinsic calls with dynamically optional arguments

system_clock intrinsic calls with dynamically optional arguments

Modify intrinsic system_clock calls to allow for an argument that is optional
or a disassociated pointer or an unallocated allocatable.  A call with such an
argument is the same as a call that does not specify that argument.

Rename (genIsNotNull -> genIsNotNullAddr) and (genIsNull -> genIsNullAddr)
and add a use of genIsNotNullAddr.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D127616

Co-authored-by: V Donaldson <vdonaldson@nvidia.com>
This commit is contained in:
vdonaldson 2022-06-13 17:32:26 +02:00 committed by Valentin Clement
parent 111b32ecb4
commit 70ade047a4
No known key found for this signature in database
GPG Key ID: 086D54783C928776
10 changed files with 183 additions and 28 deletions

View File

@ -377,10 +377,10 @@ public:
}
/// Generate code testing \p addr is not a null address.
mlir::Value genIsNotNull(mlir::Location loc, mlir::Value addr);
mlir::Value genIsNotNullAddr(mlir::Location loc, mlir::Value addr);
/// Generate code testing \p addr is a null address.
mlir::Value genIsNull(mlir::Location loc, mlir::Value addr);
mlir::Value genIsNullAddr(mlir::Location loc, mlir::Value addr);
/// Compute the extent of (lb:ub:step) as max((ub-lb+step)/step, 0). See
/// Fortran 2018 9.5.3.3.2 section for more details.

View File

@ -52,14 +52,14 @@ static bool isIshftcWithDynamicallyOptionalArg(
Fortran::evaluate::MayBePassedAsAbsentOptional(*expr, foldingContex);
}
/// Is this a call to SYSTEM_CLOCK or RANDOM_SEED intrinsic with arguments that
/// may be absent at runtime? This are special cases because that aspect cannot
/// Is this a call to the RANDOM_SEED intrinsic with arguments that may be
/// absent at runtime? This is a special case because that aspect cannot
/// be delegated to the runtime via a null fir.box or address given the current
/// runtime entry point.
static bool isSystemClockOrRandomSeedWithOptionalArg(
static bool isRandomSeedWithDynamicallyOptionalArg(
llvm::StringRef name, const Fortran::evaluate::ProcedureRef &procRef,
Fortran::evaluate::FoldingContext &foldingContex) {
if (name != "system_clock" && name != "random_seed")
if (name != "random_seed")
return false;
for (const auto &arg : procRef.arguments()) {
auto *expr = Fortran::evaluate::UnwrapExpr<Fortran::lower::SomeExpr>(arg);
@ -78,7 +78,7 @@ bool Fortran::lower::intrinsicRequiresCustomOptionalHandling(
Fortran::evaluate::FoldingContext &fldCtx = converter.getFoldingContext();
return isMinOrMaxWithDynamicallyOptionalArg(name, procRef, fldCtx) ||
isIshftcWithDynamicallyOptionalArg(name, procRef, fldCtx) ||
isSystemClockOrRandomSeedWithOptionalArg(name, procRef, fldCtx);
isRandomSeedWithDynamicallyOptionalArg(name, procRef, fldCtx);
}
static void prepareMinOrMaxArguments(

View File

@ -402,7 +402,7 @@ public:
if (!fir::isa_ref_type(eleTy))
eleTy = builder.getRefType(eleTy);
auto addr = builder.create<fir::BoxAddrOp>(loc, eleTy, box);
mlir::Value isPresent = builder.genIsNotNull(loc, addr);
mlir::Value isPresent = builder.genIsNotNullAddr(loc, addr);
auto absentBox = builder.create<fir::AbsentOp>(loc, boxTy);
box = builder.create<mlir::arith::SelectOp>(loc, isPresent, box,
absentBox);

View File

@ -2426,7 +2426,8 @@ void IntrinsicLibrary::genGetCommandArgument(
fir::runtime::genArgumentValue(builder, loc, number, valBox, errBox);
if (isStaticallyPresent(status)) {
mlir::Value statAddr = fir::getBase(status);
mlir::Value statIsPresentAtRuntime = builder.genIsNotNull(loc, statAddr);
mlir::Value statIsPresentAtRuntime =
builder.genIsNotNullAddr(loc, statAddr);
builder.genIfThen(loc, statIsPresentAtRuntime)
.genThen(
[&]() { builder.createStoreWithConvert(loc, stat, statAddr); })
@ -2435,7 +2436,7 @@ void IntrinsicLibrary::genGetCommandArgument(
}
if (isStaticallyPresent(length)) {
mlir::Value lenAddr = fir::getBase(length);
mlir::Value lenIsPresentAtRuntime = builder.genIsNotNull(loc, lenAddr);
mlir::Value lenIsPresentAtRuntime = builder.genIsNotNullAddr(loc, lenAddr);
builder.genIfThen(loc, lenIsPresentAtRuntime)
.genThen([&]() {
mlir::Value len =
@ -2465,7 +2466,7 @@ void IntrinsicLibrary::genGetEnvironmentVariable(
mlir::Type i1Ty = builder.getI1Type();
mlir::Value trimNameAddr = fir::getBase(trimName);
mlir::Value trimNameIsPresentAtRuntime =
builder.genIsNotNull(loc, trimNameAddr);
builder.genIsNotNullAddr(loc, trimNameAddr);
trim = builder
.genIfOp(loc, {i1Ty}, trimNameIsPresentAtRuntime,
/*withElseRegion=*/true)
@ -2496,7 +2497,8 @@ void IntrinsicLibrary::genGetEnvironmentVariable(
valBox, trim, errBox);
if (isStaticallyPresent(status)) {
mlir::Value statAddr = fir::getBase(status);
mlir::Value statIsPresentAtRuntime = builder.genIsNotNull(loc, statAddr);
mlir::Value statIsPresentAtRuntime =
builder.genIsNotNullAddr(loc, statAddr);
builder.genIfThen(loc, statIsPresentAtRuntime)
.genThen(
[&]() { builder.createStoreWithConvert(loc, stat, statAddr); })
@ -2506,7 +2508,7 @@ void IntrinsicLibrary::genGetEnvironmentVariable(
if (isStaticallyPresent(length)) {
mlir::Value lenAddr = fir::getBase(length);
mlir::Value lenIsPresentAtRuntime = builder.genIsNotNull(loc, lenAddr);
mlir::Value lenIsPresentAtRuntime = builder.genIsNotNullAddr(loc, lenAddr);
builder.genIfThen(loc, lenIsPresentAtRuntime)
.genThen([&]() {
mlir::Value len =
@ -3311,7 +3313,7 @@ IntrinsicLibrary::genSize(mlir::Type resultType,
return builder.createConvert(
loc, resultType, fir::runtime::genSizeDim(builder, loc, array, dim));
mlir::Value isDynamicallyAbsent = builder.genIsNull(loc, dim);
mlir::Value isDynamicallyAbsent = builder.genIsNullAddr(loc, dim);
return builder
.genIfOp(loc, {resultType}, isDynamicallyAbsent,
/*withElseRegion=*/true)

View File

@ -12,6 +12,7 @@
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
#include "flang/Optimizer/Builder/Todo.h"
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
#include "flang/Parser/parse-tree.h"
#include "flang/Runtime/misc-intrinsic.h"
#include "flang/Runtime/pointer.h"
@ -332,18 +333,35 @@ void Fortran::lower::genSystemClock(fir::FirOpBuilder &builder,
mlir::Location loc, mlir::Value count,
mlir::Value rate, mlir::Value max) {
auto makeCall = [&](mlir::func::FuncOp func, mlir::Value arg) {
mlir::Type type = arg.getType();
fir::IfOp ifOp{};
const bool isOptionalArg =
fir::valueHasFirAttribute(arg, fir::getOptionalAttrName());
if (type.dyn_cast<fir::PointerType>() || type.dyn_cast<fir::HeapType>()) {
// Check for a disassociated pointer or an unallocated allocatable.
assert(!isOptionalArg && "invalid optional argument");
ifOp = builder.create<fir::IfOp>(loc, builder.genIsNotNullAddr(loc, arg),
/*withElseRegion=*/false);
} else if (isOptionalArg) {
ifOp = builder.create<fir::IfOp>(
loc, builder.create<fir::IsPresentOp>(loc, builder.getI1Type(), arg),
/*withElseRegion=*/false);
}
if (ifOp)
builder.setInsertionPointToStart(&ifOp.getThenRegion().front());
mlir::Type kindTy = func.getFunctionType().getInput(0);
int integerKind = 8;
if (auto intType =
fir::unwrapRefType(arg.getType()).dyn_cast<mlir::IntegerType>())
if (auto intType = fir::unwrapRefType(type).dyn_cast<mlir::IntegerType>())
integerKind = intType.getWidth() / 8;
mlir::Value kind = builder.createIntegerConstant(loc, kindTy, integerKind);
mlir::Value res =
builder.create<fir::CallOp>(loc, func, mlir::ValueRange{kind})
.getResult(0);
mlir::Value castRes =
builder.createConvert(loc, fir::dyn_cast_ptrEleTy(arg.getType()), res);
builder.createConvert(loc, fir::dyn_cast_ptrEleTy(type), res);
builder.create<fir::StoreOp>(loc, castRes, arg);
if (ifOp)
builder.setInsertionPointAfter(ifOp);
};
using fir::runtime::getRuntimeFunc;
if (count)

View File

@ -510,13 +510,14 @@ genNullPointerComparison(fir::FirOpBuilder &builder, mlir::Location loc,
return builder.create<mlir::arith::CmpIOp>(loc, condition, ptrToInt, c0);
}
mlir::Value fir::FirOpBuilder::genIsNotNull(mlir::Location loc,
mlir::Value fir::FirOpBuilder::genIsNotNullAddr(mlir::Location loc,
mlir::Value addr) {
return genNullPointerComparison(*this, loc, addr,
mlir::arith::CmpIPredicate::ne);
}
mlir::Value fir::FirOpBuilder::genIsNull(mlir::Location loc, mlir::Value addr) {
mlir::Value fir::FirOpBuilder::genIsNullAddr(mlir::Location loc,
mlir::Value addr) {
return genNullPointerComparison(*this, loc, addr,
mlir::arith::CmpIPredicate::eq);
}

View File

@ -427,7 +427,7 @@ fir::factory::genIsAllocatedOrAssociatedTest(fir::FirOpBuilder &builder,
mlir::Location loc,
const fir::MutableBoxValue &box) {
auto addr = MutablePropertyReader(builder, loc, box).readBaseAddress();
return builder.genIsNotNull(loc, addr);
return builder.genIsNotNullAddr(loc, addr);
}
/// Generate finalizer call and inlined free. This does not check that the
@ -447,7 +447,7 @@ void fir::factory::genFinalization(fir::FirOpBuilder &builder,
mlir::Location loc,
const fir::MutableBoxValue &box) {
auto addr = MutablePropertyReader(builder, loc, box).readBaseAddress();
auto isAllocated = builder.genIsNotNull(loc, addr);
auto isAllocated = builder.genIsNotNullAddr(loc, addr);
auto ifOp = builder.create<fir::IfOp>(loc, isAllocated,
/*withElseRegion=*/false);
auto insPt = builder.saveInsertionPoint();
@ -714,7 +714,7 @@ fir::factory::genReallocIfNeeded(fir::FirOpBuilder &builder, mlir::Location loc,
auto addr = reader.readBaseAddress();
auto i1Type = builder.getI1Type();
auto addrType = addr.getType();
auto isAllocated = builder.genIsNotNull(loc, addr);
auto isAllocated = builder.genIsNotNullAddr(loc, addr);
auto ifOp =
builder
.genIfOp(loc, {i1Type, addrType}, isAllocated,

View File

@ -35,7 +35,7 @@ void fir::runtime::genRaggedArrayAllocate(mlir::Location loc,
auto ptrTy = builder.getRefType(eleTy.cast<mlir::TupleType>().getType(1));
auto ptr = builder.create<fir::CoordinateOp>(loc, ptrTy, header, one);
auto heap = builder.create<fir::LoadOp>(loc, ptr);
auto cmp = builder.genIsNull(loc, heap);
auto cmp = builder.genIsNullAddr(loc, heap);
builder.genIfThen(loc, cmp)
.genThen([&]() {
auto asHeadersVal = builder.createIntegerConstant(loc, i1Ty, asHeaders);

View File

@ -29,3 +29,137 @@ subroutine system_clock_test()
! CHECK-NOT: fir.call
! print*, m
end subroutine
! CHECK-LABEL: @_QPss
subroutine ss(count)
! CHECK: %[[V_0:[0-9]+]] = fir.alloca !fir.box<!fir.heap<i64>> {bindc_name = "count_max", uniq_name = "_QFssEcount_max"}
! CHECK: %[[V_1:[0-9]+]] = fir.alloca !fir.heap<i64> {uniq_name = "_QFssEcount_max.addr"}
! CHECK: %[[V_2:[0-9]+]] = fir.zero_bits !fir.heap<i64>
! CHECK: fir.store %[[V_2]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_3:[0-9]+]] = fir.alloca !fir.box<!fir.ptr<i64>> {bindc_name = "count_rate", uniq_name = "_QFssEcount_rate"}
! CHECK: %[[V_4:[0-9]+]] = fir.alloca !fir.ptr<i64> {uniq_name = "_QFssEcount_rate.addr"}
! CHECK: %[[V_5:[0-9]+]] = fir.zero_bits !fir.ptr<i64>
! CHECK: fir.store %[[V_5]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>
! CHECK: %[[V_6:[0-9]+]] = fir.alloca i64 {bindc_name = "count_rate_", fir.target, uniq_name = "_QFssEcount_rate_"}
! CHECK: %[[V_7:[0-9]+]] = fir.convert %[[V_6]] : (!fir.ref<i64>) -> !fir.ptr<i64>
! CHECK: fir.store %[[V_7]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>
! CHECK: %[[V_8:[0-9]+]] = fir.allocmem i64 {uniq_name = "_QFssEcount_max.alloc"}
! CHECK: fir.store %[[V_8]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_9:[0-9]+]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
! CHECK: %[[V_10:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_11:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
! CHECK: fir.if %[[V_11]] {
! CHECK: %[[V_29:[0-9]+]] = fir.call @_FortranASystemClockCount(%c8{{.*}}_i32) : (i32) -> i64
! CHECK: fir.store %[[V_29]] to %arg0 : !fir.ref<i64>
! CHECK: }
! CHECK: %[[V_12:[0-9]+]] = fir.convert %[[V_9]] : (!fir.ptr<i64>) -> i64
! CHECK: %[[V_13:[0-9]+]] = arith.cmpi ne, %[[V_12]], %c0{{.*}}_i64 : i64
! CHECK: fir.if %[[V_13]] {
! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountRate(%c8{{.*}}_i32) : (i32) -> i64
! CHECK: fir.store %[[V_29]] to %[[V_9]] : !fir.ptr<i64>
! CHECK: }
! CHECK: %[[V_14:[0-9]+]] = fir.convert %[[V_10]] : (!fir.heap<i64>) -> i64
! CHECK: %[[V_15:[0-9]+]] = arith.cmpi ne, %[[V_14]], %c0{{.*}}_i64_0 : i64
! CHECK: fir.if %[[V_15]] {
! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountMax(%c8{{.*}}_i32) : (i32) -> i64
! CHECK: fir.store %[[V_29]] to %[[V_10]] : !fir.heap<i64>
! CHECK: }
! CHECK: %[[V_16:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
! CHECK: fir.if %[[V_16]] {
! CHECK: %[[V_31:[0-9]+]] = fir.call @_FortranAioBeginExternalListOutput
! CHECK: %[[V_32:[0-9]+]] = fir.load %arg0 : !fir.ref<i64>
! CHECK: %[[V_33:[0-9]+]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_32]]) : (!fir.ref<i8>, i64) -> i1
! CHECK: %[[V_34:[0-9]+]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
! CHECK: %[[V_35:[0-9]+]] = fir.load %[[V_34]] : !fir.ptr<i64>
! CHECK: %[[V_36:[0-9]+]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_35]]) : (!fir.ref<i8>, i64) -> i1
! CHECK: %[[V_37:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_38:[0-9]+]] = fir.load %[[V_37]] : !fir.heap<i64>
! CHECK: %[[V_39:[0-9]+]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_38]]) : (!fir.ref<i8>, i64) -> i1
! CHECK: %[[V_40:[0-9]+]] = fir.call @_FortranAioEndIoStatement(%[[V_31]]) : (!fir.ref<i8>) -> i32
! CHECK: } else {
! CHECK: %[[V_29]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
! CHECK: %[[V_30:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_31]] = fir.convert %[[V_29]] : (!fir.ptr<i64>) -> i64
! CHECK: %[[V_32]] = arith.cmpi ne, %[[V_31]], %c0{{.*}}_i64_3 : i64
! CHECK: fir.if %[[V_32]] {
! CHECK: %[[V_45:[0-9]+]] = fir.call @_FortranASystemClockCountRate(%c8{{.*}}_i32) : (i32) -> i64
! CHECK: fir.store %[[V_45]] to %[[V_29]] : !fir.ptr<i64>
! CHECK: }
! CHECK: %[[V_33]] = fir.convert %[[V_30]] : (!fir.heap<i64>) -> i64
! CHECK: %[[V_34]] = arith.cmpi ne, %[[V_33]], %c0{{.*}}_i64_4 : i64
! CHECK: fir.if %[[V_34]] {
! CHECK: %[[V_45]] = fir.call @_FortranASystemClockCountMax(%c8{{.*}}_i32) : (i32) -> i64
! CHECK: fir.store %[[V_45]] to %[[V_30]] : !fir.heap<i64>
! CHECK: }
! CHECK: %[[V_37]] = fir.call @_FortranAioBeginExternalListOutput
! CHECK: %[[V_38]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
! CHECK: %[[V_39]] = fir.load %[[V_38]] : !fir.ptr<i64>
! CHECK: %[[V_40]] = fir.call @_FortranAioOutputInteger64(%[[V_37]], %[[V_39]]) : (!fir.ref<i8>, i64) -> i1
! CHECK: %[[V_41:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_42:[0-9]+]] = fir.load %[[V_41]] : !fir.heap<i64>
! CHECK: %[[V_43:[0-9]+]] = fir.call @_FortranAioOutputInteger64(%[[V_37]], %[[V_42]]) : (!fir.ref<i8>, i64) -> i1
! CHECK: %[[V_44:[0-9]+]] = fir.call @_FortranAioEndIoStatement(%[[V_37]]) : (!fir.ref<i8>) -> i32
! CHECK: }
! CHECK: %[[V_17:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
! CHECK: fir.if %[[V_17]] {
! CHECK: %[[V_29]] = fir.convert %c0{{.*}}_i32 : (i32) -> i64
! CHECK: fir.store %[[V_29]] to %arg0 : !fir.ref<i64>
! CHECK: } else {
! CHECK: }
! CHECK: %[[V_18:[0-9]+]] = fir.zero_bits !fir.ptr<i64>
! CHECK: fir.store %[[V_18]] to %[[V_4]] : !fir.ref<!fir.ptr<i64>>
! CHECK: %[[V_19:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: fir.freemem %[[V_19]] : !fir.heap<i64>
! CHECK: %[[V_20:[0-9]+]] = fir.zero_bits !fir.heap<i64>
! CHECK: fir.store %[[V_20]] to %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_21:[0-9]+]] = fir.load %[[V_4]] : !fir.ref<!fir.ptr<i64>>
! CHECK: %[[V_22:[0-9]+]] = fir.load %[[V_1]] : !fir.ref<!fir.heap<i64>>
! CHECK: %[[V_23:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
! CHECK: fir.if %[[V_23]] {
! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCount(%c8{{.*}}_i32) : (i32) -> i64
! CHECK: fir.store %[[V_29]] to %arg0 : !fir.ref<i64>
! CHECK: }
! CHECK: %[[V_24:[0-9]+]] = fir.convert %[[V_21]] : (!fir.ptr<i64>) -> i64
! CHECK: %[[V_25:[0-9]+]] = arith.cmpi ne, %[[V_24]], %c0{{.*}}_i64_1 : i64
! CHECK: fir.if %[[V_25]] {
! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountRate(%c8{{.*}}_i32) : (i32) -> i64
! CHECK: fir.store %[[V_29]] to %[[V_21]] : !fir.ptr<i64>
! CHECK: }
! CHECK: %[[V_26:[0-9]+]] = fir.convert %[[V_22]] : (!fir.heap<i64>) -> i64
! CHECK: %[[V_27:[0-9]+]] = arith.cmpi ne, %[[V_26]], %c0{{.*}}_i64_2 : i64
! CHECK: fir.if %[[V_27]] {
! CHECK: %[[V_29]] = fir.call @_FortranASystemClockCountMax(%c8{{.*}}_i32) : (i32) -> i64
! CHECK: fir.store %[[V_29]] to %[[V_22]] : !fir.heap<i64>
! CHECK: }
! CHECK: %[[V_28:[0-9]+]] = fir.is_present %arg0 : (!fir.ref<i64>) -> i1
! CHECK: fir.if %[[V_28]] {
! CHECK: %[[V_31]] = fir.call @_FortranAioBeginExternalListOutput
! CHECK: %[[V_32]] = fir.load %arg0 : !fir.ref<i64>
! CHECK: %[[V_33]] = fir.call @_FortranAioOutputInteger64(%[[V_31]], %[[V_32]]) : (!fir.ref<i8>, i64) -> i1
! CHECK: %[[V_34]] = fir.call @_FortranAioEndIoStatement(%[[V_31]]) : (!fir.ref<i8>) -> i32
! CHECK: } else {
! CHECK: }
! CHECK: return
! CHECK: }
integer(8), optional :: count
integer(8), target :: count_rate_
integer(8), pointer :: count_rate
integer(8), allocatable :: count_max
count_rate => count_rate_
allocate(count_max)
call system_clock(count, count_rate, count_max)
if (present(count)) then
print*, count, count_rate, count_max
else
call system_clock(count_rate=count_rate, count_max=count_max)
print*, count_rate, count_max
endif
if (present(count)) count = 0
count_rate => null()
deallocate(count_max)
call system_clock(count, count_rate, count_max)
if (present(count)) print*, count
end

View File

@ -102,23 +102,23 @@ TEST_F(FIRBuilderTest, genIfWithThenAndElse) {
// Helper functions tests
//===----------------------------------------------------------------------===//
TEST_F(FIRBuilderTest, genIsNotNull) {
TEST_F(FIRBuilderTest, genIsNotNullAddr) {
auto builder = getBuilder();
auto loc = builder.getUnknownLoc();
auto dummyValue =
builder.createIntegerConstant(loc, builder.getIndexType(), 0);
auto res = builder.genIsNotNull(loc, dummyValue);
auto res = builder.genIsNotNullAddr(loc, dummyValue);
EXPECT_TRUE(mlir::isa<arith::CmpIOp>(res.getDefiningOp()));
auto cmpOp = dyn_cast<arith::CmpIOp>(res.getDefiningOp());
EXPECT_EQ(arith::CmpIPredicate::ne, cmpOp.getPredicate());
}
TEST_F(FIRBuilderTest, genIsNull) {
TEST_F(FIRBuilderTest, genIsNullAddr) {
auto builder = getBuilder();
auto loc = builder.getUnknownLoc();
auto dummyValue =
builder.createIntegerConstant(loc, builder.getIndexType(), 0);
auto res = builder.genIsNull(loc, dummyValue);
auto res = builder.genIsNullAddr(loc, dummyValue);
EXPECT_TRUE(mlir::isa<arith::CmpIOp>(res.getDefiningOp()));
auto cmpOp = dyn_cast<arith::CmpIOp>(res.getDefiningOp());
EXPECT_EQ(arith::CmpIPredicate::eq, cmpOp.getPredicate());