This repository was archived by the owner on Feb 21, 2026. It is now read-only.
[CIR] Add support for GNU ifunc attribute#2012
Draft
lanza wants to merge 2 commits intogh/lanza/13/basefrom
Draft
[CIR] Add support for GNU ifunc attribute#2012lanza wants to merge 2 commits intogh/lanza/13/basefrom
lanza wants to merge 2 commits intogh/lanza/13/basefrom
Conversation
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
Draft
lanza
added a commit
that referenced
this pull request
Nov 25, 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 25, 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 26, 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 26, 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 26, 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 26, 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 27, 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
to lanza/llvm-project
that referenced
this pull request
Dec 4, 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: 8c51a5b4d07d9228f11f4fffd8c9aa9afea576be Pull-Request: llvm/clangir#2012
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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)