[clang] [CIR] Remove failing binop test (PR #133001)

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

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

2025-04-04 Thread Andy Kaylor via cfe-commits
andykaylor wrote: > @Andres-Salamanca thanks for working on this. We usually write tests that > exercise any possible different paths codegen can take. For next rounds: it's > fine if you add less things in one go and make it more incremental with the > use of (a) errorNYI and (b) assert on mi

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

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -263,6 +264,72 @@ static void terminateBody(CIRGenBuilderTy &builder, mlir::Region &r, b->erase(); } +mlir::LogicalResult CIRGenFunction::emitIfStmt(const IfStmt &s) { + mlir::LogicalResult res = mlir::success(); + // The else branch of a consteval if statement is al

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

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -442,6 +457,25 @@ class CIRGenFunction : public CIRGenTypeCache { mlir::LogicalResult emitDeclStmt(const clang::DeclStmt &s); LValue emitDeclRefLValue(const clang::DeclRefExpr *e); + /// Emit an if on a boolean condition to the specified blocks. + /// FIXME: Based on

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

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -54,6 +56,67 @@ struct CIRFlattenCFGPass : public CIRFlattenCFGBase { void runOnOperation() override; }; +struct CIRIfFlattening : public mlir::OpRewritePattern { + using OpRewritePattern::OpRewritePattern; + + mlir::LogicalResult + matchAndRewrite(cir::IfOp ifOp, +

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

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -447,6 +448,133 @@ mlir::LogicalResult cir::ReturnOp::verify() { return success(); } +//===--===// +// IfOp +//===--===// + +ParseResult

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

2025-04-04 Thread Andy Kaylor via cfe-commits
@@ -447,6 +448,133 @@ mlir::LogicalResult cir::ReturnOp::verify() { return success(); } +//===--===// +// IfOp +//===--===// + +ParseResult

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

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

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

2025-04-05 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/132269 >From bee4e73e125c5643eb321ffef7b2b8e25f881267 Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Thu, 20 Mar 2025 11:23:02 -0700 Subject: [PATCH 1/2] [CIR] Fix unary op folding Unary ops had previously been o

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

2025-04-05 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor edited 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 initial for-loop support (PR #132266)

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

[clang] [CIR] Upstream zero init for global variables (PR #133100)

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

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

2025-04-05 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/134181 This adds ClangIR support for break and continue statements in loops. Because only loops are currently implemented upstream in CIR, only breaks in loops are supported here, but this same code will work (with

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

2025-04-05 Thread Andy Kaylor via cfe-commits
@@ -45,6 +45,41 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { return false; } + // Return true if this is the null value andykaylor wrote: This isn't quite the comment I wanted to see. It doesn't tell me any more than the function name did

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

2025-04-05 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: I'm not sure `Bool` is ever used to represent an `i8`. Typically the

[clang] [CIR] Implement lowering of int-to-bool casts (PR #132996)

2025-04-05 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor created https://github.com/llvm/llvm-project/pull/132996 Lowering of int-to-bool casts had been left as NYI because the incubator implemented it by lowering to cir.cmp, which hasn't been upstreamed yet, but there is no reason this cast can't be lowered directly to

[clang] [CIR] Upstream support for promoted types with unary plus/minus (PR #133829)

2025-04-05 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor updated https://github.com/llvm/llvm-project/pull/133829 >From 92d711c92b89e08d47d7f617a222d982040a4f19 Mon Sep 17 00:00:00 2001 From: Andy Kaylor Date: Mon, 31 Mar 2025 17:02:08 -0700 Subject: [PATCH] [CIR] Upstream support for promoted types with unary plus/minu

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

2025-04-05 Thread Andy Kaylor via cfe-commits
@@ -265,3 +265,125 @@ void test_empty_while_true() { // OGCG: br label %[[WHILE_BODY:.*]] // OGCG: [[WHILE_BODY]]: // OGCG: ret void + +void unreachable_after_continue() { + for (;;) { +continue; +int x = 1; + } +} + +// CIR: cir.func @unreachable_after_continue +

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

2025-04-05 Thread Andy Kaylor via cfe-commits
@@ -103,6 +113,36 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { getContext(), mlir::cast(type), valueAttr); } + mlir::TypedAttr getConstNullPtrAttr(mlir::Type t) { +assert(mlir::isa(t) && "expected cir.ptr"); +return getConstPtrAttr(t, 0); + } + + m

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

2025-04-05 Thread Andy Kaylor via cfe-commits
@@ -127,6 +136,8 @@ struct MissingFeatures { static bool ternaryOp() { return false; } static bool tryOp() { return false; } static bool zextOp() { return false; } + static bool opPtrStride() { return false; } + static bool opPtrDiff() { return false; }

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

2025-04-05 Thread Andy Kaylor via cfe-commits
@@ -994,6 +992,127 @@ mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite( << elementType; } +mlir::LLVM::IntegerOverflowFlags +CIRToLLVMBinOpLowering::getIntOverflowFlag(cir::BinOp op) const { + if (op.getNoUnsignedWrap()) +return mlir:

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

2025-04-04 Thread Andy Kaylor via cfe-commits
https://github.com/andykaylor closed https://github.com/llvm/llvm-project/pull/134181 ___ 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
@@ -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] Add if statement support (PR #134333)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -135,6 +135,55 @@ mlir::Location CIRGenFunction::getLoc(mlir::Location lhs, mlir::Location rhs) { return mlir::FusedLoc::get(locs, metadata, &getMLIRContext()); } +bool CIRGenFunction::ContainsLabel(const Stmt *s, bool ignoreCaseStmts) { + // Null statement, not a label

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +/// If the specified expr is a simple decay from an array to pointer, +/// return the array subexpression. +/// FIXME: this could be

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +/// If the specified expr is a simple decay from an array to pointer, +/// return the array subexpression. +/// FIXME: this could be

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +/// If the specified expr is a simple decay from an array to pointer, +/// return the array subexpression. +/// FIXME: this could be

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -198,6 +198,19 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { return create(loc, cir::BinOpKind::Div, lhs, rhs); } + + /// Create a cir.ptr_stride operation to get access to an array element. + /// idx is the index of the element to access, shouldDecay is

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -157,6 +157,15 @@ class ScalarExprEmitter : public StmtVisitor { mlir::Value VisitCastExpr(CastExpr *e); + mlir::Value VisitArraySubscriptExpr(ArraySubscriptExpr *e) { +if (e->getBase()->getType()->isVectorType()) { + assert(!cir::MissingFeatures::scalableVect

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +/// If the specified expr is a simple decay from an array to pointer, +/// return the array subexpression. +/// FIXME: this could be

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -29,8 +29,15 @@ int f[5] = {1, 2}; void func() { int arr[10]; - // CHECK: %[[ARR:.*]] = cir.alloca !cir.array, !cir.ptr>, ["arr"] + + int e = arr[1]; andykaylor wrote: Can you add a test case for `arr[0]`? That's a special case in terms of resultin

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +/// If the specified expr is a simple decay from an array to pointer, +/// return the array subexpression. +/// FIXME: this could be

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +/// If the specified expr is a simple decay from an array to pointer, +/// return the array subexpression. +/// FIXME: this could be

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -232,6 +233,161 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) { llvm_unreachable("Unknown unary operator kind!"); } +/// If the specified expr is a simple decay from an array to pointer, +/// return the array subexpression. +/// FIXME: this could be

[clang] [CIR] Upstream ArraySubscriptExpr for fixed size array (PR #134536)

2025-04-07 Thread Andy Kaylor via cfe-commits
@@ -198,6 +198,19 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy { return create(loc, cir::BinOpKind::Div, lhs, rhs); } + + /// Create a cir.ptr_stride operation to get access to an array element. + /// idx is the index of the element to access, shouldDecay is

<    2   3   4   5   6   7