LLVM 源码分析 (二)ModulePass 类
来源:互联网 发布:国外的社交软件 编辑:程序博客网 时间:2024/05/22 22:58
上一篇写的是关于pass 类 这个类是一个抽象类 具体实现是通过例如modulePass FunctionPass实现的
本文将重点介绍module pass
这个Pass 可以操作整个module 是以文件进行区分的。ModulePass 可以操作Module 下的大部分 基本是万能的但是不是最方便的。我们需要根据需要选择 FunctionPass LoopPass 等
vs2008
doxygen
主要新出现的类成员
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
/// runOnModule - Virtual method overriden by subclasses to process the module/// being operated on.virtual bool runOnModule(Module &M) = 0; bool runOnModule(Module &M) { (*Out) << Banner << M; return false; }
源码来自PrintSCC.cpp
// run - Print out SCCs in the call graph for the specified module.bool CallGraphSCC::runOnModule(Module &M) { CallGraphNode* rootNode = getAnalysis<CallGraph>().getRoot(); unsigned sccNum = 0; errs() << "SCCs for the program in PostOrder:"; for (scc_iterator<CallGraphNode*> SCCI = scc_begin(rootNode), E = scc_end(rootNode); SCCI != E; ++SCCI) { const std::vector<CallGraphNode*> &nextSCC = *SCCI; errs() << "\nSCC #" << ++sccNum << " : "; for (std::vector<CallGraphNode*>::const_iterator I = nextSCC.begin(), E = nextSCC.end(); I != E; ++I) errs() << ((*I)->getFunction() ? (*I)->getFunction()->getName() : "external node") << ", "; if (nextSCC.size() == 1 && SCCI.hasLoop()) errs() << " (Has self-loop)."; } errs() << "\n"; return true;}
下面给出源码中使用MudulePass的一个例子
#include "llvm/ADT/SetVector.h"#include "llvm/Pass.h"namespace llvm {class Type;class Value;class FindUsedTypes : public ModulePass { SetVector<Type *> UsedTypes;public: static char ID; // Pass identification, replacement for typeid FindUsedTypes() : ModulePass(ID) { initializeFindUsedTypesPass(*PassRegistry::getPassRegistry()); } /// getTypes - After the pass has been run, return the set containing all of /// the types used in the module. /// const SetVector<Type *> &getTypes() const { return UsedTypes; } /// Print the types found in the module. If the optional Module parameter is /// passed in, then the types are printed symbolically if possible, using the /// symbol table from the module. /// void print(raw_ostream &o, const Module *M) const;private: /// IncorporateType - Incorporate one type and all of its subtypes into the /// collection of used types. /// void IncorporateType(Type *Ty); /// IncorporateValue - Incorporate all of the types used by this value. /// void IncorporateValue(const Value *V);public: /// run - This incorporates all types used by the specified module bool runOnModule(Module &M); /// getAnalysisUsage - We do not modify anything. virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesAll(); }};} // End llvm namespace
- LLVM 源码分析 (二)ModulePass 类
- LLVM 源码分析 (一) pass 类
- LLVM 源码分析(三)ImmutablePass
- LLVM 源码分析(四)FunctionPass
- LLVM 源码分析(五)BasicBlockPass
- LLVM源码--PointerIntPairInfo类
- LLVM教程(二)-- LLVM的安装
- (二)使用llvm进行程序分析-hotspot、path
- LLVM(二):后端结构
- llvm學習(二)————llvm編譯與環境構建
- ResourceBundle 类介绍 (二)源码分析
- LLVM每日谈之十二 LLVM的源码分析之Pass相关
- JUnit源码分析(二)
- Log4net源码分析(二)
- Log4net源码分析(二)
- Logcat源码分析(二)
- FFMPEG源码分析(二)
- FFMPEG源码分析(二)
- 高可用性中间件 OpenSAF
- 身份证号码15到18位升位算法
- S5PV210(TQ210)学习笔记——输入子系统驱动
- java下scanner输入
- ATCA
- LLVM 源码分析 (二)ModulePass 类
- 关于字符串String
- Linux tcpdump命令
- 使用Aspose.Pdf在PDF文档中添加书签
- linux下查看硬件资源的几个常用命令
- C# 事件(2)
- AE导出图片并插入到word文档中某一固定位置
- 编译Linux内核
- ActiveMQ