Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 1 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 2 | |
| 3 | |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 4 | #include "llvm/Analysis/LiveVar/ValueSet.h" |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 5 | #include "llvm/ConstantVals.h" |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 6 | #include <iostream> |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 7 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 8 | ostream &operator<<(ostream &O, RAV V) { // func to print a Value |
| 9 | const Value *v = V.V; |
Chris Lattner | 634b352 | 2001-10-15 18:30:06 +0000 | [diff] [blame] | 10 | if (v->hasName()) |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 11 | return O << v << "(" << v->getName() << ") "; |
Chris Lattner | e9bb2df | 2001-12-03 22:26:30 +0000 | [diff] [blame] | 12 | else if (Constant *C = dyn_cast<Constant>(v)) |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 13 | return O << v << "(" << C->getStrValue() << ") "; |
Ruchira Sasanka | e27c344 | 2001-08-20 21:12:49 +0000 | [diff] [blame] | 14 | else |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 15 | return O << v << " "; |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 16 | } |
| 17 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 18 | bool ValueSet::setUnion( const ValueSet *S) { |
| 19 | bool Changed = false; |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 20 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 21 | for (const_iterator SI = S->begin(), SE = S->end(); SI != SE; ++SI) |
| 22 | if (insert(*SI).second) |
| 23 | Changed = true; |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 25 | return Changed; |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 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); |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 34 | void ValueSet::setSubtract(const ValueSet *S) { |
| 35 | for (const_iterator SI = S->begin() ; SI != S->end(); ++SI) |
| 36 | erase(*SI); |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Chris Lattner | 0665a5f | 2002-02-05 01:43:49 +0000 | [diff] [blame^] | 39 | void ValueSet::printSet() const { |
| 40 | for (const_iterator I = begin(), E = end(); I != E; ++I) |
| 41 | std::cerr << RAV(*I); |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 42 | } |