<commit_before>//===-- llvm/Support/CFG.h - Process LLVM structures as graphs ---*- C++ -*--=//
//
// This file defines specializations of GraphTraits that allow Function and
// BasicBlock graphs to be treated as proper graphs for generic algorithms.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CFG_H
#define LLVM_CFG_H

#include "Support/GraphTraits.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/InstrTypes.h"
#include "Support/iterator"

//===--------------------------------------------------------------------===//
// BasicBlock pred_iterator definition
//===--------------------------------------------------------------------===//

template <class _Ptr,  class _USE_iterator> // Predecessor Iterator
class PredIterator : public bidirectional_iterator<_Ptr, ptrdiff_t> {
  typedef bidirectional_iterator<_Ptr, ptrdiff_t> super;
  _Ptr *BB;
  _USE_iterator It;
public:
  typedef PredIterator<_Ptr,_USE_iterator> _Self;
  typedef typename super::pointer pointer;
  
  inline void advancePastConstants() {
    // TODO: This is bad
    // Loop to ignore constant pool references
    while (It != BB->use_end() && !isa<TerminatorInst>(*It))
      ++It;
  }
  
  inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) {
    advancePastConstants();
  }
  inline PredIterator(_Ptr *bb, bool) : BB(bb), It(bb->use_end()) {}
    
  inline bool operator==(const _Self& x) const { return It == x.It; }
  inline bool operator!=(const _Self& x) const { return !operator==(x); }
  
  inline pointer operator*() const { 
    assert(It != BB->use_end() && "pred_iterator out of range!");
    return cast<Instruction>(*It)->getParent(); 
  }
  inline pointer *operator->() const { return &(operator*()); }
  
  inline _Self& operator++() {   // Preincrement
    assert(It != BB->use_end() && "pred_iterator out of range!");
    ++It; advancePastConstants();
    return *this; 
  }
  
  inline _Self operator++(int) { // Postincrement
    _Self tmp = *this; ++*this; return tmp; 
  }
  
  inline _Self& operator--() { --It; return *this; }  // Predecrement
  inline _Self operator--(int) { // Postdecrement
    _Self tmp = *this; --*this; return tmp;
  }
};

typedef PredIterator<BasicBlock, Value::use_iterator> pred_iterator;
typedef PredIterator<const BasicBlock, 
                     Value::use_const_iterator> pred_const_iterator;

inline pred_iterator pred_begin(BasicBlock *BB) { return pred_iterator(BB); }
inline pred_const_iterator pred_begin(const BasicBlock *BB) {
  return pred_const_iterator(BB);
}
inline pred_iterator pred_end(BasicBlock *BB) { return pred_iterator(BB, true);}
inline pred_const_iterator pred_end(const BasicBlock *BB) {
  return pred_const_iterator(BB, true);
}



//===--------------------------------------------------------------------===//
// BasicBlock succ_iterator definition
//===--------------------------------------------------------------------===//

template <class _Term, class _BB>           // Successor Iterator
class SuccIterator : public bidirectional_iterator<_BB, ptrdiff_t> {
  const _Term Term;
  unsigned idx;
  typedef bidirectional_iterator<_BB, ptrdiff_t> super;
public:
  typedef SuccIterator<_Term, _BB> _Self;
  typedef typename super::pointer pointer;
  // TODO: This can be random access iterator, need operator+ and stuff tho
    
  inline SuccIterator(_Term T) : Term(T), idx(0) {         // begin iterator
    assert(T && "getTerminator returned null!");
  }
  inline SuccIterator(_Term T, bool)                       // end iterator
    : Term(T), idx(Term->getNumSuccessors()) {
    assert(T && "getTerminator returned null!");
  }

  inline const _Self &operator=(const _Self &I) {
    assert(Term == I.Term &&"Cannot assign iterators to two different blocks!");
    idx = I.idx;
  }
    
