-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[CIR][Dialect] Add SourceLangAttr #152511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,9 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext, | |
PtrDiffTy = | ||
cir::IntType::get(&getMLIRContext(), sizeTypeSize, /*isSigned=*/true); | ||
|
||
theModule->setAttr( | ||
cir::CIRDialect::getSourceLanguageAttrName(), | ||
cir::SourceLanguageAttr::get(&mlirContext, getCIRSourceLanguage())); | ||
theModule->setAttr(cir::CIRDialect::getTripleAttrName(), | ||
builder.getStringAttr(getTriple().str())); | ||
|
||
|
@@ -495,6 +498,25 @@ void CIRGenModule::setNonAliasAttributes(GlobalDecl gd, mlir::Operation *op) { | |
assert(!cir::MissingFeatures::setTargetAttributes()); | ||
} | ||
|
||
cir::SourceLanguage CIRGenModule::getCIRSourceLanguage() const { | ||
using ClangStd = clang::LangStandard; | ||
using CIRLang = cir::SourceLanguage; | ||
auto opts = getLangOpts(); | ||
|
||
if (opts.CPlusPlus || opts.CPlusPlus11 || opts.CPlusPlus14 || | ||
opts.CPlusPlus17 || opts.CPlusPlus20 || opts.CPlusPlus23 || | ||
opts.CPlusPlus26) | ||
return CIRLang::CXX; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we want to also encode the language standard used? That's not necessary for this PR, just something to consider. |
||
if (opts.C99 || opts.C11 || opts.C17 || opts.C23 || | ||
opts.LangStd == ClangStd::lang_c89 || | ||
opts.LangStd == ClangStd::lang_gnu89) | ||
return CIRLang::C; | ||
|
||
// TODO(cir): support remaining source languages. | ||
assert(!cir::MissingFeatures::sourceLanguageCases()); | ||
errorNYI("CIR does not yet support the given source language"); | ||
} | ||
|
||
static void setLinkageForGV(cir::GlobalOp &gv, const NamedDecl *nd) { | ||
// Set linkage and visibility in case we never see a definition. | ||
LinkageInfo lv = nd->getLinkageAndVisibility(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s | ||
|
||
// CIR: module attributes {{{.*}}cir.lang = #cir.lang<c>{{.*}}} | ||
|
||
int main() { | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be combined with the |
||
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s | ||
|
||
// CIR: module attributes {{{.*}}cir.lang = #cir.lang<cxx>{{.*}}} | ||
|
||
int main() { | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// RUN: cir-opt %s -verify-diagnostics | ||
|
||
// expected-error@below {{expected ::cir::SourceLanguage to be one of}} | ||
// expected-error@below {{failed to parse CIR_SourceLanguageAttr parameter 'value'}} | ||
module attributes {cir.lang = #cir.lang<dummy>} { } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// RUN: cir-opt %s -split-input-file -o %t.cir | ||
// RUN: FileCheck --input-file=%t.cir %s | ||
|
||
// Should parse and print C source language attribute. | ||
module attributes {cir.lang = #cir.lang<c>} { } | ||
// CHECK: module attributes {cir.lang = #cir.lang<c>} | ||
|
||
// ----- | ||
|
||
// Should parse and print C++ source language attribute. | ||
module attributes {cir.lang = #cir.lang<cxx>} { } | ||
// CHECK: module attributes {cir.lang = #cir.lang<cxx>} |
Uh oh!
There was an error while loading. Please reload this page.