blob: d86587cde4c0f156fdaab839b84f974af6d69d43 [file] [log] [blame]
Ruchira Sasanka683847f2001-07-24 17:14:13 +00001
2#include "llvm/Analysis/LiveVar/ValueSet.h"
3
4
5void 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
16ValueSet:: ValueSet() : hash_set<const Value *, hashFuncValue> () { }
17
18 // for performing two set unions
19bool 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
35void 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
49void 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
59void ValueSet::printSet() const { // for printing a live variable set
60 const_iterator it;
61 for( it = begin() ; it != end(); it++)
62 printValue( *it );
63}