X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FPassSupport.h;h=8206e5f28e6a11ec524af3db9c15295704aa94df;hb=21d03f2de0087d60dbf575d95924404a97852879;hp=567ea9adf0c4bc290d80bba7a21104b078578697;hpb=ada23c05f5ebc94ea4630283e993270f19809ae9;p=oota-llvm.git diff --git a/include/llvm/PassSupport.h b/include/llvm/PassSupport.h index 567ea9adf0c..8206e5f28e6 100644 --- a/include/llvm/PassSupport.h +++ b/include/llvm/PassSupport.h @@ -1,5 +1,12 @@ //===- llvm/PassSupport.h - Pass Support code -------------------*- C++ -*-===// // +// The LLVM Compiler Infrastructure +// +// This file was developed by the LLVM research group and is distributed under +// the University of Illinois Open Source License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// // This file defines stuff that is used to define and "use" Passes. This file // is automatically #included by Pass.h, so: // @@ -16,7 +23,8 @@ // No need to include Pass.h, we are being included by it! -class TargetData; +namespace llvm { + class TargetMachine; //===--------------------------------------------------------------------------- @@ -33,7 +41,7 @@ class PassInfo { std::vector ItfImpl;// Interfaces implemented by this pass Pass *(*NormalCtor)(); // No argument ctor - Pass *(*DataCtor)(const TargetData&);// Ctor taking TargetData object... + Pass *(*TargetCtor)(TargetMachine&); // Ctor taking TargetMachine object... public: /// PassType - Define symbolic constants that can be used to test to see if @@ -42,15 +50,16 @@ public: /// AnalysisGroup flag with others. /// enum { - Analysis = 1, Optimization = 2, LLC = 4, AnalysisGroup = 8 + Analysis = 1, Optimization = 2, AnalysisGroup = 4 }; /// PassInfo ctor - Do not call this directly, this should only be invoked /// through RegisterPass. - PassInfo(const char *name, const char *arg, const std::type_info &ti, - unsigned pt, Pass *(*normal)(), Pass *(*data)(const TargetData &)) + PassInfo(const char *name, const char *arg, const std::type_info &ti, + unsigned char pt, Pass *(*normal)() = 0, + Pass *(*targetctor)(TargetMachine &) = 0) : PassName(name), PassArgument(arg), TypeInfo(ti), PassType(pt), - NormalCtor(normal), DataCtor(data) { + NormalCtor(normal), TargetCtor(targetctor) { } /// getPassName - Return the friendly name for the pass, never returns null @@ -77,7 +86,7 @@ public: /// getNormalCtor - Return a pointer to a function, that when called, creates /// an instance of the pass and returns it. This pointer may be null if there /// is no default constructor for the pass. - /// + /// Pass *(*getNormalCtor() const)() { return NormalCtor; } @@ -94,12 +103,12 @@ public: return NormalCtor(); } - /// getDataCtor - Return a pointer to a function that creates an instance of + /// getTargetCtor - Return a pointer to a function that creates an instance of /// the pass and returns it. This returns a constructor for a version of the - /// pass that takes a TArgetData object as a parameter. + /// pass that takes a TargetMachine object as a parameter. /// - Pass *(*getDataCtor() const)(const TargetData &) { - return DataCtor; + Pass *(*getTargetCtor() const)(TargetMachine &) { + return TargetCtor; } /// addInterfaceImplemented - This method is called when this pass is @@ -126,7 +135,7 @@ public: /// for example will not be able to see the pass and attempts to create the pass /// will fail. This template is used in the follow manner (at global scope, in /// your .cpp file): -/// +/// /// static RegisterPass tmp("passopt", "My Pass Name"); /// /// This statement will cause your pass to be created by calling the default @@ -136,26 +145,40 @@ public: /// /// Pass *createMyPass(foo &opt) { return new MyPass(opt); } /// static RegisterPass tmp("passopt", "My Name", createMyPass); -/// +/// struct RegisterPassBase { /// getPassInfo - Get the pass info for the registered class... /// - const PassInfo *getPassInfo() const { return PIObj; } + const PassInfo *getPassInfo() const { return &PIObj; } - RegisterPassBase() : PIObj(0) {} - ~RegisterPassBase() { // Intentionally non-virtual... - if (PIObj) unregisterPass(PIObj); + RegisterPassBase(const char *Name, const char *Arg, const std::type_info &TI, + unsigned char PT, Pass *(*Normal)() = 0, + Pass *(*TargetCtor)(TargetMachine &) = 0) + : PIObj(Name, Arg, TI, PT, Normal, TargetCtor) { + registerPass(); + } + RegisterPassBase(const std::type_info &TI, unsigned char PT) + : PIObj("", "", TI, PT, 0, 0) { + // This ctor may only be used for analysis groups: it does not auto-register + // the pass. + assert(PT == PassInfo::AnalysisGroup && "Not an AnalysisGroup!"); + } + + ~RegisterPassBase() { // Intentionally non-virtual. + // Analysis groups are registered/unregistered by their dtor. + if (PIObj.getPassType() != PassInfo::AnalysisGroup) + unregisterPass(); } protected: - PassInfo *PIObj; // The PassInfo object for this pass - void registerPass(PassInfo *); - void unregisterPass(PassInfo *); + PassInfo PIObj; // The PassInfo object for this pass + void registerPass(); + void unregisterPass(); - /// setPreservesCFG - Notice that this pass only depends on the CFG, so + /// setOnlyUsesCFG - Notice that this pass only depends on the CFG, so /// transformations that do not modify the CFG do not invalidate this pass. /// - void setPreservesCFG(); + void setOnlyUsesCFG(); }; template @@ -163,32 +186,28 @@ Pass *callDefaultCtor() { return new PassName(); } template struct RegisterPass : public RegisterPassBase { - + // Register Pass using default constructor... - RegisterPass(const char *PassArg, const char *Name, unsigned PassTy = 0) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, - callDefaultCtor, 0)); - } + RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy = 0) + : RegisterPassBase(Name, PassArg, typeid(PassName), PassTy, + callDefaultCtor) {} // Register Pass using default constructor explicitly... - RegisterPass(const char *PassArg, const char *Name, unsigned PassTy, - Pass *(*ctor)()) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, ctor,0)); - } + RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy, + Pass *(*ctor)()) + : RegisterPassBase(Name, PassArg, typeid(PassName), PassTy, ctor) {} - // Register Pass using TargetData constructor... - RegisterPass(const char *PassArg, const char *Name, unsigned PassTy, - Pass *(*datactor)(const TargetData &)) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, - 0, datactor)); - } + // Register Pass using TargetMachine constructor... + RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy, + Pass *(*targetctor)(TargetMachine &)) + : RegisterPassBase(Name, PassArg, typeid(PassName), PassTy, + 0, targetctor) {} // Generic constructor version that has an unknown ctor type... template - RegisterPass(const char *PassArg, const char *Name, unsigned PassTy, - CtorType *Fn) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, 0, 0)); - } + RegisterPass(const char *PassArg, const char *Name, unsigned char PassTy, + CtorType *Fn) + : RegisterPassBase(Name, PassArg, typeid(PassName), PassTy, 0) {} }; /// RegisterOpt - Register something that is to show up in Opt, this is just a @@ -196,25 +215,47 @@ struct RegisterPass : public RegisterPassBase { /// template struct RegisterOpt : public RegisterPassBase { - RegisterOpt(const char *PassArg, const char *Name) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::Optimization, - callDefaultCtor, 0)); + RegisterOpt(const char *PassArg, const char *Name, bool CFGOnly = false) + : RegisterPassBase(Name, PassArg, typeid(PassName), PassInfo::Optimization, + callDefaultCtor) { + if (CFGOnly) setOnlyUsesCFG(); } /// Register Pass using default constructor explicitly... /// - RegisterOpt(const char *PassArg, const char *Name, Pass *(*ctor)()) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::Optimization, ctor, 0)); + RegisterOpt(const char *PassArg, const char *Name, Pass *(*ctor)(), + bool CFGOnly = false) + : RegisterPassBase(Name, PassArg, typeid(PassName), + PassInfo::Optimization, ctor) { + if (CFGOnly) setOnlyUsesCFG(); + } + + /// Register FunctionPass using default constructor explicitly... + /// + RegisterOpt(const char *PassArg, const char *Name, FunctionPass *(*ctor)(), + bool CFGOnly = false) + : RegisterPassBase(Name, PassArg, typeid(PassName), PassInfo::Optimization, + static_cast(ctor)) { + if (CFGOnly) setOnlyUsesCFG(); + } + + /// Register Pass using TargetMachine constructor... + /// + RegisterOpt(const char *PassArg, const char *Name, + Pass *(*targetctor)(TargetMachine &), bool CFGOnly = false) + : RegisterPassBase(Name, PassArg, typeid(PassName), + PassInfo::Optimization, 0, targetctor) { + if (CFGOnly) setOnlyUsesCFG(); } - /// Register Pass using TargetData constructor... + /// Register FunctionPass using TargetMachine constructor... /// RegisterOpt(const char *PassArg, const char *Name, - Pass *(*datactor)(const TargetData &)) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::Optimization, 0, datactor)); + FunctionPass *(*targetctor)(TargetMachine &), + bool CFGOnly = false) + : RegisterPassBase(Name, PassArg, typeid(PassName), PassInfo::Optimization, 0, + static_cast(targetctor)) { + if (CFGOnly) setOnlyUsesCFG(); } }; @@ -227,47 +268,10 @@ struct RegisterOpt : public RegisterPassBase { template struct RegisterAnalysis : public RegisterPassBase { RegisterAnalysis(const char *PassArg, const char *Name, - bool CFGOnly = false) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::Analysis, - callDefaultCtor, 0)); - if (CFGOnly) - setPreservesCFG(); - } -}; - -/// RegisterLLC - Register something that is to show up in LLC, this is just a -/// shortcut for specifying RegisterPass... -/// -template -struct RegisterLLC : public RegisterPassBase { - RegisterLLC(const char *PassArg, const char *Name) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::LLC, - callDefaultCtor, 0)); - } - - /// Register Pass using default constructor explicitly... - /// - RegisterLLC(const char *PassArg, const char *Name, Pass *(*ctor)()) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::LLC, ctor, 0)); - } - - /// Register Pass using TargetData constructor... - /// - RegisterLLC(const char *PassArg, const char *Name, - Pass *(*datactor)(const TargetData &)) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::LLC, 0, datactor)); - } - - /// Register Pass using TargetMachine constructor... - /// - RegisterLLC(const char *PassArg, const char *Name, - Pass *(*datactor)(TargetMachine &)) { - registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::LLC, 0, 0)); + bool CFGOnly = false) + : RegisterPassBase(Name, PassArg, typeid(PassName), PassInfo::Analysis, + callDefaultCtor) { + if (CFGOnly) setOnlyUsesCFG(); } }; @@ -373,4 +377,7 @@ struct PassRegistrationListener { struct IncludeFile { IncludeFile(void *); }; + +} // End llvm namespace + #endif