@@ -19,131 +19,116 @@ SPDX-License-Identifier: MIT
1919#include  < set> 
2020#include  < map> 
2121
22- namespace  IGC 
23- {
24-     class  CodeGenContext ;
22+ namespace  IGC  {
23+ class  CodeGenContext ;
2524}
2625
27- namespace  IGC 
28- {
29-     //  struct
30-     typedef  std::map<unsigned  int , llvm::Argument*> InfoToImpArgMap;
31-     typedef  std::map<llvm::Function*, InfoToImpArgMap> FuncInfoToImpArgMap;
32- 
33- 
34-     typedef  std::map<llvm::Argument*, unsigned  int > ImpArgToExpNum;
35-     typedef  std::map<llvm::Function*, ImpArgToExpNum> FuncImpToExpNumMap;
36- 
37-     // / @brief  AddImplicitArgs pass used for changing the function signatures and calls to represent
38-     // /         the implicit arguments needed by each function and passed from the OpenCL runtime
39-     // /         This pass depdends on the WIFuncAnalysis pass runing before it
40-     // / @Author Marina Yatsina
41-     class  AddImplicitArgs  : public  llvm ::ModulePass
42-     {
43-     public: 
44-         //  Pass identification, replacement for typeid
45-         static  char  ID;
46- 
47-         // / @brief  Constructor
48-         AddImplicitArgs ();
49- 
50-         // / @brief  Destructor
51-         ~AddImplicitArgs () {}
52- 
53-         // / @brief  Provides name of pass
54-         virtual  llvm::StringRef getPassName () const  override 
55-         {
56-             return  " AddImplicitArgs" 
57-         }
58- 
59-         virtual  void  getAnalysisUsage (llvm::AnalysisUsage &AU) const  override 
60-         {
61-             AU.addRequired <CodeGenContextWrapper>();
62-             AU.addRequired <MetaDataUtilsWrapper>();
63-         }
64- 
65-         // / @brief  Main entry point.
66-         // /         Goes over all functions and changes their signature to contain the implicit arguments
67-         // /         needed by each function, goes over all function calls and adds the implicit arguments
68-         // /         to the function calls
69-         // / @param  M The destination module.
70-         virtual  bool  runOnModule (llvm::Module &M) override ;
71- 
72-         // / @brief  Check if a function has a stackcall in its call path to
73-         // /         decide whether implicit args should be added
74-         // / @param  pFunc           Source function
75-         static  bool  hasStackCallInCG (const  llvm::Function* pFunc);
76-     private: 
77- 
78-         // / @brief  Create the type of the new function,
79-         // /         including all explicit and needed impliict parameters
80-         // / @param  pFunc           The old function
81-         // / @param  pImplicitArgs   The implicit arguments needed by this function
82-         // / @returns    The new function type
83-         static  llvm::FunctionType* getNewFuncType (const  llvm::Function* pFunc, const  ImplicitArgs& implicitArgs);
84- 
85-         // / @brief  Transfers uses of old arguments to new arguments, sets names of all arguments
86-         // / @param  pFunc           The old function
87-         // / @param  pNewFunc        The new function
88-         // / @param  pImplicitArgs   The implicit arguments needed by this function
89-         void  updateNewFuncArgs (llvm::Function* pFunc, llvm::Function* pNewFunc, const  ImplicitArgs& implicitArgs);
90- 
91-         // / @brief  Replace old CallInst with new CallInst
92-         void  replaceAllUsesWithNewOCLBuiltinFunction (llvm::Function* old_func, llvm::Function* new_func);
93- 
94-         static  llvm::Value* coerce (llvm::Value* arg, llvm::Type* type, llvm::Instruction* insertBefore);
95- 
96-         // / @brief  Metadata API object.
97-         IGC::IGCMD::MetaDataUtils *m_pMdUtils;
98- 
99-         FuncInfoToImpArgMap     m_FuncInfoToImpArgMap;
100-         FuncImpToExpNumMap      m_FuncImpToExpNumMap;
101-     };
26+ namespace  IGC  {
27+ //  struct
28+ typedef  std::map<unsigned  int , llvm::Argument *> InfoToImpArgMap;
29+ typedef  std::map<llvm::Function *, InfoToImpArgMap> FuncInfoToImpArgMap;
30+ 
31+ typedef  std::map<llvm::Argument *, unsigned  int > ImpArgToExpNum;
32+ typedef  std::map<llvm::Function *, ImpArgToExpNum> FuncImpToExpNumMap;
33+ 
34+ // / @brief  AddImplicitArgs pass used for changing the function signatures and calls to represent
35+ // /         the implicit arguments needed by each function and passed from the OpenCL runtime
36+ // /         This pass depdends on the WIFuncAnalysis pass runing before it
37+ // / @Author Marina Yatsina
38+ class  AddImplicitArgs  : public  llvm ::ModulePass {
39+ public: 
40+   //  Pass identification, replacement for typeid
41+   static  char  ID;
42+ 
43+   // / @brief  Constructor
44+   AddImplicitArgs ();
45+ 
46+   // / @brief  Destructor
47+   ~AddImplicitArgs () {}
48+ 
49+   // / @brief  Provides name of pass
50+   virtual  llvm::StringRef getPassName () const  override  { return  " AddImplicitArgs" 
51+ 
52+   virtual  void  getAnalysisUsage (llvm::AnalysisUsage &AU) const  override  {
53+     AU.addRequired <CodeGenContextWrapper>();
54+     AU.addRequired <MetaDataUtilsWrapper>();
55+   }
56+ 
57+   // / @brief  Main entry point.
58+   // /         Goes over all functions and changes their signature to contain the implicit arguments
59+   // /         needed by each function, goes over all function calls and adds the implicit arguments
60+   // /         to the function calls
61+   // / @param  M The destination module.
62+   virtual  bool  runOnModule (llvm::Module &M) override ;
63+ 
64+   // / @brief  Check if a function has a stackcall in its call path to
65+   // /         decide whether implicit args should be added
66+   // / @param  pFunc           Source function
67+   static  bool  hasStackCallInCG (const  llvm::Function *pFunc);
68+ 
69+ private: 
70+   // / @brief  Create the type of the new function,
71+   // /         including all explicit and needed impliict parameters
72+   // / @param  pFunc           The old function
73+   // / @param  pImplicitArgs   The implicit arguments needed by this function
74+   // / @returns    The new function type
75+   static  llvm::FunctionType *getNewFuncType (const  llvm::Function *pFunc, const  ImplicitArgs &implicitArgs);
76+ 
77+   // / @brief  Transfers uses of old arguments to new arguments, sets names of all arguments
78+   // / @param  pFunc           The old function
79+   // / @param  pNewFunc        The new function
80+   // / @param  pImplicitArgs   The implicit arguments needed by this function
81+   void  updateNewFuncArgs (llvm::Function *pFunc, llvm::Function *pNewFunc, const  ImplicitArgs &implicitArgs);
82+ 
83+   // / @brief  Replace old CallInst with new CallInst
84+   void  replaceAllUsesWithNewOCLBuiltinFunction (llvm::Function *old_func, llvm::Function *new_func);
85+ 
86+   static  llvm::Value *coerce (llvm::Value *arg, llvm::Type *type, llvm::Instruction *insertBefore);
87+ 
88+   // / @brief  Metadata API object.
89+   IGC::IGCMD::MetaDataUtils *m_pMdUtils;
90+ 
91+   FuncInfoToImpArgMap m_FuncInfoToImpArgMap;
92+   FuncImpToExpNumMap m_FuncImpToExpNumMap;
93+ };
10294
10395} //  namespace IGC
10496
10597//  Builtin CallGraph Analysis Class
106- namespace  IGC 
107- {
108- 
109-     struct  ImplicitArgumentDetail 
110-     {
111-         ImplicitArg::ArgMap     ArgsMaps;
112-         std::set<unsigned  int >  StructArgSet;
113-     };
114- 
115-     class  BuiltinCallGraphAnalysis  : public  llvm ::ModulePass
116-     {
117-     public: 
118-         static  char  ID;
119- 
120-         BuiltinCallGraphAnalysis ();
121-         ~BuiltinCallGraphAnalysis () {}
122- 
123-         virtual  llvm::StringRef getPassName () const  override 
124-         {
125-             return  " BuiltinCallGraphAnalysis" 
126-         }
127- 
128-         void  getAnalysisUsage (llvm::AnalysisUsage &AU) const  override 
129-         {
130-             AU.addRequired <MetaDataUtilsWrapper>();
131-             AU.addRequired <CodeGenContextWrapper>();
132-             AU.addRequired <llvm::CallGraphWrapperPass>();
133-         }
134- 
135-         virtual  bool  runOnModule (llvm::Module &M) override ;
136- 
137-         void  traverseCallGraphSCC (const  std::vector<llvm::CallGraphNode *> &SCCNodes);
138-         void  combineTwoArgDetail (ImplicitArgumentDetail&, const  ImplicitArgumentDetail&, llvm::Value*) const ;
139-         void  writeBackAllIntoMetaData (const  ImplicitArgumentDetail&, llvm::Function*);
140- 
141-         bool  pruneCallGraphForStackCalls (llvm::CallGraph& CG);
142- 
143-     private: 
144-         IGC::IGCMD::MetaDataUtils *m_pMdUtils;
145-         llvm::SmallDenseMap<llvm::Function*, ImplicitArgumentDetail *> argMap;
146-         llvm::SmallVector<std::unique_ptr<ImplicitArgumentDetail>, 4 > argDetails;
147-     };
98+ namespace  IGC  {
99+ 
100+ struct  ImplicitArgumentDetail  {
101+   ImplicitArg::ArgMap ArgsMaps;
102+   std::set<unsigned  int > StructArgSet;
103+ };
104+ 
105+ class  BuiltinCallGraphAnalysis  : public  llvm ::ModulePass {
106+ public: 
107+   static  char  ID;
108+ 
109+   BuiltinCallGraphAnalysis ();
110+   ~BuiltinCallGraphAnalysis () {}
111+ 
112+   virtual  llvm::StringRef getPassName () const  override  { return  " BuiltinCallGraphAnalysis" 
113+ 
114+   void  getAnalysisUsage (llvm::AnalysisUsage &AU) const  override  {
115+     AU.addRequired <MetaDataUtilsWrapper>();
116+     AU.addRequired <CodeGenContextWrapper>();
117+     AU.addRequired <llvm::CallGraphWrapperPass>();
118+   }
119+ 
120+   virtual  bool  runOnModule (llvm::Module &M) override ;
121+ 
122+   void  traverseCallGraphSCC (const  std::vector<llvm::CallGraphNode *> &SCCNodes);
123+   void  combineTwoArgDetail (ImplicitArgumentDetail &, const  ImplicitArgumentDetail &, llvm::Value *) const ;
124+   void  writeBackAllIntoMetaData (const  ImplicitArgumentDetail &, llvm::Function *);
125+ 
126+   bool  pruneCallGraphForStackCalls (llvm::CallGraph &CG);
127+ 
128+ private: 
129+   IGC::IGCMD::MetaDataUtils *m_pMdUtils;
130+   llvm::SmallDenseMap<llvm::Function *, ImplicitArgumentDetail *> argMap;
131+   llvm::SmallVector<std::unique_ptr<ImplicitArgumentDetail>, 4 > argDetails;
132+ };
148133
149134} //  namespace IGC
0 commit comments