Skip to content

Commit

Permalink
feat(spec): Spec IR generation
Browse files Browse the repository at this point in the history
gen specs if option set


Update SpecLang creation build script


Add link and make to specLang


Add node linking to spec generation


SpecLang add Accessed type setter


insert types accessed by node


Add more attributes to specLang


Add new attributes to spec generation


Init spec module only once


Remove alloca from spec language
  • Loading branch information
Anton Vassilev authored and agurfinkel committed Aug 31, 2020
1 parent 8b97d87 commit 24d8ad3
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 20 deletions.
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,15 @@ install(DIRECTORY include/seadsa DESTINATION include
if (TOP_LEVEL)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md DESTINATION .)
endif()

if(CMAKE_C_COMPILER_ID STREQUAL Clang)

add_library(SpecLang OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/lib/seadsa/SpecLang.cc)
target_compile_options(SpecLang BEFORE PRIVATE -S -emit-llvm)
install(FILES $<TARGET_OBJECTS:SpecLang>
DESTINATION lib
RENAME sea_dsa.ll)

else()
message (WARNING "Unable to build spec language \n\t Set C compiler to clang with -DCMAKE_C_COMPILER")
endif()
13 changes: 13 additions & 0 deletions include/seadsa/DsaLibFuncInfo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,20 @@ class AllocWrapInfo;

class DsaLibFuncInfo : public llvm::ImmutablePass {
using ModuleRef = std::unique_ptr<llvm::Module>;
using GraphRef = std::shared_ptr<Graph>;

private:
void initSpecModule() const;

protected:
mutable bool m_isInitialized = false;
mutable bool m_genSpecOpt = false;
mutable llvm::StringMap<llvm::Function *> m_funcs;
mutable std::vector<ModuleRef> m_modules;
// m_specModule uses defs from m_specLang so it must be deallocated after
// m_specModule
mutable ModuleRef m_specLang;
mutable ModuleRef m_specModule;

public:
static char ID;
Expand All @@ -44,8 +53,12 @@ public:
void getAnalysisUsage(llvm::AnalysisUsage &AU) const override;
llvm::StringRef getPassName() const override { return "SeaDsa Spec Pass"; }

bool genSpecs() const { return m_genSpecOpt; }

bool hasSpecFunc(const llvm::Function &F) const;
llvm::Function *getSpecFunc(const llvm::Function &F) const;
void generateSpec(const llvm::Function &F, const GraphRef G) const;
void writeSpecModule() const;
};

