ir_pipeline

Documents the legacy IR and XIR compiler pipeline, AST lowering, and optimization passes.

1.0k|108|Updated Nov 20, 2020
One-click install
npx skills add https://github.com/LuisaGroup/LuisaCompute --skill ir-pipeline
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ir_pipeline
Source: https://github.com/LuisaGroup/LuisaCompute/tree/main/.agents/skills/ir_pipeline
Command: npx skills add https://github.com/LuisaGroup/LuisaCompute --skill ir-pipeline

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Compiler contributors working on LuisaCompute need a clear map of how DSL code flows from AST through two intermediate representations (legacy Rust-based IR and the newer pure C++ XIR) into backend codegen, plus a catalog of available optimization passes.

Core Features & Use Cases

  • Dual IR Pipeline Reference: Explains the legacy Rust IR path (ast2json → Rust FFI) and the preferred XIR path (ast2xir translator, xir2json serialization, xir2ast round-trip).
  • XIR Architecture Guide: Documents the value hierarchy, instruction set (control flow, memory, SSA, arithmetic, resource, atomic, autodiff), structured control flow with merge blocks, and metadata system.
  • Optimization Pass Catalog: Lists 40+ passes in src/xir/passes/ covering DCE, mem2reg, GVN, SCCP, LICM, SROA, inlining, and autodiff, with pipeline factory helpers.
  • Use Case: When adding a new XIR optimization pass, follow the documented convention: create the pass in src/xir/passes/, register it in CMakeLists.txt, accept a Module or Function, and use XIRBuilder with replace_all_uses_with().

Quick Start

Explain how the LuisaCompute XIR pipeline lowers an AST for-loop into LoopInst blocks and which passes optimize it.

Frequently Asked Questions about ir_pipeline

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new XIR optimization pass in LuisaCompute?

Create a source file in src/xir/passes/ and a header in include/luisa/xir/passes/, then register it in src/xir/CMakeLists.txt. The pass should accept a Module or Function reference, use XIRBuilder for instruction creation, and call replace_all_uses_with() for value substitution.

What is the difference between LuisaCompute IR and XIR?

The legacy IR is implemented in Rust under src/rust/ and reached via ast2json plus C FFI, while XIR is pure C++ under src/xir/ with yyjson-based serialization. XIR is under active development and is the preferred path; the Rust IR is maintained for compatibility.

How does XIR represent control flow for GPU codegen?

XIR uses structured control flow with explicit merge blocks: IfInst has true/false/merge blocks and LoopInst has prepare/body/update/merge blocks. The destructure_cfg pass flattens this to raw branches and restructure_cfg recovers the structured form.

Which SSA and scalar optimization passes does XIR provide?

XIR provides mem2reg for alloca-to-SSA promotion, DCE, GVN, early CSE, SCCP, constant folding, algebraic simplification, reassociation, and phi cleanup. Loop passes include LICM, indvar simplification, and loop rotation.

Can XIR modules be serialized for debugging or transport?

Yes, XIR supports yyjson-based serialization through xir2json and json2xir translators in src/xir/translators/, plus xir2ast round-tripping and xir2text output. These are useful for cross-process transport and debugging.