Skip to content

Commit

Permalink
Merge pull request #23 from jcarlson23/llvm-4
Browse files Browse the repository at this point in the history
LLVM 4 Merge
  • Loading branch information
Yulei Sui authored May 7, 2017
2 parents 590b947 + 9ef3981 commit 437b2d5
Show file tree
Hide file tree
Showing 28 changed files with 229 additions and 55 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*
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)

1 change: 1 addition & 0 deletions include/MSSA/SVFG.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,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
127 changes: 127 additions & 0 deletions include/Util/GEPTypeBridgeIterator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// GEPTypeBridgeIterator
//
//
#ifndef SVF_GEPTYPEBRIDGEITERATOR_H
#define SVF_GEPTYPEBRIDGEITERATOR_H

#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/User.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"

namespace llvm {

template<typename ItTy = User::const_op_iterator>
class generic_bridge_gep_type_iterator : public std::iterator<std::forward_iterator_tag, Type *, ptrdiff_t> {

typedef std::iterator<std::forward_iterator_tag,Type *, ptrdiff_t> super;
ItTy OpIt;
PointerIntPair<Type *,1> CurTy;
unsigned AddrSpace;
generic_bridge_gep_type_iterator() {}
public:

static generic_bridge_gep_type_iterator begin(Type *Ty, ItTy It) {
generic_bridge_gep_type_iterator I;
I.CurTy.setPointer(Ty);
I.OpIt = It;
return I;
}

static generic_bridge_gep_type_iterator begin(Type *Ty, unsigned AddrSpace,
ItTy It) {
generic_bridge_gep_type_iterator I;
I.CurTy.setPointer(Ty);
I.CurTy.setInt(true);
I.AddrSpace = AddrSpace;
I.OpIt = It;
return I;
}

static generic_bridge_gep_type_iterator end(ItTy It) {
generic_bridge_gep_type_iterator I;
I.OpIt = It;
return I;
}

bool operator==(const generic_bridge_gep_type_iterator& x) const {
return OpIt == x.OpIt;
}

bool operator!=(const generic_bridge_gep_type_iterator& x) const {
return !operator==(x);
}

Type *operator*() const {
if ( CurTy.getInt() )
return CurTy.getPointer()->getPointerTo(AddrSpace);
return CurTy.getPointer();
}

Type *getIndexedType() const {
if ( CurTy.getInt() )
return CurTy.getPointer();
CompositeType *CT = cast<CompositeType>( CurTy.getPointer() );
return CT->getTypeAtIndex(getOperand());
}

// non-standard operators, these may not need be bridged but seems it's
// predunt to do so...
Type *operator->() const { return operator*(); }

Value *getOperand() const { return const_cast<Value*>(&**OpIt); }


generic_bridge_gep_type_iterator& operator++() {
if ( CurTy.getInt() ) {
CurTy.setInt(false);
} else if ( CompositeType * CT = dyn_cast<CompositeType>(CurTy.getPointer()) ) {
CurTy.setPointer(CT->getTypeAtIndex(getOperand()));
} else {
CurTy.setPointer(nullptr);
}
++OpIt;
return *this;
}


generic_bridge_gep_type_iterator operator++(int) {
generic_bridge_gep_type_iterator tmp = *this; ++*this; return tmp;
}

};


typedef generic_bridge_gep_type_iterator<> bridge_gep_iterator;

inline bridge_gep_iterator bridge_gep_begin(const User* GEP) {
auto *GEPOp = cast<GEPOperator>(GEP);
return bridge_gep_iterator::begin(GEPOp->getSourceElementType(),
cast<PointerType>(GEPOp->getPointerOperandType()->getScalarType())->getAddressSpace(),
GEP->op_begin() + 1);
}

inline bridge_gep_iterator bridge_gep_end(const User* GEP) {
return bridge_gep_iterator::end(GEP->op_end());
}

inline bridge_gep_iterator bridge_gep_begin(const User &GEP) {
auto &GEPOp = cast<GEPOperator>(GEP);
return bridge_gep_iterator::begin( GEPOp.getSourceElementType(),
cast<PointerType>(GEPOp.getPointerOperandType()->getScalarType())->getAddressSpace(),
GEP.op_begin() + 1);
}

inline bridge_gep_iterator bridge_gep_end(const User &GEP) {
return bridge_gep_iterator::end(GEP.op_end());
}

template<typename T>
inline generic_bridge_gep_type_iterator<const T*> bridge_gep_end( Type * /*Op0*/, ArrayRef<T> A ) {
return generic_bridge_gep_type_iterator<const T*>::end(A.end());
}

}

#endif
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
Loading

0 comments on commit 437b2d5

Please sign in to comment.