Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ find_package(LLVM REQUIRED CONFIG)
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD 14)

#
# We will build one library: libtmplugin.so. It corresponds to a plugin that we
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ Our program dependence graph is field senstive, context-insensitive and flow-ins
}


We have upgraded the implementation to LLVM 9.0.0. Currently, we only support building PDGs for C programs.
We have upgraded the implementation to LLVM 13.0.0. Currently, we only support building PDGs for C programs.

> Note: The `f44b510` commit's implementation uses LLVM 9.0.0 API


A PDG example looks like this (the blue part corresponds to the parameter tree):

Expand All @@ -34,9 +37,16 @@ mkdir build
cd build
cmake ..
make
opt -load libpdg.so -dot-pdg < test.bc
opt -enable-new-pm=0 -load libpdg.so -dot-pdg < test.bc
```

**Note**:
- "find_package(LLVM REQUIRED CONFIG)" in CMakeLists.txt:
- In order to find `LLVMConfig.cmake`, cmake command should be add flags like `-DLLVM_DIR={prefix_to_src}/llvm-project-13.0.0/llvm/build/lib/cmake/llvm`
- Usually you can find it in the above llvm build dir
- For LLVM 13.0.0, new pass manager is used for optimization pass, legacy pass manager is only for codegen, so `-enable-new-pm=0` must be added
- The C++ standard is changed to C++14, the `f44b510` commit uses C++11 standard

Once you finish these operations a dot file will be created. You can open it with [Graphviz](http://www.graphviz.org/).

## LLVM IR compilation
Expand Down
3 changes: 1 addition & 2 deletions include/ControlDependencyGraph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "llvm/Analysis/PostDominators.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Function.h"
#include "llvm/PassAnalysisSupport.h"
#include "llvm/Pass.h"

#include "DependencyGraph.hpp"
Expand Down Expand Up @@ -40,4 +39,4 @@ class ControlDependencyGraph : public llvm::FunctionPass
};
}

#endif
#endif
4 changes: 2 additions & 2 deletions include/ProgramDependencyGraph.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef PROGRAMDEPENDENCYGRAPH_H_
#define PROGRAMDEPENDENCYGRAPH_H_
#include "llvm/IR/Module.h"
#include "llvm/PassAnalysisSupport.h"
#include "llvm/Pass.h"
#include "ControlDependencyGraph.hpp"
#include "DataDependencyGraph.hpp"
#include "llvm/IR/DebugInfo.h"
Expand Down Expand Up @@ -62,4 +62,4 @@ class ProgramDependencyGraph : public llvm::ModulePass
};
} // namespace pdg

#endif
#endif
10 changes: 5 additions & 5 deletions src/DataDependencyGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void pdg::DataDependencyGraph::collectAliasDependencies()
MemoryLocation l_loc = MemoryLocation::get(li);
AliasResult andersAAResult = andersAA->query(s_loc, l_loc);
// AliasResult steensAAResult = steenAA->alias(s_loc, l_loc);
if (andersAAResult != NoAlias)
if (andersAAResult != llvm::AliasResult::NoAlias)
{
InstructionWrapper *loadInstW = instMap[li];
InstructionWrapper *storeInstW = instMap[si];
Expand All @@ -71,7 +71,7 @@ void pdg::DataDependencyGraph::collectAliasDependencies()
continue;
MemoryLocation s1_loc = MemoryLocation::get(si1);
AliasResult andersAAResult = andersAA->query(s_loc, s1_loc);
if (andersAAResult != NoAlias) {
if (andersAAResult != llvm::AliasResult::NoAlias) {
InstructionWrapper *store1InstW = PDGUtils::getInstance().getInstMap()[si];
InstructionWrapper *store2InstW = PDGUtils::getInstance().getInstMap()[si1];
DDG->addDependency(store1InstW, store2InstW, DependencyType::DATA_ALIAS);
Expand Down Expand Up @@ -100,7 +100,7 @@ void pdg::DataDependencyGraph::collectAliasDependencies()
continue;
}
AliasResult AA_result = andersAA->query(li1_loc, li2_loc);
if (AA_result != NoAlias)
if (AA_result != llvm::AliasResult::NoAlias)
{
InstructionWrapper *loadInstW1 = instMap[li1];
InstructionWrapper *loadInstW2 = instMap[li2];
Expand Down Expand Up @@ -185,7 +185,7 @@ std::vector<Instruction *> pdg::DataDependencyGraph::getRAWDepList(Instruction *
MemoryLocation SI_Loc = MemoryLocation::get(SI);
AliasResult andersAAResult = andersAA->query(LI_Loc, SI_Loc);
AliasResult steensAAResult = steenAA->query(LI_Loc, SI_Loc);
if (andersAAResult != NoAlias || steensAAResult != NoAlias)
if (andersAAResult != llvm::AliasResult::NoAlias || steensAAResult != llvm::AliasResult::NoAlias)
{
_flowdep_set.push_back(SI);
}
Expand Down Expand Up @@ -259,4 +259,4 @@ void pdg::DataDependencyGraph::getAnalysisUsage(AnalysisUsage &AU) const
}

static RegisterPass<pdg::DataDependencyGraph>
DDG("ddg", "Data Dependency Graph Construction", false, true);
DDG("ddg", "Data Dependency Graph Construction", false, true);
4 changes: 2 additions & 2 deletions src/ProgramDependencyGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ bool pdg::ProgramDependencyGraph::runOnModule(Module &M)
bool pdg::ProgramDependencyGraph::processIndirectCallInst(CallInst *CI, InstructionWrapper *instW)
{
auto &pdgUtils = PDGUtils::getInstance();
Type *t = CI->getCalledValue()->getType();
Type *t = CI->getCalledOperand()->getType();
FunctionType *funcTy = cast<FunctionType>(cast<PointerType>(t)->getElementType());
// collect all possible function with same function signature
std::vector<Function *> indirect_call_candidates = collectIndirectCallCandidates(funcTy);
Expand Down Expand Up @@ -865,4 +865,4 @@ typename pdg::DependencyNode<pdg::InstructionWrapper>::DependencyLinkList pdg::P
}

static RegisterPass<pdg::ProgramDependencyGraph>
PDG("pdg", "Program Dependency Graph Construction", false, true);
PDG("pdg", "Program Dependency Graph Construction", false, true);