Adding a New Pass
Create pass definition in Passes.td
Add constructor function declaration in Passes.h
Add pass to pipeline
Create file for the pass
Define the class for pass
Define the
runOnOperation()functionDefine the contructor for the pass
(Optional) Define the pattern class
Add the .cpp file for the pass to the CMakeLists.txt
Example
Example with implementation details of the KernelSelectionPass for the TorqHL to TorqHW conversion. The complete set of code is available under compiler/torq/Transforms
Create a copy of any pass available in the Passes.td. Change the name of the pass to
KernelSelectionChange the first template argument of InterfacePass. The first argument of InterfacePass is the commandline argument used to identify the pass. Here changed the name to torq-kernel-selection Change summary to provide a brief summary of the pass. Change theconstructorto a custom construction name, here changed to mlir::syna::torq::createKernelSelectionPass(). Add the dependentDialects as needed. Refer Passes.tdIn Passes.h add declaration for the constructor we have named above.
std::unique_ptr<InterfacePass<FunctionOpInterface>> createKernelSelectionPass()Add pass to the
TORQLowerExecutableTargetPassinside the TORQLowerExecutableTargetPass.cpp pipeline usingaddPassmethod. Herepipeline.addPass(createKernelSelectionPass())Create the file
KernelSelectionPass.cppin the folder compiler/torq/CodeGenDefine the KernelSelectionPass class in the file. It should inherit the KernelSelectionBase using CRTP
class KernelSelectionPass : public KernelSelectionBase<KernelSelectionPass>Define the
runOnOperation()function. Refer KernelSelectionPassDefine the
createKernelSelectionPass()constructor. It should return a unique_ptr to InterfacePass. Refer the KernelSelectionPass.cpp for more info.Define the pattern rewrite class as needed. Here the class name is
ConstPattern. It inherits from OpRewritePattern. Define it’smatchAndRewrite()function. ReferConstPatternclass inside KernelSelectionPass.cpp.