How tarunnagarajan/compiler-opt works
This is a research framework for hierarchical reinforcement learning of LLVM optimization policies. The main workflow selects an IR benchmark, extracts state, chooses a strategic macro-action and tactical pass refinement, applies compiler passes, then measures the result for the next decision and reward. Training and evaluation scripts support the research loop, including world-model prediction and baseline comparisons. Relationships among components are limited to those stated in the README or visible in indexed imports; several model and measurement internals were not sampled.
Main entry points: compiler_env.py RL compiler environment · hrl_agent.py Hierarchical policy · world_model.py World model · scripts Policy and model training
Components 25
Compiler environment
- RL compiler environment
src/env/compiler_env.py - LLVM and action config
src/config.py - Hardware profiler
src/env/hardware_profiler.py
IR representation
- IR parser and CFG
src/features/ir_parser.py - Scalar features
src/features/feature_vector.py - IR graph extraction
src/features/ir_graph_extractor.py - Loop-aware extraction
src/features/ir_graph_extractor_v5.py - Graph encoder
src/features/graph_encoder.py
Learning models
- World model
src/models/world_model.py - Scale-aware world model
src/models/world_model_v7.py - Model graph encoder
src/models/graph_encoder.py - Graph encoder V6
src/models/graph_encoder_v6.py - Hierarchical policy
src/models/hrl_agent.py - Tactical worker
src/models/hrl_worker.py - Pass history encoder
src/models/history_encoder.py - Meta calibrator
src/models/meta_calibrator.py
Passes and metrics
- Macro actions
src/actions/macro_actions.py - Micro actions
src/actions/micro_actions.py - Pass executor
src/passes/pass_executor.py - Metrics and runtime
src/passes/metrics.py
Research workflows
- Policy and model training
scripts - Evaluation and audits
scripts
Other components
- Researcher
- Benchmark inputs
- LLVM toolchain
Connections 26
- Researcher → RL compiler environment: starts episode
README.md - Benchmark inputs → RL compiler environment: supplies IR
README.md - RL compiler environment → LLVM and action config: uses configuration
src/env/compiler_env.py - RL compiler environment → IR parser and CFG: parses IR
src/env/compiler_env.py - RL compiler environment → Pass executor: applies passes
src/env/compiler_env.py - RL compiler environment → Metrics and runtime: measures outcomes
README.md - RL compiler environment → LLVM toolchain: invokes compiler
README.md - RL compiler environment → Hardware profiler: profiles hardware
- IR parser and CFG → Scalar features: provides IR stats
src/features/feature_vector.py - RL compiler environment → Graph encoder V6: uses graph encoder
src/env/compiler_env.py - World model → Scale-aware world model: uses V7 model
src/models/world_model.py - Scale-aware world model → Graph encoder V6: uses encoder
src/models/world_model_v7.py - Hierarchical policy → Tactical worker: selects refinements
README.md - Hierarchical policy → Pass history encoder: encodes pass history
README.md - Hierarchical policy → World model: predicts action effects
- Hierarchical policy → Macro actions: chooses objectives
README.md - Tactical worker → Micro actions: selects pass refinements
src/models/hrl_worker.py - RL compiler environment → Macro actions: accepts macro actions
src/env/compiler_env.py - RL compiler environment → Micro actions: accepts refined passes
src/env/compiler_env.py - Metrics and runtime → LLVM toolchain: compiles benchmarks
src/passes/metrics.py - Meta calibrator → World model: calibrates predictions
- Policy and model training → RL compiler environment: trains against
README.md - Policy and model training → Hierarchical policy: trains policy
README.md - Policy and model training → World model: trains model
README.md - Evaluation and audits → Hierarchical policy: evaluates behavior
README.md - Evaluation and audits → LLVM toolchain: compares baselines
README.md