2 #include "llvm/Analysis/LiveVar/ValueSet.h"
3 #include "llvm/ConstantVals.h"
11 void printValue(const Value *v) { // func to print a Value
13 cerr << v << "(" << v->getName() << ") ";
14 else if (Constant *C = dyn_cast<Constant>(v))
15 cerr << v << "(" << C->getStrValue() << ") ";
21 //---------------- Method implementations --------------------------
22 // for performing two set unions
23 bool ValueSet::setUnion( const ValueSet *set1) {
24 pair<iterator, bool> result;
27 for(const_iterator 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
63 for_each(begin(), end(), printValue);