feat(phase131): LLVM backend re-enable & PHI ordering bug discovery
Phase 131: JoinIR → LLVM individual fixes (minimal scope) ## Modifications ### 1. LLVM Backend Re-enable ✅ - Built with --features llvm to enable real LLVM execution - Verified Python/llvmlite environment (llvmlite 0.45.1) - Fixed llvmlite deprecated API: removed llvm.initialize() call - Successfully moved from Mock backend to real LLVM harness execution ### 2. PHI Instruction Ordering Bug Discovery ⚠️ - Discovered critical bug: PHI nodes placed AFTER terminator instructions - LLVM IR constraint: PHI must be at block start, before any non-PHI - Root cause: finalize_phis() in llvm_builder.py emits PHIs after block termination - Affects all 6 tests with control flow merges ### 3. ConsoleBox LLVM Integration ⚠️ - Confirmed ConsoleBox not registered in Rust VM environment - Deferred to Phase 132 (prerequisite issue) ## Results Modified files: - src/llvm_py/llvm_builder.py: Removed deprecated llvm.initialize() - docs/development/current/main/phase130_joinir_llvm_baseline.md: Added Phase 131 results - CURRENT_TASK.md: Added Phase 131 completion report Test results: - ✅ peek_expr_block.hako: LLVM execution success (Result: 1) - ❌ 6/7 tests: PHI ordering bug (requires Phase 132 refactoring) ## Success Criteria - ✅ LLVM backend minimal re-enable (1/7 test passing) - ⚠️ PHI ordering bug discovered and documented - ⚠️ ConsoleBox integration deferred to Phase 132 ## Phase 132 Handoff Priority 1: Fix PHI instruction ordering bug (finalize_phis() refactoring) Priority 2: Resolve ConsoleBox registration issue Priority 3: Enable remaining test cases for LLVM 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
130
CURRENT_TASK.md
130
CURRENT_TASK.md
@ -1054,24 +1054,118 @@ invalid operation: Unknown Box type: ConsoleBox. Available: Main
|
|||||||
|
|
||||||
### 🚀 次のステップ
|
### 🚀 次のステップ
|
||||||
|
|
||||||
**Phase 131: JoinIR→LLVM 個別修正ライン**(予定)
|
**Phase 132: LLVM PHI命令順序バグ修正 + ConsoleBox統合**(予定)
|
||||||
|
|
||||||
Phase 130 で検出された問題を優先度順に潰す:
|
---
|
||||||
|
|
||||||
#### 優先度1: LLVM Backend有効化
|
## 🎯 Phase 131: JoinIR → LLVM 個別修正ライン(完了)✅ 2025-12-04
|
||||||
- [ ] `cargo build --release --features llvm` 実行
|
|
||||||
- [ ] Python/llvmlite 環境確認(`src/llvm_py/venv`)
|
### 📋 実装内容
|
||||||
- [ ] 実LLVM実行での7テスト再実行
|
|
||||||
|
**目的**: Phase 130 で観測した LLVM 側の「赤ポイント3つ」を、設計を崩さずピンポイントで修正
|
||||||
#### 優先度2: ConsoleBox問題解決
|
|
||||||
- [ ] Rust VMでのConsoleBox登録状況調査
|
**スコープ**:
|
||||||
- [ ] Phase 122で解決済みの内容との差分確認
|
1. ✅ LLVM backend の最小 re-enable(代表1本を green に)
|
||||||
- [ ] PluginBox登録機構の修正(必要に応じて)
|
2. ⚠️ ConsoleBox の LLVM ライン統一(前提条件未達)
|
||||||
|
3. ⚠️ JoinIR→MIR→LLVM の成功パス確立(PHI ordering bug発見)
|
||||||
#### 優先度3: LLVM IR生成確認
|
|
||||||
- [ ] MIR → LLVM IR lowering実装状況調査
|
### 📊 Phase 131 実施結果
|
||||||
- [ ] 未対応命令の洗い出し(BoxCall/NewBox/PHI等)
|
|
||||||
- [ ] 最小ケース(joinir_if_select_simple.hako)での詳細検証
|
#### 修正1: LLVM Backend Re-enable ✅
|
||||||
|
|
||||||
|
**実施内容**:
|
||||||
|
- ✅ `cargo build --release --features llvm` でLLVM機能有効化
|
||||||
|
- ✅ Python/llvmlite環境確認(llvmlite 0.45.1)
|
||||||
|
- ✅ llvmlite非推奨API対応: `llvm.initialize()` 削除
|
||||||
|
|
||||||
|
**修正ファイル**:
|
||||||
|
- `src/llvm_py/llvm_builder.py`: `llvm.initialize()` 呼び出しコメントアウト
|
||||||
|
|
||||||
|
**成果**:
|
||||||
|
- ✅ `peek_expr_block.hako`: LLVM実行成功(Result: 1、Rust VM: RC: 1)
|
||||||
|
- ✅ Mock backend → 実LLVM実行への移行成功
|
||||||
|
|
||||||
|
#### 修正2: PHI命令順序バグ発見 ⚠️
|
||||||
|
|
||||||
|
**検出された問題**:
|
||||||
|
LLVM IR生成時、PHI命令がreturn命令の**後**に配置されるバグを発見。
|
||||||
|
|
||||||
|
**問題例**(生成されたLLVM IR):
|
||||||
|
```llvm
|
||||||
|
bb5:
|
||||||
|
ret i64 %"ret_phi_16"
|
||||||
|
%"ret_phi_16" = phi i64 [0, %"bb3"], [0, %"bb4"] ; ← エラー!PHIはretの前に必要
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**LLVM IRの制約**:
|
||||||
|
- PHI命令はBasic Blockの**先頭**に配置必須
|
||||||
|
- terminator命令(ret/br/switch等)の後に命令を配置不可
|
||||||
|
|
||||||
|
**影響範囲**:
|
||||||
|
- ❌ phase123_simple_if.hako: LLVM IR parsing error
|
||||||
|
- ❌ loop_min_while.hako: LLVM IR parsing error
|
||||||
|
- ❌ 制御フロー合流を含む全6テストが影響
|
||||||
|
|
||||||
|
**根本原因**:
|
||||||
|
- `src/llvm_py/llvm_builder.py`の`finalize_phis()`関数
|
||||||
|
- PHI nodesがblock終端処理後に追加されている
|
||||||
|
- LLVM IRbuilderのblock構築順序の設計問題
|
||||||
|
|
||||||
|
**Phase 132への引き継ぎ**: `finalize_phis()`の大規模リファクタリングが必要
|
||||||
|
|
||||||
|
#### 修正3: ConsoleBox LLVM統合 ⚠️
|
||||||
|
|
||||||
|
**現状確認**:
|
||||||
|
- ❌ Rust VM環境でもConsoleBox未登録
|
||||||
|
- ❌ LLVM環境でもConsoleBox未対応
|
||||||
|
|
||||||
|
**Phase 132への引き継ぎ**: ConsoleBox登録はRust VM側の前提条件
|
||||||
|
|
||||||
|
### 📈 Phase 131 実行結果サマリー
|
||||||
|
|
||||||
|
**修正前(Phase 130)**:
|
||||||
|
| 経路 | PASS | FAIL | 成功率 |
|
||||||
|
|--------------|------|------|--------|
|
||||||
|
| Rust VM | 6 | 1 | 85.7% |
|
||||||
|
| LLVM harness | 0 | 7 | 0% (Mock) |
|
||||||
|
|
||||||
|
**修正後(Phase 131)**:
|
||||||
|
| 経路 | PASS | FAIL | 成功率 | メモ |
|
||||||
|
|--------------|------|------|--------|------|
|
||||||
|
| Rust VM | 6 | 1 | 85.7% | 変更なし |
|
||||||
|
| LLVM harness | 1 | 6 | 14.3% | peek_expr_block.hako成功 |
|
||||||
|
|
||||||
|
**成功ケース**:
|
||||||
|
- ✅ `peek_expr_block.hako`: Rust VM ✅ → LLVM ✅(Result: 1)
|
||||||
|
|
||||||
|
**失敗ケース**(PHI ordering bug):
|
||||||
|
- ❌ `loop_min_while.hako`
|
||||||
|
- ❌ `phase123_simple_if.hako`
|
||||||
|
- ❌ `phase123_while_loop.hako`
|
||||||
|
- ❌ `joinir_if_select_simple.hako`
|
||||||
|
- ❌ `joinir_min_loop.hako`
|
||||||
|
- ❌ `esc_dirname_smoke.hako`(ConsoleBox未登録)
|
||||||
|
|
||||||
|
### 🏆 Phase 131 の価値
|
||||||
|
|
||||||
|
**最小スコープ達成**:
|
||||||
|
- ✅ LLVM backend実動作確認(Mock → Real)
|
||||||
|
- ✅ 1/7テスト成功(目標2-3本だが、PHI問題で制限)
|
||||||
|
- ✅ 根本的なPHI ordering bug発見・記録
|
||||||
|
|
||||||
|
**Phase 132への明確な引き継ぎ**:
|
||||||
|
1. **最優先**: PHI命令順序バグ修正(`finalize_phis()`リファクタリング)
|
||||||
|
2. **優先**: ConsoleBox登録問題解決
|
||||||
|
3. **通常**: 残りテストケースのLLVM対応
|
||||||
|
|
||||||
|
**設計を崩さない修正方針の実践**:
|
||||||
|
- 1箇所の軽微な修正(`llvm.initialize()`削除)で1テスト成功
|
||||||
|
- 大規模修正が必要な問題は無理せずPhase 132に回した
|
||||||
|
|
||||||
|
### 🚀 次のステップ
|
||||||
|
|
||||||
|
**Phase 132: LLVM PHI命令順序バグ修正 + ConsoleBox統合**
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -389,3 +389,101 @@ invalid operation: Unknown Box type: ConsoleBox. Available: Main
|
|||||||
2. ConsoleBoxのRust VM登録問題が再発
|
2. ConsoleBoxのRust VM登録問題が再発
|
||||||
3. JoinIR → MIR変換は全て正常動作
|
3. JoinIR → MIR変換は全て正常動作
|
||||||
4. Phase 131での優先課題が明確化
|
4. Phase 131での優先課題が明確化
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Phase 131 修正内容(2025-12-04実施)
|
||||||
|
|
||||||
|
### 修正1: LLVM Backend Re-enable ✅
|
||||||
|
|
||||||
|
**実施内容**:
|
||||||
|
1. `cargo build --release --features llvm` でLLVM機能有効化ビルド実行
|
||||||
|
2. Python/llvmlite環境確認(llvmlite 0.45.1インストール済み)
|
||||||
|
3. llvmlite非推奨API対応: `llvm.initialize()` 削除(自動初期化に移行)
|
||||||
|
|
||||||
|
**修正ファイル**:
|
||||||
|
- `src/llvm_py/llvm_builder.py`: `llvm.initialize()` 呼び出しをコメントアウト
|
||||||
|
|
||||||
|
**結果**:
|
||||||
|
- ✅ `peek_expr_block.hako`: LLVM実行成功(Result: 1、Rust VM: RC: 1)
|
||||||
|
- ✅ Mock backendから実LLVM実行への移行成功
|
||||||
|
- ✅ LLVM harness経路が正常動作
|
||||||
|
|
||||||
|
### 修正2: PHI命令順序バグ発見 ⚠️
|
||||||
|
|
||||||
|
**検出された問題**:
|
||||||
|
LLVM IR生成時、PHI命令がreturn命令の**後**に配置されるバグを発見。
|
||||||
|
|
||||||
|
**問題例**(生成されたLLVM IR):
|
||||||
|
```llvm
|
||||||
|
bb5:
|
||||||
|
ret i64 %"ret_phi_16"
|
||||||
|
%"ret_phi_16" = phi i64 [0, %"bb3"], [0, %"bb4"] ; ← エラー!PHIはretの前に必要
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**LLVM IRの制約**:
|
||||||
|
- PHI命令はBasic Blockの**先頭**に配置必須
|
||||||
|
- terminator命令(ret/br/switch等)の後に命令を配置不可
|
||||||
|
|
||||||
|
**影響範囲**:
|
||||||
|
- ❌ phase123_simple_if.hako: LLVM IR parsing error
|
||||||
|
- ❌ loop_min_while.hako: LLVM IR parsing error
|
||||||
|
- ❌ 制御フロー合流を含む全テストが影響
|
||||||
|
|
||||||
|
**根本原因**:
|
||||||
|
- `src/llvm_py/llvm_builder.py`の`finalize_phis()`関数
|
||||||
|
- PHI nodesがblock終端処理後に追加されている
|
||||||
|
- LLVM IRbuilderのblock構築順序の設計問題
|
||||||
|
|
||||||
|
**Phase 132への引き継ぎ**:
|
||||||
|
この問題は`finalize_phis()`の大規模リファクタリングが必要(100行以上の関数)。
|
||||||
|
Phase 131の最小スコープを超えるため、Phase 132で対応。
|
||||||
|
|
||||||
|
### 修正3: ConsoleBox LLVM統合 ⚠️
|
||||||
|
|
||||||
|
**現状確認**:
|
||||||
|
- ❌ Rust VM環境でもConsoleBox未登録(`apps/tests/esc_dirname_smoke.hako`実行不可)
|
||||||
|
- ❌ LLVM環境でもConsoleBox未対応
|
||||||
|
|
||||||
|
**Phase 132への引き継ぎ**:
|
||||||
|
ConsoleBoxの登録・実装はRust VM側の問題。LLVM統合の前提条件未達のため、Phase 132で対応。
|
||||||
|
|
||||||
|
### Phase 131 実行結果サマリー
|
||||||
|
|
||||||
|
**修正前(Phase 130)**:
|
||||||
|
| 経路 | PASS | PARTIAL | FAIL | 成功パス |
|
||||||
|
|--------------|------|---------|------|---------|
|
||||||
|
| Rust VM | 6 | 0 | 1 | 6/7 |
|
||||||
|
| LLVM harness | 0 | 7 (Mock)| 0 | 0/7 |
|
||||||
|
|
||||||
|
**修正後(Phase 131)**:
|
||||||
|
| 経路 | PASS | PARTIAL | FAIL | 成功パス | メモ |
|
||||||
|
|--------------|------|---------|------|---------|------|
|
||||||
|
| Rust VM | 6 | 0 | 1 | 6/7 | 変更なし |
|
||||||
|
| LLVM harness | 1 | 0 | 6 | 1/7 | peek_expr_block.hako成功 |
|
||||||
|
|
||||||
|
**成功ケース詳細**:
|
||||||
|
- ✅ `peek_expr_block.hako`: Rust VM ✅ → LLVM ✅(Result: 1)
|
||||||
|
|
||||||
|
**失敗ケース詳細**:
|
||||||
|
- ❌ `loop_min_while.hako`: PHI ordering bug
|
||||||
|
- ❌ `phase123_simple_if.hako`: PHI ordering bug
|
||||||
|
- ❌ `phase123_while_loop.hako`: PHI ordering bug
|
||||||
|
- ❌ `joinir_if_select_simple.hako`: PHI ordering bug
|
||||||
|
- ❌ `joinir_min_loop.hako`: PHI ordering bug
|
||||||
|
- ❌ `esc_dirname_smoke.hako`: ConsoleBox未登録
|
||||||
|
|
||||||
|
### Phase 131 完了判定
|
||||||
|
|
||||||
|
**達成内容**:
|
||||||
|
1. ✅ LLVM backend最小re-enable成功(peek_expr_block.hako ✅)
|
||||||
|
2. ⚠️ PHI ordering bug発見・記録(Phase 132対応)
|
||||||
|
3. ⚠️ ConsoleBox問題確認(Phase 132対応)
|
||||||
|
|
||||||
|
**最小成功パス確立**: ✅ 1/7テストで成功(目標:2-3本だが、根本的なPHI問題により1本に制限)
|
||||||
|
|
||||||
|
**Phase 132への優先課題**:
|
||||||
|
1. **最優先**: PHI命令順序バグ修正(`finalize_phis()`リファクタリング)
|
||||||
|
2. **優先**: ConsoleBox登録問題解決
|
||||||
|
3. **通常**: 残りテストケースのLLVM対応
|
||||||
|
|||||||
@ -89,8 +89,8 @@ class NyashLLVMBuilder:
|
|||||||
"""Main LLVM IR builder for Nyash MIR"""
|
"""Main LLVM IR builder for Nyash MIR"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Initialize LLVM
|
# Initialize LLVM (llvm.initialize() is deprecated in newer llvmlite)
|
||||||
llvm.initialize()
|
# llvm.initialize() # Removed - now handled automatically
|
||||||
llvm.initialize_native_target()
|
llvm.initialize_native_target()
|
||||||
llvm.initialize_native_asmprinter()
|
llvm.initialize_native_asmprinter()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user