00001 /* 00002 00003 Copyright (C) 2008 . All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 */ 00025 00026 #ifndef dipa_phase_INCLUDED 00027 #define dipa_phase_INCLUDED 00028 00029 #include <list> 00030 #include <utility> 00031 00032 #include "mempool.h" 00033 00034 /* ==================================================================== 00035 * ==================================================================== 00036 * 00037 * 00038 * Description: 00039 * 00040 * This module provides the interface for phase control. It is based on 00041 * the program-independent functions provided by rta/open64/resource.h. 00042 * 00043 * ==================================================================== 00044 * ==================================================================== 00045 */ 00046 00047 /* 00048 * Temporary: 00049 * In current implementation, phase id is bound to timer id which is used to collect resource 00050 * usage statistics. It will be changed later. 00051 */ 00052 typedef INT32 PHASE_ID; 00053 00054 #define INVALID_PHASE_ID (PHASE_ID)(-1) 00055 00056 /* Temporary references to old functions for collecting usage statistics */ 00057 #define Timer(i) Get_Rstate(i) 00058 extern void Add_Timer_To_Parent ( INT Timer_ID ); 00059 00060 class PHASE_STAT; 00061 class DIPA_Phase; 00062 00063 /* 00064 * Please extend this class to handle DIPA object files 00065 */ 00066 class DIPA_Obj { 00067 private: 00068 char *rfile; 00069 public: 00070 void Set_Rfile(char *filename) { rfile = filename; } 00071 char *Get_Rfile(void) { return rfile; } 00072 00073 // void *operator new (UINT num_bytes, MEM_POOL *pool) { 00074 // return MEM_POOL_Alloc(pool, num_bytes); 00075 // } 00076 }; 00077 00078 typedef std::list<DIPA_Obj * > DIPA_Olist; 00079 typedef DIPA_Olist::iterator DIPA_Olist_Iter; 00080 00081 00082 typedef std::pair<const char *, const char * > CMD_ARG; 00083 00084 typedef std::list<CMD_ARG> CMD_ARGS; 00085 typedef CMD_ARGS::iterator CMD_ARGS_Iter; 00086 00087 typedef std::list<DIPA_Phase *> Phase_List; 00088 typedef Phase_List::iterator Phase_Iter; 00089 00090 class DIPA_Phase { 00091 private: 00092 DIPA_Phase *parent; // parent phase if this is a sub function 00093 Phase_List childs; // double-linked list for all phases at the same level 00094 00095 CMD_ARGS arg_list; // phase specific arguments 00096 PHASE_ID phase_id; // a unique integer ID 00097 const char *phase_name; 00098 PHASE_STAT *phase_stat; // statistics information like cpu and memory usage 00099 DIPA_Olist *rolist; // Object files to be processed 00100 BOOL enabled; // if this phase is enabled or not 00101 BOOL tracing_enabled; // enable tracing or not 00102 00103 public: 00104 DIPA_Phase(const char *_name); 00105 ~DIPA_Phase(); 00106 00107 void Add_Arg(char *arg); 00108 virtual void Proc_Arg(CMD_ARGS *args, DIPA_Olist *olist); 00109 00110 const char *Get_Name(void) {return phase_name; } 00111 void Set_Name(const char *_name) { phase_name = _name; } 00112 PHASE_ID Get_Id(void) { return phase_id; } 00113 void Set_Id(PHASE_ID _id) { phase_id = _id; } 00114 00115 void Enable(void) { enabled = true; } 00116 void Disable(void) { enabled = false; } 00117 BOOL Is_Enabled(void) { return enabled; } 00118 00119 void Enable_Tracing(void) { tracing_enabled = true; } 00120 void Disable_Tracing(void) { tracing_enabled = false; } 00121 BOOL Is_Tracing_Enabled(void) { return tracing_enabled; } 00122 00123 virtual void Pre_Dump_IR(FILE *file=NULL); 00124 virtual void Post_Dump_IR(FILE *file=NULL); 00125 00126 Phase_List *Get_Childs(void) { return &childs; } 00127 00128 virtual BOOL Start(CMD_ARGS *args, DIPA_Olist *olist); /* Process IPA objects */ 00129 virtual BOOL Stop(void) {} /* Stop execution of a phase */ 00130 virtual BOOL Cleanup(void) {} /* Phase cleanup */ 00131 00132 virtual void Help(void); /* Provide phase specific help message */ 00133 00134 void Accum_Stats(void); 00135 void Accum_Stats(DIPA_Phase *ph); 00136 00137 void Set_Resource_Limit(INT32 millisecs, INT32 kbytes); 00138 void Dump_Time_Usage(FILE *file=NULL) {} 00139 void Dump_Mem_Usage(FILE *file=NULL) {} 00140 void Dump_Mem_Prof(FILE *file=NULL) {} 00141 void Dump_Stats(FILE *file=NULL); 00142 00143 void Dump_Phase(INT32 level) { 00144 for (INT32 i=0; i<level+1; i++) 00145 printf(" "); 00146 printf("phase name: [%s]\n", phase_name); 00147 if (!childs.empty()) { 00148 Phase_Iter it; 00149 for (it = childs.begin(); it != childs.end(); it++) 00150 (*it)->Dump_Phase(level+1); 00151 } 00152 } 00153 }; 00154 #endif /* dipa_phase_INCLUDED */
1.5.6