Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 2.92 KB

File metadata and controls

33 lines (25 loc) · 2.92 KB

Title: ProXPL Compiler Backend Fixes Version: 1.0 Date: 2025-12-11 Author: ProgrammerKR

ProXPL v1.3.3 Compiler Backend Fixes

Overview

Version 1.3.3 includes critical stability and correctness fixes across the ProXPL compiler's Intermediate Representation (IR) generation, optimization passes, and the LLVM backend. These fixes address malformed control-flow graphs, memory bounds errors, and strictly enforce LLVM IR validator constraints for PHI nodes.

Detailed Fixes

1. Control-Flow Graph (CFG) Integrity (ir.c)

  • addEdge() Logic: The edge creation logic has been re-implemented to correctly handle bidirectional links (successors and predecessors) without aborting early on overlapping edge inserts. This ensures accurate graph traversal for dominator and SSA passes.
  • Conditional Branches (computeCFGLinks): IR_OP_JUMP_IF parsing was updated to explicitly bind both the Then and Else successor branches to the CFG, fixing lost control-flow paths.

2. IR Generation (ir_gen.c)

  • Function Calls (EXPR_CALL): Added complete generation logic to recursively evaluate callee and argument expressions, finally emitting valid IR_OP_CALL instructions.
  • Terminator Strictness: Rewrote STMT_IF and STMT_WHILE jump logic to construct single 3-operand conditional terminators (IR_OP_JUMP_IF(Cond, Then, Else)) instead of relying on subsequent redundant unconditional jumps, which violated LLVM basic block rules.

3. Optimization and Memory Safety (ir_opt.c)

  • Heap Overflow Prevention: The memory-to-register promotion pass (promoteMemoryToRegisters) was upgraded to dynamically resize (realloc) tracking buffers for variable allocations instead of hitting a hard 1024-slot limit, preventing buffer overflows on large functions.
  • Zero-Initialization: The isConst tracking array in the constant folding pass is now safely zero-initialized using memset during reallocation.
  • Phi Node Operands: When variables lack a reaching definition from a predecessor (currentVersion == -1), the optimizer now intentionally pushes a -1 placeholder into the Phi operand list instead of dropping the operand entirely, preserving the structural integrity required by LLVM.

4. LLVM Backend Validity (backend_llvm.cpp)

  • Dummy NIL Values: The LLVM emitter's Pass 3 (addIncoming) has been fortified to intercept -1 (uninitialized) SSA references and inject a dummy NIL LLVM constant (0x7ffc000000000001). This ensures that every LLVM PHINode receives exactly one incoming value per predecessor, completely resolving LLVM IR Verifier rejections.

Future Performance Roadmap

The architectural foundation has been reviewed for future performance milestones, specifically targeting compilation speed:

  1. Translating string-based token operators to native Enums (ast.h).
  2. Adopting O(1) hash maps for variable symbol lookups.
  3. Replacing iterative dataflow algorithms with Lengauer-Tarjan dominator trees.