Skip to content
Snippets Groups Projects
Commit 3f3a8b4d authored by Jason Hiser's avatar Jason Hiser :tractor:
Browse files

First using of loops in zafl

parent 3a7f96b5
No related branches found
No related tags found
No related merge requests found
Pipeline #4007 failed
...@@ -7,6 +7,7 @@ myenv=env ...@@ -7,6 +7,7 @@ myenv=env
libname="irdb-deep" libname="irdb-deep"
files= ''' files= '''
deep.cpp deep.cpp
loops.cpp
''' '''
cpppath=''' cpppath='''
$IRDB_SDK/include/ $IRDB_SDK/include/
......
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
#include <set> #include <set>
#include <memory> #include <memory>
#include <deep.hpp> #include <deep.hpp>
#include <loops.hpp>
#include <MEDS_DeadRegAnnotation.hpp> #include <MEDS_DeadRegAnnotation.hpp>
#include <MEDS_MemoryRangeAnnotation.hpp> #include <MEDS_MemoryRangeAnnotation.hpp>
#include <MEDS_SafeFuncAnnotation.hpp> #include <MEDS_SafeFuncAnnotation.hpp>
#include <MEDS_LoopAnnotation.hpp>
using namespace libIRDB; using namespace libIRDB;
...@@ -40,7 +42,7 @@ unique_ptr<IRDB_SDK::FunctionSet_t> StarsDeepAnalysis_t::getLeafFunctions() ...@@ -40,7 +42,7 @@ unique_ptr<IRDB_SDK::FunctionSet_t> StarsDeepAnalysis_t::getLeafFunctions()
/* for each annotation for this instruction */ /* for each annotation for this instruction */
for (auto it = the_range.first; it != the_range.second; ++it) for (auto it = the_range.first; it != the_range.second; ++it)
{ {
auto p_annotation=dynamic_cast<MEDS_SafeFuncAnnotation*>(it->second); const auto p_annotation=dynamic_cast<MEDS_SafeFuncAnnotation*>(it->second);
if(p_annotation==nullptr) if(p_annotation==nullptr)
continue; continue;
...@@ -142,22 +144,44 @@ unique_ptr<IRDB_SDK::RangeSentinelSet_t> StarsDeepAnalysis_t::getRangeSentinels( ...@@ -142,22 +144,44 @@ unique_ptr<IRDB_SDK::RangeSentinelSet_t> StarsDeepAnalysis_t::getRangeSentinels(
return ret; return ret;
} }
unique_ptr<IRDB_SDK::LoopNest_t> StarsDeepAnalysis_t::getLoopNest(const IRDB_SDK::Function_t* f) const unique_ptr<IRDB_SDK::LoopNest_t> StarsDeepAnalysis_t::getLoops(IRDB_SDK::Function_t* f) const
{ {
auto ret = unique_ptr<IRDB_SDK::LoopNest_t>(); auto cfg = IRDB_SDK::ControlFlowGraph_t::factory(f);
auto ret = getLoops(cfg.get());
auto real_nest = dynamic_cast<libIRDB::LoopNest_t*>(ret.get());
real_nest->saveCFG(move(cfg));
return ret; return ret;
} }
unique_ptr<IRDB_SDK::LoopNest_t> StarsDeepAnalysis_t::getLoopNest(const IRDB_SDK::ControlFlowGraph_t* cfg) const unique_ptr<IRDB_SDK::LoopNest_t> StarsDeepAnalysis_t::getLoops(IRDB_SDK::ControlFlowGraph_t* cfg) const
{ {
auto ret = unique_ptr<IRDB_SDK::LoopNest_t>(); auto func = cfg->getFunction();
return ret; auto id_to_block_map = map<IRDB_SDK::DatabaseID_t, IRDB_SDK::BasicBlock_t*>();
} for(auto blk : cfg->getBlocks())
id_to_block_map[blk->getInstructions()[0]->getBaseID()]=blk;
auto meds_ap=stars_analysis_engine.getAnnotations();
const auto the_range = meds_ap.getAnnotations().equal_range(func->getBaseID());
auto ret = unique_ptr<IRDB_SDK::LoopNest_t>(new LoopNest_t(cfg));
for (auto it = the_range.first; it != the_range.second; ++it)
{
auto p_annotation=dynamic_cast<MEDS_LoopAnnotation*>(it->second);
if(p_annotation==nullptr) continue;
if(!p_annotation->isValid()) continue;
const auto header_id = p_annotation -> getHeaderID();
const auto loop_id = p_annotation -> getLoopID();
auto the_loop = unique_ptr<Loop_t>(new Loop_t(id_to_block_map[header_id]));
dynamic_cast<libIRDB::LoopNest_t*>(ret.get())->addLoop(loop_id,move(the_loop));
}
return move(ret);
}
unique_ptr<IRDB_SDK::DeepAnalysis_t> IRDB_SDK::DeepAnalysis_t::factory(FileIR_t* firp, const AnalysisEngine_t& ae, const vector<string>& options) unique_ptr<IRDB_SDK::DeepAnalysis_t> IRDB_SDK::DeepAnalysis_t::factory(FileIR_t* firp, const AnalysisEngine_t& ae, const vector<string>& options)
{ {
auto ret=unique_ptr<IRDB_SDK::DeepAnalysis_t>(); auto ret=unique_ptr<IRDB_SDK::DeepAnalysis_t>();
switch(ae) switch(ae)
......
...@@ -27,8 +27,8 @@ namespace libIRDB ...@@ -27,8 +27,8 @@ namespace libIRDB
virtual unique_ptr<IRDB_SDK::StaticGlobalStartMap_t> getStaticGlobalRanges() const override; virtual unique_ptr<IRDB_SDK::StaticGlobalStartMap_t> getStaticGlobalRanges() const override;
virtual unique_ptr<IRDB_SDK::RangeSentinelSet_t > getRangeSentinels() const override; virtual unique_ptr<IRDB_SDK::RangeSentinelSet_t > getRangeSentinels() const override;
virtual unique_ptr<IRDB_SDK::LoopNest_t> getLoopNest(const IRDB_SDK::Function_t* f) const override; virtual unique_ptr<IRDB_SDK::LoopNest_t> getLoops(IRDB_SDK::Function_t* f) const override;
virtual unique_ptr<IRDB_SDK::LoopNest_t> getLoopNest(const IRDB_SDK::ControlFlowGraph_t* cfg) const override; virtual unique_ptr<IRDB_SDK::LoopNest_t> getLoops(IRDB_SDK::ControlFlowGraph_t* cfg) const override;
private: private:
......
#include <loops.hpp>
using namespace libIRDB;
using namespace std;
IRDB_SDK::LoopSet_t LoopNest_t::getAllLoops() const
{
auto ret=IRDB_SDK::LoopSet_t();
for(const auto &p : loops)
{
ret.insert(p.second.get());
}
return ret;
}
/*
Copyright 2018-2019 Zephyr Software, LLC.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <irdb-core>
#include <irdb-cfg>
#include <irdb-deep>
#include <set>
#include <map>
namespace libIRDB
{
using namespace std;
class Loop_t : public IRDB_SDK::Loop_t
{
public:
Loop_t() = delete;
Loop_t(IRDB_SDK::BasicBlock_t* header_blk)
:
preheader(nullptr)
{
header = header_blk;
assert(header != nullptr);
}
Loop_t(const Loop_t& copy) = delete;
virtual ~Loop_t() {}
virtual IRDB_SDK::BasicBlock_t* getPreheader() const override { assert(0); }
virtual IRDB_SDK::BasicBlock_t* getHeader() const override { return header; }
virtual IRDB_SDK::BasicBlockSet_t getAllBlocks() const override { assert(0); }
virtual IRDB_SDK::BasicBlockSet_t getOuterBlocks() const override { assert(0); }
virtual IRDB_SDK::LoopSet_t getInnerLoops() const override { assert(0); }
virtual bool isBlockInLoop (const IRDB_SDK::BasicBlock_t* blk) const override { assert(0); }
virtual bool isBlockInInnerLoop (const IRDB_SDK::BasicBlock_t* blk) const override { assert(0); }
virtual bool isBlockOuterLoopOnly(const IRDB_SDK::BasicBlock_t* blk) const override { assert(0); }
private:
IRDB_SDK::BasicBlock_t* preheader;
IRDB_SDK::BasicBlock_t* header;
IRDB_SDK::BasicBlockSet_t blocks;
IRDB_SDK::LoopSet_t inner_loops;
};
class LoopNest_t : public IRDB_SDK::LoopNest_t
{
public:
LoopNest_t(IRDB_SDK::ControlFlowGraph_t* p_cfg)
:
cfg(p_cfg)
{}
LoopNest_t(const LoopNest_t& copy) = delete;
virtual ~LoopNest_t() {}
virtual IRDB_SDK::LoopSet_t getAllLoops() const override ;
virtual IRDB_SDK::LoopSet_t getOuterLoops() const override { assert(0); }
virtual IRDB_SDK::Function_t* getFunction() const override { return cfg->getFunction(); }
virtual IRDB_SDK::ControlFlowGraph_t* getCFG() const override { return cfg; };
void addLoop(const uint64_t loop_id, unique_ptr<IRDB_SDK::Loop_t> loop_ptr) { loops[loop_id]=move(loop_ptr); }
void saveCFG(unique_ptr<IRDB_SDK::ControlFlowGraph_t> cfg_ptr ) { saved_cfg = move(cfg_ptr); }
private:
unique_ptr<IRDB_SDK::ControlFlowGraph_t> saved_cfg;
IRDB_SDK::ControlFlowGraph_t* cfg;
map<uint64_t,unique_ptr<IRDB_SDK::Loop_t> > loops;
};
}
...@@ -50,6 +50,13 @@ class MEDS_LoopAnnotation : public MEDS_AnnotationBase ...@@ -50,6 +50,13 @@ class MEDS_LoopAnnotation : public MEDS_AnnotationBase
virtual const string toString() const { return "loop annot "; } virtual const string toString() const { return "loop annot "; }
uint64_t getHeaderID() const { return header; }
uint64_t getPreheaderID() const { return preheader; }
uint64_t getLoopID() const { return loop_no; }
const set<uint64_t>& getBlockIDs() const { return all_blocks; }
const set<uint64_t>& getInnerLoopIDs() const { return sub_loops; }
private: private:
void init(); void init();
void parse(); void parse();
...@@ -57,9 +64,9 @@ class MEDS_LoopAnnotation : public MEDS_AnnotationBase ...@@ -57,9 +64,9 @@ class MEDS_LoopAnnotation : public MEDS_AnnotationBase
string m_rawInputLine; string m_rawInputLine;
uint64_t loop_no; uint64_t loop_no;
IRDB_SDK::VirtualOffset_t preheader; uint64_t preheader;
IRDB_SDK::VirtualOffset_t header; uint64_t header;
set<IRDB_SDK::VirtualOffset_t> all_blocks; set<uint64_t> all_blocks;
set<uint64_t> sub_loops; set<uint64_t> sub_loops;
}; };
......
...@@ -125,7 +125,7 @@ void MEDS_LoopAnnotation::parse() ...@@ -125,7 +125,7 @@ void MEDS_LoopAnnotation::parse()
preheader = readInt<decltype(preheader)>(m_rawInputLine, " PREHEADER ", true); preheader = readInt<decltype(preheader)>(m_rawInputLine, " PREHEADER ", true);
all_blocks = readAddrSet<IRDB_SDK::VirtualOffset_t>(m_rawInputLine, " BLOCKLIST ", true); all_blocks = readAddrSet<IRDB_SDK::VirtualOffset_t>(m_rawInputLine, " BLOCKLIST ", true);
sub_loops = readAddrSet<uint64_t >(m_rawInputLine, " BLOCKLIST ", false); sub_loops = readAddrSet<uint64_t >(m_rawInputLine, " INNERLOOPS ", false);
setValid(); // no additional info recorded for right now. setValid(); // no additional info recorded for right now.
} }
......
Subproject commit 21c2c99f8d6f0a37fadd91b0cc3877df5a4ab735 Subproject commit 3267ac26338c701dffa3267da6c6ca15475b4999
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