Skip to content

Commit 1dba86b

Browse files
fangyi-zhoulanza
andcommitted
[CIR] Add back ability to process cir files in cc1 (llvm#1628)
Reapplying llvm/clangir@e66b670 which was reverted during rebase (after fixing some conflicts). Un-xfails the test `cc1.cir` (llvm#1497). --------- Co-authored-by: Nathan Lanza <[email protected]>
1 parent 650c424 commit 1dba86b

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

clang/include/clang/Basic/LangStandard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ enum class Language : uint8_t {
2626
/// Assembly: we accept this only so that we can preprocess it.
2727
Asm,
2828

29-
/// LLVM IR: we accept this so that we can run the optimizer on it,
30-
/// and compile it to assembly or object code.
29+
/// LLVM IR & CIR: we accept these so that we can run the optimizer on them,
30+
/// and compile them to assembly or object code (or LLVM for CIR).
3131
CIR,
3232
LLVM_IR,
3333

clang/include/clang/Driver/Types.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ TYPE("lto-ir", LTO_IR, INVALID, "s", phases
100100
TYPE("lto-bc", LTO_BC, INVALID, "o", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
101101

102102
TYPE("mlir", MLIR, INVALID, "mlir", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
103+
TYPE("cir", CIR, INVALID, "cir", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
103104

104105
// Misc.
105106
TYPE("ast", AST, INVALID, "ast", phases::Compile, phases::Backend, phases::Assemble, phases::Link)

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3020,6 +3020,9 @@ static void GenerateFrontendArgs(const FrontendOptions &Opts,
30203020
case Language::LLVM_IR:
30213021
Lang = "ir";
30223022
break;
3023+
case Language::CIR:
3024+
Lang = "cir";
3025+
break;
30233026
case Language::HLSL:
30243027
Lang = "hlsl";
30253028
break;
@@ -3283,6 +3286,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
32833286
.Cases("ast", "pcm", "precompiled-header",
32843287
InputKind(Language::Unknown, InputKind::Precompiled))
32853288
.Case("ir", Language::LLVM_IR)
3289+
.Case("cir", Language::CIR)
32863290
.Default(Language::Unknown);
32873291

32883292
if (DashX.isUnknown())
@@ -3753,6 +3757,8 @@ static StringRef GetInputKindName(InputKind IK) {
37533757
return "Asm";
37543758
case Language::LLVM_IR:
37553759
return "LLVM IR";
3760+
case Language::CIR:
3761+
return "CIR";
37563762

37573763
case Language::HLSL:
37583764
return "HLSL";
@@ -3768,7 +3774,8 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
37683774
const llvm::Triple &T,
37693775
InputKind IK) {
37703776
if (IK.getFormat() == InputKind::Precompiled ||
3771-
IK.getLanguage() == Language::LLVM_IR) {
3777+
IK.getLanguage() == Language::LLVM_IR ||
3778+
IK.getLanguage() == Language::CIR) {
37723779
if (Opts.ObjCAutoRefCount)
37733780
GenerateArg(Consumer, OPT_fobjc_arc);
37743781
if (Opts.PICLevel != 0)
@@ -4067,7 +4074,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
40674074
unsigned NumErrorsBefore = Diags.getNumErrors();
40684075

40694076
if (IK.getFormat() == InputKind::Precompiled ||
4070-
IK.getLanguage() == Language::LLVM_IR) {
4077+
IK.getLanguage() == Language::LLVM_IR ||
4078+
IK.getLanguage() == Language::CIR) {
40714079
// ObjCAAutoRefCount and Sanitize LangOpts are used to setup the
40724080
// PassManager in BackendUtil.cpp. They need to be initialized no matter
40734081
// what the input type is.

clang/lib/Frontend/FrontendOptions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ InputKind FrontendOptions::getInputKindForExtension(StringRef Extension) {
3434
.Case("hip", Language::HIP)
3535
.Cases("ll", "bc", Language::LLVM_IR)
3636
.Case("hlsl", Language::HLSL)
37+
.Case("cir", Language::CIR)
3738
.Default(Language::Unknown);
3839
}

clang/test/CIR/cc1.cir

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.cir
22
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=LLVM
3-
// XFAIL: *
43

54
module {
65
cir.func @foo() {

0 commit comments

Comments
 (0)