diff --git a/docs/WritingAnLLVMPass.html b/docs/WritingAnLLVMPass.html index 1f53f050bae..cb9729f975f 100644 --- a/docs/WritingAnLLVMPass.html +++ b/docs/WritingAnLLVMPass.html @@ -18,7 +18,7 @@
The LLVM Pass Framework is an important part of the LLVM system, because LLVM -passes are where the interesting parts of the compiler exist. Passes perform -the transformations and optimizations that make up the compiler, they build -the analysis results that are used by these transformations, and they are, above -all, a structuring technique for compiler code.
+passes are where most of the interesting parts of the compiler exist. Passes +perform the transformations and optimizations that make up the compiler, they +build the analysis results that are used by these transformations, and they are, +above all, a structuring technique for compiler code.All LLVM passes are subclasses of the Pass class, which implement functionality by overriding virtual methods inherited from Pass. Depending on how your pass works, you may be able to -inherit from the FunctionPass -or BasicBlockPass, -which gives the system more information about what your pass does, and how it -can be combined with other passes. One of the main features of the LLVM Pass -Framework is that it schedules passes to run in an efficient way based on the -constraints that your pass has.
+inherit from the CallGraphSCCPass, +FunctionPass, or BasicBlockPass classes, which gives the system +more information about what your pass does, and how it can be combined with +other passes. One of the main features of the LLVM Pass Framework is that it +schedules passes to run in an efficient way based on the constraints that your +pass meets (which are indicated by which class they derive from).We start by showing you how to construct a pass, everything from setting up the code, to compiling, loading, and executing it. After the basics are down, @@ -134,7 +141,7 @@ more advanced features are discussed.
Here we describe how to write the "hello world" of passes. The "Hello" pass is designed to simply print out the name of non-external functions that exist in -the program being compiled. It does not modify the program at all, just +the program being compiled. It does not modify the program at all, it just inspects it. The source code and files for this pass are available in the LLVM source tree in the lib/Transforms/Hello directory.
@@ -175,7 +182,7 @@ include $(LEVEL)/Makefile.common directory are to be compiled and linked together into a lib/Debug/libhello.so shared object that can be dynamically loaded by the opt or analyze tools. If your operating system uses a -suffix other than .so (such as windows of Mac OS/X), the appropriate extension +suffix other than .so (such as windows or Mac OS/X), the appropriate extension will be used.Now that we have the build scripts set up, we just need to write the code for @@ -464,6 +471,114 @@ otherwise.
The "CallGraphSCCPass" +is used by passes that need to traverse the program bottom-up on the call graph +(callees before callers). Deriving from CallGraphSCCPass provides some +mechanics for building and traversing the CallGraph, but also allows the system +to optimize execution of CallGraphSCCPass's. If your pass meets the +requirements outlined below, and doesn't meet the requirements of a FunctionPass or BasicBlockPass, you should derive from +CallGraphSCCPass.
+ +TODO: explain briefly what SCC, Tarjan's algo, and B-U mean.
+ +To be explicit, CallGraphSCCPass subclasses are:
+ +Implementing a CallGraphSCCPass is slightly tricky in some cases +because it has to handle SCCs with more than one node in it. All of the virtual +methods described below should return true if they modified the program, or +false if they didn't.
+ ++ virtual bool doInitialization(Module &M); ++ +
The doIninitialize method is allowed to do most of the things that +CallGraphSCCPass's are not allowed to do. They can add and remove +functions, get pointers to functions, etc. The doInitialization method +is designed to do simple initialization type of stuff that does not depend on +the SCCs being processed. The doInitialization method call is not +scheduled to overlap with any other pass executions (thus it should be very +fast).
+ ++ virtual bool runOnSCC(const std::vector<CallGraphNode *> &SCCM) = 0; ++ +
The runOnSCC method performs the interesting work of the pass, and +should return true if the module was modified by the transformation, false +otherwise.
+ ++ virtual bool doFinalization(Module &M); ++ +
The doFinalization method is an infrequently used method that is +called when the pass framework has finished calling runOnFunction for every function in the +program being compiled.
+ +