Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ShOptimizations.hpp

00001 #ifndef SHOPTIMIZATIONS_HPP 00002 #define SHOPTIMIZATIONS_HPP 00003 00004 #include "ShProgram.hpp" 00005 #include "ShStatement.hpp" 00006 #include <vector> 00007 #include <set> 00008 00009 // Uncomment this to turn on optimizer debugging using dot. 00010 // Warning: This is very verbose! 00011 //#define SH_DEBUG_OPTIMIZER 00012 00013 namespace SH { 00014 00016 SH_DLLEXPORT 00017 void optimize(ShProgram& p, int level); 00018 SH_DLLEXPORT 00019 void optimize(const ShProgramNodePtr& p, int level); 00020 00023 SH_DLLEXPORT 00024 void optimize(ShProgram& p); 00025 SH_DLLEXPORT 00026 void optimize(const ShProgramNodePtr& p); 00027 00028 // Internal stuff. 00029 00030 // Add value tracking information to the given program's CFG 00031 // statements. 00032 // If it already exists, overwrite it. 00033 SH_DLLEXPORT 00034 void add_value_tracking(ShProgram& prg); 00035 00037 SH_DLLEXPORT 00038 void insert_branch_instructions(ShProgram& prg); 00039 00041 SH_DLLEXPORT 00042 void remove_branch_instructions(ShProgram& prg); 00043 00045 SH_DLLEXPORT 00046 void straighten(ShProgram& p, bool& changed); 00047 00049 SH_DLLEXPORT 00050 void remove_dead_code(ShProgram& p, bool& changed); 00051 00053 SH_DLLEXPORT 00054 void propagate_constants(ShProgram& p); 00055 00056 struct 00057 SH_DLLEXPORT 00058 ValueTracking : public ShStatementInfo { 00059 ValueTracking(ShStatement* stmt); 00060 00061 ShStatementInfo* clone() const; 00062 00063 struct Def { 00064 Def(ShStatement* stmt, int index) 00065 : stmt(stmt), index(index) 00066 { 00067 } 00068 00069 ShStatement* stmt; 00070 int index; 00071 00072 bool operator<(const Def& other) const 00073 { 00074 return stmt < other.stmt || (stmt == other.stmt && index < other.index); 00075 } 00076 }; 00077 struct Use { 00078 Use(ShStatement* stmt, int source, int index) 00079 : stmt(stmt), source(source), index(index) 00080 { 00081 } 00082 00083 bool operator<(const Use& other) const 00084 { 00085 return stmt < other.stmt 00086 || (stmt == other.stmt && (source < other.source 00087 || (source == other.source && index < other.index))); 00088 } 00089 00090 ShStatement* stmt; 00091 int source; // source variable 00092 int index; // tuple index 00093 }; 00094 00095 // For each tuple element, track all of the uses of our definition. 00096 typedef std::set<Use> DefUseChain; 00097 typedef std::vector<DefUseChain> TupleDefUseChain; 00098 TupleDefUseChain uses; 00099 00100 // For each tuple element in each of our sources, track all the 00101 // definition points. 00102 typedef std::set<Def> UseDefChain; 00103 typedef std::vector<UseDefChain> TupleUseDefChain; 00104 TupleUseDefChain defs[3]; 00105 }; 00106 00107 } 00108 00109 #endif

Generated on Mon Oct 18 14:17:39 2004 for Sh by doxygen 1.3.7