You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A generic pass to convert to LLVM, using the ConvertToLLVMPatternInterface to delegate to dialects the injection of conversion patterns
for (Dialect *dialect : context->getLoadedDialects()) {
// First time we encounter this dialect: if it implements the interface,// let's populate patterns !auto *iface = dyn_cast<ConvertToLLVMPatternInterface>(dialect);
if (!iface)
continue;
iface->populateConvertToLLVMConversionPatterns(*target, *typeConverter,
tempPatterns);
populateConvertToLLVMConversionPatterns <- hook for derivated dialect interface to populate conversion patterns and mark dialect legal for the conversion target
registerConvertArithToLLVMInterface <- register the interface mentioned above
Go through all funcOp and check for attributes, including workgroupSize, subgroupSize, etc.
Go through all funcOp again, try to apply RemoveStaticDynamicCast patterns and fold greedily via a call to applyPatternsAndFoldGreedily
Populate VectorNarrowTypeRewritePatterns, rewriting extui/si(bitcast) as a mix of vector.shuffle + bitwise arithmetic.
Populate ExpandBFloat16, expanding any remaining bf16extf and trunc patterns
Populate MMAToSPIRVCoopMatrixTypeConversion, for GPU subgroup MMA ops
Populate more to-spirv patterns, including gpu, scf, memref, func, math, compelx, tensor, vector, etc.
Add IREE HAL interface op conversions.
Fold certain operations as no-ops
Try applying full conversion by calling applyFullConversion
FrozenRewritePatternSet frozenPatterns(std::move(patterns));
for (auto fn : functions) {
if (failed(applyFullConversion(fn, *target, frozenPatterns))) {
returnsignalPassFailure();
}
}
Comparison
In ConvertToLLVMPass, the patterns are populated by the dialects themselves, via their interfaces. There is no need to call the individual populate...Patterns methods.
More modularized approach
Need to implement the interface for each dialect
However, in IREE's ConvertToSPIRVPass class, there is one large runOnOperation that populates the patterns by calling all the populate...Patterns method.