ProvenanceAnalysisEvaluator.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "ProvenanceAnalysis.h"
  9. #include "llvm/Transforms/ObjCARC.h"
  10. #include "llvm/ADT/SetVector.h"
  11. #include "llvm/Analysis/AliasAnalysis.h"
  12. #include "llvm/IR/Function.h"
  13. #include "llvm/IR/InstIterator.h"
  14. #include "llvm/Support/raw_ostream.h"
  15. using namespace llvm;
  16. using namespace llvm::objcarc;
  17. static StringRef getName(Value *V) {
  18. StringRef Name = V->getName();
  19. if (Name.startswith("\1"))
  20. return Name.substr(1);
  21. return Name;
  22. }
  23. static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
  24. if (!V->hasName())
  25. return;
  26. Values.insert(V);
  27. }
  28. PreservedAnalyses PAEvalPass::run(Function &F, FunctionAnalysisManager &AM) {
  29. SetVector<Value *> Values;
  30. for (auto &Arg : F.args())
  31. insertIfNamed(Values, &Arg);
  32. for (Instruction &I : instructions(F)) {
  33. insertIfNamed(Values, &I);
  34. for (auto &Op : I.operands())
  35. insertIfNamed(Values, Op);
  36. }
  37. ProvenanceAnalysis PA;
  38. PA.setAA(&AM.getResult<AAManager>(F));
  39. for (Value *V1 : Values) {
  40. StringRef NameV1 = getName(V1);
  41. for (Value *V2 : Values) {
  42. StringRef NameV2 = getName(V2);
  43. if (NameV1 >= NameV2)
  44. continue;
  45. errs() << NameV1 << " and " << NameV2;
  46. if (PA.related(V1, V2))
  47. errs() << " are related.\n";
  48. else
  49. errs() << " are not related.\n";
  50. }
  51. }
  52. return PreservedAnalyses::all();
  53. }