blob: 680ad83428e6aced47e82d8d5ce08b198f0c6cf6 [file] [log] [blame]
Ruchira Sasanka683847f2001-07-24 17:14:13 +00001
2#include "llvm/Analysis/LiveVar/ValueSet.h"
Ruchira Sasankab2d11ba2001-07-24 18:21:21 +00003#include "llvm/ConstPoolVals.h"
Ruchira Sasanka683847f2001-07-24 17:14:13 +00004
5
6void 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()) << " ";
Ruchira Sasankab2d11ba2001-07-24 18:21:21 +000010 else if (v->getValueType() == Value::ConstantVal) // if const
11 cout << v << "(" << ((ConstPoolVal *) v)->getStrValue() << ") ";
Ruchira Sasanka683847f2001-07-24 17:14:13 +000012 else cout << v << " ";
13}
14
15
16//---------------- Method implementations --------------------------
17
18
19ValueSet:: ValueSet() : hash_set<const Value *, hashFuncValue> () { }
20
21 // for performing two set unions
22bool 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
38void 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
52void 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
62void ValueSet::printSet() const { // for printing a live variable set
63 const_iterator it;
64 for( it = begin() ; it != end(); it++)
65 printValue( *it );
66}