@@ -1398,6 +1398,33 @@ TEST_F(OpenACCUtilsTest, getDominatingDataClausesEmpty) {
13981398// isDeviceValue Tests
13991399// ===----------------------------------------------------------------------===//
14001400
1401+ namespace {
1402+ static Value memrefViewFromBlockArgWithDeclare (OpBuilder &builder, Location loc,
1403+ MLIRContext *ctx,
1404+ DataClause clause,
1405+ ModuleOp module ,
1406+ StringRef funcName) {
1407+ OpBuilder::InsertionGuard guard (builder);
1408+ builder.setInsertionPointToStart (module .getBody ());
1409+
1410+ auto i8BufTy = MemRefType::get ({40 }, builder.getI8Type ());
1411+ auto viewTy = MemRefType::get ({10 }, builder.getI32Type ());
1412+ auto funcType = builder.getFunctionType ({i8BufTy}, {});
1413+ func::FuncOp funcOp = func::FuncOp::create (builder, loc, funcName, funcType);
1414+ Block *entry = funcOp.addEntryBlock ();
1415+
1416+ builder.setInsertionPointToStart (entry);
1417+ Value buf = entry->getArgument (0 );
1418+ Value c0 = arith::ConstantIndexOp::create (builder, loc, 0 );
1419+ memref::ViewOp viewOp =
1420+ memref::ViewOp::create (builder, loc, viewTy, buf, c0, ValueRange{});
1421+ viewOp->setAttr (getDeclareAttrName (),
1422+ DeclareAttr::get (ctx, DataClauseAttr::get (ctx, clause)));
1423+ func::ReturnOp::create (builder, loc);
1424+ return viewOp.getResult ();
1425+ }
1426+ } // namespace
1427+
14011428TEST_F (OpenACCUtilsTest, isDeviceValueMemrefGlobalAddressSpace) {
14021429 // Test that a memref with GPU global address space is considered device data
14031430 auto gpuAddressSpace =
@@ -1525,6 +1552,26 @@ TEST_F(OpenACCUtilsTest, isDeviceValueGlobalWithoutGPUAddressSpace) {
15251552 EXPECT_FALSE (isDeviceValue (val));
15261553}
15271554
1555+ TEST_F (OpenACCUtilsTest, isDeviceValueAccDeclareDeviceptr) {
1556+ OwningOpRef<ModuleOp> module = ModuleOp::create (loc);
1557+ OpBuilder::InsertionGuard guard (b);
1558+ b.setInsertionPointToStart (module ->getBody ());
1559+ Value val = memrefViewFromBlockArgWithDeclare (
1560+ b, loc, &context, DataClause::acc_deviceptr, module .get (),
1561+ " test_memref_view_declare_devptr" );
1562+ EXPECT_TRUE (isDeviceValue (val));
1563+ }
1564+
1565+ TEST_F (OpenACCUtilsTest, isDeviceValueAccDeclareNonDeviceptr) {
1566+ OwningOpRef<ModuleOp> module = ModuleOp::create (loc);
1567+ OpBuilder::InsertionGuard guard (b);
1568+ b.setInsertionPointToStart (module ->getBody ());
1569+ Value val = memrefViewFromBlockArgWithDeclare (
1570+ b, loc, &context, DataClause::acc_copyin, module .get (),
1571+ " test_memref_view_declare_copyin" );
1572+ EXPECT_FALSE (isDeviceValue (val));
1573+ }
1574+
15281575// ===----------------------------------------------------------------------===//
15291576// isValidValueUse Tests
15301577// ===----------------------------------------------------------------------===//
0 commit comments