Skip to content

Commit c41fce7

Browse files
P4HIR: Add verifySymbolUses for TableActionOp
Signed-off-by: Lavanyampalli <lavanyampalli@gmail.com>
1 parent 09bc0ca commit c41fce7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

include/p4mlir/Dialect/P4HIR/P4HIR_ControlOps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def TableActionsOp : P4HIR_Op<"table_actions", [ Annotated,
189189

190190
def TableActionOp : P4HIR_Op<"table_action",
191191
[AutomaticAllocationScope, NoTerminator, Annotated,
192-
// DeclareOpInterfaceMethods<SymbolUserOpInterface>
192+
DeclareOpInterfaceMethods<SymbolUserOpInterface>
193193
]> {
194194
let arguments = (ins TypeAttrOf<FuncType>:$cplaneType, FlatSymbolRefAttr:$action,
195195
OptionalAttr<DictArrayAttr>:$arg_attrs,

lib/Dialect/P4HIR/P4HIR_Ops.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3375,6 +3375,23 @@ void P4HIR::TableApplyOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) {
33753375
setNameFn(getResult(), result);
33763376
}
33773377

3378+
LogicalResult P4HIR::TableActionOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
3379+
auto actionAttr = (*this)->getAttrOfType<FlatSymbolRefAttr>(getActionAttrName());
3380+
if (!actionAttr)
3381+
return emitOpError("requires an 'action' symbol reference attribute");
3382+
3383+
// The action attribute is the control-plane name. After inlining it may
3384+
// no longer resolve to a FuncOp (the symbol gets renamed), so only
3385+
// validate when the symbol is actually found.
3386+
auto *decl = symbolTable.lookupNearestSymbolFrom(*this, actionAttr);
3387+
if (!decl) return success(); // post-inlining: symbol renamed, skip
3388+
3389+
auto fn = llvm::dyn_cast<P4HIR::FuncOp>(decl);
3390+
if (!fn || !fn.getAction())
3391+
return emitOpError("'") << actionAttr << "' does not reference a valid action";
3392+
3393+
return success();
3394+
}
33783395
//===----------------------------------------------------------------------===//
33793396
// TablePropertyOp
33803397
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)