Skip to content

Commit

Permalink
Merge remote-tracking branch 'jcarlson23/llvm-4'
Browse files Browse the repository at this point in the history
  • Loading branch information
dtzWill committed Apr 23, 2017
2 parents 14d9b9f + 29ae917 commit ee5aead
Show file tree
Hide file tree
Showing 28 changed files with 118 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Release/
Debug/
build/
build-master/
html/
Release+Asserts/
Debug+Asserts/
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include)


add_subdirectory(lib)
add_subdirectory(tools)

24 changes: 24 additions & 0 deletions SVF Alterations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Diff between “llvm-4” and “master”

Likely the most important difference is the requirement that a NodeRef (rather than NodeType) be declared for types that will utilize the GraphTraits as part of the class definition.

I altered most of the getPassName() instances to return a llvm::StringRef rather than a const char * type. This seems rather trivial and I didn’t see a reason not to use the preferred string type choice for LLVM.

/include/Util/DataFlow.h
The PostDominatorTree becomes PostDominatorTreeWrapperPass, which is pretty consistent in recent revisions where a pass is accessed via a wrapper.

I altered the base class /include/Util/GraphUtil.h

To have a typedef typename Traits::NodeRef NodeRef, per llvm 4. I believe this is necessary, as I looked over the llvm-4. This with the NodeRef alterations in each of the specific graph classes required some alterations in terms of dereferencing, etc. Again, a quick pass and it seemed to work but this is a place where a simple “*” might have a subtle unintended consequence.

include/WPA/WPAPass.h

Here I had to remove the explicit inheritance from “AliasAnalysis”, and this likely needs a fix, as AliasAnalysis needs a TargetLibraryInfo to be passed as the argument now and I’m a little unsure as to where to get that from. There is no more default constructor… To get the TargetLibraryInfo it seems the best convention is:

TLInfo = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();

But it didn’t seem to “drop in” to the wpa tool perfectly. It seems that inheriting from AAResultsWrapperPass might make sense? Or to have a dependency there? That said, I’m still learning so I wanted to point this out and let others more familiar make that decision.

I had a number of CMAKE issues, most of which I was able to solve but might have a few redundancies, perhaps that is because I’m on a Mac.

I believe the rest is pretty straightforward. Looking back the WPAPass is likely an issue to be solved prior to merging into master, the rest
1 change: 1 addition & 0 deletions include/MSSA/SVFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ struct GraphTraits<Inverse<SVFGNode *> > : public GraphTraits<Inverse<GenericNod
};

template<> struct GraphTraits<SVFG*> : public GraphTraits<GenericGraph<SVFGNode,SVFGEdge>* > {
typedef SVFGNode *NodeRef;
};
}

Expand Down
2 changes: 1 addition & 1 deletion include/MSSA/SVFGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MemSSADF : public llvm::DominanceFrontier {

bool runOnDT(llvm::DominatorTree& dt) {
releaseMemory();
getBase().analyze(dt);
analyze(dt);
return false;
}
};
Expand Down
1 change: 1 addition & 0 deletions include/MemoryModel/CHA.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ struct GraphTraits<Inverse<CHNode*> > : public GraphTraits<Inverse<GenericNode<C
};

template<> struct GraphTraits<CHGraph*> : public GraphTraits<GenericGraph<CHNode,CHEdge>* > {
typedef CHNode *NodeRef;
};

}
Expand Down
1 change: 1 addition & 0 deletions include/MemoryModel/ConsG.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ struct GraphTraits<Inverse<ConstraintNode *> > : public GraphTraits<Inverse<Gene
};

template<> struct GraphTraits<ConstraintGraph*> : public GraphTraits<GenericGraph<ConstraintNode,ConstraintEdge>* > {
typedef ConstraintNode *NodeRef;
};

}
Expand Down
1 change: 1 addition & 0 deletions include/MemoryModel/PAG.h
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ template<> struct GraphTraits<Inverse<PAGNode *> > : public GraphTraits<Inverse<
};

