blob: 431ccc6222982dac3a5c12a43ca02e66ab431ec3 [file] [log] [blame]
Ruchira Sasanka683847f2001-07-24 17:14:13 +00001
Chris Lattner0665a5f2002-02-05 01:43:49 +00002
3
Ruchira Sasanka683847f2001-07-24 17:14:13 +00004#include "llvm/Analysis/LiveVar/ValueSet.h"
Chris Lattnere9bb2df2001-12-03 22:26:30 +00005#include "llvm/ConstantVals.h"
Chris Lattner697954c2002-01-20 22:54:45 +00006#include <iostream>
Ruchira Sasanka683847f2001-07-24 17:14:13 +00007
Chris Lattner0665a5f2002-02-05 01:43:49 +00008ostream &operator<<(ostream &O, RAV V) { // func to print a Value
9 const Value *v = V.V;
Chris Lattner634b3522001-10-15 18:30:06 +000010 if (v->hasName())
Chris Lattner0665a5f2002-02-05 01:43:49 +000011 return O << v << "(" << v->getName() << ") ";
Chris Lattnere9bb2df2001-12-03 22:26:30 +000012 else if (Constant *C = dyn_cast<Constant>(v))
Chris Lattner0665a5f2002-02-05 01:43:49 +000013 return O << v << "(" << C->getStrValue() << ") ";
Ruchira Sasankae27c3442001-08-20 21:12:49 +000014 else
Chris Lattner0665a5f2002-02-05 01:43:49 +000015 return O << v << " ";
Ruchira Sasanka683847f2001-07-24 17:14:13 +000016}
17
Chris Lattner0665a5f2002-02-05 01:43:49 +000018bool ValueSet::setUnion( const ValueSet *S) {
19 bool Changed = false;
Ruchira Sasanka683847f2001-07-24 17:14:13 +000020
Chris Lattner0665a5f2002-02-05 01:43:49 +000021 for (const_iterator SI = S->begin(), SE = S->end(); SI != SE; ++SI)
22 if (insert(*SI).second)
23 Changed = true;
Ruchira Sasanka683847f2001-07-24 17:14:13 +000024
Chris Lattner0665a5f2002-02-05 01:43:49 +000025 return Changed;
Ruchira Sasanka683847f2001-07-24 17:14:13 +000026}
27
Chris Lattner0665a5f2002-02-05 01:43:49 +000028void 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);
Ruchira Sasanka683847f2001-07-24 17:14:13 +000032}
33
Chris Lattner0665a5f2002-02-05 01:43:49 +000034void ValueSet::setSubtract(const ValueSet *S) {
35 for (const_iterator SI = S->begin() ; SI != S->end(); ++SI)
36 erase(*SI);
Ruchira Sasanka683847f2001-07-24 17:14:13 +000037}
38
Chris Lattner0665a5f2002-02-05 01:43:49 +000039void ValueSet::printSet() const {
40 for (const_iterator I = begin(), E = end(); I != E; ++I)
41 std::cerr << RAV(*I);
Ruchira Sasanka683847f2001-07-24 17:14:13 +000042}