mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
529919ff31
Summary: Now that the DataLayout is a mandatory part of the module, let's start cleaning the codebase. This patch is a first attempt at doing that. This patch is not exactly NFC as for instance some places were passing a nullptr instead of the DataLayout, possibly just because there was a default value on the DataLayout argument to many functions in the API. Even though it is not purely NFC, there is no change in the validation. I turned as many pointer to DataLayout to references, this helped figuring out all the places where a nullptr could come up. I had initially a local version of this patch broken into over 30 independant, commits but some later commit were cleaning the API and touching part of the code modified in the previous commits, so it seemed cleaner without the intermediate state. Test Plan: Reviewers: echristo Subscribers: llvm-commits From: Mehdi Amini <mehdi.amini@apple.com> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231740 91177308-0d34-0410-b5e6-96231b3b80d8
95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
//===- ProvenanceAnalysisEvaluator.cpp - ObjC ARC Optimization ------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "ProvenanceAnalysis.h"
|
|
#include "llvm/Pass.h"
|
|
#include "llvm/ADT/SetVector.h"
|
|
#include "llvm/Analysis/AliasAnalysis.h"
|
|
#include "llvm/Analysis/Passes.h"
|
|
#include "llvm/IR/InstIterator.h"
|
|
#include "llvm/IR/Function.h"
|
|
#include "llvm/IR/Module.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::objcarc;
|
|
|
|
namespace {
|
|
class PAEval : public FunctionPass {
|
|
|
|
public:
|
|
static char ID;
|
|
PAEval();
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
|
bool runOnFunction(Function &F) override;
|
|
};
|
|
}
|
|
|
|
char PAEval::ID = 0;
|
|
PAEval::PAEval() : FunctionPass(ID) {}
|
|
|
|
void PAEval::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
AU.addRequired<AliasAnalysis>();
|
|
}
|
|
|
|
static StringRef getName(Value *V) {
|
|
StringRef Name = V->getName();
|
|
if (Name.startswith("\1"))
|
|
return Name.substr(1);
|
|
return Name;
|
|
}
|
|
|
|
static void insertIfNamed(SetVector<Value *> &Values, Value *V) {
|
|
if (!V->hasName())
|
|
return;
|
|
Values.insert(V);
|
|
}
|
|
|
|
bool PAEval::runOnFunction(Function &F) {
|
|
SetVector<Value *> Values;
|
|
|
|
for (auto &Arg : F.args())
|
|
insertIfNamed(Values, &Arg);
|
|
|
|
for (auto I = inst_begin(F), E = inst_end(F); I != E; ++I) {
|
|
insertIfNamed(Values, &*I);
|
|
|
|
for (auto &Op : I->operands())
|
|
insertIfNamed(Values, Op);
|
|
}
|
|
|
|
ProvenanceAnalysis PA;
|
|
PA.setAA(&getAnalysis<AliasAnalysis>());
|
|
const DataLayout &DL = F.getParent()->getDataLayout();
|
|
|
|
for (Value *V1 : Values) {
|
|
StringRef NameV1 = getName(V1);
|
|
for (Value *V2 : Values) {
|
|
StringRef NameV2 = getName(V2);
|
|
if (NameV1 >= NameV2)
|
|
continue;
|
|
errs() << NameV1 << " and " << NameV2;
|
|
if (PA.related(V1, V2, DL))
|
|
errs() << " are related.\n";
|
|
else
|
|
errs() << " are not related.\n";
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
FunctionPass *llvm::createPAEvalPass() { return new PAEval(); }
|
|
|
|
INITIALIZE_PASS_BEGIN(PAEval, "pa-eval",
|
|
"Evaluate ProvenanceAnalysis on all pairs", false, true)
|
|
INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
|
|
INITIALIZE_PASS_END(PAEval, "pa-eval",
|
|
"Evaluate ProvenanceAnalysis on all pairs", false, true)
|