Changed printValue() to print constant value if the value is a constant.
[oota-llvm.git] / lib / Analysis / LiveVar / ValueSet.cpp
1
2 #include "llvm/Analysis/LiveVar/ValueSet.h"
3 #include "llvm/ConstPoolVals.h"
4
5
6 void printValue( const Value *const v)  // func to print a Value 
7 {
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  << " ";
13 }
14
15
16 //---------------- Method implementations --------------------------
17
18
19 ValueSet:: ValueSet() : hash_set<const Value *,  hashFuncValue> () { }
20
21                                                  // for performing two set unions
22 bool ValueSet::setUnion( const ValueSet *const set1) {   
23   const_iterator set1it;
24   pair<iterator, bool> result;
25   bool changed = false;
26
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;
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       const_iterator it;
64       for( it = begin() ; it != end(); it++) 
65         printValue( *it );
66 }