Skip to content

Commit

Permalink
[CIR][driver] Forward -fno-clangir-direct-lowering option to cc1 (llv…
Browse files Browse the repository at this point in the history
…m#822)

Allow from the clang driver the use of lowering from CIR to MLIR
standard dialect.
Update the test to match the real output when
`-fno-clangir-direct-lowering` is used, or with a combination of both
`-fclangir-direct-lowering` and `-fno-clangir-direct-lowering`.

---------

Co-authored-by: Bruno Cardoso Lopes <[email protected]>
Co-authored-by: Shoaib Meenai <[email protected]>
  • Loading branch information
3 people authored and lanza committed Oct 2, 2024
1 parent 42efd8c commit 9969d9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5132,15 +5132,15 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.hasArg(options::OPT_emit_cir_flat))
CmdArgs.push_back("-fclangir");

if (Args.hasArg(options::OPT_fclangir_direct_lowering))
CmdArgs.push_back("-fclangir-direct-lowering");
Args.addOptOutFlag(CmdArgs, options::OPT_fclangir_direct_lowering,
options::OPT_fno_clangir_direct_lowering);

if (Args.hasArg(options::OPT_clangir_disable_passes))
CmdArgs.push_back("-clangir-disable-passes");

if (Args.hasArg(options::OPT_fclangir_call_conv_lowering))
CmdArgs.push_back("-fclangir-call-conv-lowering");

if (Args.hasArg(options::OPT_fclangir_mem2reg))
CmdArgs.push_back("-fclangir-mem2reg");

Expand Down
15 changes: 12 additions & 3 deletions clang/test/CIR/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fclangir-direct-lowering -S -emit-llvm %s -o %t1.ll
// RUN: FileCheck --input-file=%t1.ll %s -check-prefix=LLVM
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -S -emit-llvm %s -o %t2.ll
// RUN: FileCheck --input-file=%t2.ll %s -check-prefix=LLVM
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fclangir-direct-lowering -c -emit-llvm %s -o %t1.bc
// RUN: FileCheck --input-file=%t2.ll %s -check-prefix=CIR_STD_LLVM
// Test also the cases for both -fclangir-direct-lowering and -fno-clangir-direct-lowering,
// with -fno-clangir-direct-lowering having the preference
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fclangir-direct-lowering -fno-clangir-direct-lowering -S -emit-llvm %s -o %t2.ll
// RUN: FileCheck --input-file=%t2.ll %s -check-prefix=CIR_STD_LLVM
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -fclangir-direct-lowering -c -emit-llvm %s -o %t1.bc
// RUN: FileCheck --input-file=%t2.ll %s -check-prefix=CIR_STD_LLVM
// RUN: llvm-dis %t1.bc -o %t1.bc.ll
// RUN: FileCheck --input-file=%t1.bc.ll %s -check-prefix=LLVM
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -c -emit-llvm %s -o %t2.bc
// RUN: llvm-dis %t2.bc -o %t2.bc.ll
// RUN: FileCheck --input-file=%t2.bc.ll %s -check-prefix=LLVM
// RUN: FileCheck --input-file=%t2.bc.ll %s -check-prefix=CIR_STD_LLVM
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -c %s -o %t.o
// RUN: llvm-objdump -d %t.o | FileCheck %s -check-prefix=OBJ
// RUN: %clang -target x86_64-unknown-linux-gnu -fclangir -clangir-disable-passes -S -Xclang -emit-cir %s -o %t.cir
Expand Down Expand Up @@ -39,6 +44,10 @@ void foo(void) {}
// LLVM-NEXT: ret void
// LLVM-NEXT: }

// CIR_STD_LLVM: define void @foo()
// CIR_STD_LLVM-NEXT: ret void
// CIR_STD_LLVM-NEXT: }

// LLVM_MACOS: define void @foo()
// LLVM_MACOS-NEXT: ret void
// LLVM_MACOS-NEXT: }
Expand Down

0 comments on commit 9969d9a

Please sign in to comment.