From 99447279c75c348b375137a8759d499abba4896f Mon Sep 17 00:00:00 2001 From: Sirui Mu Date: Fri, 21 Mar 2025 02:23:59 +0800 Subject: [PATCH 01/13] [CIR][NFC] Fix a wrong test case in fc293bb (#1503) --- clang/test/CIR/CodeGen/try-catch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/CIR/CodeGen/try-catch.cpp b/clang/test/CIR/CodeGen/try-catch.cpp index 400a993991e3..7338c0c94e17 100644 --- a/clang/test/CIR/CodeGen/try-catch.cpp +++ b/clang/test/CIR/CodeGen/try-catch.cpp @@ -163,7 +163,7 @@ void tc7() { // CHECK: cir.scope { // CHECK: cir.try { // CHECK: %[[V2:.*]] = cir.load {{.*}} : !cir.ptr, !s32i -// CHECK: %[[V3:.*]] = cir.unary(inc, %[[V2]]) : !s32i, !s32i +// CHECK: %[[V3:.*]] = cir.unary(inc, %[[V2]]) nsw : !s32i, !s32i // CHECK: cir.store %[[V3]], {{.*}} : !s32i, !cir.ptr // CHECK: cir.return // CHECK: } From 80dd69e19aa55a5524c1187fd562c07ead18e5c0 Mon Sep 17 00:00:00 2001 From: Morris Hafner Date: Thu, 20 Mar 2025 19:26:31 +0100 Subject: [PATCH 02/13] cir-translate: Use default target triple instead of x86 if no target was set explicitly (#1482) This is backported from a change made in https://github.com/llvm/llvm-project/pull/131181 --------- Co-authored-by: Morris Hafner --- clang/test/CIR/Lowering/OpenMP/barrier.cir | 2 +- clang/test/CIR/Lowering/OpenMP/parallel.cir | 2 +- clang/test/CIR/Lowering/OpenMP/taskwait.cir | 2 +- clang/test/CIR/Lowering/OpenMP/taskyield.cir | 2 +- clang/test/CIR/Lowering/array.cir | 2 +- clang/test/CIR/Lowering/attribute-lowering.cir | 2 +- clang/test/CIR/Lowering/binop-fp.cir | 2 +- clang/test/CIR/Lowering/binop-overflow.cir | 2 +- clang/test/CIR/Lowering/binop-unsigned-int.cir | 2 +- clang/test/CIR/Lowering/bitint.cir | 2 +- clang/test/CIR/Lowering/bool-to-int.cir | 2 +- clang/test/CIR/Lowering/bool.cir | 2 +- clang/test/CIR/Lowering/branch.cir | 2 +- clang/test/CIR/Lowering/brcond.cir | 2 +- clang/test/CIR/Lowering/bswap.cir | 2 +- clang/test/CIR/Lowering/call-op-call-conv.cir | 2 +- clang/test/CIR/Lowering/call.cir | 2 +- clang/test/CIR/Lowering/cmp3way.cir | 2 +- clang/test/CIR/Lowering/complex.cir | 2 +- clang/test/CIR/Lowering/const-array.cir | 2 +- clang/test/CIR/Lowering/expect.cir | 2 +- clang/test/CIR/Lowering/func-call-conv.cir | 2 +- clang/test/CIR/Lowering/globals.cir | 2 +- clang/test/CIR/Lowering/if.cir | 2 +- clang/test/CIR/Lowering/int-wrap.cir | 2 +- clang/test/CIR/Lowering/intrinsics.cir | 2 +- clang/test/CIR/Lowering/ptrdiff.cir | 2 +- clang/test/CIR/Lowering/region-simplify.cir | 2 +- clang/test/CIR/Lowering/scope.cir | 2 +- clang/test/CIR/Lowering/select.cir | 2 +- clang/test/CIR/Lowering/syncscope.cir | 2 +- clang/test/CIR/Lowering/unary-inc-dec.cir | 2 +- clang/test/CIR/Lowering/unary-not.cir | 2 +- .../CIR/Tools/cir-translate/no-triple-has-data-layout.cir | 5 ----- .../CIR/Tools/cir-translate/no-triple-no-data-layout.cir | 5 ----- clang/test/CIR/Tools/cir-translate/warn-default-triple.cir | 5 +++-- clang/tools/cir-translate/cir-translate.cpp | 4 +--- 37 files changed, 37 insertions(+), 48 deletions(-) diff --git a/clang/test/CIR/Lowering/OpenMP/barrier.cir b/clang/test/CIR/Lowering/OpenMP/barrier.cir index 145117ab54a0..c6a58bb02038 100644 --- a/clang/test/CIR/Lowering/OpenMP/barrier.cir +++ b/clang/test/CIR/Lowering/OpenMP/barrier.cir @@ -1,5 +1,5 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s module { diff --git a/clang/test/CIR/Lowering/OpenMP/parallel.cir b/clang/test/CIR/Lowering/OpenMP/parallel.cir index 3422eac75ea0..dd1f0c763053 100644 --- a/clang/test/CIR/Lowering/OpenMP/parallel.cir +++ b/clang/test/CIR/Lowering/OpenMP/parallel.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s !s32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/OpenMP/taskwait.cir b/clang/test/CIR/Lowering/OpenMP/taskwait.cir index 83e8119bc479..bb4f4fff4392 100644 --- a/clang/test/CIR/Lowering/OpenMP/taskwait.cir +++ b/clang/test/CIR/Lowering/OpenMP/taskwait.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s module { diff --git a/clang/test/CIR/Lowering/OpenMP/taskyield.cir b/clang/test/CIR/Lowering/OpenMP/taskyield.cir index a701365b798f..63a525d9f75c 100644 --- a/clang/test/CIR/Lowering/OpenMP/taskyield.cir +++ b/clang/test/CIR/Lowering/OpenMP/taskyield.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s module { diff --git a/clang/test/CIR/Lowering/array.cir b/clang/test/CIR/Lowering/array.cir index 30a5aae7bfae..09830b64e5ff 100644 --- a/clang/test/CIR/Lowering/array.cir +++ b/clang/test/CIR/Lowering/array.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !s32i = !cir.int !ty_S = !cir.struct diff --git a/clang/test/CIR/Lowering/attribute-lowering.cir b/clang/test/CIR/Lowering/attribute-lowering.cir index 71ddf2002a25..3d2e2bd08e47 100644 --- a/clang/test/CIR/Lowering/attribute-lowering.cir +++ b/clang/test/CIR/Lowering/attribute-lowering.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !s32i = !cir.int !s8i = !cir.int diff --git a/clang/test/CIR/Lowering/binop-fp.cir b/clang/test/CIR/Lowering/binop-fp.cir index a2800a847c85..e69a69e6b099 100644 --- a/clang/test/CIR/Lowering/binop-fp.cir +++ b/clang/test/CIR/Lowering/binop-fp.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM module { cir.func @foo() { diff --git a/clang/test/CIR/Lowering/binop-overflow.cir b/clang/test/CIR/Lowering/binop-overflow.cir index 6a2ef54c1501..68af70aa6abb 100644 --- a/clang/test/CIR/Lowering/binop-overflow.cir +++ b/clang/test/CIR/Lowering/binop-overflow.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !u32i = !cir.int !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/binop-unsigned-int.cir b/clang/test/CIR/Lowering/binop-unsigned-int.cir index b783509d06ed..8834cc103e5a 100644 --- a/clang/test/CIR/Lowering/binop-unsigned-int.cir +++ b/clang/test/CIR/Lowering/binop-unsigned-int.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !u32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/bitint.cir b/clang/test/CIR/Lowering/bitint.cir index 61db545b0d07..ea6dcf989aa4 100644 --- a/clang/test/CIR/Lowering/bitint.cir +++ b/clang/test/CIR/Lowering/bitint.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/bool-to-int.cir b/clang/test/CIR/Lowering/bool-to-int.cir index 97ee3c1daee0..772e5c5c4e45 100644 --- a/clang/test/CIR/Lowering/bool-to-int.cir +++ b/clang/test/CIR/Lowering/bool-to-int.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s !s32i = !cir.int #false = #cir.bool : !cir.bool diff --git a/clang/test/CIR/Lowering/bool.cir b/clang/test/CIR/Lowering/bool.cir index 848b552f897a..4398c60cc6ed 100644 --- a/clang/test/CIR/Lowering/bool.cir +++ b/clang/test/CIR/Lowering/bool.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM #false = #cir.bool : !cir.bool #true = #cir.bool : !cir.bool diff --git a/clang/test/CIR/Lowering/branch.cir b/clang/test/CIR/Lowering/branch.cir index 0daea329f4b8..ed8eea362039 100644 --- a/clang/test/CIR/Lowering/branch.cir +++ b/clang/test/CIR/Lowering/branch.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int cir.func @foo(%arg0: !cir.bool) -> !s32i { diff --git a/clang/test/CIR/Lowering/brcond.cir b/clang/test/CIR/Lowering/brcond.cir index 19e778cef823..bacddbcdaa0f 100644 --- a/clang/test/CIR/Lowering/brcond.cir +++ b/clang/test/CIR/Lowering/brcond.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int #fn_attr = #cir, nothrow = #cir.nothrow, optnone = #cir.optnone})> diff --git a/clang/test/CIR/Lowering/bswap.cir b/clang/test/CIR/Lowering/bswap.cir index 0f8478ba8936..dc3a0744d0be 100644 --- a/clang/test/CIR/Lowering/bswap.cir +++ b/clang/test/CIR/Lowering/bswap.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !u32i = !cir.int diff --git a/clang/test/CIR/Lowering/call-op-call-conv.cir b/clang/test/CIR/Lowering/call-op-call-conv.cir index 92f0028e7bae..d4360158575f 100644 --- a/clang/test/CIR/Lowering/call-op-call-conv.cir +++ b/clang/test/CIR/Lowering/call-op-call-conv.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate -cir-to-llvmir --disable-cc-lowering %s -o %t.ll +// RUN: cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering %s -o %t.ll // RUN: FileCheck --input-file=%t.ll %s --check-prefix=LLVM !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/call.cir b/clang/test/CIR/Lowering/call.cir index 07957727e861..1b57a9fd92df 100644 --- a/clang/test/CIR/Lowering/call.cir +++ b/clang/test/CIR/Lowering/call.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM // XFAIL: * !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/cmp3way.cir b/clang/test/CIR/Lowering/cmp3way.cir index 9c18dfce5769..3eda6dd9fcc9 100644 --- a/clang/test/CIR/Lowering/cmp3way.cir +++ b/clang/test/CIR/Lowering/cmp3way.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s8i = !cir.int !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/complex.cir b/clang/test/CIR/Lowering/complex.cir index 27180865e377..40cbf63cc2fb 100644 --- a/clang/test/CIR/Lowering/complex.cir +++ b/clang/test/CIR/Lowering/complex.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate -cir-to-llvmir --disable-cc-lowering -o %t.ll %s +// RUN: cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll %s // RUN: FileCheck --input-file %t.ll -check-prefix=LLVM %s !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/const-array.cir b/clang/test/CIR/Lowering/const-array.cir index 84a21665bffd..cf16cca3f5b1 100644 --- a/clang/test/CIR/Lowering/const-array.cir +++ b/clang/test/CIR/Lowering/const-array.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !u8i = !cir.int #false = #cir.bool : !cir.bool diff --git a/clang/test/CIR/Lowering/expect.cir b/clang/test/CIR/Lowering/expect.cir index 57f9cf2e35da..aa300745d890 100644 --- a/clang/test/CIR/Lowering/expect.cir +++ b/clang/test/CIR/Lowering/expect.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s64i = !cir.int module { diff --git a/clang/test/CIR/Lowering/func-call-conv.cir b/clang/test/CIR/Lowering/func-call-conv.cir index 577eb854d47b..cf73d0bae285 100644 --- a/clang/test/CIR/Lowering/func-call-conv.cir +++ b/clang/test/CIR/Lowering/func-call-conv.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o %t.ll +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll // RUN: FileCheck %s --input-file=%t.ll --check-prefix=LLVM !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/globals.cir b/clang/test/CIR/Lowering/globals.cir index 3f99fd102efd..58a28490d007 100644 --- a/clang/test/CIR/Lowering/globals.cir +++ b/clang/test/CIR/Lowering/globals.cir @@ -1,6 +1,6 @@ // RUN: cir-opt %s -cir-to-llvm -o %t.mlir // RUN: FileCheck --input-file=%t.mlir %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o %t.ll +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM !void = !cir.void diff --git a/clang/test/CIR/Lowering/if.cir b/clang/test/CIR/Lowering/if.cir index 44aa412ffd13..3a077aa9ef05 100644 --- a/clang/test/CIR/Lowering/if.cir +++ b/clang/test/CIR/Lowering/if.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/int-wrap.cir b/clang/test/CIR/Lowering/int-wrap.cir index f885e745004b..b5fb79ba69ed 100644 --- a/clang/test/CIR/Lowering/int-wrap.cir +++ b/clang/test/CIR/Lowering/int-wrap.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/intrinsics.cir b/clang/test/CIR/Lowering/intrinsics.cir index 778aeb9f9182..e5ac27d89bfc 100644 --- a/clang/test/CIR/Lowering/intrinsics.cir +++ b/clang/test/CIR/Lowering/intrinsics.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM module { cir.func @test_unreachable() { diff --git a/clang/test/CIR/Lowering/ptrdiff.cir b/clang/test/CIR/Lowering/ptrdiff.cir index c0b1a4b3e314..a572367489d9 100644 --- a/clang/test/CIR/Lowering/ptrdiff.cir +++ b/clang/test/CIR/Lowering/ptrdiff.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s !s32i = !cir.int !u64i = !cir.int diff --git a/clang/test/CIR/Lowering/region-simplify.cir b/clang/test/CIR/Lowering/region-simplify.cir index a76d73d03d8e..8f1589eea9f9 100644 --- a/clang/test/CIR/Lowering/region-simplify.cir +++ b/clang/test/CIR/Lowering/region-simplify.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -canonicalize -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-opt %s -canonicalize -o - | cir-translate -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-opt %s -canonicalize -o - | cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !u32i = !cir.int diff --git a/clang/test/CIR/Lowering/scope.cir b/clang/test/CIR/Lowering/scope.cir index 850b1ec5e051..092c551a9fd6 100644 --- a/clang/test/CIR/Lowering/scope.cir +++ b/clang/test/CIR/Lowering/scope.cir @@ -1,6 +1,6 @@ // RUN: cir-opt %s -cir-to-llvm -o %t.cir // RUN: FileCheck %s --input-file=%t.cir -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !u32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/select.cir b/clang/test/CIR/Lowering/select.cir index 71ca79a390e8..5067355ca8f6 100644 --- a/clang/test/CIR/Lowering/select.cir +++ b/clang/test/CIR/Lowering/select.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate -cir-to-llvmir --disable-cc-lowering -o %t.ll %s +// RUN: cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll %s // RUN: FileCheck --input-file=%t.ll -check-prefix=LLVM %s !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/syncscope.cir b/clang/test/CIR/Lowering/syncscope.cir index 8e1aad8a743c..fe324bba3524 100644 --- a/clang/test/CIR/Lowering/syncscope.cir +++ b/clang/test/CIR/Lowering/syncscope.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !s32i = !cir.int #fn_attr = #cir, nothrow = #cir.nothrow, optnone = #cir.optnone})> diff --git a/clang/test/CIR/Lowering/unary-inc-dec.cir b/clang/test/CIR/Lowering/unary-inc-dec.cir index 4dac6ac55318..46d2f1115c59 100644 --- a/clang/test/CIR/Lowering/unary-inc-dec.cir +++ b/clang/test/CIR/Lowering/unary-inc-dec.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int module { cir.func @foo() { diff --git a/clang/test/CIR/Lowering/unary-not.cir b/clang/test/CIR/Lowering/unary-not.cir index 35cd54f3df78..1ad25d790f35 100644 --- a/clang/test/CIR/Lowering/unary-not.cir +++ b/clang/test/CIR/Lowering/unary-not.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int module { cir.func @foo() -> !s32i { diff --git a/clang/test/CIR/Tools/cir-translate/no-triple-has-data-layout.cir b/clang/test/CIR/Tools/cir-translate/no-triple-has-data-layout.cir index f2853941271f..5dc2fdb75a7c 100644 --- a/clang/test/CIR/Tools/cir-translate/no-triple-has-data-layout.cir +++ b/clang/test/CIR/Tools/cir-translate/no-triple-has-data-layout.cir @@ -2,8 +2,6 @@ // RUN: FileCheck %s -input-file %t.x86.ll -check-prefix=X86 // RUN: cir-translate --cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering %s -o %t.spirv64.ll // RUN: FileCheck %s -input-file %t.spirv64.ll -check-prefix=SPIRV64 -// RUN: cir-translate --cir-to-llvmir --disable-cc-lowering %s -o %t.default.ll -// RUN: FileCheck %s -input-file %t.default.ll -check-prefix=DEFAULT module attributes { dlti.dl_spec = #dlti.dl_spec<"dlti.global_memory_space" = 7 : ui64> @@ -18,6 +16,3 @@ module attributes { // SPIRV64-NOT: target datalayout = "G7" // SPIRV64-DAG: target triple = "spirv64-unknown-unknown" - -// DEFAULT-NOT: target datalayout = "G7" -// DEFAULT-DAG: target triple = "x86_64-unknown-linux-gnu" diff --git a/clang/test/CIR/Tools/cir-translate/no-triple-no-data-layout.cir b/clang/test/CIR/Tools/cir-translate/no-triple-no-data-layout.cir index f18f69dd876d..2e336a797c6a 100644 --- a/clang/test/CIR/Tools/cir-translate/no-triple-no-data-layout.cir +++ b/clang/test/CIR/Tools/cir-translate/no-triple-no-data-layout.cir @@ -2,8 +2,6 @@ // RUN: FileCheck %s -input-file %t.x86.ll -check-prefix=X86 // RUN: cir-translate --cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering %s -o %t.spirv64.ll // RUN: FileCheck %s -input-file %t.spirv64.ll -check-prefix=SPIRV64 -// RUN: cir-translate --cir-to-llvmir --disable-cc-lowering %s -o %t.default.ll -// RUN: FileCheck %s -input-file %t.default.ll -check-prefix=DEFAULT module { cir.func @foo() { @@ -16,6 +14,3 @@ module { // SPIRV64-DAG: target triple = "spirv64-unknown-unknown" // SPIRV64-DAG: target datalayout = "{{.*}}" - -// DEFAULT-DAG: target triple = "x86_64-unknown-linux-gnu" -// DEFAULT-DAG: target datalayout = "{{.*}}" diff --git a/clang/test/CIR/Tools/cir-translate/warn-default-triple.cir b/clang/test/CIR/Tools/cir-translate/warn-default-triple.cir index 519e96598d43..9d60324905f7 100644 --- a/clang/test/CIR/Tools/cir-translate/warn-default-triple.cir +++ b/clang/test/CIR/Tools/cir-translate/warn-default-triple.cir @@ -1,6 +1,7 @@ -// RUN: cir-translate -verify-diagnostics --cir-to-llvmir --disable-cc-lowering %s +// XFAIL: target={{.*windows.*}} +// RUN: cir-translate -verify-diagnostics --cir-to-llvmir --disable-cc-lowering %s 2>&1 -// expected-warning@below {{no target triple provided, assuming x86_64-unknown-linux-gnu}} +// expected-warning@below {{no target triple provided, assuming}} module { cir.func @foo() { cir.return diff --git a/clang/tools/cir-translate/cir-translate.cpp b/clang/tools/cir-translate/cir-translate.cpp index bc8fea1f635e..d0e33b45ccf4 100644 --- a/clang/tools/cir-translate/cir-translate.cpp +++ b/clang/tools/cir-translate/cir-translate.cpp @@ -69,9 +69,7 @@ std::string prepareCIRModuleTriple(mlir::ModuleOp mod) { // Treat "" as the default target machine. if (triple.empty()) { - // Currently ClangIR only supports a couple of targets. Not specifying a - // target triple will default to x86_64-unknown-linux-gnu. - triple = "x86_64-unknown-linux-gnu"; + triple = llvm::sys::getDefaultTargetTriple(); mod.emitWarning() << "no target triple provided, assuming " << triple; } From dbd480906347dcf4d214edb08086ea8792895016 Mon Sep 17 00:00:00 2001 From: Sharp-Edged <48861530+Sharp-Edged@users.noreply.github.com> Date: Thu, 20 Mar 2025 18:27:37 +0000 Subject: [PATCH 03/13] [CIR][CUDA] Decorate global CUDA shadow variables with appropriate CIR attribute. (#1467) Started decorating CUDA shadow variables with the shadow_name CIR attribute which will be used for registering the globals. --- clang/lib/CIR/CodeGen/CIRGenCUDARuntime.cpp | 53 ++++++++++++++++++++- clang/lib/CIR/CodeGen/CIRGenCUDARuntime.h | 6 +++ clang/lib/CIR/CodeGen/CIRGenModule.cpp | 45 +++++++++++++++++ clang/lib/CIR/CodeGen/CIRGenModule.h | 8 ++++ clang/test/CIR/CodeGen/CUDA/global-vars.cu | 7 +++ 5 files changed, 118 insertions(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenCUDARuntime.cpp b/clang/lib/CIR/CodeGen/CIRGenCUDARuntime.cpp index 2695e731b061..71041f1493cc 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCUDARuntime.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenCUDARuntime.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "CIRGenCUDARuntime.h" +#include "CIRGenCXXABI.h" #include "CIRGenFunction.h" #include "mlir/IR/Operation.h" #include "clang/Basic/Cuda.h" @@ -23,9 +24,26 @@ using namespace clang; using namespace clang::CIRGen; +static std::unique_ptr initDeviceMC(CIRGenModule &cgm) { + // If the host and device have different C++ ABIs, mark it as the device + // mangle context so that the mangling needs to retrieve the additional + // device lambda mangling number instead of the regular host one. + if (cgm.getASTContext().getAuxTargetInfo() && + cgm.getASTContext().getTargetInfo().getCXXABI().isMicrosoft() && + cgm.getASTContext().getAuxTargetInfo()->getCXXABI().isItaniumFamily()) { + return std::unique_ptr( + cgm.getASTContext().createDeviceMangleContext( + *cgm.getASTContext().getAuxTargetInfo())); + } + + return std::unique_ptr(cgm.getASTContext().createMangleContext( + cgm.getASTContext().getAuxTargetInfo())); +} + CIRGenCUDARuntime::~CIRGenCUDARuntime() {} -CIRGenCUDARuntime::CIRGenCUDARuntime(CIRGenModule &cgm) : cgm(cgm) { +CIRGenCUDARuntime::CIRGenCUDARuntime(CIRGenModule &cgm) + : cgm(cgm), deviceMC(initDeviceMC(cgm)) { if (cgm.getLangOpts().OffloadViaLLVM) llvm_unreachable("NYI"); else if (cgm.getLangOpts().HIP) @@ -289,6 +307,39 @@ mlir::Operation *CIRGenCUDARuntime::getKernelHandle(cir::FuncOp fn, return globalOp; } +std::string CIRGenCUDARuntime::getDeviceSideName(const NamedDecl *nd) { + GlobalDecl gd; + // nd could be either a kernel or a variable. + if (auto *fd = dyn_cast(nd)) + gd = GlobalDecl(fd, KernelReferenceKind::Kernel); + else + gd = GlobalDecl(nd); + std::string deviceSideName; + MangleContext *mc; + if (cgm.getLangOpts().CUDAIsDevice) + mc = &cgm.getCXXABI().getMangleContext(); + else + mc = deviceMC.get(); + if (mc->shouldMangleDeclName(nd)) { + SmallString<256> buffer; + llvm::raw_svector_ostream out(buffer); + mc->mangleName(gd, out); + deviceSideName = std::string(out.str()); + } else + deviceSideName = std::string(nd->getIdentifier()->getName()); + + // Make unique name for device side static file-scope variable for HIP. + if (cgm.getASTContext().shouldExternalize(nd) && + cgm.getLangOpts().GPURelocatableDeviceCode) { + SmallString<256> buffer; + llvm::raw_svector_ostream out(buffer); + out << deviceSideName; + cgm.printPostfixForExternalizedDecl(out, nd); + deviceSideName = std::string(out.str()); + } + return deviceSideName; +} + void CIRGenCUDARuntime::internalizeDeviceSideVar( const VarDecl *d, cir::GlobalLinkageKind &linkage) { if (cgm.getLangOpts().GPURelocatableDeviceCode) diff --git a/clang/lib/CIR/CodeGen/CIRGenCUDARuntime.h b/clang/lib/CIR/CodeGen/CIRGenCUDARuntime.h index 8cbadb849129..84edcb6b7a3e 100644 --- a/clang/lib/CIR/CodeGen/CIRGenCUDARuntime.h +++ b/clang/lib/CIR/CodeGen/CIRGenCUDARuntime.h @@ -47,6 +47,9 @@ class CIRGenCUDARuntime { std::string addPrefixToName(StringRef FuncName) const; std::string addUnderscoredPrefixToName(StringRef FuncName) const; + // Mangle context for device. + std::unique_ptr deviceMC; + public: CIRGenCUDARuntime(CIRGenModule &cgm); virtual ~CIRGenCUDARuntime(); @@ -60,6 +63,9 @@ class CIRGenCUDARuntime { virtual mlir::Operation *getKernelHandle(cir::FuncOp fn, GlobalDecl GD); virtual void internalizeDeviceSideVar(const VarDecl *d, cir::GlobalLinkageKind &linkage); + /// Returns function or variable name on device side even if the current + /// compilation is for host. + virtual std::string getDeviceSideName(const NamedDecl *nd); }; } // namespace clang::CIRGen diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 6c2c907f0573..d83a00626967 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -576,6 +576,25 @@ bool CIRGenModule::shouldEmitCUDAGlobalVar(const VarDecl *global) const { global->getType()->isCUDADeviceBuiltinTextureType(); } +void CIRGenModule::printPostfixForExternalizedDecl(llvm::raw_ostream &os, + const Decl *d) const { + // ptxas does not allow '.' in symbol names. On the other hand, HIP prefers + // postfix beginning with '.' since the symbol name can be demangled. + if (langOpts.HIP) + os << (isa(d) ? ".static." : ".intern."); + else + os << (isa(d) ? "__static__" : "__intern__"); + + // If the CUID is not specified we try to generate a unique postfix. + if (getLangOpts().CUID.empty()) { + // TODO: Once we add 'PreprocessorOpts' into CIRGenModule this part can be + // brought in from OG. + llvm_unreachable("NYI"); + } else { + os << getASTContext().getCUIDHash(); + } +} + void CIRGenModule::emitGlobal(GlobalDecl gd) { llvm::TimeTraceScope scope("build CIR Global", [&]() -> std::string { auto *nd = dyn_cast(gd.getDecl()); @@ -1496,6 +1515,32 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *d, } } + // Decorate CUDA shadow variables with the cu.shadow_name attribute so we know + // how to register them when lowering. + if (langOpts.CUDA && !langOpts.CUDAIsDevice && + (d->hasAttr() || d->hasAttr())) { + // Shadow variables and their properties must be registered with CUDA + // runtime. Skip Extern global variables, which will be registered in + // the TU where they are defined. + // + // Don't register a C++17 inline variable. The local symbol can be + // discarded and referencing a discarded local symbol from outside the + // comdat (__cuda_register_globals) is disallowed by the ELF spec. + // + // HIP managed variables need to be always recorded in device and host + // compilations for transformation. + // + // HIP managed variables and variables in CUDADeviceVarODRUsedByHost are + // added to llvm.compiler-used, therefore they are safe to be registered. + if ((!d->hasExternalStorage() && !d->isInline()) || + getASTContext().CUDADeviceVarODRUsedByHost.contains(d) || + d->hasAttr()) { + auto shadowName = cudaRuntime->getDeviceSideName(cast(d)); + auto attr = CUDAShadowNameAttr::get(&getMLIRContext(), shadowName); + gv->setAttr(CUDAShadowNameAttr::getMnemonic(), attr); + } + } + // Set initializer and finalize emission CIRGenModule::setInitializer(gv, init); if (emitter) diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.h b/clang/lib/CIR/CodeGen/CIRGenModule.h index a4c593e86ee9..b3e5e104cf43 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.h +++ b/clang/lib/CIR/CodeGen/CIRGenModule.h @@ -274,6 +274,14 @@ class CIRGenModule : public CIRGenTypeCache { bool shouldEmitCUDAGlobalVar(const VarDecl *global) const; + /// Print the postfix for externalized static variable or kernels for single + /// source offloading languages CUDA and HIP. The unique postfix is created + /// using either the CUID argument, or the file's UniqueID and active macros. + /// The fallback method without a CUID requires that the offloading toolchain + /// does not define separate macros via the -cc1 options. + void printPostfixForExternalizedDecl(llvm::raw_ostream &OS, + const Decl *D) const; + bool shouldEmitConvergenceTokens() const { // TODO: this shuld probably become unconditional once the controlled // convergence becomes the norm. diff --git a/clang/test/CIR/CodeGen/CUDA/global-vars.cu b/clang/test/CIR/CodeGen/CUDA/global-vars.cu index 25de5f28dd91..55d4c67967fa 100644 --- a/clang/test/CIR/CodeGen/CUDA/global-vars.cu +++ b/clang/test/CIR/CodeGen/CUDA/global-vars.cu @@ -10,9 +10,15 @@ // RUN: %s -o %t.cir // RUN: FileCheck --check-prefix=LLVM-DEVICE --input-file=%t.cir %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \ +// RUN: -x cuda -emit-cir -target-sdk-version=12.3 \ +// RUN: %s -o %t.cir +// RUN: FileCheck --check-prefix=CIR-HOST --input-file=%t.cir %s + __device__ int a; // CIR-DEVICE: cir.global external addrspace(offload_global) @a = #cir.int<0> // LLVM-DEVICE: @a = addrspace(1) externally_initialized global i32 0, align 4 +// CIR-HOST: {{.*}}cir.global external @a = #cir.undef : !s32i {alignment = 4 : i64, cu.shadow_name = #cir.cu.shadow_name}{{.*}} __shared__ int shared; // CIR-DEVICE: cir.global external addrspace(offload_local) @shared = #cir.undef @@ -21,3 +27,4 @@ __shared__ int shared; __constant__ int b; // CIR-DEVICE: cir.global constant external addrspace(offload_constant) @b = #cir.int<0> : !s32i {alignment = 4 : i64, cu.externally_initialized = #cir.cu.externally_initialized} // LLVM-DEVICE: @b = addrspace(4) externally_initialized constant i32 0, align 4 +// CIR-HOST: {{.*}}cir.global external @b = #cir.undef : !s32i {alignment = 4 : i64, cu.shadow_name = #cir.cu.shadow_name}{{.*}} From ab5aa17536499a6a3ea870ae59c86666f0fd9965 Mon Sep 17 00:00:00 2001 From: Iris <0.0@owo.li> Date: Fri, 21 Mar 2025 02:28:25 +0800 Subject: [PATCH 04/13] [CIR][CIRGen][Builtin] add `__builtin_tan` (#1502) Closes #1354. --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 1 + clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 3 +- .../test/CIR/CodeGen/builtin-floating-point.c | 68 +++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 3f00dda0f904..830da08a27fe 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -4752,6 +4752,7 @@ def RoundOp : UnaryFPToFPBuiltinOp<"round", "RoundOp">; def RoundEvenOp : UnaryFPToFPBuiltinOp<"roundeven", "RoundEvenOp">; def SinOp : UnaryFPToFPBuiltinOp<"sin", "SinOp">; def SqrtOp : UnaryFPToFPBuiltinOp<"sqrt", "SqrtOp">; +def TanOp : UnaryFPToFPBuiltinOp<"tan", "TanOp">; def TruncOp : UnaryFPToFPBuiltinOp<"trunc", "FTruncOp">; def AbsOp : CIR_Op<"abs", [Pure, SameOperandsAndResultType]> { diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 78d96c39396b..075c951f1086 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -896,7 +896,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_tanf16: case Builtin::BI__builtin_tanl: case Builtin::BI__builtin_tanf128: - llvm_unreachable("Builtin::BItan like NYI"); + assert(!cir::MissingFeatures::fastMathFlags()); + return emitUnaryMaybeConstrainedFPBuiltin(*this, *E); case Builtin::BItanh: case Builtin::BItanhf: diff --git a/clang/test/CIR/CodeGen/builtin-floating-point.c b/clang/test/CIR/CodeGen/builtin-floating-point.c index 2e9b18c51a33..8af6fd7b4ed4 100644 --- a/clang/test/CIR/CodeGen/builtin-floating-point.c +++ b/clang/test/CIR/CodeGen/builtin-floating-point.c @@ -1159,6 +1159,74 @@ long double call_sqrtl(long double f) { // LLVM: } } +// tan + +float my_tanf(float f) { + return __builtin_tanf(f); + // CHECK: cir.func @my_tanf + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.float + + // LLVM: define dso_local float @my_tanf(float %0) + // LLVM: %{{.+}} = call float @llvm.tan.f32(float %{{.+}}) + // LLVM: } +} + +double my_tan(double f) { + return __builtin_tan(f); + // CHECK: cir.func @my_tan + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.double + + // LLVM: define dso_local double @my_tan(double %0) + // LLVM: %{{.+}} = call double @llvm.tan.f64(double %{{.+}}) + // LLVM: } +} + +long double my_tanl(long double f) { + return __builtin_tanl(f); + // CHECK: cir.func @my_tanl + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.long_double + // AARCH64: {{.+}} = cir.tan {{.+}} : !cir.long_double + + // LLVM: define dso_local x86_fp80 @my_tanl(x86_fp80 %0) + // LLVM: %{{.+}} = call x86_fp80 @llvm.tan.f80(x86_fp80 %{{.+}}) + // LLVM: } +} + +float tanf(float); +double tan(double); +long double tanl(long double); + +float call_tanf(float f) { + return tanf(f); + // CHECK: cir.func @call_tanf + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.float + + // LLVM: define dso_local float @call_tanf(float %0) + // LLVM: %{{.+}} = call float @llvm.tan.f32(float %{{.+}}) + // LLVM: } +} + +double call_tan(double f) { + return tan(f); + // CHECK: cir.func @call_tan + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.double + + // LLVM: define dso_local double @call_tan(double %0) + // LLVM: %{{.+}} = call double @llvm.tan.f64(double %{{.+}}) + // LLVM: } +} + +long double call_tanl(long double f) { + return tanl(f); + // CHECK: cir.func @call_tanl + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.long_double + // AARCH64: {{.+}} = cir.tan {{.+}} : !cir.long_double + + // LLVM: define dso_local x86_fp80 @call_tanl(x86_fp80 %0) + // LLVM: %{{.+}} = call x86_fp80 @llvm.tan.f80(x86_fp80 %{{.+}}) + // LLVM: } +} + // trunc float my_truncf(float f) { From 7fdcea6c2376f237a690f2498ac16fabcb0b1020 Mon Sep 17 00:00:00 2001 From: Amr Hesham Date: Thu, 20 Mar 2025 19:31:07 +0100 Subject: [PATCH 05/13] [CIR][CIRGen][Builtin][Neon] Lower neon vcaltd_f64 (#1505) Lower neon vcaltd_f64 --- clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp | 3 ++- clang/test/CIR/CodeGen/AArch64/neon.c | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp index ef09403264ac..a3d2bed57fa4 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp @@ -2713,7 +2713,8 @@ static mlir::Value emitCommonNeonSISDBuiltinExpr( return emitNeonCall(builder, {argTy}, ops, "aarch64.neon.facge", resultTy, loc); case NEON::BI__builtin_neon_vcaltd_f64: - llvm_unreachable(" neon_vcaltd_f64 NYI "); + return emitNeonCall(builder, {argTy}, ops, "aarch64.neon.facgt", resultTy, + loc); case NEON::BI__builtin_neon_vcalts_f32: llvm_unreachable(" neon_vcalts_f32 NYI "); case NEON::BI__builtin_neon_vcvtad_s64_f64: diff --git a/clang/test/CIR/CodeGen/AArch64/neon.c b/clang/test/CIR/CodeGen/AArch64/neon.c index 6419c43e4baa..a634af0f1f4e 100644 --- a/clang/test/CIR/CodeGen/AArch64/neon.c +++ b/clang/test/CIR/CodeGen/AArch64/neon.c @@ -15185,12 +15185,16 @@ uint64_t test_vcaled_f64(float64_t a, float64_t b) { // return (uint32_t)vcalts_f32(a, b); // } -// NYI-LABEL: @test_vcaltd_f64( -// NYI: [[VCALTD_F64_I:%.*]] = call i64 @llvm.aarch64.neon.facgt.i64.f64(double %b, double %a) -// NYI: ret i64 [[VCALTD_F64_I]] -// uint64_t test_vcaltd_f64(float64_t a, float64_t b) { -// return (uint64_t)vcaltd_f64(a, b); -// } +uint64_t test_vcaltd_f64(float64_t a, float64_t b) { + return (uint64_t)vcaltd_f64(a, b); + + // CIR-LABEL: vcaltd_f64 + // CIR: [[TMP0:%.*]] = cir.llvm.intrinsic "aarch64.neon.facgt" {{.*}}, {{.*}} : (!cir.double, !cir.double) -> !u64i + + // LLVM-LABEL: @test_vcaltd_f64( + // LLVM: [[VCALTD_F64_I:%.*]] = call i64 @llvm.aarch64.neon.facgt.i64.f64(double %0, double %1) + // LLVM: ret i64 [[VCALTD_F64_I]] +} int64_t test_vshrd_n_s64(int64_t a) { return (int64_t)vshrd_n_s64(a, 1); From ab322c0e5d3099539f5de1c1625440cf1ec39579 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Thu, 20 Mar 2025 14:46:06 -0700 Subject: [PATCH 06/13] Revert "cir-translate: Use default target triple instead of x86 if no target was set explicitly" (#1509) Reverts llvm/clangir#1482 @mmha this is crashing on macos on asserts build: ``` FAIL: Clang :: CIR/Tools/cir-translate/warn-default-triple.cir (472 of 552) ******************** TEST 'Clang :: CIR/Tools/cir-translate/warn-default-triple.cir' FAILED ******************** Exit Code: 134 Command Output (stdout): -- Assertion failed: (!DataLayoutString.empty() && "Uninitialized DataLayout!"), function getDataLayoutString, file TargetInfo.h, line 1282. ``` Perhaps besides picking a default you maybe need to do some missing datalayout init? --- clang/test/CIR/Lowering/OpenMP/barrier.cir | 2 +- clang/test/CIR/Lowering/OpenMP/parallel.cir | 2 +- clang/test/CIR/Lowering/OpenMP/taskwait.cir | 2 +- clang/test/CIR/Lowering/OpenMP/taskyield.cir | 2 +- clang/test/CIR/Lowering/array.cir | 2 +- clang/test/CIR/Lowering/attribute-lowering.cir | 2 +- clang/test/CIR/Lowering/binop-fp.cir | 2 +- clang/test/CIR/Lowering/binop-overflow.cir | 2 +- clang/test/CIR/Lowering/binop-unsigned-int.cir | 2 +- clang/test/CIR/Lowering/bitint.cir | 2 +- clang/test/CIR/Lowering/bool-to-int.cir | 2 +- clang/test/CIR/Lowering/bool.cir | 2 +- clang/test/CIR/Lowering/branch.cir | 2 +- clang/test/CIR/Lowering/brcond.cir | 2 +- clang/test/CIR/Lowering/bswap.cir | 2 +- clang/test/CIR/Lowering/call-op-call-conv.cir | 2 +- clang/test/CIR/Lowering/call.cir | 2 +- clang/test/CIR/Lowering/cmp3way.cir | 2 +- clang/test/CIR/Lowering/complex.cir | 2 +- clang/test/CIR/Lowering/const-array.cir | 2 +- clang/test/CIR/Lowering/expect.cir | 2 +- clang/test/CIR/Lowering/func-call-conv.cir | 2 +- clang/test/CIR/Lowering/globals.cir | 2 +- clang/test/CIR/Lowering/if.cir | 2 +- clang/test/CIR/Lowering/int-wrap.cir | 2 +- clang/test/CIR/Lowering/intrinsics.cir | 2 +- clang/test/CIR/Lowering/ptrdiff.cir | 2 +- clang/test/CIR/Lowering/region-simplify.cir | 2 +- clang/test/CIR/Lowering/scope.cir | 2 +- clang/test/CIR/Lowering/select.cir | 2 +- clang/test/CIR/Lowering/syncscope.cir | 2 +- clang/test/CIR/Lowering/unary-inc-dec.cir | 2 +- clang/test/CIR/Lowering/unary-not.cir | 2 +- .../CIR/Tools/cir-translate/no-triple-has-data-layout.cir | 5 +++++ .../CIR/Tools/cir-translate/no-triple-no-data-layout.cir | 5 +++++ clang/test/CIR/Tools/cir-translate/warn-default-triple.cir | 5 ++--- clang/tools/cir-translate/cir-translate.cpp | 4 +++- 37 files changed, 48 insertions(+), 37 deletions(-) diff --git a/clang/test/CIR/Lowering/OpenMP/barrier.cir b/clang/test/CIR/Lowering/OpenMP/barrier.cir index c6a58bb02038..145117ab54a0 100644 --- a/clang/test/CIR/Lowering/OpenMP/barrier.cir +++ b/clang/test/CIR/Lowering/OpenMP/barrier.cir @@ -1,5 +1,5 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s module { diff --git a/clang/test/CIR/Lowering/OpenMP/parallel.cir b/clang/test/CIR/Lowering/OpenMP/parallel.cir index dd1f0c763053..3422eac75ea0 100644 --- a/clang/test/CIR/Lowering/OpenMP/parallel.cir +++ b/clang/test/CIR/Lowering/OpenMP/parallel.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s !s32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/OpenMP/taskwait.cir b/clang/test/CIR/Lowering/OpenMP/taskwait.cir index bb4f4fff4392..83e8119bc479 100644 --- a/clang/test/CIR/Lowering/OpenMP/taskwait.cir +++ b/clang/test/CIR/Lowering/OpenMP/taskwait.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s module { diff --git a/clang/test/CIR/Lowering/OpenMP/taskyield.cir b/clang/test/CIR/Lowering/OpenMP/taskyield.cir index 63a525d9f75c..a701365b798f 100644 --- a/clang/test/CIR/Lowering/OpenMP/taskyield.cir +++ b/clang/test/CIR/Lowering/OpenMP/taskyield.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s module { diff --git a/clang/test/CIR/Lowering/array.cir b/clang/test/CIR/Lowering/array.cir index 09830b64e5ff..30a5aae7bfae 100644 --- a/clang/test/CIR/Lowering/array.cir +++ b/clang/test/CIR/Lowering/array.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !s32i = !cir.int !ty_S = !cir.struct diff --git a/clang/test/CIR/Lowering/attribute-lowering.cir b/clang/test/CIR/Lowering/attribute-lowering.cir index 3d2e2bd08e47..71ddf2002a25 100644 --- a/clang/test/CIR/Lowering/attribute-lowering.cir +++ b/clang/test/CIR/Lowering/attribute-lowering.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !s32i = !cir.int !s8i = !cir.int diff --git a/clang/test/CIR/Lowering/binop-fp.cir b/clang/test/CIR/Lowering/binop-fp.cir index e69a69e6b099..a2800a847c85 100644 --- a/clang/test/CIR/Lowering/binop-fp.cir +++ b/clang/test/CIR/Lowering/binop-fp.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM module { cir.func @foo() { diff --git a/clang/test/CIR/Lowering/binop-overflow.cir b/clang/test/CIR/Lowering/binop-overflow.cir index 68af70aa6abb..6a2ef54c1501 100644 --- a/clang/test/CIR/Lowering/binop-overflow.cir +++ b/clang/test/CIR/Lowering/binop-overflow.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !u32i = !cir.int !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/binop-unsigned-int.cir b/clang/test/CIR/Lowering/binop-unsigned-int.cir index 8834cc103e5a..b783509d06ed 100644 --- a/clang/test/CIR/Lowering/binop-unsigned-int.cir +++ b/clang/test/CIR/Lowering/binop-unsigned-int.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !u32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/bitint.cir b/clang/test/CIR/Lowering/bitint.cir index ea6dcf989aa4..61db545b0d07 100644 --- a/clang/test/CIR/Lowering/bitint.cir +++ b/clang/test/CIR/Lowering/bitint.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/bool-to-int.cir b/clang/test/CIR/Lowering/bool-to-int.cir index 772e5c5c4e45..97ee3c1daee0 100644 --- a/clang/test/CIR/Lowering/bool-to-int.cir +++ b/clang/test/CIR/Lowering/bool-to-int.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s !s32i = !cir.int #false = #cir.bool : !cir.bool diff --git a/clang/test/CIR/Lowering/bool.cir b/clang/test/CIR/Lowering/bool.cir index 4398c60cc6ed..848b552f897a 100644 --- a/clang/test/CIR/Lowering/bool.cir +++ b/clang/test/CIR/Lowering/bool.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM #false = #cir.bool : !cir.bool #true = #cir.bool : !cir.bool diff --git a/clang/test/CIR/Lowering/branch.cir b/clang/test/CIR/Lowering/branch.cir index ed8eea362039..0daea329f4b8 100644 --- a/clang/test/CIR/Lowering/branch.cir +++ b/clang/test/CIR/Lowering/branch.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int cir.func @foo(%arg0: !cir.bool) -> !s32i { diff --git a/clang/test/CIR/Lowering/brcond.cir b/clang/test/CIR/Lowering/brcond.cir index bacddbcdaa0f..19e778cef823 100644 --- a/clang/test/CIR/Lowering/brcond.cir +++ b/clang/test/CIR/Lowering/brcond.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int #fn_attr = #cir, nothrow = #cir.nothrow, optnone = #cir.optnone})> diff --git a/clang/test/CIR/Lowering/bswap.cir b/clang/test/CIR/Lowering/bswap.cir index dc3a0744d0be..0f8478ba8936 100644 --- a/clang/test/CIR/Lowering/bswap.cir +++ b/clang/test/CIR/Lowering/bswap.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !u32i = !cir.int diff --git a/clang/test/CIR/Lowering/call-op-call-conv.cir b/clang/test/CIR/Lowering/call-op-call-conv.cir index d4360158575f..92f0028e7bae 100644 --- a/clang/test/CIR/Lowering/call-op-call-conv.cir +++ b/clang/test/CIR/Lowering/call-op-call-conv.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering %s -o %t.ll +// RUN: cir-translate -cir-to-llvmir --disable-cc-lowering %s -o %t.ll // RUN: FileCheck --input-file=%t.ll %s --check-prefix=LLVM !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/call.cir b/clang/test/CIR/Lowering/call.cir index 1b57a9fd92df..07957727e861 100644 --- a/clang/test/CIR/Lowering/call.cir +++ b/clang/test/CIR/Lowering/call.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM // XFAIL: * !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/cmp3way.cir b/clang/test/CIR/Lowering/cmp3way.cir index 3eda6dd9fcc9..9c18dfce5769 100644 --- a/clang/test/CIR/Lowering/cmp3way.cir +++ b/clang/test/CIR/Lowering/cmp3way.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s8i = !cir.int !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/complex.cir b/clang/test/CIR/Lowering/complex.cir index 40cbf63cc2fb..27180865e377 100644 --- a/clang/test/CIR/Lowering/complex.cir +++ b/clang/test/CIR/Lowering/complex.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll %s +// RUN: cir-translate -cir-to-llvmir --disable-cc-lowering -o %t.ll %s // RUN: FileCheck --input-file %t.ll -check-prefix=LLVM %s !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/const-array.cir b/clang/test/CIR/Lowering/const-array.cir index cf16cca3f5b1..84a21665bffd 100644 --- a/clang/test/CIR/Lowering/const-array.cir +++ b/clang/test/CIR/Lowering/const-array.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !u8i = !cir.int #false = #cir.bool : !cir.bool diff --git a/clang/test/CIR/Lowering/expect.cir b/clang/test/CIR/Lowering/expect.cir index aa300745d890..57f9cf2e35da 100644 --- a/clang/test/CIR/Lowering/expect.cir +++ b/clang/test/CIR/Lowering/expect.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s64i = !cir.int module { diff --git a/clang/test/CIR/Lowering/func-call-conv.cir b/clang/test/CIR/Lowering/func-call-conv.cir index cf73d0bae285..577eb854d47b 100644 --- a/clang/test/CIR/Lowering/func-call-conv.cir +++ b/clang/test/CIR/Lowering/func-call-conv.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o %t.ll // RUN: FileCheck %s --input-file=%t.ll --check-prefix=LLVM !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/globals.cir b/clang/test/CIR/Lowering/globals.cir index 58a28490d007..3f99fd102efd 100644 --- a/clang/test/CIR/Lowering/globals.cir +++ b/clang/test/CIR/Lowering/globals.cir @@ -1,6 +1,6 @@ // RUN: cir-opt %s -cir-to-llvm -o %t.mlir // RUN: FileCheck --input-file=%t.mlir %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o %t.ll // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM !void = !cir.void diff --git a/clang/test/CIR/Lowering/if.cir b/clang/test/CIR/Lowering/if.cir index 3a077aa9ef05..44aa412ffd13 100644 --- a/clang/test/CIR/Lowering/if.cir +++ b/clang/test/CIR/Lowering/if.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/int-wrap.cir b/clang/test/CIR/Lowering/int-wrap.cir index b5fb79ba69ed..f885e745004b 100644 --- a/clang/test/CIR/Lowering/int-wrap.cir +++ b/clang/test/CIR/Lowering/int-wrap.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/intrinsics.cir b/clang/test/CIR/Lowering/intrinsics.cir index e5ac27d89bfc..778aeb9f9182 100644 --- a/clang/test/CIR/Lowering/intrinsics.cir +++ b/clang/test/CIR/Lowering/intrinsics.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM module { cir.func @test_unreachable() { diff --git a/clang/test/CIR/Lowering/ptrdiff.cir b/clang/test/CIR/Lowering/ptrdiff.cir index a572367489d9..c0b1a4b3e314 100644 --- a/clang/test/CIR/Lowering/ptrdiff.cir +++ b/clang/test/CIR/Lowering/ptrdiff.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s !s32i = !cir.int !u64i = !cir.int diff --git a/clang/test/CIR/Lowering/region-simplify.cir b/clang/test/CIR/Lowering/region-simplify.cir index 8f1589eea9f9..a76d73d03d8e 100644 --- a/clang/test/CIR/Lowering/region-simplify.cir +++ b/clang/test/CIR/Lowering/region-simplify.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -canonicalize -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-opt %s -canonicalize -o - | cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-opt %s -canonicalize -o - | cir-translate -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !u32i = !cir.int diff --git a/clang/test/CIR/Lowering/scope.cir b/clang/test/CIR/Lowering/scope.cir index 092c551a9fd6..850b1ec5e051 100644 --- a/clang/test/CIR/Lowering/scope.cir +++ b/clang/test/CIR/Lowering/scope.cir @@ -1,6 +1,6 @@ // RUN: cir-opt %s -cir-to-llvm -o %t.cir // RUN: FileCheck %s --input-file=%t.cir -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !u32i = !cir.int module { diff --git a/clang/test/CIR/Lowering/select.cir b/clang/test/CIR/Lowering/select.cir index 5067355ca8f6..71ca79a390e8 100644 --- a/clang/test/CIR/Lowering/select.cir +++ b/clang/test/CIR/Lowering/select.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o %t.ll %s +// RUN: cir-translate -cir-to-llvmir --disable-cc-lowering -o %t.ll %s // RUN: FileCheck --input-file=%t.ll -check-prefix=LLVM %s !s32i = !cir.int diff --git a/clang/test/CIR/Lowering/syncscope.cir b/clang/test/CIR/Lowering/syncscope.cir index fe324bba3524..8e1aad8a743c 100644 --- a/clang/test/CIR/Lowering/syncscope.cir +++ b/clang/test/CIR/Lowering/syncscope.cir @@ -1,4 +1,4 @@ -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering -o - | FileCheck %s -check-prefix=LLVM !s32i = !cir.int #fn_attr = #cir, nothrow = #cir.nothrow, optnone = #cir.optnone})> diff --git a/clang/test/CIR/Lowering/unary-inc-dec.cir b/clang/test/CIR/Lowering/unary-inc-dec.cir index 46d2f1115c59..4dac6ac55318 100644 --- a/clang/test/CIR/Lowering/unary-inc-dec.cir +++ b/clang/test/CIR/Lowering/unary-inc-dec.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int module { cir.func @foo() { diff --git a/clang/test/CIR/Lowering/unary-not.cir b/clang/test/CIR/Lowering/unary-not.cir index 1ad25d790f35..35cd54f3df78 100644 --- a/clang/test/CIR/Lowering/unary-not.cir +++ b/clang/test/CIR/Lowering/unary-not.cir @@ -1,5 +1,5 @@ // RUN: cir-opt %s -cir-to-llvm -o - | FileCheck %s -check-prefix=MLIR -// RUN: cir-translate %s -cir-to-llvmir --target x86_64-unknown-linux-gnu --disable-cc-lowering | FileCheck %s -check-prefix=LLVM +// RUN: cir-translate %s -cir-to-llvmir --disable-cc-lowering | FileCheck %s -check-prefix=LLVM !s32i = !cir.int module { cir.func @foo() -> !s32i { diff --git a/clang/test/CIR/Tools/cir-translate/no-triple-has-data-layout.cir b/clang/test/CIR/Tools/cir-translate/no-triple-has-data-layout.cir index 5dc2fdb75a7c..f2853941271f 100644 --- a/clang/test/CIR/Tools/cir-translate/no-triple-has-data-layout.cir +++ b/clang/test/CIR/Tools/cir-translate/no-triple-has-data-layout.cir @@ -2,6 +2,8 @@ // RUN: FileCheck %s -input-file %t.x86.ll -check-prefix=X86 // RUN: cir-translate --cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering %s -o %t.spirv64.ll // RUN: FileCheck %s -input-file %t.spirv64.ll -check-prefix=SPIRV64 +// RUN: cir-translate --cir-to-llvmir --disable-cc-lowering %s -o %t.default.ll +// RUN: FileCheck %s -input-file %t.default.ll -check-prefix=DEFAULT module attributes { dlti.dl_spec = #dlti.dl_spec<"dlti.global_memory_space" = 7 : ui64> @@ -16,3 +18,6 @@ module attributes { // SPIRV64-NOT: target datalayout = "G7" // SPIRV64-DAG: target triple = "spirv64-unknown-unknown" + +// DEFAULT-NOT: target datalayout = "G7" +// DEFAULT-DAG: target triple = "x86_64-unknown-linux-gnu" diff --git a/clang/test/CIR/Tools/cir-translate/no-triple-no-data-layout.cir b/clang/test/CIR/Tools/cir-translate/no-triple-no-data-layout.cir index 2e336a797c6a..f18f69dd876d 100644 --- a/clang/test/CIR/Tools/cir-translate/no-triple-no-data-layout.cir +++ b/clang/test/CIR/Tools/cir-translate/no-triple-no-data-layout.cir @@ -2,6 +2,8 @@ // RUN: FileCheck %s -input-file %t.x86.ll -check-prefix=X86 // RUN: cir-translate --cir-to-llvmir --target spirv64-unknown-unknown --disable-cc-lowering %s -o %t.spirv64.ll // RUN: FileCheck %s -input-file %t.spirv64.ll -check-prefix=SPIRV64 +// RUN: cir-translate --cir-to-llvmir --disable-cc-lowering %s -o %t.default.ll +// RUN: FileCheck %s -input-file %t.default.ll -check-prefix=DEFAULT module { cir.func @foo() { @@ -14,3 +16,6 @@ module { // SPIRV64-DAG: target triple = "spirv64-unknown-unknown" // SPIRV64-DAG: target datalayout = "{{.*}}" + +// DEFAULT-DAG: target triple = "x86_64-unknown-linux-gnu" +// DEFAULT-DAG: target datalayout = "{{.*}}" diff --git a/clang/test/CIR/Tools/cir-translate/warn-default-triple.cir b/clang/test/CIR/Tools/cir-translate/warn-default-triple.cir index 9d60324905f7..519e96598d43 100644 --- a/clang/test/CIR/Tools/cir-translate/warn-default-triple.cir +++ b/clang/test/CIR/Tools/cir-translate/warn-default-triple.cir @@ -1,7 +1,6 @@ -// XFAIL: target={{.*windows.*}} -// RUN: cir-translate -verify-diagnostics --cir-to-llvmir --disable-cc-lowering %s 2>&1 +// RUN: cir-translate -verify-diagnostics --cir-to-llvmir --disable-cc-lowering %s -// expected-warning@below {{no target triple provided, assuming}} +// expected-warning@below {{no target triple provided, assuming x86_64-unknown-linux-gnu}} module { cir.func @foo() { cir.return diff --git a/clang/tools/cir-translate/cir-translate.cpp b/clang/tools/cir-translate/cir-translate.cpp index d0e33b45ccf4..bc8fea1f635e 100644 --- a/clang/tools/cir-translate/cir-translate.cpp +++ b/clang/tools/cir-translate/cir-translate.cpp @@ -69,7 +69,9 @@ std::string prepareCIRModuleTriple(mlir::ModuleOp mod) { // Treat "" as the default target machine. if (triple.empty()) { - triple = llvm::sys::getDefaultTargetTriple(); + // Currently ClangIR only supports a couple of targets. Not specifying a + // target triple will default to x86_64-unknown-linux-gnu. + triple = "x86_64-unknown-linux-gnu"; mod.emitWarning() << "no target triple provided, assuming " << triple; } From 138a950721be77ec502947594d3795066104d6d7 Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Thu, 20 Mar 2025 14:38:39 -0700 Subject: [PATCH 07/13] [CIR] Match comment in upstream https://github.com/llvm/llvm-project/pull/132269 --- clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp index f923ac69dbeb..70ad67ed666c 100644 --- a/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp +++ b/clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp @@ -178,8 +178,8 @@ void CIRCanonicalizePass::runOnOperation() { // Collect operations to apply patterns. llvm::SmallVector ops; getOperation()->walk([&](Operation *op) { - // CastOp here is to perform a manual `fold` in - // applyOpPatternsAndFold + // CastOp and UnaryOp are here to perform a manual `fold` in + // applyOpPatternsGreedily. if (isa(op)) ops.push_back(op); From 2037fdffa25b97d17cf5524d29410eb4780cf2b8 Mon Sep 17 00:00:00 2001 From: Letu Ren Date: Fri, 21 Mar 2025 05:53:49 +0800 Subject: [PATCH 08/13] [CIR] Backport clang commit to unxfail some builtin call (#1501) Ref: https://github.com/llvm/clangir/commit/cd269fee05a0f78fb53b65f701b4e06e9ddab424 Related: https://github.com/llvm/clangir/issues/1497 --- clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 8 +++++--- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 3 ++- clang/test/CIR/CodeGen/builtins-memory.c | 1 - clang/test/CIR/CodeGen/builtins.cpp | 1 - clang/test/CIR/CodeGen/libcall.cpp | 1 - clang/test/CIR/Lowering/builtin-binary-fp2fp.c | 1 - 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 075c951f1086..a3de06ebef9a 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -2772,8 +2772,10 @@ cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *FD, unsigned BuiltinID) { assert(astContext.BuiltinInfo.isLibFunction(BuiltinID)); - // Get the name, skip over the __builtin_ prefix (if necessary). - StringRef Name; + // Get the name, skip over the __builtin_ prefix (if necessary). We may have + // to build this up so provide a small stack buffer to handle the vast + // majority of names. + llvm::SmallString<64> Name; GlobalDecl D(FD); // TODO: This list should be expanded or refactored after all GCC-compatible @@ -2832,7 +2834,7 @@ cir::FuncOp CIRGenModule::getBuiltinLibFunction(const FunctionDecl *FD, AIXLongDouble64Builtins.end()) Name = AIXLongDouble64Builtins[BuiltinID]; else - Name = StringRef(astContext.BuiltinInfo.getName(BuiltinID).data(), 10); + Name = astContext.BuiltinInfo.getName(BuiltinID).substr(10); } auto Ty = convertType(FD->getType()); diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index d83a00626967..90c632ec7066 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -3695,7 +3695,8 @@ struct FunctionIsDirectlyRecursive unsigned builtinId = func->getBuiltinID(); if (!builtinId || !builtinCtx.isLibFunction(builtinId)) return false; - StringRef builtinName = builtinCtx.getName(builtinId); + std::string builtinNameStr = builtinCtx.getName(builtinId); + StringRef builtinName = builtinNameStr; return builtinName.starts_with("__builtin_") && name == builtinName.slice(strlen("__builtin_"), StringRef::npos); } diff --git a/clang/test/CIR/CodeGen/builtins-memory.c b/clang/test/CIR/CodeGen/builtins-memory.c index a6401b92eb12..9c7a74301aaa 100644 --- a/clang/test/CIR/CodeGen/builtins-memory.c +++ b/clang/test/CIR/CodeGen/builtins-memory.c @@ -3,7 +3,6 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o - \ // RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll // RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s -// XFAIL: * typedef __SIZE_TYPE__ size_t; void test_memcpy_chk(void *dest, const void *src, size_t n) { diff --git a/clang/test/CIR/CodeGen/builtins.cpp b/clang/test/CIR/CodeGen/builtins.cpp index a0e27c49c3d7..504ec13da6ee 100644 --- a/clang/test/CIR/CodeGen/builtins.cpp +++ b/clang/test/CIR/CodeGen/builtins.cpp @@ -4,7 +4,6 @@ // RUN: -emit-llvm -fno-clangir-call-conv-lowering -o - %s \ // RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll // RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s -// XFAIL: * // This test file is a collection of test cases for all target-independent // builtins that are related to memory operations. diff --git a/clang/test/CIR/CodeGen/libcall.cpp b/clang/test/CIR/CodeGen/libcall.cpp index 990240e75746..192b0ff13294 100644 --- a/clang/test/CIR/CodeGen/libcall.cpp +++ b/clang/test/CIR/CodeGen/libcall.cpp @@ -1,6 +1,5 @@ // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -mconstructor-aliases -emit-cir %s -o %t.cir // RUN: FileCheck --input-file=%t.cir %s -// XFAIL: * typedef __builtin_va_list va_list; diff --git a/clang/test/CIR/Lowering/builtin-binary-fp2fp.c b/clang/test/CIR/Lowering/builtin-binary-fp2fp.c index d44444769889..2877aa5cef30 100644 --- a/clang/test/CIR/Lowering/builtin-binary-fp2fp.c +++ b/clang/test/CIR/Lowering/builtin-binary-fp2fp.c @@ -2,7 +2,6 @@ // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -ffast-math -fclangir -emit-llvm %s -o %t.ll // RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM-FASTMATH -// XFAIL: * // copysign From 43c2f4d07170b2ee627f6c2fd5f18a5e4489b438 Mon Sep 17 00:00:00 2001 From: Iris Shi <0.0@owo.li> Date: Thu, 20 Mar 2025 23:35:32 +0800 Subject: [PATCH 09/13] [CIR] Add `AddressPointAttr` --- clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 17 +++++++++++++++++ clang/include/clang/CIR/Dialect/IR/CIROps.td | 6 ++---- clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp | 7 +++++-- .../Targets/LoweringPrepareItaniumCXXABI.cpp | 2 +- .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 8 +++++--- clang/test/CIR/CodeGen/derived-to-base.cpp | 2 +- clang/test/CIR/CodeGen/dynamic-cast-exact.cpp | 4 ++-- .../CodeGen/dynamic-cast-relative-layout.cpp | 2 +- clang/test/CIR/CodeGen/dynamic-cast.cpp | 2 +- clang/test/CIR/CodeGen/vtable-rtti.cpp | 4 ++-- 10 files changed, 37 insertions(+), 17 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index 68c15fb8a403..4387acada482 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -1407,6 +1407,23 @@ def GlobalAnnotationValuesAttr : CIR_Attr<"GlobalAnnotationValues", let genVerifyDecl = 1; } +//===----------------------------------------------------------------------===// +// AddressPointAttr +//===----------------------------------------------------------------------===// + +def AddressPointAttr : CIR_Attr<"AddressPoint", "address_point"> { + let summary = "Address point attribute"; + + let description = [{ }]; + + let parameters = (ins "int32_t":$vtable_index, + "int32_t":$address_point_index); + + let assemblyFormat = [{ + `(` $vtable_index `,` $address_point_index `)` + }]; +} + include "clang/CIR/Dialect/IR/CIRTBAAAttrs.td" include "clang/CIR/Dialect/IR/CIROpenCLAttrs.td" diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 830da08a27fe..0069551fd681 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -2591,8 +2591,7 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point", let arguments = (ins OptionalAttr:$name, Optional:$sym_addr, - I32Attr:$vtable_index, - I32Attr:$address_point_index); + AddressPointAttr:$address_point); let results = (outs Res:$addr); let assemblyFormat = [{ @@ -2600,8 +2599,7 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point", ($name^)? ($sym_addr^ `:` type($sym_addr))? `,` - `vtable_index` `=` $vtable_index `,` - `address_point_index` `=` $address_point_index + `address_point` `=` $address_point `)` `:` qualified(type($addr)) attr-dict }]; diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp index 2e887647ef8a..ca5f44f1b666 100644 --- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp @@ -950,7 +950,7 @@ CIRGenCallee CIRGenItaniumCXXABI::getVirtualFunctionPointer( auto VTableSlotPtr = CGF.getBuilder().create( loc, CGF.getBuilder().getPointerTo(TyPtr), ::mlir::FlatSymbolRefAttr{}, VTable, - /*vtable_index=*/0, VTableIndex); + cir::AddressPointAttr::get(CGF.getBuilder().getContext(), 0, VTableIndex)); VFuncLoad = CGF.getBuilder().createAlignedLoad(loc, TyPtr, VTableSlotPtr, CGF.getPointerAlign()); } @@ -1011,7 +1011,10 @@ CIRGenItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base, return builder.create( CGM.getLoc(VTableClass->getSourceRange()), vtablePtrTy, mlir::FlatSymbolRefAttr::get(vtable.getSymNameAttr()), mlir::Value{}, - AddressPoint.VTableIndex, AddressPoint.AddressPointIndex); + cir::AddressPointAttr::get( + CGM.getBuilder().getContext(), AddressPoint.VTableIndex, + AddressPoint.AddressPointIndex) + ); } mlir::Value CIRGenItaniumCXXABI::getVTableAddressPointInStructor( diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp index bba759494e3b..abd3bcd00d98 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/LoweringPrepareItaniumCXXABI.cpp @@ -120,7 +120,7 @@ buildDynamicCastToVoidAfterNullCheck(CIRBaseBuilderTy &builder, auto vtablePtr = builder.createLoad(loc, vtablePtrPtr); auto offsetToTopSlotPtr = builder.create( loc, vtablePtrTy, mlir::FlatSymbolRefAttr{}, vtablePtr, - /*vtable_index=*/0, -2ULL); + cir::AddressPointAttr::get(builder.getContext(), 0, -2)); auto offsetToTop = builder.createAlignedLoad(loc, offsetToTopSlotPtr, vtableElemAlign); diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index c014bab10d3e..16f6c6cb13c2 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -3661,13 +3661,15 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite( if (!symAddr) { symAddr = getValueForVTableSymbol(op, rewriter, getTypeConverter(), op.getNameAttr(), eltType); - offsets = llvm::SmallVector{0, op.getVtableIndex(), - op.getAddressPointIndex()}; + offsets = llvm::SmallVector{ + 0, op.getAddressPointAttr().getVtableIndex(), + op.getAddressPointAttr().getAddressPointIndex()}; } else { // Get indirect vtable address point retrieval symAddr = adaptor.getSymAddr(); eltType = converter->convertType(symAddr.getType()); - offsets = llvm::SmallVector{op.getAddressPointIndex()}; + offsets = llvm::SmallVector{ + op.getAddressPointAttr().getAddressPointIndex()}; } assert(eltType && "Shouldn't ever be missing an eltType here"); diff --git a/clang/test/CIR/CodeGen/derived-to-base.cpp b/clang/test/CIR/CodeGen/derived-to-base.cpp index c6dc92d3ac7b..275af963f995 100644 --- a/clang/test/CIR/CodeGen/derived-to-base.cpp +++ b/clang/test/CIR/CodeGen/derived-to-base.cpp @@ -120,7 +120,7 @@ void vcall(C1 &c1) { // CHECK: %6 = cir.load %3 : !cir.ptr, !ty_buffy // CHECK: %7 = cir.cast(bitcast, %4 : !cir.ptr), !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>> // CHECK: %8 = cir.load %7 : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>>, !cir.ptr, !s32i, !ty_buffy) -> !s32i>>> -// CHECK: %9 = cir.vtable.address_point( %8 : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>, vtable_index = 0, address_point_index = 2) : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>> +// CHECK: %9 = cir.vtable.address_point( %8 : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>, address_point = (0, 2)) : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>> // CHECK: %10 = cir.load align(8) %9 : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>, !cir.ptr, !s32i, !ty_buffy) -> !s32i>> // CHECK: %11 = cir.call %10(%4, %5, %6) : (!cir.ptr, !s32i, !ty_buffy) -> !s32i>>, !cir.ptr, !s32i, !ty_buffy) -> !s32i // CHECK: cir.return diff --git a/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp b/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp index cb962ea437ee..e7118253d9bf 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp @@ -16,7 +16,7 @@ struct Derived final : Base1 {}; Derived *ptr_cast(Base1 *ptr) { return dynamic_cast(ptr); // CHECK: %[[#SRC:]] = cir.load %{{.+}} : !cir.ptr>, !cir.ptr - // CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, vtable_index = 0, address_point_index = 2) : !cir.ptr !u32i>>> + // CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = (0, 2)) : !cir.ptr !u32i>>> // CHECK-NEXT: %[[#SRC_VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr !u32i>>>> // CHECK-NEXT: %[[#SRC_VPTR:]] = cir.load %[[#SRC_VPTR_PTR]] : !cir.ptr !u32i>>>>, !cir.ptr !u32i>>> // CHECK-NEXT: %[[#SUCCESS:]] = cir.cmp(eq, %[[#SRC_VPTR]], %[[#EXPECTED_VPTR]]) : !cir.ptr !u32i>>>, !cir.bool @@ -39,7 +39,7 @@ Derived *ptr_cast(Base1 *ptr) { Derived &ref_cast(Base1 &ref) { return dynamic_cast(ref); // CHECK: %[[#SRC:]] = cir.load %{{.+}} : !cir.ptr>, !cir.ptr - // CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, vtable_index = 0, address_point_index = 2) : !cir.ptr !u32i>>> + // CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = (0, 2)) : !cir.ptr !u32i>>> // CHECK-NEXT: %[[#SRC_VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr !u32i>>>> // CHECK-NEXT: %[[#SRC_VPTR:]] = cir.load %[[#SRC_VPTR_PTR]] : !cir.ptr !u32i>>>>, !cir.ptr !u32i>>> // CHECK-NEXT: %[[#SUCCESS:]] = cir.cmp(eq, %[[#SRC_VPTR]], %[[#EXPECTED_VPTR]]) : !cir.ptr !u32i>>>, !cir.bool diff --git a/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp b/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp index 27cff8b2d172..10e74f08c346 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp @@ -21,7 +21,7 @@ void *ptr_cast_to_complete(Base *ptr) { // AFTER-NEXT: %{{.+}} = cir.ternary(%[[#SRC_IS_NOT_NULL]], true { // AFTER-NEXT: %[[#VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr> // AFTER-NEXT: %[[#VPTR:]] = cir.load %[[#VPTR_PTR]] : !cir.ptr>, !cir.ptr -// AFTER-NEXT: %[[#OFFSET_TO_TOP_PTR:]] = cir.vtable.address_point( %[[#VPTR]] : !cir.ptr, vtable_index = 0, address_point_index = -2) : !cir.ptr +// AFTER-NEXT: %[[#OFFSET_TO_TOP_PTR:]] = cir.vtable.address_point( %[[#VPTR]] : !cir.ptr, address_point = (0, -2)) : !cir.ptr // AFTER-NEXT: %[[#OFFSET_TO_TOP:]] = cir.load align(4) %[[#OFFSET_TO_TOP_PTR]] : !cir.ptr, !s32i // AFTER-NEXT: %[[#SRC_BYTES_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr // AFTER-NEXT: %[[#DST_BYTES_PTR:]] = cir.ptr_stride(%[[#SRC_BYTES_PTR]] : !cir.ptr, %[[#OFFSET_TO_TOP]] : !s32i), !cir.ptr diff --git a/clang/test/CIR/CodeGen/dynamic-cast.cpp b/clang/test/CIR/CodeGen/dynamic-cast.cpp index 2d1393b4a582..587ecaab1a33 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast.cpp @@ -73,7 +73,7 @@ void *ptr_cast_to_complete(Base *ptr) { // AFTER-NEXT: %{{.+}} = cir.ternary(%[[#SRC_IS_NOT_NULL]], true { // AFTER-NEXT: %[[#VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr> // AFTER-NEXT: %[[#VPTR:]] = cir.load %[[#VPTR_PTR]] : !cir.ptr>, !cir.ptr -// AFTER-NEXT: %[[#BASE_OFFSET_PTR:]] = cir.vtable.address_point( %[[#VPTR]] : !cir.ptr, vtable_index = 0, address_point_index = -2) : !cir.ptr +// AFTER-NEXT: %[[#BASE_OFFSET_PTR:]] = cir.vtable.address_point( %[[#VPTR]] : !cir.ptr, address_point = (0, -2)) : !cir.ptr // AFTER-NEXT: %[[#BASE_OFFSET:]] = cir.load align(8) %[[#BASE_OFFSET_PTR]] : !cir.ptr, !s64i // AFTER-NEXT: %[[#SRC_BYTES_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr // AFTER-NEXT: %[[#DST_BYTES_PTR:]] = cir.ptr_stride(%[[#SRC_BYTES_PTR]] : !cir.ptr, %[[#BASE_OFFSET]] : !s64i), !cir.ptr diff --git a/clang/test/CIR/CodeGen/vtable-rtti.cpp b/clang/test/CIR/CodeGen/vtable-rtti.cpp index 3c8a5253c526..ddf125aefc94 100644 --- a/clang/test/CIR/CodeGen/vtable-rtti.cpp +++ b/clang/test/CIR/CodeGen/vtable-rtti.cpp @@ -45,7 +45,7 @@ class B : public A // CHECK: %1 = cir.load %0 : !cir.ptr>, !cir.ptr // CHECK: %2 = cir.base_class_addr(%1 : !cir.ptr nonnull) [0] -> !cir.ptr // CHECK: cir.call @_ZN1AC2Ev(%2) : (!cir.ptr) -> () -// CHECK: %3 = cir.vtable.address_point(@_ZTV1B, vtable_index = 0, address_point_index = 2) : !cir.ptr !u32i>>> +// CHECK: %3 = cir.vtable.address_point(@_ZTV1B, address_point = (0, 2)) : !cir.ptr !u32i>>> // CHECK: %4 = cir.cast(bitcast, %1 : !cir.ptr), !cir.ptr !u32i>>>> // CHECK: cir.store %3, %4 : !cir.ptr !u32i>>>, !cir.ptr !u32i>>>> // CHECK: cir.return @@ -73,7 +73,7 @@ class B : public A // CHECK: %0 = cir.alloca !cir.ptr, !cir.ptr>, ["this", init] {alignment = 8 : i64} // CHECK: cir.store %arg0, %0 : !cir.ptr, !cir.ptr> // CHECK: %1 = cir.load %0 : !cir.ptr>, !cir.ptr -// CHECK: %2 = cir.vtable.address_point(@_ZTV1A, vtable_index = 0, address_point_index = 2) : !cir.ptr !u32i>>> +// CHECK: %2 = cir.vtable.address_point(@_ZTV1A, address_point = (0, 2)) : !cir.ptr !u32i>>> // CHECK: %3 = cir.cast(bitcast, %1 : !cir.ptr), !cir.ptr !u32i>>>> // CHECK: cir.store %2, %3 : !cir.ptr !u32i>>>, !cir.ptr !u32i>>>> // CHECK: cir.return From a4589d5d62fc0b9fecd7cd7c832e7adf29cc958a Mon Sep 17 00:00:00 2001 From: Iris Shi <0.0@owo.li> Date: Thu, 20 Mar 2025 23:49:08 +0800 Subject: [PATCH 10/13] docs --- clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 15 ++++++++++++++- clang/include/clang/CIR/Dialect/IR/CIROps.td | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index 4387acada482..0701cd7c8cc8 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -1414,7 +1414,20 @@ def GlobalAnnotationValuesAttr : CIR_Attr<"GlobalAnnotationValues", def AddressPointAttr : CIR_Attr<"AddressPoint", "address_point"> { let summary = "Address point attribute"; - let description = [{ }]; + let description = [{ + Attribute specifying the address point within a C++ virtual table (vtable). + + The `vtable_index` parameter identifies which vtable to use within a vtable + group, while the `address_point_index` specifies the offset within + that vtable where the address begins. + + Example: + ```mlir + cir.global linkonce_odr @_ZTV1B = ... + ... + %3 = cir.vtable.address_point(@_ZTV1B, address_point = (0, 2)) : !cir.ptr i32>> + ``` + }]; let parameters = (ins "int32_t":$vtable_index, "int32_t":$address_point_index); diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 0069551fd681..8d7022d9b984 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -2585,7 +2585,7 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point", ```mlir cir.global linkonce_odr @_ZTV1B = ... ... - %3 = cir.vtable.address_point(@_ZTV1B, vtable_index = 0, address_point_index = 2) : !cir.ptr i32>> + %3 = cir.vtable.address_point(@_ZTV1B, address_point = (0, 2)) : !cir.ptr i32>> ``` }]; From 860f246fdd6f75a80478f9668165d1babdad8fd7 Mon Sep 17 00:00:00 2001 From: Iris Shi <0.0@owo.li> Date: Fri, 21 Mar 2025 11:35:16 +0800 Subject: [PATCH 11/13] renaming and formatting --- clang/include/clang/CIR/Dialect/IR/CIRAttrs.td | 12 ++++++------ clang/include/clang/CIR/Dialect/IR/CIROps.td | 2 +- clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp | 7 +++---- clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 6 +++--- clang/test/CIR/CodeGen/derived-to-base.cpp | 2 +- clang/test/CIR/CodeGen/dynamic-cast-exact.cpp | 4 ++-- .../CIR/CodeGen/dynamic-cast-relative-layout.cpp | 2 +- clang/test/CIR/CodeGen/dynamic-cast.cpp | 2 +- clang/test/CIR/CodeGen/vtable-rtti.cpp | 4 ++-- 9 files changed, 20 insertions(+), 21 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td index 0701cd7c8cc8..0ae6e1c4c5de 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRAttrs.td @@ -1417,23 +1417,23 @@ def AddressPointAttr : CIR_Attr<"AddressPoint", "address_point"> { let description = [{ Attribute specifying the address point within a C++ virtual table (vtable). - The `vtable_index` parameter identifies which vtable to use within a vtable - group, while the `address_point_index` specifies the offset within + The `index` (vtable index) parameter identifies which vtable to use within a vtable + group, while the `offset` (address point index) specifies the offset within that vtable where the address begins. Example: ```mlir cir.global linkonce_odr @_ZTV1B = ... ... - %3 = cir.vtable.address_point(@_ZTV1B, address_point = (0, 2)) : !cir.ptr i32>> + %3 = cir.vtable.address_point(@_ZTV1B, address_point = )) : !cir.ptr i32>> ``` }]; - let parameters = (ins "int32_t":$vtable_index, - "int32_t":$address_point_index); + let parameters = (ins "int32_t":$index, + "int32_t":$offset); let assemblyFormat = [{ - `(` $vtable_index `,` $address_point_index `)` + `<` struct($index, $offset) `>` }]; } diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 8d7022d9b984..d42845382398 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -2585,7 +2585,7 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point", ```mlir cir.global linkonce_odr @_ZTV1B = ... ... - %3 = cir.vtable.address_point(@_ZTV1B, address_point = (0, 2)) : !cir.ptr i32>> + %3 = cir.vtable.address_point(@_ZTV1B, address_point = ) : !cir.ptr i32>> ``` }]; diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp index ca5f44f1b666..6b30a57582c1 100644 --- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp @@ -1011,10 +1011,9 @@ CIRGenItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base, return builder.create( CGM.getLoc(VTableClass->getSourceRange()), vtablePtrTy, mlir::FlatSymbolRefAttr::get(vtable.getSymNameAttr()), mlir::Value{}, - cir::AddressPointAttr::get( - CGM.getBuilder().getContext(), AddressPoint.VTableIndex, - AddressPoint.AddressPointIndex) - ); + cir::AddressPointAttr::get(CGM.getBuilder().getContext(), + AddressPoint.VTableIndex, + AddressPoint.AddressPointIndex)); } mlir::Value CIRGenItaniumCXXABI::getVTableAddressPointInStructor( diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 16f6c6cb13c2..d840c7ea4067 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -3662,14 +3662,14 @@ mlir::LogicalResult CIRToLLVMVTableAddrPointOpLowering::matchAndRewrite( symAddr = getValueForVTableSymbol(op, rewriter, getTypeConverter(), op.getNameAttr(), eltType); offsets = llvm::SmallVector{ - 0, op.getAddressPointAttr().getVtableIndex(), - op.getAddressPointAttr().getAddressPointIndex()}; + 0, op.getAddressPointAttr().getIndex(), + op.getAddressPointAttr().getOffset()}; } else { // Get indirect vtable address point retrieval symAddr = adaptor.getSymAddr(); eltType = converter->convertType(symAddr.getType()); offsets = llvm::SmallVector{ - op.getAddressPointAttr().getAddressPointIndex()}; + op.getAddressPointAttr().getOffset()}; } assert(eltType && "Shouldn't ever be missing an eltType here"); diff --git a/clang/test/CIR/CodeGen/derived-to-base.cpp b/clang/test/CIR/CodeGen/derived-to-base.cpp index 275af963f995..5ba1dd264cbc 100644 --- a/clang/test/CIR/CodeGen/derived-to-base.cpp +++ b/clang/test/CIR/CodeGen/derived-to-base.cpp @@ -120,7 +120,7 @@ void vcall(C1 &c1) { // CHECK: %6 = cir.load %3 : !cir.ptr, !ty_buffy // CHECK: %7 = cir.cast(bitcast, %4 : !cir.ptr), !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>> // CHECK: %8 = cir.load %7 : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>>, !cir.ptr, !s32i, !ty_buffy) -> !s32i>>> -// CHECK: %9 = cir.vtable.address_point( %8 : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>, address_point = (0, 2)) : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>> +// CHECK: %9 = cir.vtable.address_point( %8 : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>, address_point = ) : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>> // CHECK: %10 = cir.load align(8) %9 : !cir.ptr, !s32i, !ty_buffy) -> !s32i>>>, !cir.ptr, !s32i, !ty_buffy) -> !s32i>> // CHECK: %11 = cir.call %10(%4, %5, %6) : (!cir.ptr, !s32i, !ty_buffy) -> !s32i>>, !cir.ptr, !s32i, !ty_buffy) -> !s32i // CHECK: cir.return diff --git a/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp b/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp index e7118253d9bf..df2533501faf 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp @@ -16,7 +16,7 @@ struct Derived final : Base1 {}; Derived *ptr_cast(Base1 *ptr) { return dynamic_cast(ptr); // CHECK: %[[#SRC:]] = cir.load %{{.+}} : !cir.ptr>, !cir.ptr - // CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = (0, 2)) : !cir.ptr !u32i>>> + // CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = ) : !cir.ptr !u32i>>> // CHECK-NEXT: %[[#SRC_VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr !u32i>>>> // CHECK-NEXT: %[[#SRC_VPTR:]] = cir.load %[[#SRC_VPTR_PTR]] : !cir.ptr !u32i>>>>, !cir.ptr !u32i>>> // CHECK-NEXT: %[[#SUCCESS:]] = cir.cmp(eq, %[[#SRC_VPTR]], %[[#EXPECTED_VPTR]]) : !cir.ptr !u32i>>>, !cir.bool @@ -39,7 +39,7 @@ Derived *ptr_cast(Base1 *ptr) { Derived &ref_cast(Base1 &ref) { return dynamic_cast(ref); // CHECK: %[[#SRC:]] = cir.load %{{.+}} : !cir.ptr>, !cir.ptr - // CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = (0, 2)) : !cir.ptr !u32i>>> + // CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = ) : !cir.ptr !u32i>>> // CHECK-NEXT: %[[#SRC_VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr !u32i>>>> // CHECK-NEXT: %[[#SRC_VPTR:]] = cir.load %[[#SRC_VPTR_PTR]] : !cir.ptr !u32i>>>>, !cir.ptr !u32i>>> // CHECK-NEXT: %[[#SUCCESS:]] = cir.cmp(eq, %[[#SRC_VPTR]], %[[#EXPECTED_VPTR]]) : !cir.ptr !u32i>>>, !cir.bool diff --git a/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp b/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp index 10e74f08c346..c50d03fa68ed 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp @@ -21,7 +21,7 @@ void *ptr_cast_to_complete(Base *ptr) { // AFTER-NEXT: %{{.+}} = cir.ternary(%[[#SRC_IS_NOT_NULL]], true { // AFTER-NEXT: %[[#VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr> // AFTER-NEXT: %[[#VPTR:]] = cir.load %[[#VPTR_PTR]] : !cir.ptr>, !cir.ptr -// AFTER-NEXT: %[[#OFFSET_TO_TOP_PTR:]] = cir.vtable.address_point( %[[#VPTR]] : !cir.ptr, address_point = (0, -2)) : !cir.ptr +// AFTER-NEXT: %[[#OFFSET_TO_TOP_PTR:]] = cir.vtable.address_point( %[[#VPTR]] : !cir.ptr, address_point = ) : !cir.ptr // AFTER-NEXT: %[[#OFFSET_TO_TOP:]] = cir.load align(4) %[[#OFFSET_TO_TOP_PTR]] : !cir.ptr, !s32i // AFTER-NEXT: %[[#SRC_BYTES_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr // AFTER-NEXT: %[[#DST_BYTES_PTR:]] = cir.ptr_stride(%[[#SRC_BYTES_PTR]] : !cir.ptr, %[[#OFFSET_TO_TOP]] : !s32i), !cir.ptr diff --git a/clang/test/CIR/CodeGen/dynamic-cast.cpp b/clang/test/CIR/CodeGen/dynamic-cast.cpp index 587ecaab1a33..ba3208b907b7 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast.cpp @@ -73,7 +73,7 @@ void *ptr_cast_to_complete(Base *ptr) { // AFTER-NEXT: %{{.+}} = cir.ternary(%[[#SRC_IS_NOT_NULL]], true { // AFTER-NEXT: %[[#VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr> // AFTER-NEXT: %[[#VPTR:]] = cir.load %[[#VPTR_PTR]] : !cir.ptr>, !cir.ptr -// AFTER-NEXT: %[[#BASE_OFFSET_PTR:]] = cir.vtable.address_point( %[[#VPTR]] : !cir.ptr, address_point = (0, -2)) : !cir.ptr +// AFTER-NEXT: %[[#BASE_OFFSET_PTR:]] = cir.vtable.address_point( %[[#VPTR]] : !cir.ptr, address_point = ) : !cir.ptr // AFTER-NEXT: %[[#BASE_OFFSET:]] = cir.load align(8) %[[#BASE_OFFSET_PTR]] : !cir.ptr, !s64i // AFTER-NEXT: %[[#SRC_BYTES_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr), !cir.ptr // AFTER-NEXT: %[[#DST_BYTES_PTR:]] = cir.ptr_stride(%[[#SRC_BYTES_PTR]] : !cir.ptr, %[[#BASE_OFFSET]] : !s64i), !cir.ptr diff --git a/clang/test/CIR/CodeGen/vtable-rtti.cpp b/clang/test/CIR/CodeGen/vtable-rtti.cpp index ddf125aefc94..b9857a58b38c 100644 --- a/clang/test/CIR/CodeGen/vtable-rtti.cpp +++ b/clang/test/CIR/CodeGen/vtable-rtti.cpp @@ -45,7 +45,7 @@ class B : public A // CHECK: %1 = cir.load %0 : !cir.ptr>, !cir.ptr // CHECK: %2 = cir.base_class_addr(%1 : !cir.ptr nonnull) [0] -> !cir.ptr // CHECK: cir.call @_ZN1AC2Ev(%2) : (!cir.ptr) -> () -// CHECK: %3 = cir.vtable.address_point(@_ZTV1B, address_point = (0, 2)) : !cir.ptr !u32i>>> +// CHECK: %3 = cir.vtable.address_point(@_ZTV1B, address_point = ) : !cir.ptr !u32i>>> // CHECK: %4 = cir.cast(bitcast, %1 : !cir.ptr), !cir.ptr !u32i>>>> // CHECK: cir.store %3, %4 : !cir.ptr !u32i>>>, !cir.ptr !u32i>>>> // CHECK: cir.return @@ -73,7 +73,7 @@ class B : public A // CHECK: %0 = cir.alloca !cir.ptr, !cir.ptr>, ["this", init] {alignment = 8 : i64} // CHECK: cir.store %arg0, %0 : !cir.ptr, !cir.ptr> // CHECK: %1 = cir.load %0 : !cir.ptr>, !cir.ptr -// CHECK: %2 = cir.vtable.address_point(@_ZTV1A, address_point = (0, 2)) : !cir.ptr !u32i>>> +// CHECK: %2 = cir.vtable.address_point(@_ZTV1A, address_point = ) : !cir.ptr !u32i>>> // CHECK: %3 = cir.cast(bitcast, %1 : !cir.ptr), !cir.ptr !u32i>>>> // CHECK: cir.store %2, %3 : !cir.ptr !u32i>>>, !cir.ptr !u32i>>>> // CHECK: cir.return From 5057bf69bc6ec7821aa05c34b89b3931d80b1f0f Mon Sep 17 00:00:00 2001 From: Iris Shi <0.0@owo.li> Date: Fri, 21 Mar 2025 11:59:02 +0800 Subject: [PATCH 12/13] formatting again --- clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp index 6b30a57582c1..bb342648a9af 100644 --- a/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp @@ -950,7 +950,8 @@ CIRGenCallee CIRGenItaniumCXXABI::getVirtualFunctionPointer( auto VTableSlotPtr = CGF.getBuilder().create( loc, CGF.getBuilder().getPointerTo(TyPtr), ::mlir::FlatSymbolRefAttr{}, VTable, - cir::AddressPointAttr::get(CGF.getBuilder().getContext(), 0, VTableIndex)); + cir::AddressPointAttr::get(CGF.getBuilder().getContext(), 0, + VTableIndex)); VFuncLoad = CGF.getBuilder().createAlignedLoad(loc, TyPtr, VTableSlotPtr, CGF.getPointerAlign()); } From 4c2d255209a834c743f0bcb02cddb5ec57ac6195 Mon Sep 17 00:00:00 2001 From: Iris Shi <0.0@owo.li> Date: Sun, 23 Mar 2025 23:42:57 +0800 Subject: [PATCH 13/13] modify documentation to match the code --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index d42845382398..2828cf05e15d 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -2575,8 +2575,8 @@ def VTableAddrPointOp : CIR_Op<"vtable.address_point", (address point) of a C++ virtual table. An object internal `__vptr` gets initializated on top of the value returned by this operation. - `vtable_index` provides the appropriate vtable within the vtable group - (as specified by Itanium ABI), and `addr_point_index` the actual address + `address_point.index` (vtable index) provides the appropriate vtable within the vtable group + (as specified by Itanium ABI), and `address_point.offset` (address point index) the actual address point within that vtable. The return type is always a `!cir.ptr i32>>`.