Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame^] | 1 | |
| 2 | #include "llvm/Analysis/LiveVar/ValueSet.h" |
| 3 | |
| 4 | |
| 5 | void printValue( const Value *const v) // func to print a Value |
| 6 | { |
| 7 | if( (*v).hasName() ) cout << v << "(" << ((*v).getName()) << ") "; |
| 8 | //if( (*v).hasName() ) cout << ((*v).getName()) << " "; |
| 9 | else cout << v << " "; |
| 10 | } |
| 11 | |
| 12 | |
| 13 | //---------------- Method implementations -------------------------- |
| 14 | |
| 15 | |
| 16 | ValueSet:: ValueSet() : hash_set<const Value *, hashFuncValue> () { } |
| 17 | |
| 18 | // for performing two set unions |
| 19 | bool ValueSet::setUnion( const ValueSet *const set1) { |
| 20 | const_iterator set1it; |
| 21 | pair<iterator, bool> result; |
| 22 | bool changed = false; |
| 23 | |
| 24 | for( set1it = set1->begin() ; set1it != set1->end(); set1it++) { |
| 25 | // for all all elements in set1 |
| 26 | result = insert( *set1it ); // insert to this set |
| 27 | if( result.second == true) changed = true; |
| 28 | } |
| 29 | |
| 30 | return changed; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | // for performing set difference |
| 35 | void ValueSet::setDifference( const ValueSet *const set1, |
| 36 | const ValueSet *const set2) { |
| 37 | |
| 38 | const_iterator set1it, set2it; |
| 39 | for( set1it = set1->begin() ; set1it != set1->end(); set1it++) { |
| 40 | // for all elements in set1 |
| 41 | iterator set2it = set2->find( *set1it ); // find wether the elem is in set2 |
| 42 | if( set2it == set2->end() ) // if the element is not in set2 |
| 43 | insert( *set1it ); // insert to this set |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | |
| 48 | // for performing set subtraction |
| 49 | void ValueSet::setSubtract( const ValueSet *const set1) { |
| 50 | const_iterator set1it; |
| 51 | for( set1it = set1->begin() ; set1it != set1->end(); set1it++) |
| 52 | // for all elements in set1 |
| 53 | erase( *set1it ); // erase that element from this set |
| 54 | } |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | void ValueSet::printSet() const { // for printing a live variable set |
| 60 | const_iterator it; |
| 61 | for( it = begin() ; it != end(); it++) |
| 62 | printValue( *it ); |
| 63 | } |