Skip to content
Snippets Groups Projects
Commit afd40e56 authored by Anh Nguyen-Tuong's avatar Anh Nguyen-Tuong
Browse files

Add critical edge analysis

Former-commit-id: 93a398f4a294995005eb6dd416326e475d1436d3
parent eade5776
No related branches found
No related tags found
No related merge requests found
......@@ -19,9 +19,6 @@
*/
typedef std::set<BasicBlock_t*> BasicBlockSet_t;
class ControlFlowGraph_t
{
public:
......
/*
* Copyright (c) 2019 - Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
*/
typedef std::set<BasicBlock_t*> BasicBlockSet_t;
typedef std::tuple<BasicBlock_t*, BasicBlock_t*> BasicBlockEdge_t;
typedef std::set<BasicBlockEdge_t> BasicBlockEdgeSet_t;
class CriticalEdgeAnalyzer_t
{
public:
CriticalEdgeAnalyzer_t(const ControlFlowGraph_t &p_cfg);
BasicBlockEdgeSet_t GetAllCriticalEdges() const;
private:
ControlFlowGraph_t m_cfg;
};
......@@ -37,6 +37,7 @@ namespace libIRDB
#include <cfg/CFG.hpp>
#include <cfg/callgraph.hpp>
#include <cfg/domgraph.hpp>
#include <cfg/criticaledge.hpp>
};
......
......@@ -8,7 +8,7 @@ myenv.Replace(SECURITY_TRANSFORMS_HOME=os.environ['SECURITY_TRANSFORMS_HOME'])
libname="IRDB-cfg"
files= '''
BasicBlock.cpp callgraph.cpp CFG.cpp domgraph.cpp
BasicBlock.cpp callgraph.cpp CFG.cpp domgraph.cpp criticaledge.cpp
'''
cpppath='''
$SECURITY_TRANSFORMS_HOME/include/
......
/*
* Copyright (c) 2019 - Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
*/
#include <libIRDB-cfg.hpp>
#include <utils.hpp>
using namespace std;
using namespace libIRDB;
CriticalEdgeAnalyzer_t::CriticalEdgeAnalyzer_t(ControlFlowGraph_t* p_cfg) :
m_cfg(p_cfg)
{
assert(m_cfg);
}
/*
* Critical edge between two nodes is where the source node has multiple successsors,
* and the target node has multiple predecessors
*/
BasicBlockEdgeSet_t CriticalEdgeAnalyzer_t::GetAllCriticalEdges()
{
BasicBlockEdgeSet_t criticals;
for (const auto &src : m_cfg->GetBlocks())
{
for (const auto &tgt : src->GetSuccessors())
{
if (src->GetSuccessors().size() > 1 && tgt->GetPredecessors().size() > 1)
{
BasicBlockEdge_t e(src, tgt);
criticals.insert(e);
}
}
}
return criticals;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment