From a081baac7726cfa49cc0879230feba258053600c Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Mon, 16 Sep 2002 16:01:39 +0000 Subject: [PATCH] Add support for passes that use a TargetMachine object. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3748 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/PassSupport.h | 52 ++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/include/llvm/PassSupport.h b/include/llvm/PassSupport.h index 567ea9adf0c..62fdf265eb0 100644 --- a/include/llvm/PassSupport.h +++ b/include/llvm/PassSupport.h @@ -33,7 +33,8 @@ class PassInfo { std::vector ItfImpl;// Interfaces implemented by this pass Pass *(*NormalCtor)(); // No argument ctor - Pass *(*DataCtor)(const TargetData&);// Ctor taking TargetData object... + Pass *(*DataCtor)(const TargetData&);// Ctor taking const TargetData object... + Pass *(*TargetCtor)(TargetMachine&); // Ctor taking TargetMachine object... public: /// PassType - Define symbolic constants that can be used to test to see if @@ -48,9 +49,11 @@ public: /// 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 &)) + unsigned pt, Pass *(*normal)() = 0, + Pass *(*datactor)(const TargetData &) = 0, + Pass *(*targetctor)(TargetMachine &) = 0) : PassName(name), PassArgument(arg), TypeInfo(ti), PassType(pt), - NormalCtor(normal), DataCtor(data) { + NormalCtor(normal), DataCtor(datactor), TargetCtor(targetctor) { } /// getPassName - Return the friendly name for the pass, never returns null @@ -96,12 +99,20 @@ public: /// getDataCtor - 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 TargetData object as a parameter. /// Pass *(*getDataCtor() const)(const TargetData &) { return DataCtor; } + /// 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 TargetMachine object as a parameter. + /// + Pass *(*getTargetCtor() const)(TargetMachine &) { + return TargetCtor; + } + /// addInterfaceImplemented - This method is called when this pass is /// registered as a member of an analysis group with the RegisterAnalysisGroup /// template. @@ -167,13 +178,13 @@ 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)); + 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(new PassInfo(Name, PassArg, typeid(PassName), PassTy, ctor)); } // Register Pass using TargetData constructor... @@ -183,11 +194,18 @@ struct RegisterPass : public RegisterPassBase { 0, datactor)); } + // Register Pass using TargetMachine constructor... + RegisterPass(const char *PassArg, const char *Name, unsigned PassTy, + Pass *(*targetctor)(TargetMachine &)) { + registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassTy, + 0, 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(new PassInfo(Name, PassArg, typeid(PassName), PassTy, 0)); } }; @@ -199,14 +217,14 @@ struct RegisterOpt : public RegisterPassBase { RegisterOpt(const char *PassArg, const char *Name) { registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassInfo::Optimization, - callDefaultCtor, 0)); + callDefaultCtor)); } /// 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)); + PassInfo::Optimization, ctor)); } /// Register Pass using TargetData constructor... @@ -216,6 +234,14 @@ struct RegisterOpt : public RegisterPassBase { registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassInfo::Optimization, 0, datactor)); } + + /// Register Pass using TargetMachine constructor... + /// + RegisterOpt(const char *PassArg, const char *Name, + Pass *(*targetctor)(TargetMachine &)) { + registerPass(new PassInfo(Name, PassArg, typeid(PassName), + PassInfo::Optimization, 0, 0, targetctor)); + } }; /// RegisterAnalysis - Register something that is to show up in Analysis, this @@ -230,7 +256,7 @@ struct RegisterAnalysis : public RegisterPassBase { bool CFGOnly = false) { registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassInfo::Analysis, - callDefaultCtor, 0)); + callDefaultCtor)); if (CFGOnly) setPreservesCFG(); } @@ -244,14 +270,14 @@ struct RegisterLLC : public RegisterPassBase { RegisterLLC(const char *PassArg, const char *Name) { registerPass(new PassInfo(Name, PassArg, typeid(PassName), PassInfo::LLC, - callDefaultCtor, 0)); + callDefaultCtor)); } /// 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)); + PassInfo::LLC, ctor)); } /// Register Pass using TargetData constructor... @@ -267,7 +293,7 @@ struct RegisterLLC : public RegisterPassBase { RegisterLLC(const char *PassArg, const char *Name, Pass *(*datactor)(TargetMachine &)) { registerPass(new PassInfo(Name, PassArg, typeid(PassName), - PassInfo::LLC, 0, 0)); + PassInfo::LLC)); } };