diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c0b441..f03865e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/README.md b/README.md index 99dbfd9..c5f6aa9 100644 --- a/README.md +++ b/README.md @@ -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): @@ -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 diff --git a/include/ControlDependencyGraph.hpp b/include/ControlDependencyGraph.hpp index eeef468..b1675e1 100644 --- a/include/ControlDependencyGraph.hpp +++ b/include/ControlDependencyGraph.hpp @@ -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" @@ -40,4 +39,4 @@ class ControlDependencyGraph : public llvm::FunctionPass }; } -#endif \ No newline at end of file +#endif diff --git a/include/ProgramDependencyGraph.hpp b/include/ProgramDependencyGraph.hpp index 7ad692a..29e1eb7 100644 --- a/include/ProgramDependencyGraph.hpp +++ b/include/ProgramDependencyGraph.hpp @@ -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" @@ -62,4 +62,4 @@ class ProgramDependencyGraph : public llvm::ModulePass }; } // namespace pdg -#endif \ No newline at end of file +#endif diff --git a/src/DataDependencyGraph.cpp b/src/DataDependencyGraph.cpp index afa413d..bf4dbd1 100644 --- a/src/DataDependencyGraph.cpp +++ b/src/DataDependencyGraph.cpp @@ -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]; @@ -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); @@ -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]; @@ -185,7 +185,7 @@ std::vector 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); } @@ -259,4 +259,4 @@ void pdg::DataDependencyGraph::getAnalysisUsage(AnalysisUsage &AU) const } static RegisterPass - DDG("ddg", "Data Dependency Graph Construction", false, true); \ No newline at end of file + DDG("ddg", "Data Dependency Graph Construction", false, true); diff --git a/src/ProgramDependencyGraph.cpp b/src/ProgramDependencyGraph.cpp index 7a01946..bd5f14f 100644 --- a/src/ProgramDependencyGraph.cpp +++ b/src/ProgramDependencyGraph.cpp @@ -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(cast(t)->getElementType()); // collect all possible function with same function signature std::vector indirect_call_candidates = collectIndirectCallCandidates(funcTy); @@ -865,4 +865,4 @@ typename pdg::DependencyNode::DependencyLinkList pdg::P } static RegisterPass - PDG("pdg", "Program Dependency Graph Construction", false, true); \ No newline at end of file + PDG("pdg", "Program Dependency Graph Construction", false, true);