Published on

IREE Pass 与 Dialect 完整指南

Authors
  • avatar
    Name
    alan
    Twitter

本文档记录了 IREE 编译器中所有自定义的 Dialect 和 Pass,包括它们的作用、作用对象以及在编译 Pipeline 中的顺序。


目录

  1. IREE 自有 Dialect 列表
  2. Pass 总览
  3. Pass 详细分类
  4. 编译 Pipeline 阶段与 Pass 顺序
  5. 关键源文件索引
  6. Pass 命名与位置对应关系

1. IREE 自有 Dialect 列表

IREE 编译器共定义了 19 个 自定义 Dialect:

Dialect 名称命名空间定义文件主要用途
utilIREE::UtilDialect/Util/IR/UtilBase.tdIREE 各子 dialect 通用的类型与工具 op
flowIREE::FlowDialect/Flow/IR/FlowBase.td建模执行数据流与分区(dispatch region)
streamIREE::StreamDialect/Stream/IR/StreamDialect.td显式异步调度执行,位于 flow 与 hal 之间
halIREE::HALDialect/HAL/IR/HALDialect.td硬件抽象层(Vulkan-like,无图形部分)
vmIREE::VMDialect/VM/IR/VMBase.td抽象虚拟机,可序列化为字节码或继续 lower
vmvxIREE::VMVXDialect/VMVX/IR/VMVXBase.tdVM 向量扩展/微内核库方言
iree_linalg_extIREE::LinalgExtDialect/LinalgExt/IR/LinalgExtBase.tdLinalg 非结构化/实验性扩展
iree_tensor_extIREE::TensorExtDialect/TensorExt/IR/TensorExtBase.tdTensor 方言实验性扩展
iree_encodingIREE::EncodingDialect/Encoding/IR/EncodingBase.td张量编码属性与相关 op(data-tiling)
iree_codegenIREE::CodegenCodegen/Dialect/Codegen/IR/IREECodegenDialect.td代码生成通用属性与状态
iree_cpuIREE::CPUCodegen/Dialect/CPU/IR/IREECPUDialect.tdCPU 代码生成专用属性/op
iree_gpuIREE::GPUCodegen/Dialect/GPU/IR/IREEGPUDialect.tdGPU 代码生成专用属性/op
iree_mapIREE::MapCodegen/Dialect/Map/IR/IREEMapBase.td描述层次化坐标映射的 map 代数
pcfIREE::PCFCodegen/Dialect/PCF/IR/PCFBase.td并行控制流(Parallel Control Flow)
iree_vector_extIREE::VectorExtCodegen/Dialect/VectorExt/IR/VectorExtBase.tdVector 方言实验性扩展
hal_inlineIREE::HAL::InlineModules/HAL/Inline/IR/HALInlineBase.td进程内同步 HAL 互操作运行时模块
hal_loaderIREE::HAL::LoaderModules/HAL/Loader/IR/HALLoaderBase.td动态加载可执行文件并调度
io_parametersIREE::IO::ParametersModules/IO/Parameters/IR/IOParametersBase.td外部参数资源管理 API
checkIREE::CheckModules/Check/IR/CheckBase.td测试断言 dialect

Dialect 注册入口

  • 核心 Dialect: Tools/init_iree_dialects.h - 注册前 18 个 Dialect
  • 模块 Dialect: Tools/init_compiler_modules.h - 注册 check

2. Pass 总览

IREE 编译器共定义了 486 个 自定义 Pass,按组件分类如下:

组件Pass 数量主要目录
Codegen243Codegen/Common/, Codegen/LLVMCPU/, Codegen/LLVMGPU/, Codegen/SPIRV/, Codegen/VMVX/
Dialect 转换152Dialect/{Flow,Stream,HAL,Util,VM,VMVX,LinalgExt,TensorExt}/Transforms/
DispatchCreation31DispatchCreation/
GlobalOptimization22GlobalOptimization/
Preprocessing15Preprocessing/Common/
InputConversion9InputConversion/Common/
Modules8Modules/HAL/Inline/, Modules/HAL/Loader/, Modules/IO/Parameters/
Bindings3Bindings/Native/, Bindings/TFLite/
Transforms2Transforms/
ConstEval1ConstEval/
合计486

3. Pass 详细分类

