[Mlir-commits] [mlir] [mlir][ArmSME] Use liveness information in the tile allocator (PR #90448)
Andrzej WarzyĆski
llvmlistbot at llvm.org
Tue May 7 08:29:50 PDT 2024
================
@@ -116,4 +116,50 @@ VectorType getSMETileTypeForElement(Type elementType) {
return VectorType::get({minNumElts, minNumElts}, elementType, {true, true});
}
+void eraseTriviallyDeadTileOps(IRRewriter &rewriter,
+ FunctionOpInterface function) {
+ SmallVector<Operation *> worklist;
+ function->walk([&](Operation *op) {
+ auto armSMEOp = dyn_cast<arm_sme::ArmSMETileOpInterface>(op);
+ if (armSMEOp && isOpTriviallyDead(armSMEOp))
+ worklist.push_back(armSMEOp);
+ });
+ while (!worklist.empty()) {
+ Operation *op = worklist.pop_back_val();
+ if (!isOpTriviallyDead(op))
+ continue;
+ for (Value value : op->getOperands()) {
+ if (auto armSMEOp = value.getDefiningOp<arm_sme::ArmSMETileOpInterface>())
+ worklist.push_back(armSMEOp);
+ }
+ rewriter.eraseOp(op);
+ }
+}
+
+bool isTriviallyCloneableTileOp(arm_sme::ArmSMETileOpInterface tileOp) {
+ return tileOp && tileOp->getNumResults() == 1 &&
+ tileOp->getNumOperands() == 0 && isPure(tileOp);
+}
----------------
banach-space wrote:
Please document:
```
/// A helper function that helps to filter out Ops that are not trivial to clone. Conditions that are checked:
/// * no more than one result/operand - otherwise we'd have to investigate these as well,
/// * pure - otherwise we'd need to reason whether moving/duplicating might change the semantics.
```
Also, the name of this function suggests that the input is an actual Operation. Could you update like this:
```cpp
bool isTriviallyCloneableTileOp(arm_sme::ArmSMETileOpInterface tileOp) {
assert(tileOp && "Expected an operation producing an SME tile");
return tileOp->getNumResults() == 1 &&
tileOp->getNumOperands() == 0 && isPure(tileOp);
}
```
And then, when this hook is used (modulo formatting):
```cpp
if (!operandTileOpt)
return tileOp.emitOpError("cannot clone a block argument - failed to rectify tile operand with tile "
"result (move required)");
if (!isTriviallyCloneableTileOp(operandTileOp))
return tileOp.emitOpError("not a trivially clonable Op - failed to rectify tile operand with tile "
"result (move required)");
```
In general, lets diagnose and document reasons for failure as early and verbosely as possible (within reason).
https://github.com/llvm/llvm-project/pull/90448
More information about the Mlir-commits
mailing list