Skip to content

MLIR Useful API/Code Snippets#

IR Traversal#

  • RegionUtils.h: utilities for usedef traversal
  • CallGraph: generate callgraph of CallOpInterface and CallableOpInterface ops
  • Block::findAncestorOpInBlock: Returns ‘op’ if ‘op’ lies in this block, or otherwise finds the ancestor operation of ‘op’ that lies in this block. Returns nullptr if the latter fails.

Conversion/Pass Utils#

Graph Algorithms#

  • scc_iterator: generate strongly connected nodes
  • ReversePostOrderTraversal
  • GraphTraits: traits class to specialize to be able to use llvm graph algorithms
  • DirectedGraph: directed graph class
  • GraphWriter: graph emitter
  • BreadthFirstIterator.h

BarePtrFuncOpConversion

getBranchSuccessorArgument

verifyBranchSuccessorOperands verifyTypesAlongControlFlowEdges

RegionSuccessor::getSuccessor,isParent,getSuccessorInputs

CallOpOpConversion

struct CallOpSignatureConversion : public OpConversionPattern {


generateOpgraphAst generate Node Ast

  • Needs to be an object
  • contains unoptimized code/syntax tree
  • Compile to code instance/funcpointer
  • UI binds to unoptimized version
  • UI modifies AST
    • Generate MLIR
  • MLIR parses unoptimized version
  • MLIR spits out ast of optimized versoin
-Code to ast
-Ast to mlir
-mlir to emitted optimized version

struct TileAndVectorizeWorkgroups
public PassWrapper\ { void getDependentDialects(DialectRegistry &registry) const override { registry.insert\(); } void runOnFunction() override; }; } // namespace

void TileAndVectorizeWorkgroups::runOnFunction() {

/// Distribute linalg ops among iree.workgroup logical threads. std::unique_ptr\<OperationPass> createLinalgTileAndDistributePass();

/// Vectorize linalg ops executed in the same iree.workgroup. std::unique_ptr createLinalgTileAndVectorizeWorkgroupsPass();

FuncBufferize createFuncBufferizePass

Linalgop::DeduplicateInputs


Last update: August 23, 2021