-
Notifications
You must be signed in to change notification settings - Fork 182
[CIR] Add support for GNU ifunc attribute #2012
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
Open
lanza
wants to merge
2
commits into
gh/lanza/13/base
Choose a base branch
from
gh/lanza/13/head
base: gh/lanza/13/base
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lanza
added a commit
that referenced
this pull request
Nov 23, 2025
This patch implements support for the GNU indirect function (ifunc) attribute in ClangIR, enabling runtime CPU feature detection and function dispatch. Background: The ifunc attribute is a GNU extension that allows selecting function implementations at runtime based on CPU capabilities. A resolver function is called at program startup to return a pointer to the appropriate implementation. Implementation: - Added cir.func.ifunc operation to CIROps.td to represent ifunc declarations in CIR with a resolver function reference - Implemented emitIFuncDefinition() in CIRGenModule to generate cir.func.ifunc operations from AST IFuncDecls - Extended GetOrCreateCIRFunction() to handle ifunc lookups and create/retrieve IFuncOp operations - Updated ReplaceUsesOfNonProtoTypeWithRealFunction() to support replacing ifunc operations when prototypes change - Modified emitDirectCallee() to allow calls through IFuncOp - Added CallOp verifier support to accept IFuncOp as valid callee - Implemented CIRToLLVMIFuncOpLowering to lower cir.func.ifunc to LLVM dialect IFuncOp, using ptr type for resolver_type parameter The implementation closely follows the original CodeGen approach for generating ifunc declarations, adapted to MLIR's operation-based model. Testing: Added comprehensive test coverage in clang/test/CIR/CodeGen/ifunc.c with three scenarios: 1. Basic ifunc with simple resolver 2. Multiple implementations with function pointer typedef 3. Extern declaration followed by ifunc definition Tests verify: - CIR emission produces correct cir.func.ifunc operations - Direct-to-LLVM lowering generates proper ifunc declarations - Output matches original CodeGen behavior Test Plan: $ build/Release/bin/llvm-lit clang/test/CIR/CodeGen/ifunc.c PASS: Clang :: CIR/CodeGen/ifunc.c (1 of 1) ghstack-source-id: 8c51a5b Pull-Request: #2012
lanza
added a commit
that referenced
this pull request
Nov 24, 2025
This patch implements support for the GNU indirect function (ifunc) attribute in ClangIR, enabling runtime CPU feature detection and function dispatch. Background: The ifunc attribute is a GNU extension that allows selecting function implementations at runtime based on CPU capabilities. A resolver function is called at program startup to return a pointer to the appropriate implementation. Implementation: - Added cir.func.ifunc operation to CIROps.td to represent ifunc declarations in CIR with a resolver function reference - Implemented emitIFuncDefinition() in CIRGenModule to generate cir.func.ifunc operations from AST IFuncDecls - Extended GetOrCreateCIRFunction() to handle ifunc lookups and create/retrieve IFuncOp operations - Updated ReplaceUsesOfNonProtoTypeWithRealFunction() to support replacing ifunc operations when prototypes change - Modified emitDirectCallee() to allow calls through IFuncOp - Added CallOp verifier support to accept IFuncOp as valid callee - Implemented CIRToLLVMIFuncOpLowering to lower cir.func.ifunc to LLVM dialect IFuncOp, using ptr type for resolver_type parameter The implementation closely follows the original CodeGen approach for generating ifunc declarations, adapted to MLIR's operation-based model. Testing: Added comprehensive test coverage in clang/test/CIR/CodeGen/ifunc.c with three scenarios: 1. Basic ifunc with simple resolver 2. Multiple implementations with function pointer typedef 3. Extern declaration followed by ifunc definition Tests verify: - CIR emission produces correct cir.func.ifunc operations - Direct-to-LLVM lowering generates proper ifunc declarations - Output matches original CodeGen behavior Test Plan: $ build/Release/bin/llvm-lit clang/test/CIR/CodeGen/ifunc.c PASS: Clang :: CIR/CodeGen/ifunc.c (1 of 1) ghstack-source-id: 8c51a5b Pull-Request: #2012
This was referenced Nov 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
This patch implements support for the GNU indirect function (ifunc)
attribute in ClangIR, enabling runtime CPU feature detection and
function dispatch.
Background:
The ifunc attribute is a GNU extension that allows selecting function
implementations at runtime based on CPU capabilities. A resolver
function is called at program startup to return a pointer to the
appropriate implementation.
Implementation:
declarations in CIR with a resolver function reference
cir.func.ifunc operations from AST IFuncDecls
create/retrieve IFuncOp operations
replacing ifunc operations when prototypes change
LLVM dialect IFuncOp, using ptr type for resolver_type parameter
The implementation closely follows the original CodeGen approach for
generating ifunc declarations, adapted to MLIR's operation-based model.
Testing:
Added comprehensive test coverage in clang/test/CIR/CodeGen/ifunc.c
with three scenarios:
Tests verify:
Test Plan:
$ build/Release/bin/llvm-lit clang/test/CIR/CodeGen/ifunc.c
PASS: Clang :: CIR/CodeGen/ifunc.c (1 of 1)