2001-07-24 17:14:13 +00:00
|
|
|
|
|
|
|
#include "llvm/Analysis/LiveVar/ValueSet.h"
|
2001-12-03 22:26:30 +00:00
|
|
|
#include "llvm/ConstantVals.h"
|
2002-02-04 16:35:12 +00:00
|
|
|
#include <algorithm>
|
2002-01-20 22:54:45 +00:00
|
|
|
#include <iostream>
|
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
|
|
|
using std::pair;
|
|
|
|
using std::hash_set;
|
2001-07-24 17:14:13 +00:00
|
|
|
|
2002-02-04 16:35:12 +00:00
|
|
|
void printValue(const Value *v) { // func to print a Value
|
2001-10-15 18:30:06 +00:00
|
|
|
if (v->hasName())
|
2002-02-04 16:35:12 +00:00
|
|
|
cerr << v << "(" << v->getName() << ") ";
|
2001-12-03 22:26:30 +00:00
|
|
|
else if (Constant *C = dyn_cast<Constant>(v))
|
|
|
|
cerr << v << "(" << C->getStrValue() << ") ";
|
2001-08-20 21:12:49 +00:00
|
|
|
else
|
2001-10-15 18:30:06 +00:00
|
|
|
cerr << v << " ";
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------- Method implementations --------------------------
|
2001-08-20 21:12:49 +00:00
|
|
|
// for performing two set unions
|
2002-02-04 16:35:12 +00:00
|
|
|
bool ValueSet::setUnion( const ValueSet *set1) {
|
2001-07-24 17:14:13 +00:00
|
|
|
pair<iterator, bool> result;
|
|
|
|
bool changed = false;
|
|
|
|
|
2002-02-04 16:35:12 +00:00
|
|
|
for(const_iterator set1it = set1->begin() ; set1it != set1->end(); ++set1it) {
|
2001-08-20 21:12:49 +00:00
|
|
|
// for all all elements in set1
|
2002-02-04 16:35:12 +00:00
|
|
|
result = insert(*set1it); // insert to this set
|
|
|
|
if(result.second == true) changed = true;
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
// for performing set difference
|
2001-07-24 17:14:13 +00:00
|
|
|
void ValueSet::setDifference( const ValueSet *const set1,
|
|
|
|
const ValueSet *const set2) {
|
|
|
|
|
|
|
|
const_iterator set1it, set2it;
|
2002-01-20 22:54:45 +00:00
|
|
|
for( set1it = set1->begin() ; set1it != set1->end(); ++set1it) {
|
2001-07-24 17:14:13 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
// for performing set subtraction
|
2001-07-24 17:14:13 +00:00
|
|
|
void ValueSet::setSubtract( const ValueSet *const set1) {
|
|
|
|
const_iterator set1it;
|
2002-01-20 22:54:45 +00:00
|
|
|
for( set1it = set1->begin() ; set1it != set1->end(); ++set1it)
|
2001-07-24 17:14:13 +00:00
|
|
|
// for all elements in set1
|
|
|
|
erase( *set1it ); // erase that element from this set
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-08-20 21:12:49 +00:00
|
|
|
void ValueSet::printSet() const { // for printing a live variable set
|
2002-01-20 22:54:45 +00:00
|
|
|
for_each(begin(), end(), printValue);
|
2001-07-24 17:14:13 +00:00
|
|
|
}
|