Changeset 4804
- Timestamp:
- Sep 28, 2015, 2:39:59 PM (3 years ago)
- Location:
- icGREP/icgrep-devel/icgrep
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
icGREP/icgrep-devel/icgrep/UCD/ucd_compiler.cpp
r4797 r4804 9 9 10 10 namespace UCD { 11 12 /** ------------------------------------------------------------------------------------------------------------- * 13 * @brief addTarget 14 ** ------------------------------------------------------------------------------------------------------------- */ 15 inline void UCDCompiler::addTarget(const UnicodeSet & set) { 16 mTargetMap.emplace(&set, PabloBlock::createZeroes()); 17 } 11 18 12 19 /** ------------------------------------------------------------------------------------------------------------- * … … 89 96 } 90 97 } 91 for ( Target t : nonIntersectingTargets) {92 mTargetMap. insert(t);98 for (const Target t : nonIntersectingTargets) { 99 mTargetMap.emplace(t.first, t.second); 93 100 } 94 101 } … … 99 106 ** ------------------------------------------------------------------------------------------------------------- */ 100 107 void UCDCompiler::generateSubRanges(const codepoint_t lo, const codepoint_t hi, PabloBuilder & builder) { 101 for ( Target& t : mTargetMap) {108 for (auto & t : mTargetMap) { 102 109 const auto range = rangeIntersect(*t.first, lo, hi); 103 110 PabloAST * target = t.second; … … 354 361 } 355 362 return ranges; 356 }357 358 /** ------------------------------------------------------------------------------------------------------------- *359 * @brief addTarget360 ** ------------------------------------------------------------------------------------------------------------- */361 inline void UCDCompiler::addTarget(const UnicodeSet & set) {362 #ifdef USE_BOOST363 mTargetMap.emplace(&set, PabloBlock::createZeroes());364 #else365 mTargetMap.insert(std::make_pair(&set, PabloBlock::createZeroes()));366 #endif367 363 } 368 364 -
icGREP/icgrep-devel/icgrep/UCD/ucd_compiler.hpp
r4797 r4804 35 35 using TargetMap = std::unordered_map<const UnicodeSet *, PabloAST *>; 36 36 #endif 37 using Target = TargetMap::value_type;37 using Target = std::pair<const UnicodeSet *, PabloAST *>; 38 38 using TargetVector = std::vector<Target>; 39 39 -
icGREP/icgrep-devel/icgrep/icgrep-devel.config
r4797 r4804 1 #define USE_BOOST2 #define USE_BOOST_MMAP -
icGREP/icgrep-devel/icgrep/pablo/analysis/pabloverifier.cpp
r4799 r4804 4 4 #include <pablo/printer_pablos.h> 5 5 #include <iostream> 6 #ifdef USE_BOOST 6 7 #include <boost/container/flat_set.hpp> 7 # include <boost/container/flat_map.hpp>8 9 using namespace boost::container; 8 #else 9 #include <unordered_set> 10 #endif 10 11 11 12 namespace pablo { 12 13 13 using ScopeSet = flat_set<const PabloBlock *>; 14 #ifdef USE_BOOST 15 template <typename Type> 16 using SmallSet = boost::container::flat_set<Type>; 17 #else 18 template <typename Type> 19 using SmallSet = std::unordered_set<Type>; 20 #endif 21 22 using ScopeSet = SmallSet<const PabloBlock *>; 14 23 15 24 /** ------------------------------------------------------------------------------------------------------------- * … … 202 211 private: 203 212 const OrderingVerifier * const mParent; 204 boost::container::flat_set<const PabloAST *> mSet;213 SmallSet<const PabloAST *> mSet; 205 214 }; 206 215 -
icGREP/icgrep-devel/icgrep/pablo/optimizers/booleanreassociationpass.cpp
r4797 r4804 6 6 #include <boost/graph/filtered_graph.hpp> 7 7 #include <boost/graph/topological_sort.hpp> 8 #include <boost/graph/strong_components.hpp>9 8 #include <pablo/optimizers/pablo_simplifier.hpp> 10 9 #include <pablo/analysis/pabloverifier.hpp> … … 124 123 default: 125 124 return false; 126 }127 }128 129 inline bool isConstant(const VertexData & data) {130 switch (getType(data)) {131 case TypeId::Zeroes:132 case TypeId::Ones:133 return true;134 default: return false;135 125 } 136 126 } -
icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_bddminimization.cpp
r4797 r4804 2 2 #include <pablo/codegenstate.h> 3 3 #include <pablo/builder.hpp> 4 #include <stack>5 #include <iostream>6 4 #include <pablo/printer_pablos.h> 7 5 #include <cudd.h> 8 #include <cuddInt.h>9 6 #include <util.h> 10 #include <queue>11 #include <boost/circular_buffer.hpp>12 7 #include <pablo/optimizers/pablo_simplifier.hpp> 13 8 #include <pablo/analysis/pabloverifier.hpp> 9 #include <stack> 14 10 15 11 using namespace llvm; … … 117 113 } 118 114 } else { // attempt to characterize this statement and replace it if we've encountered an equivalent one 115 116 /// TODO: I found evidence that some of the UCD functions have disjunctions of nested marker values 117 /// in which one is a superset of the other. It's not safe to eliminate the subset marker unless the 118 /// condition that lead us to compute the first marker is a superset of the condition that let us 119 /// compute the subset value too. We can alter the superset condition to include the union of both 120 /// but this may lead to taking an expensive branch more often. So, we'd need to decide whether the 121 /// cost of each scope is close enough w.r.t. the probability both branches are taken. 122 119 123 DdNode * bdd = nullptr; 120 124 bool test = false; -
icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_bddminimization.h
r4775 r4804 48 48 void eliminateLogicallyEquivalentStatements(Statement * const stmt, SubsitutionMap & map); 49 49 std::pair<DdNode *, bool> characterize(Statement * const stmt); 50 void identifyHiddenContradicionsAndTautologies(PabloBlock & block);51 50 private: 52 51 DdNode * Zero() const; -
icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_codesinking.cpp
r4799 r4804 58 58 59 59 ScopeSet scopes; 60 bool canSinkInstruction= false;60 bool sinkable = false; 61 61 for (const PabloAST * use : stmt->users()) { 62 62 if (const Statement * user = dyn_cast<Statement>(use)) { 63 63 if (mProcessed.count(user->getParent())) { 64 canSinkInstruction= true;64 sinkable = true; 65 65 scopes.insert(user->getParent()); 66 66 continue; 67 67 } 68 canSinkInstruction= false;68 sinkable = false; 69 69 break; 70 70 } 71 71 } 72 if ( canSinkInstruction) {72 if (sinkable) { 73 73 74 74 while (scopes.size() > 1) { … … 102 102 // But if the LCA is the current block, we can't sink the statement. 103 103 if (scope1 == &block) { 104 canSinkInstruction= false;104 sinkable = false; 105 105 break; 106 106 } … … 108 108 } 109 109 110 if ( canSinkInstruction) {110 if (sinkable) { 111 111 assert (scopes.size() == 1); 112 112 stmt->insertBefore(scopes.front()->front()); -
icGREP/icgrep-devel/icgrep/pablo/optimizers/pablo_simplifier.cpp
r4797 r4804 5 5 #include <pablo/printer_pablos.h> 6 6 #include <pablo/analysis/pabloverifier.hpp> 7 #include <unordered_map> 7 #ifdef USE_BOOST 8 #include <boost/container/flat_set.hpp> 9 #else 10 #include <unordered_set> 11 #endif 8 12 #include <iostream> 9 13 10 14 namespace pablo { 15 16 #ifdef USE_BOOST 17 template <typename Type> 18 using SmallSet = boost::container::flat_set<Type>; 19 #else 20 template <typename Type> 21 using SmallSet = std::unordered_set<Type>; 22 #endif 11 23 12 24 bool Simplifier::optimize(PabloFunction & function) { … … 72 84 } 73 85 86 inline void replaceReachableUsersOfWith(Statement * stmt, PabloAST * expr) { 87 const PabloBlock * const root = stmt->getParent(); 88 SmallSet<const PabloBlock *> forbidden; 89 for (PabloAST * use : stmt->users()) { 90 if (LLVM_UNLIKELY(isa<Next>(use))) { 91 const PabloBlock * parent = cast<Next>(use)->getParent(); 92 if (parent != root) { 93 forbidden.insert(parent); 94 } 95 } 96 } 97 for (PabloAST * use : stmt->users()) { 98 if (Statement * user = dyn_cast<Statement>(use)) { 99 const PabloBlock * parent = user->getParent(); 100 while (parent && forbidden.count(parent) == 0) { 101 if (LLVM_UNLIKELY(parent == root)) { 102 user->replaceUsesOfWith(stmt, expr); 103 break; 104 } 105 parent = parent->getParent(); 106 } 107 } 108 } 109 } 110 74 111 void Simplifier::eliminateRedundantCode(PabloBlock & block, ExpressionTable * predecessor) { 75 112 ExpressionTable encountered(predecessor); … … 87 124 continue; 88 125 } 89 // Force the uses of an local Assign to be the expression instead. 90 for (PabloAST * use : assign->users()) { 91 if (Statement * user = dyn_cast<Statement>(use)) { 92 if (LLVM_UNLIKELY(user->getParent() == &block)) { 93 user->replaceUsesOfWith(assign, assign->getExpression()); 94 } 95 } 96 } 126 // Force the uses of an Assign node that can reach the original expression to use the expression instead. 127 replaceReachableUsersOfWith(assign, assign->getExpression()); 128 } else if (Next * next = dyn_cast<Next>(stmt)) { 129 replaceReachableUsersOfWith(next, next->getExpr()); 97 130 } else if (If * ifNode = dyn_cast<If>(stmt)) { 98 131 // Check to see if the Cond is Zero and delete the loop. 99 132 if (LLVM_UNLIKELY(isa<Zeroes>(ifNode->getCondition()))) { 100 for (Assign * defVar : ifNode->getDefined()) {101 defVar->replaceWith(PabloBlock::createZeroes(), false, true);102 }103 133 stmt = stmt->eraseFromParent(true); 104 134 continue; … … 143 173 } 144 174 } 145 } else if (isa<While>(stmt)) { 146 eliminateRedundantCode(cast<While>(stmt)->getBody(), &encountered); 175 } else if (While * whileNode = dyn_cast<While>(stmt)) { 176 177 const PabloAST * initial = whileNode->getCondition(); 178 if (LLVM_LIKELY(isa<Next>(initial))) { 179 initial = cast<Next>(initial)->getInitial(); 180 } 181 if (LLVM_UNLIKELY(isa<Zeroes>(initial))) { 182 stmt = stmt->eraseFromParent(true); 183 continue; 184 } 185 186 eliminateRedundantCode(whileNode->getBody(), &encountered); 187 188 147 189 } else if (canTriviallyFold(stmt)) { // non-Assign node 148 190 // Do a trivial folding test to see if we're using all 0s or 1s as an operand.
Note: See TracChangeset
for help on using the changeset viewer.