[clang] [CIR] Upstream TernaryOp (PR #137184)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 24 15:39:04 PDT 2025
================
@@ -254,10 +254,61 @@ class CIRLoopOpInterfaceFlattening
}
};
+class CIRTernaryOpFlattening : public mlir::OpRewritePattern<cir::TernaryOp> {
+public:
+ using OpRewritePattern<cir::TernaryOp>::OpRewritePattern;
+
+ mlir::LogicalResult
+ matchAndRewrite(cir::TernaryOp op,
+ mlir::PatternRewriter &rewriter) const override {
+ Location loc = op->getLoc();
+ Block *condBlock = rewriter.getInsertionBlock();
+ Block::iterator opPosition = rewriter.getInsertionPoint();
+ Block *remainingOpsBlock = rewriter.splitBlock(condBlock, opPosition);
+ llvm::SmallVector<mlir::Location, 2> locs;
+ // Ternary result is optional, make sure to populate the location only
+ // when relevant.
+ if (op->getResultTypes().size())
+ locs.push_back(loc);
+ auto *continueBlock =
----------------
andykaylor wrote:
```suggestion
Block *continueBlock =
```
https://github.com/llvm/llvm-project/pull/137184
More information about the cfe-commits
mailing list