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

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 14 13:46:53 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:

The createDummyValue he added is in the CIR codegen, and it's doing something different. These do seem like utility functions that will probably be useful elsewhere though. Or maybe a wrapper function isn't even needed.

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


More information about the cfe-commits mailing list