template<> struct GraphTraits<PAG*> : public GraphTraits<GenericGraph<PAGNode,PAGEdge>* > {
typedef PAGNode *NodeRef;
};
}
#endif /* PAG_H_ */
4 changes: 2 additions & 2 deletions include/MemoryModel/PAGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ class GepValPN: public ValPN {
/// Return name of a LLVM value
const std::string getValueName() {
if (value && value->hasName())
return value->getName().str() + "_" + llvm::utostr_32(getOffset());
return "offset_" + llvm::utostr_32(getOffset());
return value->getName().str() + "_" + llvm::utostr(getOffset());
return "offset_" + llvm::utostr(getOffset());
}

const llvm::Type *getType() const {
Expand Down
2 changes: 1 addition & 1 deletion include/SABER/DoubleFreeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class DoubleFreeChecker : public LeakChecker {
}

/// Get pass name
virtual const char* getPassName() const {
virtual llvm::StringRef getPassName() const {
return "Double Free Analysis";
}

Expand Down
2 changes: 1 addition & 1 deletion include/SABER/FileChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class FileChecker : public LeakChecker {
}

/// Get pass name
virtual const char* getPassName() const {
virtual llvm::StringRef getPassName() const {
return "File Open/Close Analysis";
}

Expand Down
2 changes: 1 addition & 1 deletion include/SABER/LeakChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class LeakChecker : public SrcSnkDDA, public llvm::ModulePass {
}

/// Get pass name
virtual const char* getPassName() const {
virtual llvm::StringRef getPassName() const {
return "Static Memory Leak Analysis";
}

Expand Down
4 changes: 2 additions & 2 deletions include/Util/BreakConstantExpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BreakConstantGEPs : public llvm::ModulePass {
public:
static char ID;
BreakConstantGEPs() : ModulePass(ID) {}
const char *getPassName() const {
llvm::StringRef getPassName() const {
return "Remove Constant GEP Expressions";
}
virtual bool runOnModule (llvm::Module & M);
Expand All @@ -62,7 +62,7 @@ class MergeFunctionRets : public llvm::ModulePass {
public:
static char ID;
MergeFunctionRets() : ModulePass(ID) {}
const char *getPassName() const {
llvm::StringRef getPassName() const {
return "unify function exit into one dummy exit basic block";
}
virtual bool runOnModule (llvm::Module & M) {
Expand Down
9 changes: 5 additions & 4 deletions include/Util/DataFlowUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,11 @@ class PTACFInfoBuilder {
llvm::Function* fun = const_cast<llvm::Function*>(f);
FunToPostDTMap::iterator it = funToPDTMap.find(fun);
if(it==funToPDTMap.end()) {
llvm::PostDominatorTree* postDT = new llvm::PostDominatorTree();
llvm::PostDominatorTreeWrapperPass* postDT = new llvm::PostDominatorTreeWrapperPass();
postDT->runOnFunction(*fun);
funToPDTMap[fun] = postDT;
return postDT;
llvm::PostDominatorTree * PDT = &(postDT->getPostDomTree());
funToPDTMap[fun] = PDT;
return PDT;
}
else
return it->second;
Expand Down Expand Up @@ -225,7 +226,7 @@ class IteratedDominanceFrontier: public llvm::DominanceFrontierBase<llvm::BasicB

virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<llvm::DominanceFrontier>();
// AU.addRequired<llvm::DominanceFrontier>();
}

// virtual bool runOnFunction(llvm::Function &m) {
Expand Down
7 changes: 4 additions & 3 deletions include/Util/GraphUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <llvm/Support/Debug.h> // for debug
#include <llvm/ADT/GraphTraits.h> // for Graphtraits
#include <llvm/Support/ToolOutputFile.h>
#include <llvm/Support/CommandLine.h> // for tool output file
#include <llvm/Support/CommandLine.h> // for tool output file
#include <llvm/Support/GraphWriter.h> // for graph write
#include <llvm/Support/FileSystem.h> // for file open flag

Expand Down Expand Up @@ -82,7 +82,8 @@ class GraphPrinter {
const GraphType &GT) {
///Define the GTraits and node iterator for printing
typedef GraphTraits<GraphType> GTraits;
typedef typename GTraits::NodeType NodeType;

typedef typename GTraits::NodeRef NodeRef;
typedef typename GTraits::nodes_iterator node_iterator;
typedef typename GTraits::ChildIteratorType child_iterator;

Expand All @@ -91,7 +92,7 @@ class GraphPrinter {
node_iterator I = GTraits::nodes_begin(GT);
node_iterator E = GTraits::nodes_end(GT);
for (; I != E; ++I) {
NodeType *Node = *I;
NodeRef *Node = *I;
O << "node :" << Node << "'\n";
child_iterator EI = GTraits::child_begin(Node);
child_iterator EE = GTraits::child_end(Node);
Expand Down
5 changes: 5 additions & 0 deletions include/Util/PTACallGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class PTACallGraphEdge : public GenericCallGraphEdgeTy {
enum CEDGEK {
CallRetEdge,TDForkEdge,TDJoinEdge,HareParForEdge
};


private:
CallInstSet directCalls;
CallInstSet indirectCalls;
Expand Down Expand Up @@ -216,6 +218,7 @@ class PTACallGraph : public GenericCallGraphTy {
destroy();
}


/// Get callees from an indirect callsite
//@{
inline CallEdgeMap& getIndCallMap() {
Expand Down Expand Up @@ -368,8 +371,10 @@ struct GraphTraits<Inverse<PTACallGraphNode *> > : public GraphTraits<Inverse<Ge
};

template<> struct GraphTraits<PTACallGraph*> : public GraphTraits<GenericGraph<PTACallGraphNode,PTACallGraphEdge>* > {
typedef PTACallGraphNode *NodeRef;
};


}


Expand Down
6 changes: 3 additions & 3 deletions include/Util/SCC.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SCCDetection {
private:
///Define the GTraits and node iterator for printing
typedef llvm::GraphTraits<GraphType> GTraits;
typedef typename GTraits::NodeType GNODE;
typedef typename GTraits::NodeRef GNODE;
typedef typename GTraits::nodes_iterator node_iterator;
typedef typename GTraits::ChildIteratorType child_iterator;
typedef unsigned NodeID ;
Expand Down Expand Up @@ -207,11 +207,11 @@ class SCCDetection {
return _NodeSCCAuxInfo[n].inSCC();
}

inline GNODE* Node(NodeID id) const {
inline GNODE Node(NodeID id) const {
return GTraits::getNode(_graph, id);
}

inline NodeID Node_Index(GNODE* node) const {
inline NodeID Node_Index(GNODE node) const {
return GTraits::getNodeID(node);
}

Expand Down
14 changes: 10 additions & 4 deletions include/WPA/WPAPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@

#include "MemoryModel/PointerAnalysis.h"
#include <llvm/Analysis/AliasAnalysis.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/Pass.h>


/*!
* Whole program pointer analysis.
* This class performs various pointer analysis on the given module.
*/
class WPAPass: public llvm::ModulePass, public llvm::AliasAnalysis {
// excised ", public llvm::AliasAnalysis" as that has a very light interface
// and I want to see what breaks.
class WPAPass: public llvm::ModulePass {
typedef std::vector<PointerAnalysis*> PTAVector;

public:
Expand All @@ -59,8 +62,11 @@ class WPAPass: public llvm::ModulePass, public llvm::AliasAnalysis {
Precise ///< return alias result by the most precise pta
};

/// Constructor
WPAPass() : llvm::ModulePass(ID), llvm::AliasAnalysis() {}
/// Constructor needs TargetLibraryInfo to be passed to the AliasAnalysis
WPAPass() : llvm::ModulePass(ID) {

}

/// Destructor
~WPAPass();

Expand Down Expand Up @@ -88,7 +94,7 @@ class WPAPass: public llvm::ModulePass, public llvm::AliasAnalysis {
virtual bool runOnModule(llvm::Module& module);

/// PTA name
virtual inline const char* getPassName() const {
virtual inline llvm::StringRef getPassName() const {
return "WPAPass";
}

Expand Down
10 changes: 5 additions & 5 deletions include/WPA/WPASolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright (C) <2013-2016> <Jingling Xue>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// it under the terms of the GNU Gg12eneral Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

Expand Down Expand Up @@ -43,7 +43,7 @@ class WPASolver {
public:
///Define the GTraits and node iterator for printing
typedef llvm::GraphTraits<GraphType> GTraits;
typedef typename GTraits::NodeType GNODE;
typedef typename GTraits::NodeRef GNODE;
typedef typename GTraits::EdgeType GEDGE;
typedef typename GTraits::ChildIteratorType child_iterator;

Expand Down Expand Up @@ -122,8 +122,8 @@ class WPASolver {

/// Propagation for the solving, to be implemented in the child class
virtual void propagate(GNODE* v) {
child_iterator EI = GTraits::direct_child_begin(v);
child_iterator EE = GTraits::direct_child_end(v);
child_iterator EI = GTraits::direct_child_begin(*v);
child_iterator EE = GTraits::direct_child_end(*v);
for (; EI != EE; ++EI) {
if (propFromSrcToDst(*(EI.getCurrent())))
pushIntoWorklist(Node_Index(*EI));
Expand Down Expand Up @@ -162,7 +162,7 @@ class WPASolver {
}

/// Get node ID
inline NodeID Node_Index(GNODE* node) {
inline NodeID Node_Index(GNODE node) {
return GTraits::getNodeID(node);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ set(SOURCES
add_llvm_loadable_module(Svf ${SOURCES})
add_llvm_Library(LLVMSvf ${SOURCES})

# It seems that the Svf library needs to explictly require the CUDD alloc/init/etc so LLVMCudd
link_directories( ${CMAKE_BINARY_DIR}/lib/Cudd )

llvm_map_components_to_libnames(llvm_libs bitwriter core ipo irreader instcombine instrumentation target linker analysis scalaropts support )
target_link_libraries(LLVMSvf ${llvm_libs})
target_link_libraries(Svf LLVMCudd ${llvm_libs})

if(DEFINED IN_SOURCE_BUILD)
add_dependencies(Svf intrinsics_gen)
Expand Down
10 changes: 5 additions & 5 deletions lib/MemoryModel/LocMemModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool LocSymTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) {
if (index <= baseIndex) {
/// variant offset
// Handling pointer types
if (const PointerType* pty = dyn_cast<PointerType>(*gi)) {
if (const PointerType* pty = dyn_cast<PointerType>(gi.getIndexedType())) {
const Type* et = pty->getElementType();
Size_t sz = getTypeSizeInBytes(et);

Expand All @@ -73,7 +73,7 @@ bool LocSymTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) {
ls.addElemNumStridePair(std::make_pair(num, sz));
}
// Calculate the size of the array element
else if(const ArrayType* at = dyn_cast<ArrayType>(*gi)) {
else if(const ArrayType* at = dyn_cast<ArrayType>(gi.getIndexedType())) {
const Type* et = at->getElementType();
Size_t sz = getTypeSizeInBytes(et);
Size_t num = at->getNumElements();
Expand All @@ -94,19 +94,19 @@ bool LocSymTableInfo::computeGepOffset(const llvm::User *V, LocationSet& ls) {
// Handling pointer types
// These GEP instructions are simply making address computations from the base pointer address
// e.g. idx1 = (char*) &MyVar + 4, at this case gep only one offset index (idx)
if (const PointerType* pty = dyn_cast<PointerType>(*gi)) {
if (const PointerType* pty = dyn_cast<PointerType>(gi.getIndexedType())) {
const Type* et = pty->getElementType();
Size_t sz = getTypeSizeInBytes(et);
ls.offset += idx * sz;
}
// Calculate the size of the array element
else if(const ArrayType* at = dyn_cast<ArrayType>(*gi)) {
else if(const ArrayType* at = dyn_cast<ArrayType>(gi.getIndexedType())) {
const Type* et = at->getElementType();
Size_t sz = getTypeSizeInBytes(et);
ls.offset += idx * sz;
}
// Handling struct here
else if (const StructType *ST = dyn_cast<StructType>(*gi)) {
else if (const StructType *ST = gi.getStructTypeOrNull() ) {
assert(op && "non-const struct index in GEP");
const vector<u32_t> &so = SymbolTableInfo::Symbolnfo()->getStructOffsetVec(ST);
if ((unsigned)idx >= so.size()) {
Expand Down
Loading

0 comments on commit ee5aead

Please sign in to comment.