The full implementation of C and C++ ClangIR #1926
Open
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.
High-Level Goals
!cir.ptr
in the post-conversion IR: No CIR pointer types should survive the CIR→MLIR lowering boundary; all must be llvm.ptr (or rewritten through memref paths if you keep that dual-mode strategy).Recommended Phased Approach
Phase 0: Instrument & Guard (Short)
!cir.ptr
remains or if any cir.* op other than an explicitly whitelisted late op exists.--cir-lower-allow-varargs
) while iterating.Phase 1: Type System & Pointer Foundations
unrealized_conversion_cast
to allow staged replacement.Phase 2: Variadic Function Declaration & Call Lowering
Phase 3: Indirect Call Metadata & Attributes
Phase 4: Aggregate Constant Lowering
CIRAggConstantLowering
pattern:i8 0
if target disallows truly empty (depends on LLVM struct support).Phase 5: Final Pointer Purge
unrealized_conversion_cast
bridging pointer types (your earlier cleanup pattern for ptr already partially does this—extend it to cover multi-use benign cases).Phase 6: Testing & Validation
Add targeted lit tests:
varargs-basic.cir
: direct call to printf-like with mixed int/double/ptr.indirect-call.cir
: take address of function, call through pointer.record-constant.cir
: nested struct + array initializer lowered into single llvm.constant.struct-copy.cir
: ensure cir.copy -> llvm.memcpy with expected size.leftover-ptr-fail.cir
: intentionally leave a cir.ptr and assert failure remark.Each test: run cir-opt --cir-lower-to-mlir (or the pass pipeline) and FileCheck expected textual IR.
Phase 7 (Optional / Later)
Key Helpers & Skeleton Snippets
Type Converter Materializations
Call Lowering (Indirect Case Excerpt)
Aggregate Constant Builder (Pseudo)
(Real code must respect MLIR’s expected attribute kinds: use
AggregateAttr
/ ArrayAttr / numeric attrs; then feed to mlir::LLVM::ConstantOp.)Edge Cases & Risks
Incremental Landing Order (Suggested)
Success Criteria (Definition of Done)
!cir.ptr
types in final IR after the conversion pass (verified by a checker).Suggested Follow-Up Quality Extras
--cir-lower-report-stats
printing counts of: ptr bridges created/pruned, calls lowered (direct/indirect/vararg), aggregates materialized, fallbacks.