From db12ece6cacc2a84ba3e82e7e254e16a68f5042e Mon Sep 17 00:00:00 2001 From: gitoleg Date: Mon, 11 Nov 2024 17:52:34 +0300 Subject: [PATCH 1/5] [CIR][ABI][AArch64] convers one more case for struct passing + refactoring --- .../CIR/Dialect/Builder/CIRBaseBuilder.h | 1 + .../TargetLowering/LowerFunction.cpp | 126 ++++++++++++------ .../AArch64/aarch64-cc-structs.c | 24 +++- 3 files changed, 103 insertions(+), 48 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h index c8b9a0a03cbf..c5bd9e3d20c2 100644 --- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h +++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h @@ -544,6 +544,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { // Block handling helpers // ---------------------- // + static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block) { auto last = std::find_if(block->rbegin(), block->rend(), [](mlir::Operation &op) { diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp index d2a7e83e7020..fd9c252a8706 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp @@ -19,6 +19,7 @@ #include "mlir/IR/PatternMatch.h" #include "mlir/Support/LogicalResult.h" #include "clang/CIR/ABIArgInfo.h" +#include "clang/CIR/Dialect/Builder/CIRBaseBuilder.h" #include "clang/CIR/Dialect/IR/CIRAttrs.h" #include "clang/CIR/Dialect/IR/CIRDialect.h" #include "clang/CIR/Dialect/IR/CIRTypes.h" @@ -140,6 +141,79 @@ static mlir::Value coerceIntOrPtrToIntOrPtr(mlir::Value val, mlir::Type typ, return val; } +// FIXME(cir): Create a custom rewriter class to abstract this away. +mlir::Value createBitcast(mlir::Value Src, mlir::Type Ty, LowerFunction &LF) { + return LF.getRewriter().create(Src.getLoc(), Ty, CastKind::bitcast, + Src); +} + +ConstantOp createUInt64(LowerFunction& LF, mlir::Location loc, uint64_t val) { + auto& rw = LF.getRewriter(); + auto* ctxt = rw.getContext(); + auto i64Ty = IntType::get(ctxt, 64, false); + return rw.create(loc, IntAttr::get(i64Ty, val)); +} + +bool isVoidPtr(mlir::Value v) { + if (auto p = mlir::dyn_cast(v.getType())) + return mlir::isa(p.getPointee()); + return false; +} + +AllocaOp createTmpAlloca(LowerFunction& LF, mlir::Location loc, mlir::Type ty) { + auto& rw = LF.getRewriter(); + auto* ctxt = rw.getContext(); + mlir::PatternRewriter::InsertionGuard guard(rw); + + // find function's entry block and use it to find a best place for alloca + auto* blk = rw.getBlock(); + auto* op = blk->getParentOp(); + FuncOp fun = mlir::dyn_cast(op); + if (!fun) + fun = op->getParentOfType(); + auto& entry = fun.getBody().front(); + + auto ip = CIRBaseBuilderTy::getBestAllocaInsertPoint(&entry); + rw.restoreInsertionPoint(ip); + + auto align = LF.LM.getDataLayout().getABITypeAlign(ty); + auto alignAttr = rw.getI64IntegerAttr(align.value()); + auto ptrTy = PointerType::get(ctxt, ty); + return rw.create(loc, ptrTy, ty, "tmp", alignAttr); +} + +MemCpyOp createMemCpy(LowerFunction &LF, mlir::Value src, mlir::Value dst, mlir::Value len) { + assert(mlir::isa(src.getType())); + assert(mlir::isa(dst.getType())); + + auto* ctxt = LF.getRewriter().getContext(); + auto voidPtr = PointerType::get(ctxt, cir::VoidType::get(ctxt)); + + if (!isVoidPtr(src)) + src = createBitcast(src, voidPtr, LF); + if (!isVoidPtr(dst)) + dst = createBitcast(dst, voidPtr, LF); + + return LF.getRewriter().create(src.getLoc(), dst, src, len); +} + +cir::AllocaOp findAlloca(mlir::Operation *op) { + if (!op) + return {}; + + if (auto al = mlir::dyn_cast(op)) { + return al; + } else if (auto ret = mlir::dyn_cast(op)) { + auto vals = ret.getInput(); + if (vals.size() == 1) + return findAlloca(vals[0].getDefiningOp()); + } else if (auto load = mlir::dyn_cast(op)) { + return findAlloca(load.getAddr().getDefiningOp()); + } + + return {}; +} + /// Create a store to \param Dst from \param Src where the source and /// destination may have different types. /// @@ -187,16 +261,13 @@ void createCoercedStore(mlir::Value Src, mlir::Value Dst, bool DstIsVolatile, auto addr = bld.create(Dst.getLoc(), ptrTy, CastKind::bitcast, Dst); bld.create(Dst.getLoc(), Src, addr); } else { - cir_cconv_unreachable("NYI"); + auto tmp = createTmpAlloca(CGF, Src.getLoc(), SrcTy); + CGF.getRewriter().create(Src.getLoc(), Src, tmp); + auto len = createUInt64(CGF, Src.getLoc(), DstSize.getFixedValue()); + createMemCpy(CGF, tmp, Dst, len); } } -// FIXME(cir): Create a custom rewriter class to abstract this away. -mlir::Value createBitcast(mlir::Value Src, mlir::Type Ty, LowerFunction &LF) { - return LF.getRewriter().create(Src.getLoc(), Ty, CastKind::bitcast, - Src); -} - /// Coerces a \param Src value to a value of type \param Ty. /// /// This safely handles the case when the src type is smaller than the @@ -223,7 +294,7 @@ mlir::Value createCoercedValue(mlir::Value Src, mlir::Type Ty, llvm::TypeSize DstSize = CGF.LM.getDataLayout().getTypeAllocSize(Ty); - if (auto SrcSTy = mlir::dyn_cast(SrcTy)) { + if (auto SrcSTy = mlir::dyn_cast(SrcTy)) { Src = enterStructPointerForCoercedAccess(Src, SrcSTy, DstSize.getFixedValue(), CGF); SrcTy = Src.getType(); @@ -261,23 +332,6 @@ mlir::Value emitAddressAtOffset(LowerFunction &LF, mlir::Value addr, return addr; } -cir::AllocaOp findAlloca(mlir::Operation *op) { - if (!op) - return {}; - - if (auto al = mlir::dyn_cast(op)) { - return al; - } else if (auto ret = mlir::dyn_cast(op)) { - auto vals = ret.getInput(); - if (vals.size() == 1) - return findAlloca(vals[0].getDefiningOp()); - } else if (auto load = mlir::dyn_cast(op)) { - return findAlloca(load.getAddr().getDefiningOp()); - } - - return {}; -} - /// After the calling convention is lowered, an ABI-agnostic type might have to /// be loaded back to its ABI-aware couterpart so it may be returned. If they /// differ, we have to do a coerced load. A coerced load, which means to load a @@ -329,25 +383,9 @@ mlir::Value castReturnValue(mlir::Value Src, mlir::Type Ty, LowerFunction &LF) { // Otherwise do coercion through memory. if (auto addr = findAlloca(Src.getDefiningOp())) { auto &rewriter = LF.getRewriter(); - auto *ctxt = LF.LM.getMLIRContext(); - auto ptrTy = PointerType::get(ctxt, Ty); - auto voidPtr = PointerType::get(ctxt, cir::VoidType::get(ctxt)); - - // insert alloca near the previuos one - auto point = rewriter.saveInsertionPoint(); - rewriter.setInsertionPointAfter(addr); - auto align = LF.LM.getDataLayout().getABITypeAlign(Ty); - auto alignAttr = rewriter.getI64IntegerAttr(align.value()); - auto tmp = - rewriter.create(Src.getLoc(), ptrTy, Ty, "tmp", alignAttr); - rewriter.restoreInsertionPoint(point); - - auto srcVoidPtr = createBitcast(addr, voidPtr, LF); - auto dstVoidPtr = createBitcast(tmp, voidPtr, LF); - auto i64Ty = IntType::get(ctxt, 64, false); - auto len = rewriter.create( - Src.getLoc(), IntAttr::get(i64Ty, SrcSize.getFixedValue())); - rewriter.create(Src.getLoc(), dstVoidPtr, srcVoidPtr, len); + auto tmp = createTmpAlloca(LF, Src.getLoc(), Ty); + auto len = createUInt64(LF, Src.getLoc(), SrcSize.getFixedValue()); + createMemCpy(LF, addr, tmp, len); return rewriter.create(Src.getLoc(), tmp.getResult()); } diff --git a/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c b/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c index eb1899840713..50e619531ad9 100644 --- a/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c +++ b/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c @@ -83,10 +83,10 @@ typedef struct { // CHECK: cir.func {{.*@retS}}() -> !cir.array // CHECK: %[[#V0:]] = cir.alloca !ty_S, !cir.ptr, ["__retval"] {alignment = 4 : i64} // CHECK: %[[#V1:]] = cir.alloca !cir.array, !cir.ptr>, ["tmp"] {alignment = 8 : i64} -// CHECK: %[[#V2:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr -// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr -// CHECK: %[[#V4:]] = cir.const #cir.int<12> : !u64i -// CHECK: cir.libc.memcpy %[[#V4]] bytes from %[[#V2]] to %[[#V3]] : !u64i, !cir.ptr -> !cir.ptr +// CHECK: %[[#V3:]] = cir.const #cir.int<12> : !u64i +// CHECK: %[[#V4:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr +// CHECK: %[[#V5:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr +// CHECK: cir.libc.memcpy %[[#V3]] bytes from %[[#V4]] to %[[#V5]] : !u64i, !cir.ptr -> !cir.ptr // CHECK: %[[#V5:]] = cir.load %[[#V1]] : !cir.ptr>, !cir.array // CHECK: cir.return %[[#V5]] : !cir.array @@ -152,3 +152,19 @@ void pass_eq_128(EQ_128 s) {} // LLVM: store ptr %0, ptr %[[#V1]], align 8 // LLVM: %[[#V2:]] = load ptr, ptr %[[#V1]], align 8 void pass_gt_128(GT_128 s) {} + +// CHECK: cir.func @passS(%arg0: !cir.array +// CHECK: %[[#V0:]] = cir.alloca !ty_S, !cir.ptr, [""] {alignment = 4 : i64} +// CHECK: %[[#V1:]] = cir.alloca !cir.array, !cir.ptr>, ["tmp"] {alignment = 8 : i64} +// CHECK: cir.store %arg0, %[[#V1]] : !cir.array, !cir.ptr> +// CHECK: %[[#V2:]] = cir.const #cir.int<12> : !u64i +// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr +// CHECK: %[[#V4:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr +// CHECK: cir.libc.memcpy %[[#V2]] bytes from %[[#V3]] to %[[#V4]] : !u64i, !cir.ptr -> !cir.ptr + +// LLVM: void @passS([2 x i64] %[[#ARG:]]) +// LLVM: %[[#V1:]] = alloca %struct.S, i64 1, align 4 +// LLVM: %[[#V2:]] = alloca [2 x i64], i64 1, align 8 +// LLVM: store [2 x i64] %[[#ARG]], ptr %[[#V2]], align 8 +// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr %[[#V1]], ptr %[[#V2]], i64 12, i1 false) +void passS(S s) {} \ No newline at end of file From 14e6bdef040cf8f135a97b5fee4c5fd2eec94bb5 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Tue, 12 Nov 2024 13:57:52 +0300 Subject: [PATCH 2/5] clang-format ... --- .../CIR/Dialect/Builder/CIRBaseBuilder.h | 3 +- .../TargetLowering/LowerFunction.cpp | 37 ++++++++++--------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h index c5bd9e3d20c2..a4753d3e79d6 100644 --- a/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h +++ b/clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h @@ -544,8 +544,7 @@ class CIRBaseBuilderTy : public mlir::OpBuilder { // Block handling helpers // ---------------------- // - static - OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block) { + static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block) { auto last = std::find_if(block->rbegin(), block->rend(), [](mlir::Operation &op) { return mlir::isa(&op); diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp index fd9c252a8706..1ea04eb276c2 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp @@ -147,9 +147,9 @@ mlir::Value createBitcast(mlir::Value Src, mlir::Type Ty, LowerFunction &LF) { Src); } -ConstantOp createUInt64(LowerFunction& LF, mlir::Location loc, uint64_t val) { - auto& rw = LF.getRewriter(); - auto* ctxt = rw.getContext(); +ConstantOp createUInt64(LowerFunction &LF, mlir::Location loc, uint64_t val) { + auto &rw = LF.getRewriter(); + auto *ctxt = rw.getContext(); auto i64Ty = IntType::get(ctxt, 64, false); return rw.create(loc, IntAttr::get(i64Ty, val)); } @@ -160,19 +160,19 @@ bool isVoidPtr(mlir::Value v) { return false; } -AllocaOp createTmpAlloca(LowerFunction& LF, mlir::Location loc, mlir::Type ty) { - auto& rw = LF.getRewriter(); - auto* ctxt = rw.getContext(); +AllocaOp createTmpAlloca(LowerFunction &LF, mlir::Location loc, mlir::Type ty) { + auto &rw = LF.getRewriter(); + auto *ctxt = rw.getContext(); mlir::PatternRewriter::InsertionGuard guard(rw); // find function's entry block and use it to find a best place for alloca - auto* blk = rw.getBlock(); - auto* op = blk->getParentOp(); + auto *blk = rw.getBlock(); + auto *op = blk->getParentOp(); FuncOp fun = mlir::dyn_cast(op); if (!fun) fun = op->getParentOfType(); - auto& entry = fun.getBody().front(); - + auto &entry = fun.getBody().front(); + auto ip = CIRBaseBuilderTy::getBestAllocaInsertPoint(&entry); rw.restoreInsertionPoint(ip); @@ -182,19 +182,20 @@ AllocaOp createTmpAlloca(LowerFunction& LF, mlir::Location loc, mlir::Type ty) { return rw.create(loc, ptrTy, ty, "tmp", alignAttr); } -MemCpyOp createMemCpy(LowerFunction &LF, mlir::Value src, mlir::Value dst, mlir::Value len) { +MemCpyOp createMemCpy(LowerFunction &LF, mlir::Value src, mlir::Value dst, + mlir::Value len) { assert(mlir::isa(src.getType())); - assert(mlir::isa(dst.getType())); - - auto* ctxt = LF.getRewriter().getContext(); + assert(mlir::isa(dst.getType())); + + auto *ctxt = LF.getRewriter().getContext(); auto voidPtr = PointerType::get(ctxt, cir::VoidType::get(ctxt)); - + if (!isVoidPtr(src)) src = createBitcast(src, voidPtr, LF); if (!isVoidPtr(dst)) dst = createBitcast(dst, voidPtr, LF); - - return LF.getRewriter().create(src.getLoc(), dst, src, len); + + return LF.getRewriter().create(src.getLoc(), dst, src, len); } cir::AllocaOp findAlloca(mlir::Operation *op) { @@ -294,7 +295,7 @@ mlir::Value createCoercedValue(mlir::Value Src, mlir::Type Ty, llvm::TypeSize DstSize = CGF.LM.getDataLayout().getTypeAllocSize(Ty); - if (auto SrcSTy = mlir::dyn_cast(SrcTy)) { + if (auto SrcSTy = mlir::dyn_cast(SrcTy)) { Src = enterStructPointerForCoercedAccess(Src, SrcSTy, DstSize.getFixedValue(), CGF); SrcTy = Src.getType(); From e1fcac97598a7c40771071dc33295842e4f8b966 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Wed, 13 Nov 2024 11:38:49 +0300 Subject: [PATCH 3/5] refactoring --- .../TargetLowering/LowerFunction.cpp | 34 ++++++++----------- .../AArch64/aarch64-cc-structs.c | 16 ++++----- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp index 1ea04eb276c2..e8644008f566 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp @@ -147,19 +147,6 @@ mlir::Value createBitcast(mlir::Value Src, mlir::Type Ty, LowerFunction &LF) { Src); } -ConstantOp createUInt64(LowerFunction &LF, mlir::Location loc, uint64_t val) { - auto &rw = LF.getRewriter(); - auto *ctxt = rw.getContext(); - auto i64Ty = IntType::get(ctxt, 64, false); - return rw.create(loc, IntAttr::get(i64Ty, val)); -} - -bool isVoidPtr(mlir::Value v) { - if (auto p = mlir::dyn_cast(v.getType())) - return mlir::isa(p.getPointee()); - return false; -} - AllocaOp createTmpAlloca(LowerFunction &LF, mlir::Location loc, mlir::Type ty) { auto &rw = LF.getRewriter(); auto *ctxt = rw.getContext(); @@ -182,12 +169,19 @@ AllocaOp createTmpAlloca(LowerFunction &LF, mlir::Location loc, mlir::Type ty) { return rw.create(loc, ptrTy, ty, "tmp", alignAttr); } -MemCpyOp createMemCpy(LowerFunction &LF, mlir::Value src, mlir::Value dst, - mlir::Value len) { +bool isVoidPtr(mlir::Value v) { + if (auto p = mlir::dyn_cast(v.getType())) + return mlir::isa(p.getPointee()); + return false; +} + +MemCpyOp createMemCpy(LowerFunction &LF, mlir::Value dst, mlir::Value src, + uint64_t len) { assert(mlir::isa(src.getType())); assert(mlir::isa(dst.getType())); auto *ctxt = LF.getRewriter().getContext(); + auto &rw = LF.getRewriter(); auto voidPtr = PointerType::get(ctxt, cir::VoidType::get(ctxt)); if (!isVoidPtr(src)) @@ -195,7 +189,9 @@ MemCpyOp createMemCpy(LowerFunction &LF, mlir::Value src, mlir::Value dst, if (!isVoidPtr(dst)) dst = createBitcast(dst, voidPtr, LF); - return LF.getRewriter().create(src.getLoc(), dst, src, len); + auto i64Ty = IntType::get(ctxt, 64, false); + auto length = rw.create(src.getLoc(), IntAttr::get(i64Ty, len)); + return rw.create(src.getLoc(), dst, src, length); } cir::AllocaOp findAlloca(mlir::Operation *op) { @@ -264,8 +260,7 @@ void createCoercedStore(mlir::Value Src, mlir::Value Dst, bool DstIsVolatile, } else { auto tmp = createTmpAlloca(CGF, Src.getLoc(), SrcTy); CGF.getRewriter().create(Src.getLoc(), Src, tmp); - auto len = createUInt64(CGF, Src.getLoc(), DstSize.getFixedValue()); - createMemCpy(CGF, tmp, Dst, len); + createMemCpy(CGF, Dst, tmp, DstSize.getFixedValue()); } } @@ -385,8 +380,7 @@ mlir::Value castReturnValue(mlir::Value Src, mlir::Type Ty, LowerFunction &LF) { if (auto addr = findAlloca(Src.getDefiningOp())) { auto &rewriter = LF.getRewriter(); auto tmp = createTmpAlloca(LF, Src.getLoc(), Ty); - auto len = createUInt64(LF, Src.getLoc(), SrcSize.getFixedValue()); - createMemCpy(LF, addr, tmp, len); + createMemCpy(LF, tmp, addr, SrcSize.getFixedValue()); return rewriter.create(Src.getLoc(), tmp.getResult()); } diff --git a/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c b/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c index 50e619531ad9..d9f13be0be66 100644 --- a/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c +++ b/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c @@ -83,10 +83,10 @@ typedef struct { // CHECK: cir.func {{.*@retS}}() -> !cir.array // CHECK: %[[#V0:]] = cir.alloca !ty_S, !cir.ptr, ["__retval"] {alignment = 4 : i64} // CHECK: %[[#V1:]] = cir.alloca !cir.array, !cir.ptr>, ["tmp"] {alignment = 8 : i64} -// CHECK: %[[#V3:]] = cir.const #cir.int<12> : !u64i -// CHECK: %[[#V4:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr -// CHECK: %[[#V5:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr -// CHECK: cir.libc.memcpy %[[#V3]] bytes from %[[#V4]] to %[[#V5]] : !u64i, !cir.ptr -> !cir.ptr +// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr +// CHECK: %[[#V4:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr +// CHECK: %[[#V5:]] = cir.const #cir.int<12> : !u64i +// CHECK: cir.libc.memcpy %[[#V5]] bytes from %[[#V3]] to %[[#V4]] : !u64i, !cir.ptr -> !cir.ptr // CHECK: %[[#V5:]] = cir.load %[[#V1]] : !cir.ptr>, !cir.array // CHECK: cir.return %[[#V5]] : !cir.array @@ -157,10 +157,10 @@ void pass_gt_128(GT_128 s) {} // CHECK: %[[#V0:]] = cir.alloca !ty_S, !cir.ptr, [""] {alignment = 4 : i64} // CHECK: %[[#V1:]] = cir.alloca !cir.array, !cir.ptr>, ["tmp"] {alignment = 8 : i64} // CHECK: cir.store %arg0, %[[#V1]] : !cir.array, !cir.ptr> -// CHECK: %[[#V2:]] = cir.const #cir.int<12> : !u64i -// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr -// CHECK: %[[#V4:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr -// CHECK: cir.libc.memcpy %[[#V2]] bytes from %[[#V3]] to %[[#V4]] : !u64i, !cir.ptr -> !cir.ptr +// CHECK: %[[#V2:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr +// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr +// CHECK: %[[#V4:]] = cir.const #cir.int<12> : !u64i +// CHECK: cir.libc.memcpy %[[#V4]] bytes from %[[#V2]] to %[[#V3]] : !u64i, !cir.ptr -> !cir.ptr // LLVM: void @passS([2 x i64] %[[#ARG:]]) // LLVM: %[[#V1:]] = alloca %struct.S, i64 1, align 4 From 783b710db1520f1ada2c9550134d1babda110548 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Wed, 13 Nov 2024 15:47:59 +0300 Subject: [PATCH 4/5] minor --- .../CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp index e8644008f566..cf2fdda5b483 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp @@ -177,8 +177,8 @@ bool isVoidPtr(mlir::Value v) { MemCpyOp createMemCpy(LowerFunction &LF, mlir::Value dst, mlir::Value src, uint64_t len) { - assert(mlir::isa(src.getType())); - assert(mlir::isa(dst.getType())); + cir_cconv_assert(mlir::isa(src.getType())); + cir_cconv_assert(mlir::isa(dst.getType())); auto *ctxt = LF.getRewriter().getContext(); auto &rw = LF.getRewriter(); From febf399c010d686188da7b25ddde3e7463178427 Mon Sep 17 00:00:00 2001 From: gitoleg Date: Wed, 13 Nov 2024 15:51:28 +0300 Subject: [PATCH 5/5] minor fix in tests --- .../CIR/CallConvLowering/AArch64/aarch64-cc-structs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c b/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c index d9f13be0be66..1acc75da262f 100644 --- a/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c +++ b/clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c @@ -83,10 +83,10 @@ typedef struct { // CHECK: cir.func {{.*@retS}}() -> !cir.array // CHECK: %[[#V0:]] = cir.alloca !ty_S, !cir.ptr, ["__retval"] {alignment = 4 : i64} // CHECK: %[[#V1:]] = cir.alloca !cir.array, !cir.ptr>, ["tmp"] {alignment = 8 : i64} -// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr -// CHECK: %[[#V4:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr -// CHECK: %[[#V5:]] = cir.const #cir.int<12> : !u64i -// CHECK: cir.libc.memcpy %[[#V5]] bytes from %[[#V3]] to %[[#V4]] : !u64i, !cir.ptr -> !cir.ptr +// CHECK: %[[#V2:]] = cir.cast(bitcast, %[[#V0]] : !cir.ptr), !cir.ptr +// CHECK: %[[#V3:]] = cir.cast(bitcast, %[[#V1]] : !cir.ptr>), !cir.ptr +// CHECK: %[[#V4:]] = cir.const #cir.int<12> : !u64i +// CHECK: cir.libc.memcpy %[[#V4]] bytes from %[[#V2]] to %[[#V3]] : !u64i, !cir.ptr -> !cir.ptr // CHECK: %[[#V5:]] = cir.load %[[#V1]] : !cir.ptr>, !cir.array // CHECK: cir.return %[[#V5]] : !cir.array