summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/LiveVar/ValueSet.cpp
blob: 431ccc6222982dac3a5c12a43ca02e66ab431ec3 (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



#include "llvm/Analysis/LiveVar/ValueSet.h"
#include "llvm/ConstantVals.h"
#include <iostream>

ostream &operator<<(ostream &O, RAV V) { // func to print a Value 
  const Value *v = V.V;
  if (v->hasName())
    return O << v << "(" << v->getName() << ") ";
  else if (Constant *C = dyn_cast<Constant>(v))
    return O << v << "(" << C->getStrValue() << ") ";
  else
    return O << v  << " ";
}

bool ValueSet::setUnion( const ValueSet *S) {   
  bool Changed = false;

  for (const_iterator SI = S->begin(), SE = S->end(); SI != SE; ++SI)
    if (insert(*SI).second)
      Changed = true;

  return Changed;
}

void ValueSet::setDifference(const ValueSet *S1, const ValueSet *S2) {
  for (const_iterator SI = S1->begin(), SE = S1->end() ; SI != SE; ++SI)
    if (S2->find(*SI) == S2->end())       // if the element is not in set2
      insert(*SI);
}

void ValueSet::setSubtract(const ValueSet *S) { 
  for (const_iterator SI = S->begin() ; SI != S->end(); ++SI)  
    erase(*SI);
}

void ValueSet::printSet() const {
  for (const_iterator I = begin(), E = end(); I != E; ++I)
    std::cerr << RAV(*I);
}
OpenPOWER on IntegriCloud