Example #1
0
void RandomSet::remove(int element) {
  boost::unordered_set<int>::iterator set_it = this->element_set.find(element);
  
  if(set_it != this->element_set.end()) {
    this->element_set.erase(set_it);
    
    std::vector<int>::iterator it = iterator_to(element);
    if(it != this->elements.end()) {
      this->elements.erase(it);
    }
  }
}
Example #2
0
void MethodTransform::inline_tail_call(DexMethod* caller,
                                       DexMethod* callee,
                                       DexInstruction* invoke) {
  TRACE(INL, 2, "caller: %s\ncallee: %s\n", SHOW(caller), SHOW(callee));
  MethodTransformer tcaller(caller);
  MethodTransformer tcallee(callee);
  auto fcaller = tcaller->m_fmethod;
  auto fcallee = tcallee->m_fmethod;

  auto bregs = caller->get_code()->get_registers_size();
  auto eregs = callee->get_code()->get_registers_size();
  auto bins = caller->get_code()->get_ins_size();
  auto eins = callee->get_code()->get_ins_size();
  always_assert(bins >= eins);
  auto newregs = std::max(bregs, uint16_t(eregs + bins - eins));
  always_assert(newregs <= 16);

  // Remap registers to account for possibly larger frame, more ins
  remap_caller_regs(caller, fcaller, newregs);
  remap_callee_regs(invoke, callee, fcallee, newregs);

  callee->get_code()->set_ins_size(bins);

  auto pos = std::find_if(fcaller->begin(),
                          fcaller->end(),
                          [invoke](const MethodItemEntry& mei) {
                            return mei.type == MFLOW_OPCODE && mei.insn == invoke;
                          });

  cleanup_callee_debug(fcallee);
  auto it = fcallee->begin();
  while (it != fcallee->end()) {
    auto& mei = *it++;
    fcallee->erase(fcallee->iterator_to(mei));
    fcaller->insert(pos, mei);
  }
  // Delete the vestigial tail.
  while (pos != fcaller->end()) {
    if (pos->type == MFLOW_OPCODE) {
      pos = fcaller->erase_and_dispose(pos, FatMethodDisposer());
    } else {
      ++pos;
    }
  }

  caller->get_code()->set_outs_size(callee->get_code()->get_outs_size());
}
Example #3
0
bool
DynamicPersistenceTrails<D,CT,OT,E,Cmp,CCmp>::
transpose(iterator i, const DimensionFunctor& dimension, Visitor visitor)
{
#if LOGGING
    typename Traits::OutputMap outmap(order());
#endif

    Count(cTransposition);
    typedef                 typename Element::Trail::iterator           TrailIterator;

    visitor.transpose(i);
    
    iterator i_prev = i++;

    if (dimension(i_prev) != dimension(i))
    {
        swap(i_prev, i);
        rLog(rlTranspositions, "Different dimension");
        Count(cTranspositionDiffDim);
        return false;
    }
    
    bool si = i_prev->sign(), sii = i->sign();
    if (si && sii)
    {
        rLog(rlTranspositions, "Trail prev: %s", i_prev->trail.tostring(outmap).c_str());

        // Case 1
        if (trail_remove_if_contains(i_prev, index(i)))
            rLog(rlTranspositions, "Case 1, U[i,i+1] = 1");

        iterator k = iterator_to(i_prev->pair);
        iterator l = iterator_to(i->pair);
        
        // rLog(rlTranspositions, "(i_prev, k), (i, l): (%s, %s), (%s, %s)", 
        //                         outmap(i_prev).c_str(), outmap(k).c_str(),
        //                         outmap(i).c_str(),      outmap(l).c_str());

        // Explicit treatment of unpaired simplex
        if (l == i)
        {
            swap(i_prev, i);
            rLog(rlTranspositions, "Case 1.2 --- unpaired");
            rLog(rlTranspositions, "%s", outmap(i_prev).c_str());
            Count(cTranspositionCase12);
            return false;
        } else if (k == i_prev)
        {
            if (!(l->cycle.contains(index(i_prev))))
            {
                // Case 1.2
                swap(i_prev, i);
                rLog(rlTranspositions, "Case 1.2 --- unpaired");
                rLog(rlTranspositions, outmap(i_prev).c_str());
                Count(cTranspositionCase12);
                return false;
            } else
            {
                // Case 1.2 --- special version (plain swap, but pairing switches)
                swap(i_prev, i);
                pairing_switch(i_prev, i);
                visitor.switched(i, Case12);
                rLog(rlTranspositions, "Case 1.2 --- unpaired (pairing switch)");
                rLog(rlTranspositions, outmap(i_prev).c_str());
                Count(cTranspositionCase12s);
                return true;
            }
        }
        
        rLog(rlTranspositions, "l cycle: %s", l->cycle.tostring(outmap).c_str());
        if (!(l->cycle.contains(index(i_prev))))
        {
            // Case 1.2
            rLog(rlTranspositions, "k is in l: %d", (bool) l->trail.contains(index(k)));       // if true, a special update would be needed to maintain lazy decomposition
            swap(i_prev, i);
            rLog(rlTranspositions, "Case 1.2");
            Count(cTranspositionCase12);
            return false;
        } else
        {
            // Case 1.1
            if (std::not2(order_comparison())(index(k),index(l)))
            {
                // Case 1.1.1
                swap(i_prev, i);
                cycle_add(l, k->cycle);               // Add column k to l
                trail_add(k, l->trail);               // Add row l to k
                rLog(rlTranspositions, "Case 1.1.1");
                Count(cTranspositionCase111);
                return false;
            } else
            {
                // Case 1.1.2
                swap(i_prev, i);
                cycle_add(k, l->cycle);               // Add column l to k
                trail_add(l, k->trail);               // Add row k to l
                pairing_switch(i_prev, i);
                visitor.switched(i, Case112);
                rLog(rlTranspositions, "Case 1.1.2");
                Count(cTranspositionCase112);
                return true;
            }
        }
    } else if (!si && !sii)
    {
        // Case 2
        if (!(i_prev->trail.contains(index(i))))
        {
            // Case 2.2
            swap(i_prev, i);
            rLog(rlTranspositions, "Case 2.2");
            Count(cTranspositionCase22);
            return false;
        } else
        {
            // Case 2.1
            iterator low_i =    iterator_to(i_prev->pair);
            iterator low_ii =   iterator_to(i->pair);
            trail_add(i_prev, i->trail);                   // Add row i to i_prev
            cycle_add(i, i_prev->cycle);                   // Add column i_prev to i
            swap(i_prev, i);    
            if (std::not2(order_comparison())(index(low_ii), index(low_i)))
            {
                // Case 2.1.2
                cycle_add(i_prev, i->cycle);               // Add column i to i_prev (after transposition)
                trail_add(i, i_prev->trail);               // Add row i to i_prev
                pairing_switch(i_prev, i);
                visitor.switched(i, Case212);
                rLog(rlTranspositions, "Case 2.1.2");
                Count(cTranspositionCase212);
                return true;
            } 
            
            // Case 2.1.1
            rLog(rlTranspositions, "Case 2.1.1");
            Count(cTranspositionCase211);
            return false;
        }
    } else if (!si && sii)
    {
        // Case 3
        if (!(i_prev->trail.contains(index(i))))
        {
            // Case 3.2
            swap(i_prev, i);
            rLog(rlTranspositions, "Case 3.2");
            Count(cTranspositionCase32);
            return false;
        } else
        {
            // Case 3.1
            trail_add(i_prev, i->trail);                   // Add row i to i_prev
            cycle_add(i, i_prev->cycle);                   // Add column i_prev to i
            swap(i_prev, i);
            cycle_add(i_prev, i->cycle);                   // Add column i_prev to i (after transposition)
            trail_add(i, i_prev->trail);                   // Add row i to i_prev
            pairing_switch(i_prev, i);
            visitor.switched(i, Case31);
            rLog(rlTranspositions, "Case 3.1");
            Count(cTranspositionCase31);
            return true;
        }
    } else if (si && !sii)
    {
        // Case 4
        if (trail_remove_if_contains(i_prev, index(i)))
            rLog(rlTranspositions, "Case 4, U[i,i+1] = 1");
        swap(i_prev, i);
        rLog(rlTranspositions, "Case 4");
        Count(cTranspositionCase4);
        return false;
    }
    
    return false; // to avoid compiler complaints; we should never reach this point
}
Example #4
0
IRList::difference_type IRList::index_of(const MethodItemEntry& mie) const {
  return std::distance(iterator_to(mie), begin());
}
Example #5
0
void 
StaticPersistence<D, CT, OT, E, Cmp>::
pair_simplices(iterator bg, iterator end, bool store_negative, const Visitor& visitor)
{
#if LOGGING
    typename ContainerTraits::OutputMap outmap(order_);
#endif

    // FIXME: need sane output for logging
    rLog(rlPersistence, "Entered: pair_simplices");
    for (iterator j = bg; j != end; ++j)
    {
        visitor.init(j);
        rLog(rlPersistence, "Simplex %s", outmap(j).c_str());

        Cycle z;
        swap_cycle(j, z);
        rLog(rlPersistence, "  has boundary: %s", z.tostring(outmap).c_str());

        // Sparsify the cycle by removing the negative elements
        if (!store_negative)
        {
            typename OrderElement::Cycle zz;
            BOOST_FOREACH(OrderIndex i, z)
                if (i->sign())           // positive
                    zz.push_back(i);
            z.swap(zz);
        }
        // --------------------------
        
        CountNum(cPersistencePairBoundaries, z.size());
#ifdef COUNTERS
        Count(cPersistencePair);
#endif // COUNTERS

        while(!z.empty())
        {
            OrderIndex i = z.top(ocmp_);            // take the youngest element with respect to the OrderComparison
            rLog(rlPersistence, "  %s: %s", outmap(i).c_str(), outmap(i->pair).c_str());
            // TODO: is this even a meaningful assert?
            AssertMsg(!ocmp_(i, index(j)), 
                      "Simplices in the cycle must precede current simplex: (%s in cycle of %s)",
                      outmap(i).c_str(), outmap(j).c_str());

            // i is not paired, so we pair j with i
            if (iterator_to(i->pair) == iterator_to(i))
            {
                rLog(rlPersistence, "  Pairing %s and %s with cycle %s", 
                                   outmap(i).c_str(), outmap(j).c_str(), 
                                   z.tostring(outmap).c_str());
             
                set_pair(i, j);
                swap_cycle(j, z);
                set_pair(j, i);
                
                CountNum(cPersistencePairCycleLength,   j->cycle.size());
                CountBy (cPersistencePairCycleLength,   j->cycle.size());
                break;
            }

            // update element
            z.add(i->pair->cycle, ocmp_);
            visitor.update(j, iterator_to(i));
            rLog(rlPersistence, "    new cycle: %s", z.tostring(outmap).c_str());
        }
        // if z was empty, so is (already) j->cycle, so nothing to do
        visitor.finished(j);
        rLog(rlPersistence, "Finished with %s: %s", 
                            outmap(j).c_str(), outmap(j->pair).c_str());
    }