DirectXShaderCompiler/lib/Analysis/MemDepPrinter.cpp

169 строки
5.2 KiB
C++
Исходник Обычный вид История

2016-12-28 22:52:27 +03:00
//===- MemDepPrinter.cpp - Printer for MemoryDependenceAnalysis -----------===//
Revert license text in banner comments to original llvm verbage (#33) Fix #30: Revert license text in banner comments to original llvm verbage This commit removes the Microsoft-specific copyright in llvm files and reverts the copyright wording to the original llvm wording. We used the following method to find the files to change: 1. Find all files in DirectXShaderCompiler that are also in llvm 3.7 2. For those files that have the Microsoft-specific copyright, revert it to the original llvm copyright as present in llvm 3.7 3. Revert the copyright in a few files that are not in llvm, but are mostly copies of files in llvm: lib\Transforms\Scalar\ScalarReplAggregatesHLSL.cpp lib\Transforms\Scalar\Reg2MemHLSL.cpp Leave the Microsoft-specific copyright header in files not present in stock llvm: include\dxc\* lib\HLSL\* lib\DxcSupport\* tools\clang\test\HLSL\* tools\clang\test\CodeGenHLSL\* tools\clang\unittests\HLSL\* tools\clang\unittests\HLSLHost\* tools\clang\tools\dxcompiler\* tools\clang\tools\dxa\* tools\clang\tools\dxc\* tools\clang\tools\dxopt\* tools\clang\tools\dxr\* tools\clang\tools\dxv\* tools\clang\tools\dotnetc\* utils\hct\* CONTRIBUTING.md COPYRIGHT LICENSE-MIT README.md cmake\modules\FindD3D12.cmake cmake\modules\FindDiaSDK.cmake cmake\modules\FindTAEF.cmake docs\DXIL.rst docs\HLSLChanges.rst docs\_themes\dxc-theme\layout.html docs\_themes\dxc-theme\theme.conf docs\_themes\dxc-theme\static\dxc-theme.css include\llvm\llvm_assert\assert.h include\llvm\llvm_assert\cassert include\llvm\Support\MSFileSystem.h include\llvm\Support\OacrIgnoreCond.h lib\MSSupport\CMakeLists.txt lib\MSSupport\MSFileSystemImpl.cpp lib\Support\assert.cpp lib\Support\MSFileSystemBasic.cpp lib\Support\Windows\MSFileSystem.inc.cpp lib\Transforms\Scalar\Reg2MemHLSL.cpp lib\Transforms\Scalar\ScalarReplAggregatesHLSL.cpp tools\clang\docs\UsingDxc.rst tools\clang\include\clang\AST\HlslTypes.h tools\clang\include\clang\Basic\BuiltinsDXIL.def tools\clang\include\clang\Basic\LangOptions.fixed.def tools\clang\include\clang\Parse\ParseHLSL.h tools\clang\include\clang\Sema\SemaHLSL.h tools\clang\lib\AST\ASTContextHLSL.cpp tools\clang\lib\AST\HlslTypes.cpp tools\clang\lib\CodeGen\CGHLSLMS.cpp tools\clang\lib\CodeGen\CGHLSLRuntime.cpp tools\clang\lib\CodeGen\CGHLSLRuntime.h tools\clang\lib\Frontend\Rewrite\FrontendActions_rewrite.cpp tools\clang\lib\Parse\HLSLRootSignature.cpp tools\clang\lib\Parse\HLSLRootSignature.h tools\clang\lib\Parse\ParseHLSL.cpp tools\clang\lib\Sema\gen_intrin_main_tables_15.h tools\clang\lib\Sema\SemaHLSL.cpp tools\clang\tools\d3dcomp\CMakeLists.txt tools\clang\tools\d3dcomp\d3dcomp.cpp tools\clang\tools\d3dcomp\d3dcomp.def tools\clang\tools\libclang\dxcisenseimpl.cpp tools\clang\tools\libclang\dxcisenseimpl.h tools\clang\tools\libclang\dxcrewriteunused.cpp tools\clang\tools\libclang\libclang.rc tools\dxexp\CMakeLists.txt tools\dxexp\dxexp.cpp tools\dxexp\LLVMBuild.txt
2017-01-25 04:54:00 +03:00
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//
2016-12-28 22:52:27 +03:00
#include "llvm/Analysis/Passes.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.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<AliasAnalysis>();
AU.addRequiredTransitive<MemoryDependenceAnalysis>();
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(MemoryDependenceAnalysis)
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;
MemoryDependenceAnalysis &MDA = getAnalysis<MemoryDependenceAnalysis>();
// All this code uses non-const interfaces because MemDep is not
// const-friendly, though nothing is actually modified.
for (auto &I : inst_range(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 MemoryDependenceAnalysis::NonLocalDepInfo &NLDI =
MDA.getNonLocalCallDependency(CS);
DepSet &InstDeps = Deps[Inst];
for (MemoryDependenceAnalysis::NonLocalDepInfo::const_iterator
I = NLDI.begin(), E = NLDI.end(); I != E; ++I) {
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 (SmallVectorImpl<NonLocalDepResult>::const_iterator
I = NLDI.begin(), E = NLDI.end(); I != E; ++I) {
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 : inst_range(*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";
}
}