You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
bindings
cmake
docs
examples
include
lib
Analysis
AliasAnalysis.cpp
AliasAnalysisEvaluator.cpp
AliasAnalysisSummary.cpp
AliasAnalysisSummary.h
AliasSetTracker.cpp
Analysis.cpp
AssumptionCache.cpp
BasicAliasAnalysis.cpp
BlockFrequencyInfo.cpp
BlockFrequencyInfoImpl.cpp
BranchProbabilityInfo.cpp
CFG.cpp
CFGPrinter.cpp
CFLAndersAliasAnalysis.cpp
CFLGraph.h
CFLSteensAliasAnalysis.cpp
CGSCCPassManager.cpp
CMakeLists.txt
CallGraph.cpp
CallGraphSCCPass.cpp
CallPrinter.cpp
CaptureTracking.cpp
CmpInstAnalysis.cpp
CodeMetrics.cpp
ConstantFolding.cpp
CostModel.cpp
Delinearization.cpp
DemandedBits.cpp
DependenceAnalysis.cpp.REMOVED.git-id
DivergenceAnalysis.cpp
DomPrinter.cpp
DominanceFrontier.cpp
EHPersonalities.cpp
GlobalsModRef.cpp
IVUsers.cpp
IndirectCallPromotionAnalysis.cpp
InlineCost.cpp
InstCount.cpp
InstructionSimplify.cpp.REMOVED.git-id
Interval.cpp
IntervalPartition.cpp
IteratedDominanceFrontier.cpp
LLVMBuild.txt
LazyBlockFrequencyInfo.cpp
LazyBranchProbabilityInfo.cpp
LazyCallGraph.cpp
LazyValueInfo.cpp
Lint.cpp
Loads.cpp
LoopAccessAnalysis.cpp
LoopAnalysisManager.cpp
LoopInfo.cpp
LoopPass.cpp
LoopUnrollAnalyzer.cpp
MemDepPrinter.cpp
MemDerefPrinter.cpp
MemoryBuiltins.cpp
MemoryDependenceAnalysis.cpp
MemoryLocation.cpp
MemorySSA.cpp
MemorySSAUpdater.cpp
ModuleDebugInfoPrinter.cpp
ModuleSummaryAnalysis.cpp
ObjCARCAliasAnalysis.cpp
ObjCARCAnalysisUtils.cpp
ObjCARCInstKind.cpp
OptimizationRemarkEmitter.cpp
OrderedBasicBlock.cpp
PHITransAddr.cpp
PostDominators.cpp
ProfileSummaryInfo.cpp
PtrUseVisitor.cpp
README.txt
RegionInfo.cpp
RegionPass.cpp
RegionPrinter.cpp
ScalarEvolution.cpp.REMOVED.git-id
ScalarEvolutionAliasAnalysis.cpp
ScalarEvolutionExpander.cpp
ScalarEvolutionNormalization.cpp
ScopedNoAliasAA.cpp
StratifiedSets.h
TargetLibraryInfo.cpp
TargetTransformInfo.cpp
Trace.cpp
TypeBasedAliasAnalysis.cpp
TypeMetadataUtils.cpp
ValueLattice.cpp
ValueLatticeUtils.cpp
ValueTracking.cpp.REMOVED.git-id
VectorUtils.cpp
AsmParser
BinaryFormat
Bitcode
CodeGen
DebugInfo
Demangle
ExecutionEngine
FuzzMutate
Fuzzer
IR
IRReader
LTO
LineEditor
Linker
MC
Object
ObjectYAML
Option
Passes
ProfileData
Support
TableGen
Target
Testing
ToolDrivers
Transforms
WindowsManifest
XRay
CMakeLists.txt
LLVMBuild.txt
projects
resources
runtimes
scripts
test
tools
unittests
utils
.arcconfig
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
LLVMBuild.txt
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in
version.txt.in
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
167 lines
5.0 KiB
C++
167 lines
5.0 KiB
C++
![]() |
//===- MemDepPrinter.cpp - Printer for MemoryDependenceAnalysis -----------===//
|
||
|
//
|
||
|
// The LLVM Compiler Infrastructure
|
||
|
//
|
||
|
// This file is distributed under the University of Illinois Open Source
|
||
|
// License. See LICENSE.TXT for details.
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
//
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
|
||
|
#include "llvm/ADT/SetVector.h"
|
||
|
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
|
||
|
#include "llvm/Analysis/Passes.h"
|
||
|
#include "llvm/IR/CallSite.h"
|
||
|
#include "llvm/IR/InstIterator.h"
|
||
|
#include "llvm/IR/LLVMContext.h"
|
||
|
#include "llvm/Support/ErrorHandling.h"
|
||
|
#include "llvm/Support/raw_ostream.h"
|
||
|
using namespace llvm;
|
||
|
|
||
|
namespace {
|
||
|
struct MemDepPrinter : public FunctionPass {
|
||
|
const Function *F;
|
||
|
|
||
|
enum DepType {
|
||
|
Clobber = 0,
|
||
|
Def,
|
||
|
NonFuncLocal,
|
||
|
Unknown
|
||
|
};
|
||
|
|
||
|
static const char *const DepTypeStr[];
|
||
|
|
||
|
typedef PointerIntPair<const Instruction *, 2, DepType> InstTypePair;
|
||
|
typedef std::pair<InstTypePair, const BasicBlock *> Dep;
|
||
|
typedef SmallSetVector<Dep, 4> DepSet;
|
||
|
typedef DenseMap<const Instruction *, DepSet> DepSetMap;
|
||
|
DepSetMap Deps;
|
||
|
|
||
|
static char ID; // Pass identifcation, replacement for typeid
|
||
|
MemDepPrinter() : FunctionPass(ID) {
|
||
|
initializeMemDepPrinterPass(*PassRegistry::getPassRegistry());
|
||
|
}
|
||
|
|
||
|
bool runOnFunction(Function &F) override;
|
||
|
|
||
|
void print(raw_ostream &OS, const Module * = nullptr) const override;
|
||
|
|
||
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||
|
AU.addRequiredTransitive<AAResultsWrapperPass>();
|
||
|
AU.addRequiredTransitive<MemoryDependenceWrapperPass>();
|
||
|
AU.setPreservesAll();
|
||
|
}
|
||
|
|
||
|
void releaseMemory() override {
|
||
|
Deps.clear();
|
||
|
F = nullptr;
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
static InstTypePair getInstTypePair(MemDepResult dep) {
|
||
|
if (dep.isClobber())
|
||
|
return InstTypePair(dep.getInst(), Clobber);
|
||
|
if (dep.isDef())
|
||
|
return InstTypePair(dep.getInst(), Def);
|
||
|
if (dep.isNonFuncLocal())
|
||
|
return InstTypePair(dep.getInst(), NonFuncLocal);
|
||
|
assert(dep.isUnknown() && "unexpected dependence type");
|
||
|
return InstTypePair(dep.getInst(), Unknown);
|
||
|
}
|
||
|
static InstTypePair getInstTypePair(const Instruction* inst, DepType type) {
|
||
|
return InstTypePair(inst, type);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
char MemDepPrinter::ID = 0;
|
||
|
INITIALIZE_PASS_BEGIN(MemDepPrinter, "print-memdeps",
|
||
|
"Print MemDeps of function", false, true)
|
||
|
INITIALIZE_PASS_DEPENDENCY(MemoryDependenceWrapperPass)
|
||
|
INITIALIZE_PASS_END(MemDepPrinter, "print-memdeps",
|
||
|
"Print MemDeps of function", false, true)
|
||
|
|
||
|
FunctionPass *llvm::createMemDepPrinter() {
|
||
|
return new MemDepPrinter();
|
||
|
}
|
||
|
|
||
|
const char *const MemDepPrinter::DepTypeStr[]
|
||
|
= {"Clobber", "Def", "NonFuncLocal", "Unknown"};
|
||
|
|
||
|
bool MemDepPrinter::runOnFunction(Function &F) {
|
||
|
this->F = &F;
|
||
|
MemoryDependenceResults &MDA = getAnalysis<MemoryDependenceWrapperPass>().getMemDep();
|
||
|
|
||
|
// All this code uses non-const interfaces because MemDep is not
|
||
|
// const-friendly, though nothing is actually modified.
|
||
|
for (auto &I : instructions(F)) {
|
||
|
Instruction *Inst = &I;
|
||
|
|
||
|
if (!Inst->mayReadFromMemory() && !Inst->mayWriteToMemory())
|
||
|
continue;
|
||
|
|
||
|
MemDepResult Res = MDA.getDependency(Inst);
|
||
|
if (!Res.isNonLocal()) {
|
||
|
Deps[Inst].insert(std::make_pair(getInstTypePair(Res),
|
||
|
static_cast<BasicBlock *>(nullptr)));
|
||
|
} else if (auto CS = CallSite(Inst)) {
|
||
|
const MemoryDependenceResults::NonLocalDepInfo &NLDI =
|
||
|
MDA.getNonLocalCallDependency(CS);
|
||
|
|
||
|
DepSet &InstDeps = Deps[Inst];
|
||
|
for (const NonLocalDepEntry &I : NLDI) {
|
||
|
const MemDepResult &Res = I.getResult();
|
||
|
InstDeps.insert(std::make_pair(getInstTypePair(Res), I.getBB()));
|
||
|
}
|
||
|
} else {
|
||
|
SmallVector<NonLocalDepResult, 4> NLDI;
|
||
|
assert( (isa<LoadInst>(Inst) || isa<StoreInst>(Inst) ||
|
||
|
isa<VAArgInst>(Inst)) && "Unknown memory instruction!");
|
||
|
MDA.getNonLocalPointerDependency(Inst, NLDI);
|
||
|
|
||
|
DepSet &InstDeps = Deps[Inst];
|
||
|
for (const NonLocalDepResult &I : NLDI) {
|
||
|
const MemDepResult &Res = I.getResult();
|
||
|
InstDeps.insert(std::make_pair(getInstTypePair(Res), I.getBB()));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
void MemDepPrinter::print(raw_ostream &OS, const Module *M) const {
|
||
|
for (const auto &I : instructions(*F)) {
|
||
|
const Instruction *Inst = &I;
|
||
|
|
||
|
DepSetMap::const_iterator DI = Deps.find(Inst);
|
||
|
if (DI == Deps.end())
|
||
|
continue;
|
||
|
|
||
|
const DepSet &InstDeps = DI->second;
|
||
|
|
||
|
for (const auto &I : InstDeps) {
|
||
|
const Instruction *DepInst = I.first.getPointer();
|
||
|
DepType type = I.first.getInt();
|
||
|
const BasicBlock *DepBB = I.second;
|
||
|
|
||
|
OS << " ";
|
||
|
OS << DepTypeStr[type];
|
||
|
if (DepBB) {
|
||
|
OS << " in block ";
|
||
|
DepBB->printAsOperand(OS, /*PrintType=*/false, M);
|
||
|
}
|
||
|
if (DepInst) {
|
||
|
OS << " from: ";
|
||
|
DepInst->print(OS);
|
||
|
}
|
||
|
OS << "\n";
|
||
|
}
|
||
|
|
||
|
Inst->print(OS);
|
||
|
OS << "\n\n";
|
||
|
}
|
||
|
}
|