3.1 Bindings(3 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-abi-convert-streamable-opsConvertStreamableOpsPassModuleOp将输入 dialect 中可流式传输的 op 转换为 IREE dialect 形式
--iree-abi-wrap-entry-pointsWrapEntryPointsPassModuleOp包装入口函数以兼容原生 IREE ABI
--iree-tflite-wrap-entry-pointsWrapEntryPointsPassModuleOp包装入口函数以兼容 IREE TFLite C 绑定

3.2 Codegen / Common / CPU(3 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-codegen-cpu-lower-to-ukernelsCPULowerToUKernelsPass-将 IR 中可映射到微内核的部分分离出来
--iree-codegen-cpu-prepare-ukernelsCPUPrepareUkernelsPassFunctionOpInterface对 op 进行降维以适配现有 ukernel 要求
--iree-codegen-cpu-propagate-data-layoutCPUPropagateDataLayoutPassFunctionOpInterface传播 pack/unpack/reshape 使整个 dispatch 数据布局一致

3.3 Codegen / Common / GPU(43 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-codegen-amdgpu-lower-async-dmaAMDGPULowerAsyncDMAPassFunctionOpInterface将 async_dma 降到 amdgpu.gather_to_lds
--iree-codegen-amdgpu-lower-coalesced-dma-to-gather-ldsAMDGPULowerCoalescedDMAToGatherLDSPassFunctionOpInterface将合并 DMA 降到 amdgpu.gather_to_lds
--iree-codegen-gpu-decompose-horizontally-fused-gemmsDecomposeHorizontallyFusedGemmsPassFunctionOpInterface分解水平融合的 GEMM
--iree-codegen-expand-gpu-opsExpandGPUOpsPassFunctionOpInterface展开高级 GPU op(如 clustered subgroup_reduce)
--iree-codegen-gpu-alloc-private-memory-for-dps-opsGPUAllocPrivateMemoryForDPSOpsPassFunctionOpInterface在 DPS 接口 op 前添加私有内存分配
--iree-codegen-gpu-apply-padding-levelGPUApplyPaddingLevelPassFunctionOpInterface按 tiling 配置填充
--iree-codegen-gpu-apply-tiling-levelGPUApplyTilingLevelPassFunctionOpInterface按 tiling 配置对 tensor op 分块
--iree-codegen-gpu-bubble-resource-castsGPUBubbleResourceCastsPass-将 iree_gpu.buffer_resource_cast 向上冒泡
--iree-codegen-gpu-check-resource-usageGPUCheckResourceUsagePassFunctionOpInterface检查共享内存等 GPU 资源约束
--iree-codegen-gpu-combine-layout-transformationGPUCombineLayoutTransformationPassFunctionOpInterface合并布局转换到单个 map_store
--iree-codegen-gpu-combine-value-semantic-barriersGPUCombineValueSemanticBarriersPass-合并 value_barrier 与 barrier_region
--iree-codegen-gpu-convert-to-coalesced-dmaGPUConvertToCoalescedDMAPassFunctionOpInterface转换为合并 DMA
--iree-codegen-gpu-create-fast-slow-pathGPUCreateFastSlowPathPassFunctionOpInterface创建快慢路径处理 padding
--iree-codegen-gpu-distribute-copy-using-forallGPUDistributeCopyUsingForallPassFunctionOpInterface将 copy 分布到线程
--iree-codegen-gpu-distribute-forallGPUDistributeForallPassFunctionOpInterface分布 scf.forall
--iree-codegen-gpu-distributeGPUDistributePassFunctionOpInterface使用上游模式分布 scf.forall
--iree-codegen-gpu-distribute-scf-forGPUDistributeScfForPassFunctionOpInterface将分块循环分布到调用
--iree-codegen-gpu-distribute-shared-memory-copyGPUDistributeSharedMemoryCopyPassFunctionOpInterface将共享内存 copy 分布到线程
--iree-codegen-gpu-fuse-and-hoist-parallel-loopsGPUFuseAndHoistParallelLoopsPassFunctionOpInterface贪婪融合并提升并行循环
--iree-codegen-gpu-fuse-subgroup-consumersGPUFuseSubgroupConsumersPass-将可 tile 消费者融合到 subgroup 级 pcf.generic
--iree-codegen-gpu-generalize-named-opsGPUGeneralizeNamedOpsPassFunctionOpInterface将命名 Linalg op 转为 linalg.generic
--iree-codegen-gpu-greedily-distribute-to-threadsGPUGreedilyDistributeToThreadsPassFunctionOpInterface贪婪将剩余可 tile op 分布到线程
--iree-codegen-gpu-infer-memory-spaceGPUInferMemorySpacePassFunctionOpInterface推断并设置 alloc_tensor 内存空间
--iree-codegen-gpu-multi-bufferingGPUMultiBufferingPassFunctionOpInterface软件多缓冲
--iree-codegen-gpu-pack-partial-reductionsGPUPackPartialReductionsPassFunctionOpInterface将 reduction 维度拆分为 [outer, inner]
--iree-codegen-gpu-pack-to-intrinsicsGPUPackToIntrinsicsPassFunctionOpInterface打包类 matmul 并转为 iree_codegen.inner_tiled
--iree-codegen-gpu-pad-convsGPUPadConvsPassFunctionOpInterface按配置填充卷积操作数
--iree-codegen-gpu-pad-operandsGPUPadOperandsPassFunctionOpInterface按配置填充 op 操作数
--iree-codegen-gpu-pipeliningGPUPipeliningPassFunctionOpInterface软件流水线
--iree-codegen-gpu-promote-matmul-operandsGPUPromoteMatmulOperandsPassFunctionOpInterface插入不同 lower 配置的 copy
--iree-codegen-gpu-reduce-bank-conflictsGPUReduceBankConflictsPassFunctionOpInterface通过 padding memref.alloc 减少 bank 冲突
--iree-codegen-gpu-reuse-shared-memory-allocsGPUReuseSharedMemoryAllocsPassFunctionOpInterface复用无重叠生命期的共享内存分配
--iree-codegen-gpu-tensor-allocGPUTensorAllocPassFunctionOpInterface为某些 tensor 值创建分配
--iree-codegen-gpu-tensor-tileGPUTensorTilePassFunctionOpInterface在 GPU workgroup 内对 tensor (linalg) op 分块
--iree-codegen-gpu-tensor-tile-to-serial-loopsGPUTensorTileToSerialLoopsPassFunctionOpInterface对某些 GPU op 的 reduction 维度分块
--iree-codegen-gpu-tile-and-convert-conv-to-matmulGPUTileAndConvertConvToMatmulPassFunctionOpInterface通过 tiling 将卷积转为 matmul
--iree-codegen-gpu-tileGPUTilePassFunctionOpInterface将 tensor 语义 Linalg op tile 到调用
--iree-codegen-gpu-tile-reductionGPUTileReductionPassFunctionOpInterface对 linalg reduction 维度分块
--iree-codegen-gpu-vector-allocGPUVectorAllocPassFunctionOpInterface为 contraction 输入创建分配
--iree-codegen-gpu-verify-distributionGPUVerifyDistributionPassFunctionOpInterface在解析分布式上下文前验证写操作
--iree-codegen-reorder-workgroupsReorderWorkgroupsPassFunctionOpInterface重排 workgroup id 改善缓存复用
--iree-codegen-test-gpu-promotion-analysisTestGPUPromotionAnalysisPassFunctionOpInterface测试 GPU promotion 类型反向分析
--iree-codegen-vector-reduction-to-gpuVectorReductionToGPUPassFunctionOpInterface将 vector reduction 转为 GPU op

3.4 Codegen / Common(关键 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-codegen-tile-and-distribute-to-workgroups-using-forall-opTileAndDistributeToWorkgroupsUsingForallOpPassFunctionOpInterface使用 scf.forall 将 op tile 并分布到 workgroup
--iree-codegen-iree-comprehensive-bufferizeIREEComprehensiveBufferizePassFunctionOpInterface将 tensor Linalg op 全面 bufferize
--iree-codegen-generic-vectorizationGenericVectorizationPassFunctionOpInterface对 tensor/linalg op 做向量化
--iree-codegen-materialize-user-configsMaterializeUserConfigsPassModuleOp从用户配置设置 lowering config 与 translation info
--iree-codegen-materialize-tuning-specsMaterializeTuningSpecsPassModuleOp加载 tuning spec transform dialect 库
--iree-codegen-link-tuning-specsLinkTuningSpecsPassModuleOp链接嵌套 tuning spec named sequence
--iree-codegen-lower-executable-using-transform-dialectLowerExecutableUsingTransformDialectPassModuleOp用模块内 transform dialect 配方 lower executable
--iree-transform-dialect-interpreterTransformDialectInterpreterPass-应用 transform dialect 操作
--iree-transform-dialect-drop-scheduleDropSchedulePass-删除 op 上的 schedule
--iree-codegen-lower-ukernel-ops-to-callsLowerUKernelOpsToCallsPassModuleOp将微内核包装 op 降为函数调用

3.5 Codegen / Dialect / GPU(5 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-gpu-convert-forall-to-generic-nestConvertForallToGenericNestGPUPassFunctionOpInterface将 GPU 映射的 scf.forall 转为 pcf.generic
--iree-gpu-distribute-inner-tiled-to-lanesDistributeInnerTiledToLanesPassFunctionOpInterface将 inner_tiled op 分布到 lane
--iree-gpu-expand-undistributed-inner-tilesExpandUndistributedInnerTilesPassFunctionOpInterface扩展 inner_tiled op 内维以匹配线程布局
--iree-gpu-lower-opsLowerIREEGPUOpsPassFunctionOpInterfacebufferization 后 iree_gpu op 的 lower
--iree-gpu-unroll-to-intrinsicsUnrollToIntrinsicsPassFunctionOpInterface将 iree_gpu.multi_mma unroll 到内取向量大小

3.6 Codegen / LLVMCPU(24 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-convert-to-llvmConvertToLLVMPassModuleOp最终降到 LLVMIR dialect
--iree-llvmcpu-select-lowering-strategyLLVMCPUSelectLoweringStrategyPassModuleOp选择 lowering pipeline attribute
--iree-llvmcpu-lower-executable-targetLLVMCPULowerExecutableTargetPassFunctionOpInterfaceLLVMCPU 可执行目标 lower
--iree-llvmcpu-tileLLVMCPUTilePass-LLVMCPU tiling
--iree-llvmcpu-tile-to-vector-sizeLLVMCPUTileToVectorSizePass-Tile 到向量大小
--iree-llvmcpu-peelLLVMCPUPeelPass-Loop peeling
--iree-llvmcpu-split-reductionLLVMCPUSplitReductionPass-拆分 reduction
--iree-llvmcpu-vector-virtual-loweringLLVMCPUVectorVirtualLoweringPass-向量虚拟 lowering
--iree-llvmcpu-vector-transpose-loweringLLVMCPUVectorTransposeLoweringPass-向量转置 lowering
--iree-llvmcpu-vector-shape-cast-loweringLLVMCPUVectorShapeCastLoweringPass-向量 shape cast lowering
--iree-llvmcpu-assign-constant-ordinalsLLVMCPUAssignConstantOrdinalsPassModuleOp分配常量序号
--iree-llvmcpu-assign-import-ordinalsLLVMCPUAssignImportOrdinalsPassModuleOp分配导入序号
--iree-llvmcpu-link-executablesLLVMCPULinkExecutablesPassModuleOp链接可执行文件

3.7 Codegen / LLVMGPU(24 个 Pass)+ ROCDL(4 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-convert-to-nvvmConvertToNVVMPassModuleOp最终降到 NVVM
--iree-convert-to-rocdlConvertToROCDLPassModuleOp最终降到 ROCDL
--iree-llvmgpu-select-lowering-strategyLLVMGPUSelectLoweringStrategyPassModuleOp选择 LLVMGPU lowering 策略
--iree-llvmgpu-lower-executable-targetLLVMGPULowerExecutableTargetPassFunctionOpInterfaceLLVMGPU 可执行目标 lower
--iree-llvmgpu-tile-and-distributeLLVMGPUTileAndDistributePass-Tile 并分布
--iree-llvmgpu-tensor-core-vectorizationLLVMGPUTensorCoreVectorizationPass-Tensor Core 向量化
--iree-llvmgpu-vector-distributeLLVMGPUVectorDistributePass-向量分布
--iree-llvmgpu-vector-loweringLLVMGPUVectorLoweringPass-向量 lowering
--iree-llvmgpu-vector-flatteningLLVMGPUVectorFlatteningPass-向量扁平化
--iree-llvmgpu-vector-to-gpuLLVMGPUVectorToGPUPass-向量到 GPU op 转换

3.8 Codegen / SPIRV(16 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-convert-to-spirvConvertToSPIRVPassModuleOp最终转到 SPIR-V dialect
--iree-spirv-select-lowering-strategySPIRVSelectLoweringStrategyPassModuleOp选择 SPIR-V lowering 策略
--iree-spirv-lower-executable-targetSPIRVLowerExecutableTargetPassFunctionOpInterfaceSPIR-V 可执行目标 lower
--iree-spirv-tile-and-distributeSPIRVTileAndDistributePass-Tile 并分布
--iree-spirv-tile-and-promoteSPIRVTileAndPromotePass-Tile 并提升
--iree-spirv-tile-to-cooperative-opsSPIRVTileToCooperativeOpsPass-Tile 到协作操作
--iree-spirv-link-executablesSPIRVLinkExecutablesPassModuleOp链接 SPIR-V 可执行文件

3.9 Codegen / VMVX(5 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-vmvx-select-lowering-strategyVMVXSelectLoweringStrategyPassModuleOp选择 VMVX lowering 策略
--iree-vmvx-lower-executable-targetVMVXLowerExecutableTargetPassFunctionOpInterfaceVMVX 可执行目标 lower
--iree-vmvx-lower-linalg-microkernelsVMVXLowerLinalgMicrokernelsPass-降低 Linalg 微内核
--iree-vmvx-assign-constant-ordinalsVMVXAssignConstantOrdinalsPassModuleOp分配常量序号
--iree-vmvx-link-executablesVMVXLinkExecutablesPassModuleOp链接 VMVX 可执行文件

3.10 ConstEval(1 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-consteval-jit-globalsJitGlobalsPassModuleOpJIT 求值全局初始化器

3.11 Dialect / Flow(19 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-verify-input-legalityVerifyInputLegalityPass-验证输入合法性
--iree-flow-initialize-empty-tensorsInitializeEmptyTensorsPass-初始化空张量
--iree-flow-capture-dynamic-dimsCaptureDynamicDimsPass-捕获动态维度
--iree-flow-canonicalizeCanonicalizePass-Flow dialect 规范化
--iree-flow-outline-dispatch-externsOutlineDispatchExternsPass-提取外部 dispatch
--iree-flow-outline-dispatch-regionsOutlineDispatchRegionsPass-提取 dispatch 区域
--iree-flow-annotate-dispatchesAnnotateDispatchesPass-注解 dispatch 的执行信息
--iree-flow-deduplicate-executablesDeduplicateExecutablesPass-去重可执行文件
--iree-flow-replicate-globals-per-affinityReplicateGlobalsPerAffinityPass-按亲和性复制全局变量
--iree-flow-inject-dispatch-tracingInjectDispatchTracingPass-注入 dispatch 追踪
--iree-flow-inject-tensor-tracingInjectTensorTracingPass-注入 tensor 追踪
--iree-flow-outline-constantsOutlineConstantsPass-提取常量
--iree-flow-export-benchmark-funcsExportBenchmarkFuncsPassModuleOp导出基准测试函数
--iree-flow-dump-dispatch-graphDumpDispatchGraphPassModuleOp输出 dispatch 计算图
--iree-flow-top-level-scf-to-cfgTopLevelSCFToCFGPass-将顶层 SCF 转为 CFG
--iree-flow-convert-to-flowConvertToFlowPass-转换到 Flow dialect
--iree-flow-cleanup-tensor-shapesCleanupTensorShapesPass-清理 tensor 形状

3.12 Dialect / HAL(37 个 Pass)

类别关键 Pass描述
设备相关AssignTargetDevicesPass分配目标设备
MaterializeTargetDevicesPass具体化目标设备
ResolveDevicePromisesPass解析设备 promise
ResolveDeviceAliasesPass解析设备别名
VerifyDevicesPass验证设备
Executable 配置ConfigureExecutablesPass配置可执行文件
ConfigureTargetExecutableVariantsPass配置目标可执行文件变体
TranslateAllExecutablesPass翻译所有可执行文件
SerializeAllExecutablesPass序列化所有可执行文件
LinkAllExecutablesPass链接所有可执行文件
PruneExecutablesPass裁剪可执行文件
源码/调试CaptureExecutableSourcesPass捕获可执行源码
DumpExecutableSourcesPass输出可执行源码
StripExecutableContentsPass剥离可执行内容
LoweringConvertToHALPass转换到 HAL dialect
MaterializeInterfacesPass具体化接口
MaterializeResourceCachesPass具体化资源缓存
命令优化InitializeDevicesPass初始化设备
MemoizeDeviceSelectionPass记忆设备选择
ElideRedundantCommandsPass消除冗余命令
RepeatDispatchesPass重复 dispatch

3.13 Dialect / Stream(40 个 Pass)

类别关键 Pass描述
验证VerifyInputPass验证输入
VerifyLoweringToTensorsPass验证 Tensor lowering
VerifyLoweringToAsyncPass验证 Async lowering
VerifyLoweringToCmdPass验证 Cmd lowering
转换ConvertToStreamPass转换到 Stream dialect
CloneToConsumersPass克隆到消费者
AnnotateAffinitiesPass注解亲和性
编码/内存EncodeHostTensorsPass编码主机张量
EncodeDeviceTensorsPass编码设备张量
MaterializeEncodingsPass具体化编码
SpecializeEncodingsPass特化编码
调度/分配ScheduleExecutionPass调度执行
ScheduleConcurrencyPass调度并发
ScheduleAllocationPass调度分配
LayoutSlicesPass布局切片
优化ElideAsyncCopiesPass消除异步拷贝
EmplaceAllocationsPass安置分配
EmplaceTransientsPass安置瞬态
ReuseAllocationsPass复用分配
FuseDispatchBindingsPass融合 dispatch 绑定
常量/参数PackConstantsPass打包常量
PackDispatchOperandsPass打包 dispatch 操作数
ARCAutomaticReferenceCountingPass自动引用计数

3.14 Dialect / Util(22 个 Pass)

类别关键 Pass描述
全局优化FoldGlobalsPass折叠全局变量
FuseGlobalsPass融合全局变量
CombineInitializersPass合并初始化器
HoistIntoGlobalsPass提升为全局变量
OptimizeIntArithmeticPass优化整数算术
IPO/链接IPOPass过程间优化
LinkModulesPass链接模块
AttributeCallGraphPass属性调用图
调试/测试AnnotateOpOrdinalsPass注解 op 序号
DumpModulePass输出模块
StripDebugOpsPass剥离调试 op

3.15 Dialect / VM(13 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-vm-conversionConversionPassModuleOp从标准/HAL 等 dialect 转到 VM dialect
--iree-vm-global-initializationGlobalInitializationPass-全局初始化
--iree-vm-ordinal-allocationOrdinalAllocationPassModuleOp分配序号
--iree-vm-deduplicate-rodataDeduplicateRodataPass-去重只读数据
--iree-vm-hoist-inlined-rodataHoistInlinedRodataPass-提升内联只读数据
--iree-vm-resolve-rodata-loadsResolveRodataLoadsPass-解析只读数据加载
--iree-vm-drop-empty-module-initializersDropEmptyModuleInitializersPass-删除空模块初始化器
--iree-vm-drop-unused-callsDropUnusedCallsPass-删除未使用的调用

3.16 Dialect / VMVX(3 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-vmvx-conversionConversionPassModuleOpVMVX 转换
--iree-vmvx-materialize-constantsMaterializeConstantsPassModuleOp具体化常量
--iree-vmvx-resolve-buffer-descriptorsResolveBufferDescriptorsPass-解析缓冲区描述符

3.17 Dialect / LinalgExt(13 个 Pass)

命令行 FlagPass 类名描述
--iree-linalg-ext-convert-attention-to-online-attentionConvertAttentionToOnlineAttentionPass将 Attention 转为 Online Attention
--iree-linalg-ext-decompose-attentionDecomposeAttentionPass分解 Attention
--iree-linalg-ext-convert-conv2d-to-winogradConvertConv2DToWinogradPass将 Conv2D 转为 Winograd
--iree-linalg-ext-decompose-winograd-transformDecomposeWinogradTransformPass分解 Winograd 变换
--iree-linalg-ext-convert-conv-to-im2colConvertConvToIm2ColOpPass将 Conv 转为 Im2Col
--iree-linalg-ext-to-loopsLinalgExtToLoopsPassLinalgExt 转循环
--iree-linalg-ext-pad-contraction-to-block-sizePadContractionToBlockSizePass填充 contraction 到块大小
--iree-linalg-ext-fold-unit-extent-dimsFoldUnitExtentDimsPass折叠单位维度
--iree-linalg-ext-topk-split-reductionTopkSplitReductionPassTopK 拆分 reduction

3.18 DispatchCreation(31 个 Pass)

类别关键 Pass描述
区域形成FormDispatchRegionsPass形成 dispatch 区域
FormScalarDispatchesPass形成标量 dispatch
FormSplitReductionDispatchesPass形成拆分 reduction dispatch
ConvertDispatchRegionsToWorkgroupsPass将 dispatch 区域转为 workgroup
融合ElementwiseOpFusionPass元素级 op 融合
FuseMultiUseElementwiseProducerPass多用途元素级生产者融合
FuseHorizontalContractionsPass水平 contraction 融合
CloneProducersIntoDispatchRegionsPass将生产者克隆到 dispatch 区域
编码/数据布局SetEncodingPass设置编码
PropagateEncodingsPass传播编码
ConvertEncodingToFlowPass编码转 Flow
HoistEncodingOpsPass提升编码 op
维度/reshapeCollapseDimensionsPass折叠维度
FoldUnitExtentDimsPass折叠单位维度
BubbleUpExpandShapesPass冒泡展开形状
SinkReshapesPass下沉 reshape
TransposeGenericOpsPass转置通用 op
规约拆分SplitReductionPass拆分 reduction
SetSplitReductionSizesPass设置拆分 reduction 大小
其他ConvertTensorToFlowPassTensor 转 Flow
InsertTensorBarriersPass插入 tensor 屏障

3.19 GlobalOptimization(22 个 Pass)

命令行 FlagPass 类名描述
--iree-global-opt-detach-elementwise-from-named-opsDetachElementwiseFromNamedOpsPass从命名 op 分离元素级
--iree-global-opt-generalize-linalg-named-opsGeneralizeLinalgNamedOpsPass泛化 Linalg 命名 op
--iree-global-opt-convert-conv2d-to-img2colConvertConv2DToImg2ColPassConv2D 转 Img2Col
--iree-global-opt-propagate-linalg-transposePropagateLinalgTransposePass传播 Linalg 转置
--iree-global-opt-raise-special-opsRaiseSpecialOpsPass提升特殊 op
--iree-global-opt-data-layout-propagationDataLayoutPropagationPass数据布局传播
--iree-global-opt-simplify-pack-unpackSimplifyPackUnpackPass简化 pack/unpack
--iree-global-opt-materialize-homogeneous-encodingsMaterializeHomogeneousEncodingsPass化同质编码
--iree-global-opt-demote-contraction-inputsDemoteContractionInputsPass降级 contraction 输入
--iree-global-opt-fuse-dequantization-matmulFuseDequantizationMatmulPass融合反量化 matmul
--iree-global-opt-expand-tensor-shapesExpandTensorShapesPass展开张量形状
--iree-global-opt-global-loop-invariant-code-motionGlobalLoopInvariantCodeMotionPass全局循环不变量代码移动
--iree-global-opt-infer-numeric-narrowingInferNumericNarrowingPass推断数值收窄
--iree-global-opt-optimize-numericsOptimizeNumericsPass优化数值
--iree-global-opt-cleanup-numeric-narrowingCleanupNumericNarrowingPass清理数值收窄
--iree-global-opt-warn-on-uninitialized-valuesWarnOnUninitializedValuesPass未初始化值警告

3.20 InputConversion / Common(9 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-auto-input-conversionAutoInputConversionPipelinePass-自动选择输入 pipeline
--iree-import-publicIREEImportPublicPass-导入公共接口
--iree-import-ml-programImportMLProgramPass-导入 ML program
--iree-sanitize-module-namesSanitizeModuleNamesPassModuleOp清理模块名称
--iree-promote-f16-to-f32PromoteF16ToF32Pass-F16 提升为 F32
--iree-promote-bf16-to-f32PromoteBF16ToF32Pass-BF16 提升为 F32
--iree-demote-f32-to-f16DemoteF32ToF16Pass-F32 降级为 F16
--iree-demote-f64-to-f32DemoteF64ToF32Pass-F64 降级为 F32
--iree-demote-i64-to-i32DemoteI64ToI32Pass-I64 降级为 I32

3.21 Modules / HAL Inline(2 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-hal-inline-conversionConversionPassModuleOpHAL Inline 转换
--iree-hal-inline-executablesInlineExecutablesPassModuleOp内联可执行文件

3.22 Modules / HAL Loader(3 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-hal-loader-conversionConversionPassModuleOpHAL Loader 转换
--iree-hal-loader-materialize-executablesMaterializeExecutablesPassModuleOp具体化可执行文件
--iree-hal-loader-resolve-export-ordinalsResolveExportOrdinalsPassModuleOp解析导出序号

3.23 Modules / IO Parameters(3 个 Pass)

命令行 FlagPass 类名作用 Op描述
--iree-io-import-parametersImportParametersPassModuleOp导入参数
--iree-io-export-parametersExportParametersPassModuleOp导出参数
--iree-io-generate-splat-parameter-archiveGenerateSplatParameterArchivePassModuleOp生成 splat 参数归档

3.24 Preprocessing / Common(15 个 Pass)

命令行 FlagPass 类名描述
--iree-preprocessing-apply-pdl-patternsApplyPDLPatternsPass应用 PDL 模式
--iree-preprocessing-interpreterInterpreterPass解释器
--iree-preprocessing-attr-based-pipelineAttrBasedPipelinePass基于属性的 pipeline
--iree-preprocessing-convert-conv-to-channels-lastConvertConvToChannelsLastPass将 Conv 转为 channels-last
--iree-preprocessing-convert-1x1-filter-conv2d-to-matmulConvert1X1FilterConv2DToMatmulPass1x1 卷积转 matmul
--iree-preprocessing-generalize-linalg-matmulGeneralizeLinalgMatMulPass泛化 Linalg MatMul
--iree-preprocessing-transpose-matmulTransposeMatmulPass转置 MatMul
--iree-preprocessing-pad-linalg-opsPadLinalgOpsPass填充 Linalg op
--iree-preprocessing-pad-to-intrinsicsPadToIntrinsicsPass填充到内建函数
--iree-preprocessing-promote-linalg-outputsPromoteLinalgOutputsPass提升 Linalg 输出
--iree-preprocessing-fold-attention-with-transposeFoldAttentionWithTransposePass折叠 Attention 与 transpose
--iree-preprocessing-make-single-dispatch-for-functionMakeSingleDispatchForFunctionPass为函数创建单个 dispatch

3.25 Transforms(2 个 Pass)

命令行 FlagPass 类名描述
--iree-affine-expand-index-opsIREEAffineExpandIndexOpsPass展开 Affine 索引 op
--iree-lower-affineIREELowerAffinePass降低 Affine

4. 编译 Pipeline 阶段与 Pass 顺序

4.1 顶层 IREE VM Pipeline

定义位置: Pipelines/Pipelines.cpp

阶段主要 Pass 顺序
1. Input 输入转换AutoInputConversionPipelinePass → buildCommonInputConversionPassPipeline
2. ABI 入口包装IREE::ABI::buildTransformPassPipeline (Native) / IREE::TFLite::buildTransformPassPipeline (TFLite)
3. HAL 设备分配AssignLegacyTargetDevicesPass → MaterializeTargetDevicesPass → ResolveDevicePromisesPass → ResolveDeviceAliasesPass → VerifyDevicesPass
4. Preprocessing 预处理buildPreprocessingPassPipeline
5. GlobalOptimization 全局优化常量提升、Linalg 规范化、数据布局传播、编码物化、数值优化等
6. DispatchCreation 创建元素级融合、编码、区域形成、split reduction、转 tensor 到 flow
7. Flow 转换VerifyInputLegalityPass → InitializeEmptyTensorsPass → CaptureDynamicDimsPass → OutlineDispatchRegionsPass → OutlineDispatchExternsPass → AnnotateDispatchesPass → DeduplicateExecutablesPass
8. Stream 异步调度buildStreamTensorPassPipeline → buildStreamAsyncPassPipeline → buildStreamCmdPassPipeline → buildStreamOptimizationPassPipeline
9. HAL 硬件抽象buildHALConfigurationPassPipeline → buildHALTransformPassPipeline → ConvertToHALPass → MaterializeResourceCachesPass → InitializeDevicesPass
10. VM 虚拟机buildVMTransformPassPipeline

4.2 Stream Pipeline 子阶段

定义位置: Dialect/Stream/Transforms/Passes.cpp

子阶段Pass 顺序
TensorVerifyInputPass → cleanup → CloneToConsumersPass → AnnotateAffinitiesPass → ConvertToStreamPass → VerifyLoweringToTensorsPass
AsyncSpecializeEncodingsPass → EncodeHostTensorsPass / EncodeDeviceTensorsPass → MaterializeEncodingsPass → LayoutSlicesPass → ScheduleExecutionPass / ScheduleConcurrencyPass → MaterializeBuiltinsPass → VerifyLoweringToAsyncPass
CmdScheduleAllocationPass → EmplaceTransientsPass → PackConstantsPass → AutomaticReferenceCountingPass → VerifyLoweringToCmdPass
OptimizationIPO → reuse allocations → fuse bindings → fold operands

4.3 HAL Pipeline 子阶段

定义位置: Dialect/HAL/Transforms/Passes.cpp

子阶段Pass 顺序
配置MaterializeDispatchInstrumentationPass → MaterializeInterfacesPass → PruneExecutablesPass → ConfigureExecutablesPass
翻译TranslateAllExecutablesPass
后处理ConvertToHALPass → OutlineMemoizeRegionsPass → PruneExecutablesPass → LinkAllExecutablesPass → ResolveExportOrdinalsPass → MaterializeResourceCachesPass → InitializeDevicesPass
序列化SerializeAllExecutablesPass

4.4 Codegen Pipeline 典型顺序

目标后端典型顺序
LLVMCPUSelectLoweringStrategyPass → TileAndDistributeToWorkgroupsUsingForallOpPass → Bufferize → Vectorize → Tile → Peel → CPULowerToUKernelsPass → ConvertToLLVMPass
LLVMGPUSelectLoweringStrategyPass → TileAndDistributeToWorkgroupsUsingForallOpPass → Bufferize → Vectorize → LLVMGPUTensorCoreVectorizationPass → ConvertToNVVMPass / ConvertToROCDLPass
SPIRVSelectLoweringStrategyPass → SPIRVTileAndDistributePass → SPIRVTileToCooperativeOpsPass → ConvertToSPIRVPass
VMVXSelectLoweringStrategyPass → VMVXLowerLinalgMicrokernelsPass → VMVXLinkExecutablesPass

5. 关键源文件索引

类别文件路径
全局 Dialect 注册Tools/init_iree_dialects.h
编译器模块 Dialect 注册Tools/init_compiler_modules.h
全局 Pass 注册Tools/init_iree_passes.h
顶层 PipelinePipelines/Pipelines.cpp
Flow PipelineDialect/Flow/Transforms/Passes.cpp
Stream PipelineDialect/Stream/Transforms/Passes.cpp
HAL PipelineDialect/HAL/Transforms/Passes.cpp
VM PipelineDialect/VM/Transforms/Passes.cpp
DispatchCreation PipelineDispatchCreation/Passes.cpp
GlobalOptimization PipelineGlobalOptimization/Passes.cpp
CPU Codegen PipelineCodegen/LLVMCPU/Passes.cpp
GPU Codegen PipelineCodegen/LLVMGPU/Passes.cpp
SPIRV Codegen PipelineCodegen/SPIRV/Passes.cpp

6. Pass 命名与位置对应关系

以 --iree-flow-annotate-dispatches 为例说明 Pass 的对应关系:

项目值说明
命令行 Flag--iree-flow-annotate-dispatches用户在 iree-opt 或 iree-compile 中使用
Pass 类名AnnotateDispatchesPassC++ 中的类名称
TableGen 定义文件Dialect/Flow/Transforms/Passes.tdPass 的 TableGen 定义
实现文件Dialect/Flow/Transforms/AnnotateDispatches.cppPass 的实际 C++ 实现代码
注册文件Dialect/Flow/Transforms/Passes.h包含 GEN_PASS_REGISTRATION 宏
命名空间IREE::Flow所属 Dialect 的命名空间
Pipeline 函数buildFlowTransformPassPipeline添加此 Pass 的 Pipeline 构建函数

TableGen 定义示例

// 文件: Dialect/Flow/Transforms/Passes.td
def AnnotateDispatchesPass :
    Pass<"iree-flow-annotate-dispatches", "mlir::ModuleOp"> {
  let summary = "Annotates dispatch execution information";
  let description = [{
    注解 dispatch 的执行信息,如工作负载大小等。
  }];
  let constructor = "createAnnotateDispatchesPass()";
}

C++ 注册示例

// 文件: Dialect/Flow/Transforms/Passes.h
#ifndef IREE_COMPILER_DIALECT_FLOW_TRANSFORMS_PASSES_H_
#define IREE_COMPILER_DIALECT_FLOW_TRANSFORMS_PASSES_H_

#include "mlir/Pass/Pass.h"

namespace mlir::iree_compiler::IREE::Flow {

std::unique_ptr<OperationPass<ModuleOp>> createAnnotateDispatchesPass();

// 生成 Pass 注册代码
#define GEN_PASS_REGISTRATION
#include "iree/compiler/Dialect/Flow/Transforms/Passes.h.inc"

} // namespace mlir::iree_compiler::IREE::Flow
#endif // IREE_COMPILER_DIALECT_FLOW_TRANSFORMS_PASSES_H_

Pipeline 添加示例

// 文件: Dialect/Flow/Transforms/Passes.cpp
void buildFlowTransformPassPipeline(OpPassManager &passManager) {
  // ... 其他 Pass
  passManager.addPass(createAnnotateDispatchesPass());
  // ... 其他 Pass
}

命名约定模式

组件命名前缀示例
Flow Dialectiree-flow---iree-flow-annotate-dispatches
Stream Dialectiree-stream---iree-stream-schedule-execution
HAL Dialectiree-hal---iree-hal-convert-to-hal
VM Dialectiree-vm---iree-vm-conversion
DispatchCreationiree-codegen---iree-codegen-form-dispatch-regions
GlobalOptimizationiree-global-opt---iree-global-opt-generalize-linalg-named-ops
LLVMCPU Codegeniree-llvmcpu---iree-llvmcpu-select-lowering-strategy
LLVMGPU Codegeniree-llvmgpu---iree-llvmgpu-tile-and-distribute
SPIRV Codegeniree-spirv---iree-spirv-convert-to-spirv

总结

  • Dialect 总数: 19 个
  • Pass 总数: 486 个
  • 主要 Pipeline 阶段: 10 个(Input → ABI → HAL Device → Preprocessing → GlobalOptimization → DispatchCreation → Flow → Stream → HAL → VM)
  • 目标后端: LLVMCPU、LLVMGPU(NVVM/ROCDL)、SPIRV、VMVX

所有 Pass 和 Dialect 都定义在 compiler/src/iree/compiler/ 目录下,通过 TableGen 定义并使用 C++ 实现。