Clean up MethodLiveVarInfo
[oota-llvm.git] / lib / Analysis / LiveVar / ValueSet.cpp
1
2 #include "llvm/Analysis/LiveVar/ValueSet.h"
3 #include "llvm/ConstantVals.h"
4 #include <algorithm>
5 #include <iostream>
6 using std::cerr;
7 using std::endl;
8 using std::pair;
9 using std::hash_set;
10
11 void printValue(const Value *v) { // func to print a Value 
12   if (v->hasName())
13     cerr << v << "(" << v->getName() << ") ";
14   else if (Constant *C = dyn_cast<Constant>(v))
15     cerr << v << "(" << C->getStrValue() << ") ";
16   else
17     cerr << v  << " ";
18 }
19
20
21 //---------------- Method implementations --------------------------
22                                              // for performing two set unions
23 bool ValueSet::setUnion( const ValueSet *set1) {   
24   pair<iterator, bool> result;
25   bool changed = false;
26
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;
31   }
32
33   return changed;
34 }
35
36
37                                              // for performing set difference
38 void ValueSet::setDifference( const ValueSet *const set1, 
39                               const ValueSet *const set2) { 
40
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
47   }
48 }
49
50
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
57 }
58
59
60
61
62 void ValueSet::printSet()  const {     // for printing a live variable set
63   for_each(begin(), end(), printValue);
64 }