  inline bool operator==(const _Self& x) const { return idx == x.idx; }
  inline bool operator!=(const _Self& x) const { return !operator==(x); }
  <commit_msg>Fix bug in last checkin<commit_after>//===-- llvm/Support/CFG.h - Process LLVM structures as graphs ---*- C++ -*--=//
//
// This file defines specializations of GraphTraits that allow Function and
// BasicBlock graphs to be treated as proper graphs for generic algorithms.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CFG_H
#define LLVM_CFG_H

#include "Support/GraphTraits.h"
#include "llvm/Function.h"
#include "llvm/BasicBlock.h"
#include "llvm/InstrTypes.h"
#include "Support/iterator"

//===--------------------------------------------------------------------===//
// BasicBlock pred_iterator definition
//===--------------------------------------------------------------------===//

template <class _Ptr,  class _USE_iterator> // Predecessor Iterator
class PredIterator : public bidirectional_iterator<_Ptr, ptrdiff_t> {
  typedef bidirectional_iterator<_Ptr, ptrdiff_t> super;
  _Ptr *BB;
  _USE_iterator It;
public:
  typedef PredIterator<_Ptr,_USE_iterator> _Self;
  typedef typename super::pointer pointer;
  
  inline void advancePastConstants() {
    // TODO: This is bad
    // Loop to ignore constant pool references
    while (It != BB->use_end() && !isa<TerminatorInst>(*It))
      ++It;
  }
  
  inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) {
    advancePastConstants();
  }
  inline PredIterator(_Ptr *bb, bool) : BB(bb), It(bb->use_end()) {}
    
  inline bool operator==(const _Self& x) const { return It == x.It; }
  inline bool operator!=(const _Self& x) const { return !operator==(x); }
  
  inline pointer operator*() const { 
    assert(It != BB->use_end() && "pred_iterator out of range!");
    return cast<Instruction>(*It)->getParent(); 
  }
  inline pointer *operator->() const { return &(operator*()); }
  
  inline _Self& operator++() {   // Preincrement
    assert(It != BB->use_end() && "pred_iterator out of range!");
    ++It; advancePastConstants();
    return *this; 
  }
  
  inline _Self operator++(int) { // Postincrement
    _Self tmp = *this; ++*this; return tmp; 
  }
  
  inline _Self& operator--() { --It; return *this; }  // Predecrement
  inline _Self operator--(int) { // Postdecrement
    _Self tmp = *this; --*this; return tmp;
  }
};

typedef PredIterator<BasicBlock, Value::use_iterator> pred_iterator;
typedef PredIterator<const BasicBlock, 
                     Value::use_const_iterator> pred_const_iterator;

inline pred_iterator pred_begin(BasicBlock *BB) { return pred_iterator(BB); }
inline pred_const_iterator pred_begin(const BasicBlock *BB) {
  return pred_const_iterator(BB);
}
inline pred_iterator pred_end(BasicBlock *BB) { return pred_iterator(BB, true);}
inline pred_const_iterator pred_end(const BasicBlock *BB) {
  return pred_const_iterator(BB, true);
}



//===--------------------------------------------------------------------===//
// BasicBlock succ_iterator definition
//===--------------------------------------------------------------------===//

template <class _Term, class _BB>           // Successor Iterator
class SuccIterator : public bidirectional_iterator<_BB, ptrdiff_t> {
  const _Term Term;
  unsigned idx;
  typedef bidirectional_iterator<_BB, ptrdiff_t> super;
public:
  typedef SuccIterator<_Term, _BB> _Self;
  typedef typename super::pointer pointer;
  // TODO: This can be random access iterator, need operator+ and stuff tho
    
  inline SuccIterator(_Term T) : Term(T), idx(0) {         // begin iterator
    assert(T && "getTerminator returned null!");
  }
  inline SuccIterator(_Term T, bool)                       // end iterator
    : Term(T), idx(Term->getNumSuccessors()) {
    assert(T && "getTerminator returned null!");
  }

  inline const _Self &operator=(const _Self &I) {
    assert(Term == I.Term &&"Cannot assign iterators to two different blocks!");
    idx = I.idx;
    return *this;
  }
    
  inline bool operator==(const _Self& x) const { return idx == x.idx; }
  inline bool operator!=(const _Self& x) const { return !operator==(x); }
  
{'fraction_non_alphanumeric': 0.214018458468446, 'fraction_numerical': 0.0002494387627837366, 'mean_word_length': 2.5943523083818913, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3919487', 'n_tokens_mistral': 2334, 'n_tokens_neox': 2279, 'n_words': 646}