brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 8906fb8 Raw
67 lines · cpp
1//===- ProvenanceAnalysisEvaluator.cpp - ObjC ARC Optimization ------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "ProvenanceAnalysis.h"10#include "llvm/Transforms/ObjCARC.h"11#include "llvm/ADT/SetVector.h"12#include "llvm/Analysis/AliasAnalysis.h"13#include "llvm/IR/Function.h"14#include "llvm/IR/InstIterator.h"15#include "llvm/Support/raw_ostream.h"16 17using namespace llvm;18using namespace llvm::objcarc;19 20static StringRef getName(Value *V) {21  StringRef Name = V->getName();22  if (Name.starts_with("\1"))23    return Name.substr(1);24  return Name;25}26 27static void insertIfNamed(SetVector<Value *> &Values, Value *V) {28  if (!V->hasName())29    return;30  if (!V->getType()->isPointerTy())31    return;32  Values.insert(V);33}34 35PreservedAnalyses PAEvalPass::run(Function &F, FunctionAnalysisManager &AM) {36  SetVector<Value *> Values;37 38  for (auto &Arg : F.args())39    insertIfNamed(Values, &Arg);40 41  for (Instruction &I : instructions(F)) {42    insertIfNamed(Values, &I);43 44    for (auto &Op : I.operands())45      insertIfNamed(Values, Op);46  }47 48  ProvenanceAnalysis PA;49  PA.setAA(&AM.getResult<AAManager>(F));50 51  for (Value *V1 : Values) {52    StringRef NameV1 = getName(V1);53    for (Value *V2 : Values) {54      StringRef NameV2 = getName(V2);55      if (NameV1 >= NameV2)56        continue;57      errs() << NameV1 << " and " << NameV2;58      if (PA.related(V1, V2))59        errs() << " are related.\n";60      else61        errs() << " are not related.\n";62    }63  }64 65  return PreservedAnalyses::all();66}67