================
@@ -39,58 +30,94 @@ namespace mlir {
 
 namespace {
 
+// The raised operation requires matching operand types. The searched value
+// arrives by reference and must share the iterator type.
+template <typename TargetOp> bool operandTypesMatch(CallOp call);
+
+template <> bool operandTypesMatch<StdFindOp>(CallOp call) {
+  mlir::Type iterTy = call.getOperand(0).getType();
+  return iterTy == call.getOperand(1).getType() &&
+         iterTy == call.getOperand(2).getType() &&
+         iterTy == call->getResult(0).getType();
+}
+
+// Raises a direct cir.call to `TargetOp` when the callee carries the
+// matching identity tag.
+template <typename TargetOp> class StdRecognizer {
+  template <size_t... Indices>
+  static TargetOp buildCall(cir::CIRBaseBuilderTy &builder, CallOp call,
+                            std::index_sequence<Indices...>) {
+    return TargetOp::create(builder, call.getLoc(),
+                            call->getResult(0).getType(),
+                            call.getOperand(Indices)..., call.getCalleeAttr());
+  }
+
+public:
+  static bool raise(CallOp call, mlir::MLIRContext &context,
+                    mlir::SymbolTableCollection &symbolTables) {
+    // A musttail call must stay a call, so it is never raised.
+    constexpr unsigned numArgs = TargetOp::getNumArgs();
+    if (!call.getCallee() || call.getNumOperands() != numArgs ||
+        call->getNumResults() != 1 || call.getMusttail() ||
+        !operandTypesMatch<TargetOp>(call))
----------------
SharmaRithik wrote:

Done, moved the count checks.

https://github.com/llvm/llvm-project/pull/208854
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to