* Code Cleanups
[oota-llvm.git] / lib / Analysis / LiveVar / ValueSet.cpp
1
2
3
4 #include "llvm/Analysis/LiveVar/ValueSet.h"
5 #include "llvm/ConstantVals.h"
6 #include <iostream>
7
8 ostream &operator<<(ostream &O, RAV V) { // func to print a Value 
9   const Value *v = V.V;
10   if (v->hasName())
11     return O << v << "(" << v->getName() << ") ";
12   else if (Constant *C = dyn_cast<Constant>(v))
13     return O << v << "(" << C->getStrValue() << ") ";
14   else
15     return O << v  << " ";
16 }
17
18 bool ValueSet::setUnion( const ValueSet *S) {   
19   bool Changed = false;
20
21   for (const_iterator SI = S->begin(), SE = S->end(); SI != SE; ++SI)
22     if (insert(*SI).second)
23       Changed = true;
24
25   return Changed;
26 }
27
28 void ValueSet::setDifference(const ValueSet *S1, const ValueSet *S2) {
29   for (const_iterator SI = S1->begin(), SE = S1->end() ; SI != SE; ++SI)
30     if (S2->find(*SI) == S2->end())       // if the element is not in set2
31       insert(*SI);
32 }
33
34 void ValueSet::setSubtract(const ValueSet *S) { 
35   for (const_iterator SI = S->begin() ; SI != S->end(); ++SI)  
36     erase(*SI);
37 }
38
39 void ValueSet::printSet() const {
40   for (const_iterator I = begin(), E = end(); I != E; ++I)
41     std::cerr << RAV(*I);
42 }