2 #include "llvm/Analysis/LiveVar/ValueSet.h"
3 #include "llvm/ConstPoolVals.h"
6 void printValue( const Value *const v) // func to print a Value
10 cout << v << "(" << ((*v).getName()) << ") ";
11 else if (v->getValueType() == Value::ConstantVal) // if const
12 cout << v << "(" << ((ConstPoolVal *) v)->getStrValue() << ") ";
18 //---------------- Method implementations --------------------------
21 ValueSet:: ValueSet() : hash_set<const Value *, hashFuncValue> () { }
23 // for performing two set unions
24 bool ValueSet::setUnion( const ValueSet *const set1) {
25 const_iterator set1it;
26 pair<iterator, bool> result;
29 for( set1it = set1->begin() ; set1it != set1->end(); set1it++) {
30 // for all all elements in set1
31 result = insert( *set1it ); // insert to this set
32 if( result.second == true) changed = true;
39 // for performing set difference
40 void ValueSet::setDifference( const ValueSet *const set1,
41 const ValueSet *const set2) {
43 const_iterator set1it, set2it;
44 for( set1it = set1->begin() ; set1it != set1->end(); set1it++) {
45 // for all elements in set1
46 iterator set2it = set2->find( *set1it ); // find wether the elem is in set2
47 if( set2it == set2->end() ) // if the element is not in set2
48 insert( *set1it ); // insert to this set
53 // for performing set subtraction
54 void ValueSet::setSubtract( const ValueSet *const set1) {
55 const_iterator set1it;
56 for( set1it = set1->begin() ; set1it != set1->end(); set1it++)
57 // for all elements in set1
58 erase( *set1it ); // erase that element from this set
64 void ValueSet::printSet() const { // for printing a live variable set
66 for( it = begin() ; it != end(); it++)