blob: 6806d1c563868bb952733439819cefea587eb9a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include "llvm/Analysis/LiveVar/ValueSet.h"
#include "llvm/ConstantVals.h"
void printValue( const Value *const v) // func to print a Value
{
if (v->hasName())
cerr << v << "(" << ((*v).getName()) << ") ";
else if (Constant *C = dyn_cast<Constant>(v))
cerr << v << "(" << C->getStrValue() << ") ";
else
cerr << v << " ";
}
//---------------- Method implementations --------------------------
ValueSet:: ValueSet() : hash_set<const Value *, hashFuncValue> () { }
// for performing two set unions
bool ValueSet::setUnion( const ValueSet *const set1) {
const_iterator set1it;
pair<iterator, bool> result;
bool changed = false;
for( set1it = set1->begin() ; set1it != set1->end(); set1it++) {
// for all all elements in set1
result = insert( *set1it ); // insert to this set
if( result.second == true) changed = true;
}
return changed;
}
// for performing set difference
void ValueSet::setDifference( const ValueSet *const set1,
const ValueSet *const set2) {
const_iterator set1it, set2it;
for( set1it = set1->begin() ; set1it != set1->end(); set1it++) {
// for all elements in set1
iterator set2it = set2->find( *set1it ); // find wether the elem is in set2
if( set2it == set2->end() ) // if the element is not in set2
insert( *set1it ); // insert to this set
}
}
// for performing set subtraction
void ValueSet::setSubtract( const ValueSet *const set1) {
const_iterator set1it;
for( set1it = set1->begin() ; set1it != set1->end(); set1it++)
// for all elements in set1
erase( *set1it ); // erase that element from this set
}
void ValueSet::printSet() const { // for printing a live variable set
const_iterator it;
for( it = begin() ; it != end(); it++)
printValue( *it );
}
|