Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 4 #18

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
54415ad
Starting to move this into 4.0; likely with some errors, but it looks…
jcarlson23 Mar 28, 2017
73f69af
A few compilation fixes, the dataflow looks reasonable while the anal…
jcarlson23 Mar 28, 2017
ea5c7d4
I think I almost have the specializations right for the PTACallgraph
jcarlson23 Apr 3, 2017
9abbd56
Ok, fixed the PTACallGraph graph trait issue - at least for compilation
jcarlson23 Apr 3, 2017
fdab9cd
Fixed the SVFG Noderef issue, but looks like I need to clear the X** …
jcarlson23 Apr 4, 2017
ef3bb89
Had to clean up where I was, should be moving forward again, needs cl…
jcarlson23 Apr 4, 2017
b62082f
Have an iterator conflict but if I can get past that looks like I'm m…
jcarlson23 Apr 4, 2017
cab36c2
Fixed that iterator mismatch by changing the GNODE type in WPASolver.h
jcarlson23 Apr 5, 2017
af491dc
Fixed const char to StringRef in the getPassName() of BreakConstantExpr
jcarlson23 Apr 5, 2017
5fbd66b
A number of small fixes, mostly replacing const char* with llvm::Stri…
jcarlson23 Apr 5, 2017
de31c27
Couple trivial fixes, more StringRef and a ref to pointer
jcarlson23 Apr 6, 2017
7b7e39d
Starting to compile actual products but linkage errors likely indicat…
jcarlson23 Apr 6, 2017
837d2d2
1% more to go...
jcarlson23 Apr 13, 2017
099e767
Ok, down to one little header issue and then write it up and pass it …
Apr 15, 2017
e5c9dd3
Fixed that header issue, looks like the next few are pretty simple
Apr 17, 2017
37111d4
Fixed the wpa and saber tools - just needed a few args changed and us…
jcarlson23 Apr 17, 2017
29ae917
Ready to issue a PR, one issue for others to decide I think but the r…
jcarlson23 Apr 18, 2017
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
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 @@ -678,6 +678,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this snuck in!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow, sorry, I can update that if need be.. obviously just a typo... :(

// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The newly added part causes an error when linking "Svf.so" in my ubuntu machine (completely ok on mac), see below:

/usr/bin/ld: CUDD/libLLVMCudd.a(cuddInit.c.o): relocation R_X86_64_32S against `Cudd_OutOfMem' can not be used when making a shared object; recompile with -fPIC
CUDD/libLLVMCudd.a: error adding symbols: Bad value

If I delete those five lines, it will be all good on ubuntu, but causing a linking error on mac os ;(

If possible, could you please take a look at it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this ought to be straightforward I think. I just moved computers but let me create a VM to test in and put in a architecture check and I think this can be resolved... (I'll try to update tonight).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I have a fix but have been in VM purgatory today so but basically just used CMAKE_SYSTEM_NAME and a little if-else.. so just will test again, today got away from me but this is the easy part...

Copy link
Author

@jcarlson23 jcarlson23 May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, this built for me on Ubuntu16.04 LT with the following changes:

Diff for CMakeLists.txt

I can reissue the pull request if that's easier but this is trivial so I'm going to focus on the iterator issue below.

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