================
@@ -110,6 +111,112 @@ Operation
*cir::CIRDialect::materializeConstant(mlir::OpBuilder &builder,
mlir::cast<mlir::TypedAttr>(value));
}
+//===----------------------------------------------------------------------===//
+// Offload container helpers
+//===----------------------------------------------------------------------===//
+
+bool cir::isOffloadContainer(mlir::ModuleOp module) {
+ return module->hasAttr(cir::CIRDialect::getOffloadContainerAttrName());
+}
+
+mlir::ModuleOp cir::getOffloadHostModule(mlir::ModuleOp container) {
+ assert(isOffloadContainer(container) && "expected an offload container");
+ return mlir::cast<mlir::ModuleOp>(container.getBody()->front());
+}
+
+llvm::iterator_range<mlir::Block::op_iterator<mlir::ModuleOp>>
+cir::getOffloadDeviceModules(mlir::ModuleOp container) {
+ assert(isOffloadContainer(container) && "expected an offload container");
+ mlir::Block &body = *container.getBody();
+ auto begin = body.op_begin<mlir::ModuleOp>();
+ auto end = body.op_end<mlir::ModuleOp>();
+ if (begin != end)
+ ++begin;
+ return {begin, end};
----------------
steffenlarsen wrote:
Since verification requires containers to be non-empty, the branching here
seems redundant to me.
```suggestion
return {body.op_begin<mlir::ModuleOp>() + 1, body.op_end<mlir::ModuleOp>()};
```
If we want to be sure, we could have an assert checking that it is non-empty.
If so, it might also make sense to add to `getOffloadHostModule`.
https://github.com/llvm/llvm-project/pull/206576
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits