[IRBuilder] Add Align argument for CreateMaskedExpandLoad and CreateMaskedCompressSto...
[llvm-project.git] / llvm / lib / Transforms / ObjCARC / ProvenanceAnalysisEvaluator.cpp
blobe563ecfb16228b72cc9418f8fe08fbb17adb69f7
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 //===----------------------------------------------------------------------===//
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"
17 using namespace llvm;
18 using namespace llvm::objcarc;
20 static StringRef getName(Value *V) {
21 StringRef Name = V->getName();
22 if (Name.starts_with("\1"))
23 return Name.substr(1);
24 return Name;
27 static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
28 if (!V->hasName())
29 return;
30 Values.insert(V);
33 PreservedAnalyses PAEvalPass::run(Function &F, FunctionAnalysisManager &AM) {
34 SetVector<Value *> Values;
36 for (auto &Arg : F.args())
37 insertIfNamed(Values, &Arg);
39 for (Instruction &I : instructions(F)) {
40 insertIfNamed(Values, &I);
42 for (auto &Op : I.operands())
43 insertIfNamed(Values, Op);
46 ProvenanceAnalysis PA;
47 PA.setAA(&AM.getResult<AAManager>(F));
49 for (Value *V1 : Values) {
50 StringRef NameV1 = getName(V1);
51 for (Value *V2 : Values) {
52 StringRef NameV2 = getName(V2);
53 if (NameV1 >= NameV2)
54 continue;
55 errs() << NameV1 << " and " << NameV2;
56 if (PA.related(V1, V2))
57 errs() << " are related.\n";
58 else
59 errs() << " are not related.\n";
63 return PreservedAnalyses::all();