-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CIR] Add functionality for inline functions #167135
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?
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clangir Author: None (rashmika0220) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167135.diff 3 Files Affected:
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 6f9a69e697cc3..707b5ff88a356 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2521,7 +2521,8 @@ def CIR_FuncOp : CIR_Op<"func", [
OptionalAttr<DictArrayAttr>:$res_attrs,
OptionalAttr<FlatSymbolRefAttr>:$aliasee,
CIR_OptionalPriorityAttr:$global_ctor_priority,
- CIR_OptionalPriorityAttr:$global_dtor_priority);
+ CIR_OptionalPriorityAttr:$global_dtor_priority,
+ OptionalAttr<CIR_InlineAttr>:$inlining);
let regions = (region AnyRegion:$body);
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 9f9b2db4771df..c4c260e9e5fe8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -1928,6 +1928,23 @@ void CIRGenModule::setFunctionAttributes(GlobalDecl globalDecl,
"available body!");
assert(!cir::MissingFeatures::attributeNoBuiltin());
}
+
+ // Handle inline-related attributes (noinline, always_inline, inline hint)
+ // Check for explicit noinline attribute - this takes highest precedence
+ if (fd->hasAttr<NoInlineAttr>()) {
+ func.setInliningAttr(cir::InlineAttr::get(
+ builder.getContext(), cir::InlineKind::NoInline));
+ }
+ // Check for explicit always_inline attribute
+ else if (fd->hasAttr<AlwaysInlineAttr>()) {
+ func.setInliningAttr(cir::InlineAttr::get(
+ builder.getContext(), cir::InlineKind::AlwaysInline));
+ }
+ // Check for inline keyword (provides inline hint)
+ else if (fd->isInlined()) {
+ func.setInliningAttr(cir::InlineAttr::get(
+ builder.getContext(), cir::InlineKind::InlineHint));
+ }
}
void CIRGenModule::setCIRFunctionAttributesForDefinition(
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ba967a43ce59a..84af42258e1ed 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1800,7 +1800,7 @@ void CIRToLLVMFuncOpLowering::lowerFuncAttributes(
attr.getName() == getLinkageAttrNameString() ||
attr.getName() == func.getGlobalVisibilityAttrName() ||
attr.getName() == func.getDsoLocalAttrName() ||
- attr.getName() == func.getInlineKindAttrName() ||
+ attr.getName() == func.getInliningAttrName() ||
(filterArgAndResAttrs &&
(attr.getName() == func.getArgAttrsAttrName() ||
attr.getName() == func.getResAttrsAttrName())))
@@ -1885,10 +1885,10 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite(
assert(!cir::MissingFeatures::opFuncMultipleReturnVals());
- if (auto inlineKind = op.getInlineKind()) {
- fn.setNoInline(inlineKind == cir::InlineKind::NoInline);
- fn.setInlineHint(inlineKind == cir::InlineKind::InlineHint);
- fn.setAlwaysInline(inlineKind == cir::InlineKind::AlwaysInline);
+ if (auto inlining = op.getInlining()) {
+ fn.setNoInline(*inlining == cir::InlineKind::NoInline);
+ fn.setInlineHint(*inlining == cir::InlineKind::InlineHint);
+ fn.setAlwaysInline(*inlining == cir::InlineKind::AlwaysInline);
}
fn.setVisibility_Attr(mlir::LLVM::VisibilityAttr::get(
|
|
@llvm/pr-subscribers-clang Author: None (rashmika0220) ChangesFull diff: https://github.com/llvm/llvm-project/pull/167135.diff 3 Files Affected:
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 6f9a69e697cc3..707b5ff88a356 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -2521,7 +2521,8 @@ def CIR_FuncOp : CIR_Op<"func", [
OptionalAttr<DictArrayAttr>:$res_attrs,
OptionalAttr<FlatSymbolRefAttr>:$aliasee,
CIR_OptionalPriorityAttr:$global_ctor_priority,
- CIR_OptionalPriorityAttr:$global_dtor_priority);
+ CIR_OptionalPriorityAttr:$global_dtor_priority,
+ OptionalAttr<CIR_InlineAttr>:$inlining);
let regions = (region AnyRegion:$body);
diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
index 9f9b2db4771df..c4c260e9e5fe8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -1928,6 +1928,23 @@ void CIRGenModule::setFunctionAttributes(GlobalDecl globalDecl,
"available body!");
assert(!cir::MissingFeatures::attributeNoBuiltin());
}
+
+ // Handle inline-related attributes (noinline, always_inline, inline hint)
+ // Check for explicit noinline attribute - this takes highest precedence
+ if (fd->hasAttr<NoInlineAttr>()) {
+ func.setInliningAttr(cir::InlineAttr::get(
+ builder.getContext(), cir::InlineKind::NoInline));
+ }
+ // Check for explicit always_inline attribute
+ else if (fd->hasAttr<AlwaysInlineAttr>()) {
+ func.setInliningAttr(cir::InlineAttr::get(
+ builder.getContext(), cir::InlineKind::AlwaysInline));
+ }
+ // Check for inline keyword (provides inline hint)
+ else if (fd->isInlined()) {
+ func.setInliningAttr(cir::InlineAttr::get(
+ builder.getContext(), cir::InlineKind::InlineHint));
+ }
}
void CIRGenModule::setCIRFunctionAttributesForDefinition(
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ba967a43ce59a..84af42258e1ed 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1800,7 +1800,7 @@ void CIRToLLVMFuncOpLowering::lowerFuncAttributes(
attr.getName() == getLinkageAttrNameString() ||
attr.getName() == func.getGlobalVisibilityAttrName() ||
attr.getName() == func.getDsoLocalAttrName() ||
- attr.getName() == func.getInlineKindAttrName() ||
+ attr.getName() == func.getInliningAttrName() ||
(filterArgAndResAttrs &&
(attr.getName() == func.getArgAttrsAttrName() ||
attr.getName() == func.getResAttrsAttrName())))
@@ -1885,10 +1885,10 @@ mlir::LogicalResult CIRToLLVMFuncOpLowering::matchAndRewrite(
assert(!cir::MissingFeatures::opFuncMultipleReturnVals());
- if (auto inlineKind = op.getInlineKind()) {
- fn.setNoInline(inlineKind == cir::InlineKind::NoInline);
- fn.setInlineHint(inlineKind == cir::InlineKind::InlineHint);
- fn.setAlwaysInline(inlineKind == cir::InlineKind::AlwaysInline);
+ if (auto inlining = op.getInlining()) {
+ fn.setNoInline(*inlining == cir::InlineKind::NoInline);
+ fn.setInlineHint(*inlining == cir::InlineKind::InlineHint);
+ fn.setAlwaysInline(*inlining == cir::InlineKind::AlwaysInline);
}
fn.setVisibility_Attr(mlir::LLVM::VisibilityAttr::get(
|
Lancern
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. Please add tests for your change.
| fn.setNoInline(inlineKind == cir::InlineKind::NoInline); | ||
| fn.setInlineHint(inlineKind == cir::InlineKind::InlineHint); | ||
| fn.setAlwaysInline(inlineKind == cir::InlineKind::AlwaysInline); | ||
| if (auto inlining = op.getInlining()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (auto inlining = op.getInlining()) { | |
| if (std::optional<cir::InlineKind> inlining = op.getInlining()) { |
| @@ -2521,7 +2521,8 @@ def CIR_FuncOp : CIR_Op<"func", [ | |||
| OptionalAttr<DictArrayAttr>:$res_attrs, | |||
| OptionalAttr<FlatSymbolRefAttr>:$aliasee, | |||
| CIR_OptionalPriorityAttr:$global_ctor_priority, | |||
| CIR_OptionalPriorityAttr:$global_dtor_priority); | |||
| CIR_OptionalPriorityAttr:$global_dtor_priority, | |||
| OptionalAttr<CIR_InlineAttr>:$inlining); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the differences between $inlining and $inline_kind?
andykaylor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR appears to be entirely redundant, duplicating the existing inline handling with a different attribute name.
No description provided.