<commit_before>//===- AliasAnalysisEvaluator.cpp - Alias Analysis Accuracy Evaluator -----===//
//
// This file implements a simple N^2 alias analysis accuracy evaluator.
// Basically, for each function in the program, it simply queries to see how the
// alias analysis implementation answers alias queries between each pair of
// pointers in the function.
//
// This is inspired and adapted from code by: <NAME>, <NAME>, and <NAME>.
//
//===----------------------------------------------------------------------===//

#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Type.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Assembly/Writer.h"
#include "Support/CommandLine.h"

namespace {
  cl::opt<bool> PrintNo  ("print-no-aliases", cl::ReallyHidden);
  cl::opt<bool> PrintMay ("print-may-aliases", cl::ReallyHidden);
  cl::opt<bool> PrintMust("print-must-aliases", cl::ReallyHidden);

  class AAEval : public FunctionPass {
    unsigned No, May, Must;

  public:
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<AliasAnalysis>();
      AU.setPreservesAll();
    }
    
    bool doInitialization(Module &M) { No = May = Must = 0; return false; }
    bool runOnFunction(Function &F);
    bool doFinalization(Module &M);
  };

  RegisterOpt<AAEval>
  X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator");
}

static inline void PrintResults(const char *Msg, bool P, Value *V1, Value *V2) {
  if (P) {
    std::cerr << "  " << Msg << ":\t";
    WriteAsOperand(std::cerr, V1) << ", ";
    WriteAsOperand(std::cerr, V2) << "\n";
  }
}

bool AAEval::runOnFunction(Function &F) {
  AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
  
  std::vector<Value *> Pointers;

  for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I)
    if (isa<PointerType>(I->getType()))    // Add all pointer arguments
      Pointers.push_back(I);

  for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
    if (isa<PointerType>((*I)->getType())) // Add all pointer instructions
      Pointers.push_back(*I);

  if (PrintNo || PrintMay || PrintMust)
    std::cerr << "Function: " << F.getName() << "\n";

  // iterate over the worklist, and run the full (n^2)/2 disambiguations
  for (std::vector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
       I1 != E; ++I1)
    for (std::vector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2)
      switch (AA.alias(*I1, *I2)) {
      case AliasAnalysis::NoAlias:
        PrintResults("No", PrintNo, *I1, *I2);
        ++No; break;
      case AliasAnalysis::MayAlias:
        PrintResults("May", PrintMay, *I1, *I2);
        ++May; break;
      case AliasAnalysis::MustAlias:
        PrintResults("Must", PrintMust, *I1, *I2);
        ++Must; break;
      default:
        std::cerr << "Unknown alias query result!\n";
      }

  return false;
}

bool AAEval::doFinalization(Module &M) {
  unsigned Sum = No+May+Must;
  std::cerr << "===== Alias Analysis Evaluator Report =====\n";
  if (Sum == 0) {
    std::cerr << "  Alias Analysis Evaluator Summary: No pointers!\n";
    return false;<commit_msg>Adjust to new AA interface<commit_after>//===- AliasAnalysisEvaluator.cpp - Alias Analysis Accuracy Evaluator -----===//
//
// This file implements a simple N^2 alias analysis accuracy evaluator.
// Basically, for each function in the program, it simply queries to see how the
// alias analysis implementation answers alias queries between each pair of
// pointers in the function.
//
// This is inspired and adapted from code by: <NAME>, <NAME>, and <NAME>.
//
//===----------------------------------------------------------------------===//

#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Pass.h"
#include "llvm/Function.h"
#include "llvm/Type.h"
#include "llvm/Support/InstIterator.h"
#include "llvm/Assembly/Writer.h"
#include "Support/CommandLine.h"

namespace {
  cl::opt<bool> PrintNo  ("print-no-aliases", cl::ReallyHidden);
  cl::opt<bool> PrintMay ("print-may-aliases", cl::ReallyHidden);
  cl::opt<bool> PrintMust("print-must-aliases", cl::ReallyHidden);

  class AAEval : public FunctionPass {
    unsigned No, May, Must;

  public:
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.addRequired<AliasAnalysis>();
      AU.setPreservesAll();
    }
    
    bool doInitialization(Module &M) { No = May = Must = 0; return false; }
    bool runOnFunction(Function &F);
    bool doFinalization(Module &M);
  };

  RegisterOpt<AAEval>
  X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator");
}

static inline void PrintResults(const char *Msg, bool P, Value *V1, Value *V2) {
  if (P) {
    std::cerr << "  " << Msg << ":\t";
    WriteAsOperand(std::cerr, V1) << ", ";
    WriteAsOperand(std::cerr, V2) << "\n";
  }
}

bool AAEval::runOnFunction(Function &F) {
  AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
  
  std::vector<Value *> Pointers;

  for (Function::aiterator I = F.abegin(), E = F.aend(); I != E; ++I)
    if (isa<PointerType>(I->getType()))    // Add all pointer arguments
      Pointers.push_back(I);

  for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
    if (isa<PointerType>((*I)->getType())) // Add all pointer instructions
      Pointers.push_back(*I);

  if (PrintNo || PrintMay || PrintMust)
    std::cerr << "Function: " << F.getName() << "\n";

  // iterate over the worklist, and run the full (n^2)/2 disambiguations
  for (std::vector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
       I1 != E; ++I1)
    for (std::vector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2)
      switch (AA.alias(*I1, 0, *I2, 0)) {
      case AliasAnalysis::NoAlias:
        PrintResults("No", PrintNo, *I1, *I2);
        ++No; break;
      case AliasAnalysis::MayAlias:
        PrintResults("May", PrintMay, *I1, *I2);
        ++May; break;
      case AliasAnalysis::MustAlias:
        PrintResults("Must", PrintMust, *I1, *I2);
        ++Must; break;
      default:
        std::cerr << "Unknown alias query result!\n";
      }

  return false;
}

bool AAEval::doFinalization(Module &M) {
  unsigned Sum = No+May+Must;
  std::cerr << "===== Alias Analysis Evaluator Report =====\n";
  if (Sum == 0) {
    std::cerr << "  Alias Analysis Evaluator Summary: No pointers!\n";
    return false;
{'fraction_non_alphanumeric': 0.18790259230164966, 'fraction_numerical': 0.007855459544383346, 'mean_word_length': 3.201980198019802, 'pattern_counts': {'":': 2, '<': 75, '<?xml version=': 0, '>': 35, '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': '4426552', 'n_tokens_mistral': 2117, 'n_tokens_neox': 2067, 'n_words': 559}