[Mlir-commits] [mlir] [mlir][SCF] Add folding for IndexSwitchOp (PR #70924)
Nicolas Vasilache
llvmlistbot at llvm.org
Wed Nov 1 06:17:19 PDT 2023
================
@@ -4166,6 +4166,33 @@ void IndexSwitchOp::getRegionInvocationBounds(
bounds.emplace_back(/*lb=*/0, /*ub=*/i == liveIndex);
}
+LogicalResult IndexSwitchOp::fold(FoldAdaptor adaptor,
+ SmallVectorImpl<OpFoldResult> &results) {
+ std::optional<int64_t> maybeCst = getConstantIntValue(getArg());
+ if (!maybeCst.has_value())
+ return failure();
+ int64_t cst = *maybeCst;
+ int64_t caseIdx, e = getNumCases();
+ for (caseIdx = 0; caseIdx < e; ++caseIdx) {
+ if (cst == getCases()[caseIdx])
+ break;
+ }
+
+ Region &r = (caseIdx < getNumCases()) ? getCaseRegions()[caseIdx]
+ : getDefaultRegion();
+ Block &source = r.front();
+ results.assign(source.getTerminator()->getOperands().begin(),
+ source.getTerminator()->getOperands().end());
+
+ Block *pDestination = (*this)->getBlock();
----------------
nicolasvasilache wrote:
don't know but it's easy enough, done
https://github.com/llvm/llvm-project/pull/70924
More information about the Mlir-commits
mailing list