Until now, a new pass was a dynamic object that was run independently. The opt tool consists of a pipeline of such passes that are registered with the pass manager, and a part of LLVM. Let's see how to register our pass with the Pass Manager.
The PassManager
class takes a list of passes, ensures that their prerequisites are set up correctly, and then schedules the passes to run efficiently. The Pass Manager does two main tasks to try to reduce the execution time of a series of passes:
Follow the given steps to register a pass with Pass Manager:
DEBUG_TYPE
macro, specifying the debugging name in the FuncBlockCount.cpp
file:#define DEBUG_TYPE "func-block-count"
FuncBlockCount
struct, specify the getAnalysisUsage
syntax as follows:void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<LoopInfoWrapperPass>(); }
INITIALIZE_PASS_BEGIN(FuncBlockCount, " funcblockcount ", "Function Block Count", false, false) INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) INITIALIZE_PASS_END(FuncBlockCount, "funcblockcount", "Function Block Count", false, false) Pass *llvm::createFuncBlockCountPass() { return new FuncBlockCount(); }
createFuncBlockCount
Pass function in the LinkAllPasses.h
file, located at include/llvm/
:(void) llvm:: createFuncBlockCountPass ();
Scalar.h
file, located at include/llvm/Transforms
:Pass * createFuncBlockCountPass ();
FuncBlockCount() : FunctionPass(ID) {initializeFuncBlockCount Pass (*PassRegistry::getPassRegistry());}
Scalar.cpp file
, located at lib/Transforms/Scalar/
, add the initialization pass entry:initializeFuncBlockCountPass (Registry);
InitializePasses.h
file, which is located at include/llvm/
:void initializeFuncBlockCountPass (Registry);
FuncBlockCount.cpp
filename to the CMakeLists.txt
file, located at lib/Transforms/Scalar/
:FuncBlockCount.cpp
Compile the LLVM with the cmake
command as specified in Chapter 1, LLVM Design and Use. The Pass Manager will include this pass in the pass pipeline of the opt command-line tool. Also, this pass can be run in isolation from the command line:
$ opt –funcblockcount sample.ll
3.145.172.146