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

Merge branch 'irdbUtil_addProv_perf_improvement'

Former-commit-id: 363700bf0029a21dd77cab4d870dc2b47eda791e
parents 8ea2b720 91ce2516
Branches
Tags
No related merge requests found
...@@ -6,41 +6,34 @@ ...@@ -6,41 +6,34 @@
class IBTProvenance_t class IBTProvenance_t
{ {
private: private:
typedef std::map<const Instruction_t*, Provenance_t> ProvMap_t;
// types
using InsnProvMap_t = std::map<const Instruction_t*, Provenance_t>;
using ICFSProvMap_t = std::map<const ICFS_t*, Provenance_t>;
// data
InsnProvMap_t prov_map;
static Provenance_t empty;
// methods
void Init() {};
void AddProvs(const Provenance_t& p, const InstructionSet_t& after) ;
public: public:
IBTProvenance_t(const FileIR_t* f=NULL) {Init(); if(f) AddFile(f);} IBTProvenance_t(const FileIR_t* f=NULL) {Init(); if(f) AddFile(f);}
virtual ~IBTProvenance_t() {;} virtual ~IBTProvenance_t() {} // default destructor not OK for some reason?
virtual void AddFile(const FileIR_t* ); void AddFile(const FileIR_t* );
/*Provenance_t getProvenance(const Instruction_t* insn) const
{
return ((ProvMap_t) prov_map)[insn];
}*/
Provenance_t& operator[] (const Instruction_t* i)
{
return prov_map[i];
}
const Provenance_t& operator[] (const Instruction_t* i) const const Provenance_t& operator[] (const Instruction_t* i) const
{ {
ProvMap_t::const_iterator it=prov_map.find(i); const auto it=prov_map.find(i);
if (it!= prov_map.end()) if (it!= prov_map.end())
return it->second; return it->second;
static Provenance_t empty;
return empty; return empty;
} }
protected:
virtual void Init() {};
private:
virtual void AddProvs(const Instruction_t* before, const InstructionSet_t& after);
ProvMap_t prov_map;
}; };
#endif #endif
......
...@@ -28,10 +28,16 @@ class Provenance_t ...@@ -28,10 +28,16 @@ class Provenance_t
prov.set((size_t) ProvType::IndCall); prov.set((size_t) ProvType::IndCall);
} }
void addProv(const Provenance_t& other)
{
prov |= other.prov;
}
bool hasReturn() const bool hasReturn() const
{ {
return prov.test((size_t) ProvType::Ret); return prov.test((size_t) ProvType::Ret);
} }
bool hasIndirectJump() const bool hasIndirectJump() const
{ {
......
...@@ -8,47 +8,57 @@ using namespace libIRDB; ...@@ -8,47 +8,57 @@ using namespace libIRDB;
using namespace std; using namespace std;
Provenance_t IBTProvenance_t::empty;
void IBTProvenance_t::AddProvs(const Instruction_t* before, const InstructionSet_t& afterset)
void IBTProvenance_t::AddFile(const FileIR_t* firp)
{ {
// Determine type of IB
const auto IndBranchAsm=DecodedInstruction_t(before); using ICFSProvMap_t = std::map<const ICFS_t*, Provenance_t>;
bool isIndJmp = IndBranchAsm.isUnconditionalBranch() && !IndBranchAsm.getOperand(0).isConstant(); auto icfs_prov_map = ICFSProvMap_t();
bool isIndCall = IndBranchAsm.isCall() && !IndBranchAsm.getOperand(0).isConstant();
bool isRet = IndBranchAsm.isReturn(); // collect before info for each icfs into icfs_prov_map
for(auto insn : firp->GetInstructions())
// Set the provenance info of targets depending on the type of IB
for(auto insn : afterset)
{ {
const auto &ibTargets=insn->GetIBTargets();
if(!ibTargets)
continue;
auto this_prov=Provenance_t();
const auto IndBranchAsm=DecodedInstruction_t(insn);
const auto isIndJmp = IndBranchAsm.isUnconditionalBranch() && !IndBranchAsm.getOperand(0).isConstant();
const auto isIndCall = IndBranchAsm.isCall() && !IndBranchAsm.getOperand(0).isConstant();
const auto isRet = IndBranchAsm.isReturn();
if(isIndJmp) if(isIndJmp)
{ {
prov_map[insn].addIndirectJump(); this_prov.addIndirectJump();
} }
else if(isIndCall) else if(isIndCall)
{ {
prov_map[insn].addIndirectCall(); this_prov.addIndirectCall();
} }
else if(isRet) else if(isRet)
{ {
prov_map[insn].addReturn(); this_prov.addReturn();
} }
else else
{ {
assert(0); assert(0);
} }
icfs_prov_map[ibTargets].addProv(this_prov);
} }
}
void IBTProvenance_t::AddFile(const FileIR_t* firp2) // deploy info for each target of the icfs
{ for(const auto &icfs : firp->GetAllICFS())
FileIR_t* firp=(FileIR_t*)firp2; // discarding const qualifier because we know we won't change the set
firp->AssembleRegistry(); // Takes time but I'm paranoid
for(auto insn : firp->GetInstructions())
{ {
// If insn is an IB, add the type of IB to the targets' provenance info assert(icfs);
if(insn->GetIBTargets()) for(const auto &insn : *icfs)
AddProvs(insn, *insn->GetIBTargets()); {
prov_map[insn].addProv(icfs_prov_map[icfs]);
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment