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 constructor 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 NarrowFloatSelectPass. The complete set of code is available under compiler/torq/Codegen
Create a copy of any pass available in the Passes.td. Change the name of the pass to
NarrowFloatSelectChange 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-narrow-float-select Change summary to provide a brief summary of the pass. Change theconstructorto a custom construction name, here changed to mlir::syna::torq::createNarrowFloatSelectPass(). Add the dependentDialects as needed. Refer Passes.tdIn Passes.h add declaration for the constructor we have named above.
std::unique_ptr<InterfacePass<FunctionOpInterface>> createNarrowFloatSelectPass()In PassesDetail.h add#define GEN_PASS_DEF_NARROWFLOATSELECTto generate the base class of the pass.Add the pass to a pipeline using the
addPassmethod, for example in TORQLowerExecutableTargetPass.cpp. NarrowFloatSelect is added to the CPU program pipeline in CompileCpuProgramsPass.cpp.Create the file
NarrowFloatSelectPass.cppin the folder compiler/torq/CodegenDefine the NarrowFloatSelectPass class in the file. It should inherit the generated impl::NarrowFloatSelectBase using CRTP
class NarrowFloatSelectPass : public impl::NarrowFloatSelectBase<NarrowFloatSelectPass>Define the
runOnOperation()function. Refer NarrowFloatSelectPassDefine the
createNarrowFloatSelectPass()constructor. It should return a unique_ptr to InterfacePass. Refer the NarrowFloatSelectPass.cpp for more info.Define the pattern rewrite class as needed. Here the class name is
NarrowSelectOfExtF. It inherits from OpRewritePattern. Define itsmatchAndRewrite()function. Refer theNarrowSelectOfExtFclass inside NarrowFloatSelectPass.cpp.Add
NarrowFloatSelectPass.cppto the source list in compiler/torq/Codegen/CMakeLists.txt.