Skip to content

Commit d455dca

Browse files
committed
Add test-case for user-defined allocator value
1 parent a6b5d96 commit d455dca

File tree

2 files changed

+32
-27
lines changed

2 files changed

+32
-27
lines changed

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,34 +1267,32 @@ static ParseResult parseAllocatorHandle(OpAsmParser &parser,
12671267
allocatorHandleAttr = IntegerAttr::get(parser.getBuilder().getI64Type(), 0);
12681268
return success();
12691269
}
1270-
auto parseKeyword = [&]() -> ParseResult {
1271-
if (failed(parser.parseKeyword(&allocatorKeyword)))
1272-
return failure();
1273-
if (allocatorKeyword == "omp_null_allocator")
1274-
allocator = 0;
1275-
else if (allocatorKeyword == "omp_default_mem_alloc")
1276-
allocator = 1;
1277-
else if (allocatorKeyword == "omp_large_cap_mem_alloc")
1278-
allocator = 2;
1279-
else if (allocatorKeyword == "omp_const_mem_alloc")
1280-
allocator = 3;
1281-
else if (allocatorKeyword == "omp_high_bw_mem_alloc")
1282-
allocator = 4;
1283-
else if (allocatorKeyword == "omp_low_lat_mem_alloc")
1284-
allocator = 5;
1285-
else if (allocatorKeyword == "omp_cgroup_mem_alloc")
1286-
allocator = 6;
1287-
else if (allocatorKeyword == "omp_pteam_mem_alloc")
1288-
allocator = 7;
1289-
else if (allocatorKeyword == "omp_thread_mem_alloc")
1290-
allocator = 8;
1291-
else
1292-
return parser.emitError(parser.getCurrentLocation())
1293-
<< allocatorKeyword << " is not a valid allocator";
1270+
OptionalParseResult parsedInteger = parser.parseOptionalInteger(allocator);
1271+
if (parsedInteger.has_value()) {
1272+
allocatorHandleAttr =
1273+
IntegerAttr::get(parser.getBuilder().getI64Type(), allocator);
12941274
return success();
1295-
};
1296-
if (parser.parseCommaSeparatedList(parseKeyword))
1275+
}
1276+
if (failed(parser.parseKeyword(&allocatorKeyword)))
12971277
return failure();
1278+
if (allocatorKeyword == "omp_null_allocator")
1279+
allocator = 0;
1280+
else if (allocatorKeyword == "omp_default_mem_alloc")
1281+
allocator = 1;
1282+
else if (allocatorKeyword == "omp_large_cap_mem_alloc")
1283+
allocator = 2;
1284+
else if (allocatorKeyword == "omp_const_mem_alloc")
1285+
allocator = 3;
1286+
else if (allocatorKeyword == "omp_high_bw_mem_alloc")
1287+
allocator = 4;
1288+
else if (allocatorKeyword == "omp_low_lat_mem_alloc")
1289+
allocator = 5;
1290+
else if (allocatorKeyword == "omp_cgroup_mem_alloc")
1291+
allocator = 6;
1292+
else if (allocatorKeyword == "omp_pteam_mem_alloc")
1293+
allocator = 7;
1294+
else if (allocatorKeyword == "omp_thread_mem_alloc")
1295+
allocator = 8;
12981296
allocatorHandleAttr =
12991297
IntegerAttr::get(parser.getBuilder().getI64Type(), allocator);
13001298
return success();
@@ -1333,6 +1331,9 @@ static void printAllocatorHandle(OpAsmPrinter &p, Operation *op,
13331331
case 8:
13341332
allocatorHandle = "omp_thread_mem_alloc";
13351333
break;
1334+
default:
1335+
p << Twine(allocator).str();
1336+
return;
13361337
}
13371338
p << allocatorHandle;
13381339
}

mlir/test/Dialect/OpenMP/ops.mlir

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3279,7 +3279,7 @@ func.func @omp_allocate_dir(%arg0 : memref<i32>, %arg1 : memref<i32>) -> () {
32793279

32803280
// Test with one data var and allocator clause
32813281
// CHECK: omp.allocate_dir(%[[ARG0]] : memref<i32>) allocator(omp_pteam_mem_alloc)
3282-
omp.allocate_dir (%arg0 : memref<i32>) allocator(omp_pteam_mem_alloc)
3282+
omp.allocate_dir (%arg0 : memref<i32>) allocator(7)
32833283

32843284
// Test with one data var, align clause and allocator clause
32853285
// CHECK: omp.allocate_dir(%[[ARG0]] : memref<i32>) align(2) allocator(omp_thread_mem_alloc)
@@ -3289,6 +3289,10 @@ func.func @omp_allocate_dir(%arg0 : memref<i32>, %arg1 : memref<i32>) -> () {
32893289
// CHECK: omp.allocate_dir(%[[ARG0]], %[[ARG1]] : memref<i32>, memref<i32>) align(2) allocator(omp_cgroup_mem_alloc)
32903290
omp.allocate_dir (%arg0, %arg1 : memref<i32>, memref<i32>) align(2) allocator(omp_cgroup_mem_alloc)
32913291

3292+
// Test with one data var and user defined allocator clause
3293+
// CHECK: omp.allocate_dir(%[[ARG0]] : memref<i32>) allocator(9)
3294+
omp.allocate_dir (%arg0 : memref<i32>) allocator(9)
3295+
32923296
return
32933297
}
32943298

0 commit comments

Comments
 (0)