<commit_before>//===- Pass.cpp - LLVM Pass Infrastructure Impementation ------------------===//
//
// This file implements the LLVM Pass infrastructure.  It is primarily
// responsible with ensuring that passes are executed and batched together
// optimally.
//
//===----------------------------------------------------------------------===//

#include "llvm/Pass.h"
#include "Support/STLExtras.h"

PassManager::~PassManager() {
  for_each(Passes.begin(), Passes.end(), deleter<Pass>);
}

class BasicBlockPassBatcher : public MethodPass {
  typedef std::vector<BasicBlockPass*> SubPassesType;
  SubPassesType SubPasses;
public:
  ~BasicBlockPassBatcher() {
    for_each(SubPasses.begin(), SubPasses.end(), deleter<BasicBlockPass>);
  }

  void add(BasicBlockPass *P) { SubPasses.push_back(P); }

  virtual bool doPassInitialization(Module *M) {
    bool Changed = false;
    for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
         I != E; ++I)
      Changed |= (*I)->doInitialization(M);
    return Changed;
  }

  virtual bool runOnMethod(Method *M) {
    bool Changed = false;

    for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
      for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
           I != E; ++I)
        Changed |= (*I)->runOnBasicBlock(*MI);
    return Changed;
  }

  virtual bool doFinalization(Module *M) {
    bool Changed = false;
    for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
         I != E; ++I)
      Changed |= (*I)->doFinalization(M);

    return Changed;
  }
};

class MethodPassBatcher : public Pass {
  typedef std::vector<MethodPass*> SubPassesType;
  SubPassesType SubPasses;
  BasicBlockPassBatcher *BBPBatcher;
public:
  ~MethodPassBatcher() {
    for_each(SubPasses.begin(), SubPasses.end(), deleter<MethodPass>);
  }

  void add(MethodPass *P) {
    if (BasicBlockPass *BBP = dynamic_cast<BasicBlockPass*>(P)) {
      if (BBPBatcher == 0) {
        BBPBatcher = new BasicBlockPassBatcher();
        SubPasses.push_back(BBPBatcher);
      }
      BBPBatcher->add(BBP);
    } else {
      BBPBatcher = 0;  // Ensure that passes don't get accidentally reordered
      SubPasses.push_back(P);
    }
  }

  virtual bool run(Module *M) {
    bool Changed = false;
    for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
         I != E; ++I)
      Changed |= (*I)->doInitialization(M);

    for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
      for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
           I != E; ++I)
        Changed |= (*I)->runOnMethod(*MI);

    for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
         I != E; ++I)
      Changed |= (*I)->doFinalization(M);

    return Changed;
  }
};




// add(MethodPass*) - MethodPass's must be batched together... make sure this
// happens now.
//
void PassManager::add(MethodPass *MP) {
  if (Batcher == 0) { // If we don't have a batcher yet, make one now.
    Batcher = new MethodPassBatcher();
    Passes.push_back(Batcher);
  }
  Batcher->add(MP);   // The Batcher will queue them passes up
}

// add - Add a pass to the PassManager, batching it up as appropriate...
void PassManager::add(Pass *P) {
  if (MethodPass *MP = dynamic_cast<MethodPass*>(P)) {
    add(MP);  // Use the methodpass specific code to do the addition
  } else {
    Batcher = 0;  // Ensure that passes don't get accidentally reordered
    Passes.push_back(P);
  }
}<commit_msg>Ooops, forgot to implement void PassManager::add(BasicBlockPass *BBP)<commit_after>//===- Pass.cpp - LLVM Pass Infrastructure Impementation ------------------===//
//
// This file implements the LLVM Pass infrastructure.  It is primarily
// responsible with ensuring that passes are executed and batched together
// optimally.
//
//===----------------------------------------------------------------------===//

#include "llvm/Pass.h"
#include "Support/STLExtras.h"

PassManager::~PassManager() {
  for_each(Passes.begin(), Passes.end(), deleter<Pass>);
}

class BasicBlockPassBatcher : public MethodPass {
  typedef std::vector<BasicBlockPass*> SubPassesType;
  SubPassesType SubPasses;
public:
  ~BasicBlockPassBatcher() {
    for_each(SubPasses.begin(), SubPasses.end(), deleter<BasicBlockPass>);
  }

  void add(BasicBlockPass *P) { SubPasses.push_back(P); }

  virtual bool doPassInitialization(Module *M) {
    bool Changed = false;
    for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
         I != E; ++I)
      Changed |= (*I)->doInitialization(M);
    return Changed;
  }

  virtual bool runOnMethod(Method *M) {
    bool Changed = false;

    for (Method::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
      for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
           I != E; ++I)
        Changed |= (*I)->runOnBasicBlock(*MI);
    return Changed;
  }

  virtual bool doFinalization(Module *M) {
    bool Changed = false;
    for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
         I != E; ++I)
      Changed |= (*I)->doFinalization(M);

    return Changed;
  }
};

class MethodPassBatcher : public Pass {
  typedef std::vector<MethodPass*> SubPassesType;
  SubPassesType SubPasses;
  BasicBlockPassBatcher *BBPBatcher;
public:
  ~MethodPassBatcher() {
    for_each(SubPasses.begin(), SubPasses.end(), deleter<MethodPass>);
  }

  void add(BasicBlockPass *BBP) {
    if (BBPBatcher == 0) {
      BBPBatcher = new BasicBlockPassBatcher();
      SubPasses.push_back(BBPBatcher);
    }
    BBPBatcher->add(BBP);
  }

  void add(MethodPass *P) {
    if (BasicBlockPass *BBP = dynamic_cast<BasicBlockPass*>(P)) {
      add(BBP);
    } else {
      BBPBatcher = 0;  // Ensure that passes don't get accidentally reordered
      SubPasses.push_back(P);
    }
  }

  virtual bool run(Module *M) {
    bool Changed = false;
    for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
         I != E; ++I)
      Changed |= (*I)->doInitialization(M);

    for (Module::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI)
      for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
           I != E; ++I)
        Changed |= (*I)->runOnMethod(*MI);

    for (SubPassesType::iterator I = SubPasses.begin(), E = SubPasses.end();
         I != E; ++I)
      Changed |= (*I)->doFinalization(M);

    return Changed;
  }
};

// add(BasicBlockPass*) - If we know it's a BasicBlockPass, we don't have to do
// any checking...
//
void PassManager::add(BasicBlockPass *BBP) {
  if (Batcher == 0)         // If we don't have a batcher yet, make one now.
    add((MethodPass*)BBP);
  else
    Batcher->add(BBP);
}


// add(MethodPass*) - MethodPass's must be batched together... make sure this
// happens now.
//
void PassManager::add(MethodPass *MP) {
  if (Batcher == 0) { // If we don't have a batcher yet, make one now.
    Batcher = new MethodPassBatcher();
    Passes.push_back(Batcher);
  }
  Batcher->add(MP);   // The Batcher will queue them passes up
}

// add - Add a pass to the PassManager, batching it up as appropriate...
void PassManager::add(Pass *P) {
  if (MethodPass *MP = dynamic_cast<MethodPass*>(P)) {
    add(MP);  // Use the methodpass specific code to do the addition
  } else {
    Batcher = 0;  // Ensure that passes don't get accidentally reordered
    Passes.push_back(P);
  }
}
{'fraction_non_alphanumeric': 0.1716928025733816, 'fraction_numerical': 0.0012062726176115801, 'mean_word_length': 2.9356540084388185, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 42, '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': '3175212', 'n_tokens_mistral': 2487, 'n_tokens_neox': 2408, 'n_words': 631}