llvm::Pass *createDsaLibFuncInfoPass();
Expand Down
15 changes: 13 additions & 2 deletions include/seadsa/sea_dsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ extern void sea_dsa_set_ptrtoint(const void *p);
extern void sea_dsa_set_inttoptr(const void *p);
// sea-dsa will mark the node pointed to by p as heap memory (H)
extern void sea_dsa_set_heap(const void *p);
// sea-dsa will mark the node pointed to by p as stack memory (S)
extern void sea_dsa_set_alloca(const void *p);
// sea-dsa will mark the node pointed to by p as external (E)
extern void sea_dsa_set_external(const void *p);
// sea-dsa will collapse the argument's cell
extern void sea_dsa_collapse(const void *p);
// sea-dsa will return a fresh memory object
extern void *sea_dsa_new() __attribute__((malloc));
// like sea_dsa_new except used for creating a node representation of an
// existing memory object
extern void *sea_dsa_mk();
// links one cell to another cell. Can be manually extended with
// sea_dsa_link_<type>(void *p, unsigned offset, <type>> *p2) in order to
// describe what type it is linking to
extern void sea_dsa_link(const void *p, unsigned offset, const void *p2);
// access type of p. Can manually extend with
// sea_dsa_access_<type>(<type> *p, unsigned offset) in order to describe the
// type p accesses at an offset
extern void sea_dsa_access(const void *p, unsigned offset);
// sea-dsa will mark the node pointed by p as a sequence node of size sz
// The noded pointed by p cannot be already a sequence node and its
// size must be less or equal than sz.
Expand Down
2 changes: 1 addition & 1 deletion lib/seadsa/DsaAnalysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ bool DsaAnalysis::runOnModule(Module &M) {
m_tliWrapper = &getAnalysis<TargetLibraryInfoWrapperPass>();
m_allocInfo = &getAnalysis<AllocWrapInfo>();
m_dsaLibFuncInfo = &getAnalysis<DsaLibFuncInfo>();
m_dsaLibFuncInfo->initialize(M);
m_allocInfo->initialize(M, this);
m_dsaLibFuncInfo->initialize(M);
auto &cg = getAnalysis<CallGraphWrapperPass>().getCallGraph();

switch (DsaGlobalAnalysis) {
Expand Down
14 changes: 11 additions & 3 deletions lib/seadsa/DsaBottomUp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ void BottomUpAnalysis::cloneAndResolveArguments(
nc.unify(c);
}

auto range = llvm::make_filter_range(callee.args(), [](auto &arg) { return arg.getType()->isPointerTy(); });
auto range = llvm::make_filter_range(
callee.args(), [](auto &arg) { return arg.getType()->isPointerTy(); });

DsaCallSite::const_actual_iterator AI = CS.actual_begin(),
AE = CS.actual_end();
for (auto FI = range.begin(), FE = range.end();
FI != FE && AI != AE; ++FI, ++AI) {
for (auto FI = range.begin(), FE = range.end(); FI != FE && AI != AE;
++FI, ++AI) {
const Value *arg = (*AI).get();
const Value *fml = &*FI;
if (calleeG.hasCell(*fml)) {
Expand Down Expand Up @@ -203,6 +204,13 @@ bool BottomUpAnalysis::runOnModule(Module &M, GraphMap &graphs) {
if (fGraph) fGraph->compress();
}

if (m_dsaLibFuncInfo.genSpecs()) {
for (auto &KVP : graphs) {
m_dsaLibFuncInfo.generateSpec(*KVP.first, KVP.second);
}
m_dsaLibFuncInfo.writeSpecModule();
}

LOG(
"dsa-bu-graph", for (auto &kv
: graphs) {
Expand Down
6 changes: 3 additions & 3 deletions lib/seadsa/DsaGlobal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ bool ContextSensitiveGlobalPass::runOnModule(Module &M) {
auto &tli = getAnalysis<TargetLibraryInfoWrapperPass>();
auto &allocInfo = getAnalysis<AllocWrapInfo>();
auto &dsaLibFuncInfo = getAnalysis<DsaLibFuncInfo>();
dsaLibFuncInfo.initialize(M);
allocInfo.initialize(M, this);
dsaLibFuncInfo.initialize(M);
CallGraph *cg = nullptr;
if (UseDsaCallGraph) {
cg = &getAnalysis<CompleteCallGraph>().getCompleteCallGraph();
Expand Down Expand Up @@ -818,8 +818,8 @@ bool BottomUpTopDownGlobalPass::runOnModule(Module &M) {
auto &tli = getAnalysis<TargetLibraryInfoWrapperPass>();
auto &allocInfo = getAnalysis<AllocWrapInfo>();
auto &dsaLibFuncInfo = getAnalysis<DsaLibFuncInfo>();
dsaLibFuncInfo.initialize(M);
allocInfo.initialize(M, this);
dsaLibFuncInfo.initialize(M);
CallGraph *cg = nullptr;
if (UseDsaCallGraph) {
cg = &getAnalysis<CompleteCallGraph>().getCompleteCallGraph();
Expand Down Expand Up @@ -853,8 +853,8 @@ bool BottomUpGlobalPass::runOnModule(Module &M) {
auto &tli = getAnalysis<TargetLibraryInfoWrapperPass>();
auto &allocInfo = getAnalysis<AllocWrapInfo>();
auto &dsaLibFuncInfo = getAnalysis<DsaLibFuncInfo>();
dsaLibFuncInfo.initialize(M);
allocInfo.initialize(M, this);
dsaLibFuncInfo.initialize(M);
CallGraph *cg = nullptr;
if (UseDsaCallGraph) {
cg = &getAnalysis<CompleteCallGraph>().getCompleteCallGraph();
Expand Down
Loading

0 comments on commit 24d8ad3

Please sign in to comment.