[clang] [CIR] Upstream support for emitting ignored statements (PR #130869)

2025-03-12 Thread Andy Kaylor via cfe-commits
@@ -165,6 +165,33 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) { return LValue(); } +/// Emit code to compute the specified expression which +/// can have any type. The result is returned as an RValue struct. +RValue CIRGenFunction::emitAnyExpr(const E

[clang] [CIR] Add transform test for cir-flatten-cfg (PR #130861)

2025-03-12 Thread Andy Kaylor via cfe-commits
andykaylor wrote: @bcardosolopes Do you have any comments on this before I merge it? https://github.com/llvm/llvm-project/pull/130861 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream support for emitting ignored statements (PR #130869)

2025-03-12 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/130869 >From a4e8aa13f97a6c73389822f6fdcf6f5970792462 Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Tue, 11 Mar 2025 17:01:44 -0700 Subject: [PATCH 1/5] [CIR] Upstream support for emitting ignored statements Thi

[clang] [CIR] Upstream support for emitting ignored statements (PR #130869)

2025-03-12 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/130869 >From a4e8aa13f97a6c73389822f6fdcf6f5970792462 Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Tue, 11 Mar 2025 17:01:44 -0700 Subject: [PATCH 1/2] [CIR] Upstream support for emitting ignored statements Thi

[clang] [CIR] Upstream basic support for ArrayType (PR #130502)

2025-03-12 Thread Andy Kaylor via cfe-commits
@@ -33,6 +33,14 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { llvm_unreachable("NYI: PPC double-double format for long double"); llvm_unreachable("Unsupported format for long double"); } + + bool isSized(mlir::Type ty) { +if (mlir::isa(ty)) + r

[clang] [CIR] Upstream basic support for ArrayType (PR #130502)

2025-03-12 Thread Andy Kaylor via cfe-commits
@@ -33,6 +33,14 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { llvm_unreachable("NYI: PPC double-double format for long double"); llvm_unreachable("Unsupported format for long double"); } + + bool isSized(mlir::Type ty) { +if (mlir::isa(ty)) + r

[clang] [CIR] Upstream support for emitting ignored statements (PR #130869)

2025-03-12 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor closed https://github.com/llvm/llvm-project/pull/130869 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream basic support for ArrayType (PR #130502)

2025-03-15 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor commented: Can you also add a test for lowering to LLVM IR? https://github.com/llvm/llvm-project/pull/130502 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commi

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-15 Thread Andy Kaylor via cfe-commits
@@ -121,29 +364,173 @@ mlir::Value CIRGenFunction::emitScalarExpr(const Expr *e) { return ScalarExprEmitter(*this, builder).Visit(const_cast(e)); } +[[maybe_unused]] static bool MustVisitNullValue(const Expr *e) { + // If a null pointer expression's type is the C++0x nullp

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

2025-03-15 Thread Andy Kaylor via cfe-commits
@@ -568,6 +568,128 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( return mlir::success(); } +mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite( +cir::UnaryOp op, OpAdaptor adaptor, +mlir::ConversionPatternRewriter &rewriter) const { +

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -0,0 +1,79 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s + +unsigned char cxxstaticcast_0(unsigned int x) { + return static_cast(x); +} + +// CHECK: cir.func @cxxstaticcast_0 +// C

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

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -468,6 +468,55 @@ def BrOp : CIR_Op<"br", }]; } +//===--===// +// UnaryOp +//===--===// + +def UnaryOpKind_Inc : I32EnumAttrCase<"Inc"

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

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -468,6 +468,55 @@ def BrOp : CIR_Op<"br", }]; } +//===--===// +// UnaryOp +//===--===// + +def UnaryOpKind_Inc : I32EnumAttrCase<"Inc"

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

2025-03-15 Thread Andy Kaylor via cfe-commits
@@ -92,6 +92,222 @@ class ScalarExprEmitter : public StmtVisitor { mlir::Value VisitCastExpr(CastExpr *E); + // Unary Operators. + mlir::Value VisitUnaryPostDec(const UnaryOperator *e) { +LValue lv = cgf.emitLValue(e->getSubExpr()); +return emitScalarPrePostIncDe

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-15 Thread Andy Kaylor via cfe-commits
@@ -0,0 +1,58 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir andykaylor wrote: It looks like floating casts are still missing. Can you add float-to-double and double-to-float test? https://github.com/llvm/ll

[clang] [CIR] Add cir-translate and cir-lsp-server tools (PR #131181)

2025-03-18 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor closed https://github.com/llvm/llvm-project/pull/131181 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -121,29 +364,173 @@ mlir::Value CIRGenFunction::emitScalarExpr(const Expr *e) { return ScalarExprEmitter(*this, builder).Visit(const_cast(e)); } +[[maybe_unused]] static bool MustVisitNullValue(const Expr *e) { + // If a null pointer expression's type is the C++0x nullp

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

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -568,6 +568,128 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( return mlir::success(); } +mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite( +cir::UnaryOp op, OpAdaptor adaptor, +mlir::ConversionPatternRewriter &rewriter) const { +

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

2025-03-14 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/131369 >From d51bb762224f70b2b879198e2466ca0d258f9eae Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Mon, 10 Mar 2025 15:07:50 -0700 Subject: [PATCH 1/2] [CIR] Upstream initial support for unary op This adds supp

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

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -568,6 +568,128 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite( return mlir::success(); } +mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite( +cir::UnaryOp op, OpAdaptor adaptor, +mlir::ConversionPatternRewriter &rewriter) const { +

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

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -468,6 +468,55 @@ def BrOp : CIR_Op<"br", }]; } +//===--===// +// UnaryOp +//===--===// + +def UnaryOpKind_Inc : I32EnumAttrCase<"Inc"

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

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -165,6 +165,54 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) { return LValue(); } +LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { + UnaryOperatorKind op = e->getOpcode(); + + // __extension__ doesn't affect lvalue-ness. + if (op

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-14 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor edited https://github.com/llvm/llvm-project/pull/130690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-14 Thread Andy Kaylor via cfe-commits
@@ -0,0 +1,100 @@ +// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -DCIR_ONLY %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-14 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor approved this pull request. LGTM with one very minor nit https://github.com/llvm/llvm-project/pull/130690 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream cir-canonicalize pass (PR #131891)

2025-03-18 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/131891 This change introduces the cir-canonicalize pass. This is a simple cir-to-cir transformation that eliminates empty scopes and redundant branches. It will be expanded in future changes to simplify other redun

[clang] [CIR] Upstream support for type aliases (PR #131912)

2025-03-18 Thread Andy Kaylor via cfe-commits
andykaylor wrote: cc: @mmha https://github.com/llvm/llvm-project/pull/131912 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream support for type aliases (PR #131912)

2025-03-18 Thread Andy Kaylor via cfe-commits
@@ -31,6 +31,20 @@ struct CIROpAsmDialectInterface : public OpAsmDialectInterface { using OpAsmDialectInterface::OpAsmDialectInterface; AliasResult getAlias(Type type, raw_ostream &os) const final { +if (auto intType = dyn_cast(type)) { + // We only provide alias

[clang] [CIR] Upstream a basic version of class LexicalScope (PR #131945)

2025-03-19 Thread Andy Kaylor via cfe-commits
andykaylor wrote: The `CIR/Lowering/func-simple.cpp` test is failing after this merge because of my change to introduce the canonicalize pass. I'll update the test as part of my type alias patch. https://github.com/llvm/llvm-project/pull/131945 ___ c

[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)

2025-03-19 Thread Andy Kaylor via cfe-commits
@@ -271,16 +314,61 @@ mlir::Attribute ConstantEmitter::tryEmitPrivate(const APValue &value, cgm.getASTContext().getTargetInfo().useFP16ConversionIntrinsics()) { cgm.errorNYI("ConstExprEmitter::tryEmitPrivate half"); return {}; -} else { - mlir::Typ

[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)

2025-03-19 Thread Andy Kaylor via cfe-commits
@@ -228,6 +257,42 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::FPAttr fltAttr) { loc, converter->convertType(fltAttr.getType()), fltAttr.getValue()); } +// ConstArrayAttr visitor +mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) { + auto llvmTy =

[clang] [CIR] Upstream support for type aliases (PR #131912)

2025-03-19 Thread Andy Kaylor via cfe-commits
@@ -89,6 +89,7 @@ list(APPEND CLANG_TEST_DEPS if(CLANG_ENABLE_CIR) list(APPEND CLANG_TEST_DEPS cir-opt +cir-translate andykaylor wrote: That won't be needed until we upstream one of the tests that uses it. Those are all in the Lowering/ThroughMLIR d

[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)

2025-03-19 Thread Andy Kaylor via cfe-commits
@@ -158,13 +158,56 @@ class ConstExprEmitter // TODO(cir): this can be shared with LLVM's codegen static QualType getNonMemoryType(CIRGenModule &cgm, QualType type) { - if (auto at = type->getAs()) { + if (const auto *at = type->getAs()) { return cgm.getASTContext().get

[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)

2025-03-19 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor edited https://github.com/llvm/llvm-project/pull/131657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)

2025-03-19 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor commented: I have just a few more issues. https://github.com/llvm/llvm-project/pull/131657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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

2025-03-15 Thread Andy Kaylor via cfe-commits
@@ -0,0 +1,392 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -emit-cir %s -o %t.cir +// RUN: FileCheck --input-file=%t.cir %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -Wno-unused-value -emit-llvm %s -o %t-cir.ll +// RUN

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

2025-03-15 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/131369 This adds support for the cir.unary operation. >From d51bb762224f70b2b879198e2466ca0d258f9eae Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Mon, 10 Mar 2025 15:07:50 -0700 Subject: [PATCH] [CIR] Upstream

[clang] [CIR] Upstream support for type aliases (PR #131912)

2025-03-18 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/131912 CIR uses aliases for standard integer types and void. This change adds upstream support for those aliases and updates existing tests. >From 7871276b608f4a9bf5e5a48180b9e10dc564ce8a Mon Sep 17 00:00:00 2001 F

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

2025-03-17 Thread Andy Kaylor via cfe-commits
andykaylor wrote: The git history says the FIXME about "Pure" was added when @cmarcelo introduced `UnaryOp` in the incubator, but there is no PR associated with the commit so I don't know what discussions may have taken place. https://github.com/llvm/llvm-project/pull/131369 __

[clang] [CIR] Follow up for addressing style comment (PR #132093)

2025-03-19 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor approved this pull request. lgtm https://github.com/llvm/llvm-project/pull/132093 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream support for type aliases (PR #131912)

2025-03-19 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/131912 >From a635a7d62251eb1b33218d5ba9fa34ad7a8f5567 Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Tue, 18 Mar 2025 13:48:03 -0700 Subject: [PATCH 1/2] [CIR] Upstream support for type aliases and clean up tests

[clang] [CIR] Fix unary op folding (PR #132269)

2025-03-20 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/132269 Unary ops had previously been omitted from the list of ops handled in the CIRCanonicalizePass. Although the incubator code doesn't use them directly, the mlir folding code does. This change enables folding

[clang] [CIR] Fix unary op folding (PR #132269)

2025-03-20 Thread Andy Kaylor via cfe-commits
andykaylor wrote: @mmha This fixes the problem you noticed earlier. https://github.com/llvm/llvm-project/pull/132269 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream initial for-loop support (PR #132266)

2025-03-20 Thread Andy Kaylor via cfe-commits
@@ -165,6 +165,25 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr *e) { return LValue(); } +mlir::Value CIRGenFunction::evaluateExprAsBool(const Expr *e) { andykaylor wrote: Even for C, we want to generate a cir.bool value. The classic codege

[clang] [CIR] Upstream initial for-loop support (PR #132266)

2025-03-20 Thread Andy Kaylor via cfe-commits
@@ -52,6 +52,15 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { return cir::BoolAttr::get(getContext(), getBoolTy(), state); } + /// Create a for operation. + cir::ForOp createFor( + mlir::Location loc, + llvm::function_ref condBuilder,

[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-21 Thread Andy Kaylor via cfe-commits
andykaylor wrote: CC: @mmha https://github.com/llvm/llvm-project/pull/132468 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -143,6 +147,114 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { return createCast(loc, cir::CastKind::bitcast, src, newTy); } + mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind, andykaylor wrote: ```suggestion mlir::Value createBi

[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-21 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/132468 Alloca operations were being emitted into the entry block of the current function unconditionally, even if the variable they represented was declared in a different scope. This change upstreams the code for ha

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor edited https://github.com/llvm/llvm-project/pull/132420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -93,16 +96,20 @@ struct MissingFeatures { static bool stackSaveOp() { return false; } static bool aggValueSlot() { return false; } static bool generateDebugInfo() { return false; } + static bool getFPFeaturesInEffect() { return false; } andykaylor wro

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -232,6 +231,61 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +LValue CIRGenFunction::emitBinaryOperatorLValue(const BinaryOperator *e) { + // Comma expressions just emit their LHS then their RHS

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -826,6 +826,129 @@ def ForOp : CIR_Op<"for", [LoopOpInterface, NoRegionArguments]> { }]; } +//===--===// +// BinOp +//===--===// + +//

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -93,16 +96,20 @@ struct MissingFeatures { static bool stackSaveOp() { return false; } static bool aggValueSlot() { return false; } static bool generateDebugInfo() { return false; } + static bool getFPFeaturesInEffect() { return false; } + static bool pointerOverflowS

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -558,8 +624,225 @@ class ScalarExprEmitter : public StmtVisitor { return res; } + + BinOpInfo emitBinOps(const BinaryOperator *e, + QualType promotionType = QualType()) { +BinOpInfo result; +result.lhs = cgf.emitPromotedScalarExpr(e->ge

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -570,13 +853,425 @@ mlir::Value CIRGenFunction::emitScalarExpr(const Expr *e) { return ScalarExprEmitter(*this, builder).Visit(const_cast(e)); } -[[maybe_unused]] static bool MustVisitNullValue(const Expr *e) { +mlir::Value CIRGenFunction::emitPromotedScalarExpr(const Ex

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -570,13 +853,425 @@ mlir::Value CIRGenFunction::emitScalarExpr(const Expr *e) { return ScalarExprEmitter(*this, builder).Visit(const_cast(e)); } -[[maybe_unused]] static bool MustVisitNullValue(const Expr *e) { +mlir::Value CIRGenFunction::emitPromotedScalarExpr(const Ex

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -143,6 +147,114 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { return createCast(loc, cir::CastKind::bitcast, src, newTy); } + mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind, + const llvm::APInt &rhs) { +return create(

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -558,8 +624,225 @@ class ScalarExprEmitter : public StmtVisitor { return res; } + + BinOpInfo emitBinOps(const BinaryOperator *e, + QualType promotionType = QualType()) { +BinOpInfo result; +result.lhs = cgf.emitPromotedScalarExpr(e->ge

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -143,6 +147,114 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { return createCast(loc, cir::CastKind::bitcast, src, newTy); } + mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind, + const llvm::APInt &rhs) { +return create(

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
@@ -72,22 +74,126 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { if (const auto arrayVal = mlir::dyn_cast(attr)) { if (mlir::isa(arrayVal.getElts())) return false; - for (const auto elt : mlir::cast(arrayVal.getElts())) { -if (!isNullVa

[clang] [CIR] Add binary operators (PR #132420)

2025-03-21 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor commented: This is an awful lot to digest in one review. Can you split out the BinOpOverflowOp and pointer arithmetic? https://github.com/llvm/llvm-project/pull/132420 ___ cfe-commits mailing list cfe-commits@lists.llvm.o

[clang] [CIR] Upstream initial for-loop support (PR #132266)

2025-03-20 Thread Andy Kaylor via cfe-commits
@@ -280,3 +313,77 @@ mlir::LogicalResult CIRGenFunction::emitReturnStmt(const ReturnStmt &s) { return mlir::success(); } + +mlir::LogicalResult CIRGenFunction::emitForStmt(const ForStmt &s) { + cir::ForOp forOp; + + // TODO: pass in an array of attributes. + auto forStmt

[clang] [Clang][Driver] Override complex number calculation method by -fno-fa… (PR #132680)

2025-03-24 Thread Andy Kaylor via cfe-commits
@@ -2997,6 +2997,7 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, LangOptions::ComplexRangeKind Range = LangOptions::ComplexRangeKind::CX_None; std::string ComplexRangeStr = ""; std::string GccRangeComplexOption = ""; + std::string LastC

[clang] [Clang][Driver] Override complex number calculation method by -fno-fa… (PR #132680)

2025-03-24 Thread Andy Kaylor via cfe-commits
@@ -177,14 +177,45 @@ // RUN: %clang -### -target x86_64 -ffast-math -fcomplex-arithmetic=basic -c %s 2>&1 \ // RUN: | FileCheck --check-prefix=BASIC %s -// BASIC: -complex-range=basic -// FULL: -complex-range=full -// PRMTD: -complex-range=promoted -// BASIC-NOT: -complex-

[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-24 Thread Andy Kaylor via cfe-commits
@@ -0,0 +1,81 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apac

[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-24 Thread Andy Kaylor via cfe-commits
@@ -293,7 +294,8 @@ void CIRGenFunction::startFunction(GlobalDecl gd, QualType returnType, mlir::Value addrVal = emitAlloca(cast(paramVar)->getName(), - convertType(paramVar->getType()), paramLoc, alignment); + convertType(param

[clang] [CIR] Add binary operators (PR #132420)

2025-03-24 Thread Andy Kaylor via cfe-commits
@@ -93,16 +96,20 @@ struct MissingFeatures { static bool stackSaveOp() { return false; } static bool aggValueSlot() { return false; } static bool generateDebugInfo() { return false; } + static bool getFPFeaturesInEffect() { return false; } + static bool pointerOverflowS

[clang] Fix complex long double division with -mno-x87. (PR #133152)

2025-03-31 Thread Andy Kaylor via cfe-commits
@@ -0,0 +1,49 @@ +// RUN %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \ +// RUN -verify -complex-range=promoted -o - | FileCheck %s + +// RUN %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \ +// RUN -verify=nopromotion -complex-range=promoted -target-fe

[clang] [CIR][NFC] Fix warnings in ClangIR code (PR #133134)

2025-03-31 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor closed https://github.com/llvm/llvm-project/pull/133134 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream CmpOp (PR #133159)

2025-03-31 Thread Andy Kaylor via cfe-commits
@@ -514,9 +515,17 @@ mlir::LogicalResult CIRToLLVMCastOpLowering::matchAndRewrite( assert(!MissingFeatures::cxxABI()); assert(!MissingFeatures::dataMemberType()); break; - case cir::CastKind::ptr_to_bool: -assert(!cir::MissingFeatures::opCmp()); + case cir::C

[clang] [clang][NFC] Refactor CodeGen's hasBooleanRepresentation (PR #134159)

2025-04-02 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/134159 The ClangIR upstreaming project needs the same logic for hasBooleanRepresentation() that is currently implemented in the standard clang codegen. In order to share this code, this change moves the implementat

[clang] [CIR] Upstream initial for-loop support (PR #132266)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -280,3 +313,77 @@ mlir::LogicalResult CIRGenFunction::emitReturnStmt(const ReturnStmt &s) { return mlir::success(); } + +mlir::LogicalResult CIRGenFunction::emitForStmt(const ForStmt &s) { + cir::ForOp forOp; + + // TODO: pass in an array of attributes. + auto forStmt

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
andykaylor wrote: @mmha https://github.com/llvm/llvm-project/pull/134333 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Generate the nsw flag correctly for unary ops (PR #133815)

2025-04-04 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor closed https://github.com/llvm/llvm-project/pull/133815 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream support for address of and dereference (PR #134317)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -193,8 +334,23 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { switch (op) { case UO_Deref: { -cgm.errorNYI(e->getSourceRange(), "UnaryOp dereference"); -return LValue(); +QualType t = e->getSubExpr()->getType()->getPointeeType(); +

[clang] [CIR] Upstream support for address of and dereference (PR #134317)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -25,6 +25,147 @@ using namespace clang; using namespace clang::CIRGen; using namespace cir; +/// Given an expression of pointer type, try to +/// derive a more accurate bound on the alignment of the pointer. +Address CIRGenFunction::emitPointerWithAlignment(const Expr *expr

[clang] [CIR] Upstream support for break and continue statements (PR #134181)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -569,6 +569,36 @@ def YieldOp : CIR_Op<"yield", [ReturnLike, Terminator, ]; } +//===--===// +// BreakOp +//===--===// + +def BreakOp : C

[clang] [CIR] Upstream initial for-loop support (PR #132266)

2025-03-20 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/132266 This change adds support for empty for-loops. This will be the infrastructre needed for complete for loops, but that depends on compare operations, which have not been upstreamed yet. >From 20c016291947451b

[clang] [CIR] Emit allocas into the proper lexical scope (PR #132468)

2025-03-25 Thread Andy Kaylor via cfe-commits
@@ -0,0 +1,81 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apac

[clang] [CIR][Upstream] Local initialization for ArrayType (PR #132974)

2025-04-03 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor approved this pull request. This looks ready. https://github.com/llvm/llvm-project/pull/132974 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR][Upstream] Local initialization for ArrayType (PR #132974)

2025-04-03 Thread Andy Kaylor via cfe-commits
@@ -110,6 +110,8 @@ class CIRGenFunction : public CIRGenTypeCache { public: mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt); + void emitNullInitialization(mlir::Location loc, Address destPtr, QualType ty); andykaylor wrote: The two em

[clang] [CIR] Upstream support for logical not operations (PR #133966)

2025-04-03 Thread Andy Kaylor via cfe-commits
@@ -1358,6 +1360,33 @@ mlir::Value CIRGenFunction::emitScalarConversion(mlir::Value src, .emitScalarConversion(src, srcTy, dstTy, loc); } +mlir::Value ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *e) { + // Perform vector logical not on comparison with zero ve

[clang] [CIR] Upstream support for address of and dereference (PR #134317)

2025-04-03 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/134317 This adds support for handling the address of and dereference unary operations in ClangIR code generation. This also adds handling for nullptr and proper initialization via the NullToPointer cast. >From d13

[clang] [CIR] Upstream support for address of and dereference (PR #134317)

2025-04-03 Thread Andy Kaylor via cfe-commits
andykaylor wrote: @mmha https://github.com/llvm/llvm-project/pull/134317 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [CIR] Upstream support for logical not operations (PR #133966)

2025-04-03 Thread Andy Kaylor via cfe-commits
@@ -1320,7 +1322,7 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) { "fixed point casts"); return {}; } -cgf.getCIRGenModule().errorNYI(subExpr->getSourceRange(), "fp options"); +assert(!cir::MissingFeatures:

[clang] [CIR] Upstream support for logical not operations (PR #133966)

2025-04-03 Thread Andy Kaylor via cfe-commits
@@ -1358,6 +1360,33 @@ mlir::Value CIRGenFunction::emitScalarConversion(mlir::Value src, .emitScalarConversion(src, srcTy, dstTy, loc); } +mlir::Value ScalarExprEmitter::VisitUnaryLNot(const UnaryOperator *e) { + // Perform vector logical not on comparison with zero ve

[clang] [CIR] Upstream support for break and continue statements (PR #134181)

2025-04-03 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/134181 >From 54454e4d52570f29c493c41fc9bf95cbaf9e0886 Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Fri, 21 Mar 2025 09:46:27 -0700 Subject: [PATCH 1/3] [CIR] Upstream support for break and continue statements T

[clang] [CIR] Upstream support for address of and dereference (PR #134317)

2025-04-03 Thread Andy Kaylor via cfe-commits
andykaylor wrote: I'm starting to be uncomfortable with the amount of alignment and LValueBaseInfo support we've skipped over. I tried to add markers in this PR where I wasn't adding support for those. I intend to fill in that support in a separate PR soon. https://github.com/llvm/llvm-projec

[clang] [CIR] Upstream support for break and continue statements (PR #134181)

2025-04-03 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/134181 >From 54454e4d52570f29c493c41fc9bf95cbaf9e0886 Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Fri, 21 Mar 2025 09:46:27 -0700 Subject: [PATCH 1/2] [CIR] Upstream support for break and continue statements T

[clang] [CIR] Upstream global initialization for ArrayType (PR #131657)

2025-03-26 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor approved this pull request. Looks good. Thanks for the updates! https://github.com/llvm/llvm-project/pull/131657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-c

[clang] [CIR] Upstream CmpOp (PR #133159)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -710,6 +710,89 @@ class ScalarExprEmitter : public StmtVisitor { HANDLEBINOP(Xor) HANDLEBINOP(Or) #undef HANDLEBINOP + + mlir::Value emitCmp(const BinaryOperator *e) { +mlir::Value result; +QualType lhsTy = e->getLHS()->getType(); +QualType rhsTy = e->getRH

[clang] [CIR] Add binary operators (PR #132420)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -143,6 +147,114 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { return createCast(loc, cir::CastKind::bitcast, src, newTy); } + mlir::Value createBinop(mlir::Value lhs, cir::BinOpKind kind, + const llvm::APInt &rhs) { +return create(

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -462,6 +462,58 @@ def ReturnOp : CIR_Op<"return", [ParentOneOf<["FuncOp", "ScopeOp", "DoWhileOp", let hasVerifier = 1; } +//===--===// +// IfOp +//===-

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -316,6 +316,106 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) { emitLValue(e); } +/// Emit an `if` on a boolean condition, filling `then` and `else` into +/// appropriated regions. +mlir::LogicalResult CIRGenFunction::emitIfOnBoolExpr(const Expr *cond, +

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -316,6 +316,106 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) { emitLValue(e); } +/// Emit an `if` on a boolean condition, filling `then` and `else` into +/// appropriated regions. +mlir::LogicalResult CIRGenFunction::emitIfOnBoolExpr(const Expr *cond, +

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -316,6 +316,106 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) { emitLValue(e); } +/// Emit an `if` on a boolean condition, filling `then` and `else` into +/// appropriated regions. +mlir::LogicalResult CIRGenFunction::emitIfOnBoolExpr(const Expr *cond, +

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -316,6 +316,106 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) { emitLValue(e); } +/// Emit an `if` on a boolean condition, filling `then` and `else` into +/// appropriated regions. +mlir::LogicalResult CIRGenFunction::emitIfOnBoolExpr(const Expr *cond, +

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -316,6 +316,106 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) { emitLValue(e); } +/// Emit an `if` on a boolean condition, filling `then` and `else` into +/// appropriated regions. +mlir::LogicalResult CIRGenFunction::emitIfOnBoolExpr(const Expr *cond, +

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -164,6 +165,20 @@ class CIRGenFunction : public CIRGenTypeCache { /// that it requires no code to be generated. bool isTrivialInitializer(const Expr *init); + /// If the specified expression does not fold to a constant, or if it does but + /// contains a label, retur

[clang] [CIR] Add if statement support (PR #134333)

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -316,6 +316,106 @@ void CIRGenFunction::emitIgnoredExpr(const Expr *e) { emitLValue(e); } +/// Emit an `if` on a boolean condition, filling `then` and `else` into +/// appropriated regions. +mlir::LogicalResult CIRGenFunction::emitIfOnBoolExpr(const Expr *cond, +

<    1   2   3   4   5   6   7   >