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