LLVM 源码分析 (一) pass 类

本文深入探讨LLVM框架中的Pass接口,包括assignPassManager、preparePassManager等方法,阐述其在编译优化过程中的作用。通过实例解析各个方法的功能,如createPass、print、dump等,以及getPassName、getPassID等获取信息的方法。同时,讨论了getAnalysis和mustPreserveAnalysisID在分析依赖管理中的角色。
摘要由CSDN通过智能技术生成



Pass interface - Implemented by all 'passes'. Subclass this if you are an interprocedural optimization or you do not fit into any of the more constrained passes described below. 

 
摘取自pass.h  更清晰显示pass类
#include "llvm/Support/Compiler.h"
#include <string>

namespace llvm {

class BasicBlock;
class Function;
class Module;
class AnalysisUsage;
class PassInfo;
class ImmutablePass;
class PMStack;
class AnalysisResolver;
class PMDataManager;
class raw_ostream;
class StringRef;

// AnalysisID - Use the PassInfo to identify a pass...
typedef const void* AnalysisID;

/// Different types of internal pass managers. External pass managers
/// (PassManager and FunctionPassManager) are not represented here.
/// Ordering of pass manager types is important here.
enum PassManagerType {
  PMT_Unknown = 0,
  PMT_ModulePassManager = 1, ///< MPPassManager
  PMT_CallGraphPassManager,  ///< CGPassManager
  PMT_FunctionPassManager,   ///< FPPassManager
  PMT_LoopPassManager,       ///< LPPassManager
  PMT_RegionPassManager,     ///< RGPassManager
  PMT_BasicBlockPassManager, ///< BBPassManager
  PMT_Last
};

// Different types of passes.
enum PassKind {
  PT_BasicBlock,
  PT_Region,
  PT_Loop,
  PT_Function,
  PT_CallGraphSCC,
  PT_Module,
  PT_PassManager
};

//===----------------------------------------------------------------------===//
/// Pass interface - Implemented by all 'passes'.  Subclass this if you are an
/// interprocedural optimization or you do not fit into any of the more
/// constrained passes described below.
///
class Pass {
  AnalysisResolver *Resolver;  // Used to resolve analysis
  const void *PassID;
  PassKind Kind;
  void operator=(const Pass&) LLVM_DELETED_FUNCTION;
  Pass(const Pass &) LLVM_DELETED_FUNCTION;

public:
  explicit Pass(PassKind K, char &pid) : Resolver(0), PassID(&pid), Kind(K) { }
  virtual ~Pass();


  PassKind getPassKind() const { return Kind; }

  /// getPassName - Return a nice clean name for a pass.  This usually
  /// implemented in terms of the name that is registered by one of the
  /// Registration templates, but can be overloaded directly.
  ///
  virtual const char *getPassName() const;

  /// getPassID - Return the PassID number that corresponds to this pass.
  AnalysisID getPassID() const {
    return PassID;
  }

  /// print - Print out the internal state of the pass.  This is called by
  /// Analyze to print out the contents of an analysis.  Otherwise it is not
  /// necessary to implement this method.  Beware that the module pointer MAY be
  /// null.  This automatically forwards to a virtual function that does not
  /// provide the Module* in case the analysis doesn't need it it can just be
  /// ignored.
  ///
  virtual void print(raw_ostream &O, const Module *M) const;
  void dump() const; // dump - Print to stderr.

  /// createPrinterPass - Get a Pass appropriate to print the IR this
  /// pass operates on (Module, Function or MachineFunction).
  virtual Pass *createPrinterPass(raw_ostream &O,
                                  const std::string &Banner) const = 0;

  /// Each
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值