[clang] [CIR] Upstream initial support for unary op (PR #131369)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 14 15:08:23 PDT 2025


================
@@ -568,6 +568,128 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
+    cir::UnaryOp op, OpAdaptor adaptor,
+    mlir::ConversionPatternRewriter &rewriter) const {
+  assert(op.getType() == op.getInput().getType() &&
+         "Unary operation's operand type and result type are different");
+  mlir::Type type = op.getType();
+  mlir::Type elementType = type;
+  bool isVector = false;
+  assert(!cir::MissingFeatures::vectorType());
+  mlir::Type llvmType = getTypeConverter()->convertType(type);
+  mlir::Location loc = op.getLoc();
+
+  auto createIntConstant = [&](int64_t value) -> mlir::Value {
----------------
andykaylor wrote:

I'm working on an incubator change to do this. There are lots of opportunities to reuse a utility function there. I'll update this PR once I have a final form for the utility function.

https://github.com/llvm/llvm-project/pull/131369


More information about the cfe-commits mailing list