Skip to content

Commit

Permalink
[CIR][Basic][NFC] Add the CIR language to the Language enum
Browse files Browse the repository at this point in the history
Add the CIR language to the Language enum and the standard usages of it.

commit-id:fd12b2c2

Reviewers: bcardosolopes, AaronBallman, erichkeane

Reviewed By: AaronBallman, bcardosolopes

Pull Request: #86072
  • Loading branch information
lanza committed Mar 21, 2024
1 parent d22cf43 commit e66b670
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions clang/include/clang/Basic/LangStandard.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ enum class Language : uint8_t {
/// Assembly: we accept this only so that we can preprocess it.
Asm,

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

///@{ Languages that the frontend can parse and compile.
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Types.def
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ TYPE("ir", LLVM_BC, INVALID, "bc", phases
TYPE("lto-ir", LTO_IR, INVALID, "s", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("lto-bc", LTO_BC, INVALID, "o", phases::Compile, phases::Backend, phases::Assemble, phases::Link)

TYPE("cir", CIR, INVALID, "cir", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
// Misc.
TYPE("ast", AST, INVALID, "ast", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("ifs", IFS, INVALID, "ifs", phases::IfsMerge)
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Basic/LangStandards.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ StringRef clang::languageToString(Language L) {
return "Asm";
case Language::LLVM_IR:
return "LLVM IR";
case Language::CIR:
return "ClangIR";
case Language::C:
return "C";
case Language::CXX:
Expand Down Expand Up @@ -92,6 +94,7 @@ LangStandard::Kind clang::getDefaultLanguageStandard(clang::Language Lang,
switch (Lang) {
case Language::Unknown:
case Language::LLVM_IR:
case Language::CIR:
llvm_unreachable("Invalid input kind!");
case Language::OpenCL:
return LangStandard::lang_opencl12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ StringRef getLanguageName(Language Lang) {
case Language::Unknown:
case Language::Asm:
case Language::LLVM_IR:
case Language::CIR:
llvm_unreachable("Unsupported language kind");
}

Expand Down
13 changes: 11 additions & 2 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2757,6 +2757,9 @@ static void GenerateFrontendArgs(const FrontendOptions &Opts,
case Language::HLSL:
Lang = "hlsl";
break;
case Language::CIR:
Lang = "cir";
break;
}

GenerateArg(Consumer, OPT_x,
Expand Down Expand Up @@ -2958,6 +2961,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
.Cases("ast", "pcm", "precompiled-header",
InputKind(Language::Unknown, InputKind::Precompiled))
.Case("ir", Language::LLVM_IR)
.Case("cir", Language::CIR)
.Default(Language::Unknown);

if (DashX.isUnknown())
Expand Down Expand Up @@ -3323,6 +3327,7 @@ static bool IsInputCompatibleWithStandard(InputKind IK,
switch (IK.getLanguage()) {
case Language::Unknown:
case Language::LLVM_IR:
case Language::CIR:
llvm_unreachable("should not parse language flags for this input");

case Language::C:
Expand Down Expand Up @@ -3388,6 +3393,8 @@ static StringRef GetInputKindName(InputKind IK) {
return "Asm";
case Language::LLVM_IR:
return "LLVM IR";
case Language::CIR:
return "Clang IR";

case Language::HLSL:
return "HLSL";
Expand All @@ -3403,7 +3410,8 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts,
const llvm::Triple &T,
InputKind IK) {
if (IK.getFormat() == InputKind::Precompiled ||
IK.getLanguage() == Language::LLVM_IR) {
IK.getLanguage() == Language::LLVM_IR ||
IK.getLanguage() == Language::CIR) {
if (Opts.ObjCAutoRefCount)
GenerateArg(Consumer, OPT_fobjc_arc);
if (Opts.PICLevel != 0)
Expand Down Expand Up @@ -3689,7 +3697,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
unsigned NumErrorsBefore = Diags.getNumErrors();

if (IK.getFormat() == InputKind::Precompiled ||
IK.getLanguage() == Language::LLVM_IR) {
IK.getLanguage() == Language::LLVM_IR ||
IK.getLanguage() == Language::CIR) {
// ObjCAAutoRefCount and Sanitize LangOpts are used to setup the
// PassManager in BackendUtil.cpp. They need to be initialized no matter
// what the input type is.
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Frontend/FrontendActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ void PrintPreambleAction::ExecuteAction() {
case Language::CUDA:
case Language::HIP:
case Language::HLSL:
case Language::CIR:
break;

case Language::Unknown:
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Frontend/FrontendOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ InputKind FrontendOptions::getInputKindForExtension(StringRef Extension) {
.Case("hip", Language::HIP)
.Cases("ll", "bc", Language::LLVM_IR)
.Case("hlsl", Language::HLSL)
.Case("cir", Language::CIR)
.Default(Language::Unknown);
}

0 comments on commit e66b670

Please sign in to comment.