Skip to content

Conversation

@rashmika0220
Copy link

No description provided.

@github-actions
Copy link

github-actions bot commented Nov 8, 2025

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 @ followed by their GitHub username.

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.

@llvmbot llvmbot added clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project labels Nov 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2025

@llvm/pr-subscribers-clangir

Author: None (rashmika0220)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/167135.diff

3 Files Affected:

  • (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+2-1)
  • (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+17)
  • (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+5-5)
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(

@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2025

@llvm/pr-subscribers-clang

Author: None (rashmika0220)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/167135.diff

3 Files Affected:

  • (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+2-1)
  • (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+17)
  • (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+5-5)
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(

Copy link
Member

@Lancern Lancern left a 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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Member

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?

Copy link
Contributor

@andykaylor andykaylor left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category ClangIR Anything related to the ClangIR project

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants