Rename ConstPoolVal -> Constant
[oota-llvm.git] / lib / Analysis / LiveVar / ValueSet.cpp
1
2 #include "llvm/Analysis/LiveVar/ValueSet.h"
3 #include "llvm/ConstantVals.h"
4
5
6 void printValue( const Value *const v)  // func to print a Value 
7 {
8   
9   if (v->hasName())
10     cerr << v << "(" << ((*v).getName()) << ") ";
11   else if (Constant *C = dyn_cast<Constant>(v))
12     cerr << v << "(" << C->getStrValue() << ") ";
13   else
14     cerr << v  << " ";
15 }
16
17
18 //---------------- Method implementations --------------------------
19
20
21 ValueSet:: ValueSet() : hash_set<const Value *,  hashFuncValue> () { }
22
23                                              // for performing two set unions
24 bool ValueSet::setUnion( const ValueSet *const set1) {   
25   const_iterator set1it;
26   pair<iterator, bool> result;
27   bool changed = false;
28
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;
33   }
34
35   return changed;
36 }
37
38
39                                              // for performing set difference
40 void ValueSet::setDifference( const ValueSet *const set1, 
41                               const ValueSet *const set2) { 
42
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
49   }
50 }
51
52
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
59 }
60
61
62
63
64 void ValueSet::printSet()  const {     // for printing a live variable set
65       const_iterator it;
66       for( it = begin() ; it != end(); it++) 
67         printValue( *it );
68 }