Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct GlobalVariableModel
: public mlir::acc::GlobalVariableOpInterface::ExternalModel<
GlobalVariableModel, fir::GlobalOp> {
bool isConstant(mlir::Operation *op) const;
mlir::Region *getInitRegion(mlir::Operation *op) const;
};

template <typename Op>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ bool GlobalVariableModel::isConstant(mlir::Operation *op) const {
return globalOp.getConstant().has_value();
}

mlir::Region *GlobalVariableModel::getInitRegion(mlir::Operation *op) const {
auto globalOp = mlir::cast<fir::GlobalOp>(op);
return globalOp.hasInitializationBody() ? &globalOp.getRegion() : nullptr;
}

// Helper to recursively process address-of operations in derived type
// descriptors and collect all needed fir.globals.
static void processAddrOfOpInDerivedTypeDescriptor(
Expand Down
2 changes: 2 additions & 0 deletions mlir/include/mlir/Dialect/OpenACC/OpenACCOpsInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ def GlobalVariableOpInterface : OpInterface<"GlobalVariableOpInterface"> {
"isConstant", (ins), [{
return false;
}]>,
InterfaceMethod<"Get the initialization region (returns nullptr if none)",
"::mlir::Region*", "getInitRegion", (ins)>,
];
}

Expand Down
5 changes: 5 additions & 0 deletions mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ struct MemrefGlobalVariableModel
auto globalOp = cast<memref::GlobalOp>(op);
return globalOp.getConstant();
}

Region *getInitRegion(Operation *op) const {
// GlobalOp uses attributes for initialization, not regions
return nullptr;
}
};

/// Helper function for any of the times we need to modify an ArrayAttr based on
Expand Down
22 changes: 22 additions & 0 deletions mlir/unittests/Dialect/OpenACC/OpenACCOpsInterfacesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,28 @@ TEST_F(OpenACCOpsInterfacesTest, GlobalVariableOpInterfaceConstant) {
EXPECT_TRUE(globalVarIface.isConstant());
}

TEST_F(OpenACCOpsInterfacesTest, GlobalVariableOpInterfaceInitRegion) {
// Test that memref::GlobalOp returns nullptr for getInitRegion()
// since it uses attributes for initialization, not regions

auto memrefType = MemRefType::get({10}, builder.getF32Type());
OwningOpRef<memref::GlobalOp> globalOp = memref::GlobalOp::create(
builder, loc,
/*sym_name=*/builder.getStringAttr("test_global"),
/*sym_visibility=*/builder.getStringAttr("private"),
/*type=*/TypeAttr::get(memrefType),
/*initial_value=*/Attribute(),
/*constant=*/UnitAttr(),
/*alignment=*/IntegerAttr());

auto globalVarIface =
dyn_cast<GlobalVariableOpInterface>(globalOp->getOperation());
ASSERT_TRUE(globalVarIface != nullptr);

// memref::GlobalOp doesn't have regions for initialization
EXPECT_EQ(globalVarIface.getInitRegion(), nullptr);
}

//===----------------------------------------------------------------------===//
// AddressOfGlobalOpInterface Tests
//===----------------------------------------------------------------------===//
Expand Down