Skip to content

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Dec 24, 2025

No description provided.

Phase 1: Consolidated 10 comparison functions (instcombine.rs)

  - Created CmpInfo struct with identity_result and compare function pointer
  - Created get_cmp_info() and unified simplify_comparison() function
  - Replaced 10 individual simplify_setXX() functions (~175 lines saved)

  Phase 2: Broke down emit_call() in both architectures

  - x86_64: Created cc/arch/x86_64/call.rs with CallArgInfo, classify_call_args(), push_stack_args(), save_clobbered_arg_regs(), setup_register_args(), handle_call_return_value(), etc.
  - aarch64: Created cc/arch/aarch64/call.rs with setup_sret_arg(), setup_darwin_variadic_args(), setup_register_args(), handle_call_return_value(), etc.
  - Reduced emit_call() from ~465/~403 lines to ~40 lines each

  Phase 3: Consolidated 3 bitwise op functions (instcombine.rs)

  - Created SelfOpResult enum and BitwiseInfo struct
  - Created get_bitwise_info() and unified simplify_bitwise() function
  - Replaced simplify_and(), simplify_or(), simplify_xor() (~50 lines saved)

  Phase 4: Added symbol-checking helpers (symbol.rs)

  - Added lookup_enum_constant() to SymbolTable
  - Updated parser.rs and ctags.rs to use the new helpers

  Phase 5: Refactored emit_load/emit_store (aarch64 codegen)

  - Created ComputedAddr enum with Direct, WithSetup, Global variants
  - Created compute_mem_addr() helper function
  - Simplified emit_load and emit_store address resolution (~80 lines of duplicated logic consolidated)
@jgarzik jgarzik requested a review from Copilot December 24, 2025 05:09
@jgarzik jgarzik self-assigned this Dec 24, 2025
@jgarzik jgarzik added enhancement New feature or request cleanup labels Dec 24, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the C99 compiler backend code by extracting large monolithic functions into separate, focused modules. The changes improve code organization without altering functionality.

Key changes:

  • Extracted expression, call, and feature code generation into separate modules for x86_64 and AArch64
  • Unified bitwise and comparison simplification logic in IR instruction combiner
  • Removed platform-reserved X18 register from AArch64 allocator
  • Minor test and formatting improvements

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sys/who.rs Fixed header formatting by removing extraneous empty string placeholder
m4/tests/integration_test.rs Simplified test build logic, removed redundant synchronization
cc/symbol.rs Added helper method for enum constant lookup
cc/parse/parser.rs Refactored to use new enum constant lookup helper
cc/ir/instcombine.rs Unified bitwise and comparison simplification using data-driven approach
cc/ctags.rs Updated to use method instead of direct field access
cc/arch/x86_64/mod.rs Declared new extracted modules
cc/arch/x86_64/features.rs New file with variadic, bswap, bit counting, setjmp/longjmp/alloca support
cc/arch/x86_64/expression.rs New file with binary/unary operations, mul/div, compare, extend
cc/arch/x86_64/call.rs New file with call argument handling and return value processing
cc/arch/x86_64/codegen.rs Refactored to extract code into new modules, changed visibility to pub(super)
cc/arch/aarch64/regalloc.rs Removed platform-reserved X18 register
cc/arch/aarch64/mod.rs Declared new extracted modules
cc/arch/aarch64/features.rs New file with AArch64 variadic, bswap, bit ops, setjmp/longjmp/alloca
cc/arch/aarch64/expression.rs New file with AArch64 binary/unary ops, mul/div, compare, extend
cc/arch/aarch64/call.rs New file with AArch64 call handling

The refactoring successfully improves maintainability by organizing related functionality into cohesive modules while preserving the existing implementation logic.

@jgarzik jgarzik merged commit 87eab11 into main Dec 24, 2025
10 checks passed
@jgarzik jgarzik deleted the updates branch December 24, 2025 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants