[flang-commits] [flang] [mlir] [mlir][flang] Added Weighted[Region]BranchOpInterface's. (PR #142079)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Tue Jun 10 22:08:25 PDT 2025


================
@@ -375,6 +375,114 @@ def SelectLikeOpInterface : OpInterface<"SelectLikeOpInterface"> {
   ];
 }
 
+//===----------------------------------------------------------------------===//
+// WeightedBranchOpInterface
+//===----------------------------------------------------------------------===//
+
+def WeightedBranchOpInterface : OpInterface<"WeightedBranchOpInterface"> {
+  let description = [{
+    This interface provides weight information for branching terminator
+    operations, i.e. terminator operations with successors.
+
+    This interface provides methods for getting/setting integer non-negative
+    weight of each branch. The probability of executing a branch
+    is computed as the ratio between the branch's weight and the total
+    sum of the weights.
+    The number of weights must match the number of successors of the operation,
+    with one exception for CallOpInterface operations, which may only
+    have on weight when they do not have any successors.
+
+    The default implementations of the methods expect the operation
+    to have an attribute of type DenseI32ArrayAttr named branch_weights.
+  }];
+  let cppNamespace = "::mlir";
+
+  let methods = [InterfaceMethod<
+                     /*desc=*/"Returns the branch weights attribute or nullptr",
+                     /*returnType=*/"::mlir::DenseI32ArrayAttr",
+                     /*methodName=*/"getBranchWeightsOrNull",
----------------
vzakhari wrote:

Yes, they are optional.  I will add it into the documentation. Thanks!

https://github.com/llvm/llvm-project/pull/142079


More information about the flang-commits mailing list