Skip to content

Commit 0800423

Browse files
jurahulTensorFlow MLIR Team
authored andcommitted
[LMHLO] Simplify FusionOp::getInputBuffers() and friends.
- No need to walk the entire region, instead just iterate over the top level operations in the region attached to the fusion op. PiperOrigin-RevId: 366528833
1 parent 38d0f96 commit 0800423

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

‎include/mlir-hlo/Dialect/mhlo/IR/lhlo_ops.td‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -687,39 +687,35 @@ def FusionOp : LHLO_Op<"fusion", [SingleBlockImplicitTerminator<"TerminatorOp">]
687687
];
688688

689689
let extraClassDeclaration = [{
690-
SmallVector<Value, 4> getInputBuffers() {
691-
SmallVector<Value, 4> buffers;
692-
this->region().walk([&](memref::TensorLoadOp load) {
693-
if (load.memref().getParentRegion()->isProperAncestor(&region()))
694-
buffers.push_back(load.memref());
695-
});
690+
SmallVector<Value> getInputBuffers() {
691+
SmallVector<Value> buffers;
692+
for (auto load : region().front().getOps<memref::TensorLoadOp>()) {
693+
buffers.push_back(load.memref());
694+
}
696695
return buffers;
697696
}
698697
699-
SmallVector<Value, 4> getOutputBuffers() {
700-
SmallVector<Value, 4> buffers;
701-
this->region().walk([&](memref::TensorStoreOp store) {
702-
if (store.memref().getParentRegion()->isProperAncestor(&region()))
703-
buffers.push_back(store.memref());
704-
});
698+
SmallVector<Value> getOutputBuffers() {
699+
SmallVector<Value> buffers;
700+
for (auto store : region().front().getOps<memref::TensorStoreOp>()) {
701+
buffers.push_back(store.memref());
702+
}
705703
return buffers;
706704
}
707705
708-
SmallVector<Value, 4> getFusionParameters() {
709-
SmallVector<Value, 4> buffers;
710-
this->region().walk([&](memref::TensorLoadOp load) {
711-
if (load.memref().getParentRegion()->isProperAncestor(&region()))
712-
buffers.push_back(load);
713-
});
706+
SmallVector<Value> getFusionParameters() {
707+
SmallVector<Value> buffers;
708+
for (auto load : region().front().getOps<memref::TensorLoadOp>()) {
709+
buffers.push_back(load);
710+
}
714711
return buffers;
715712
}
716713
717-
SmallVector<Value, 4> getFusionResults() {
718-
SmallVector<Value, 4> buffers;
719-
this->region().walk([&](memref::TensorStoreOp store) {
720-
if (store.memref().getParentRegion()->isProperAncestor(&region()))
721-
buffers.push_back(store.tensor());
722-
});
714+
SmallVector<Value> getFusionResults() {
715+
SmallVector<Value> buffers;
716+
for (auto store : region().front().getOps<memref::TensorStoreOp>()) {
717+
buffers.push_back(store.tensor());
718+
}
723719
return buffers;
724720
}
725721
}];

0 commit comments

Comments
 (0)