Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 65a44447 authored by Valentin Touzeau's avatar Valentin Touzeau Committed by EXT Valentin Touzeau
Browse files

WIP: refactoting code using policies

parent b45b9bf2
......@@ -5,11 +5,7 @@ set(PLUGIN "exactlru") # plugin name
set(NAMESPACE "") # namespace
set(SOURCES "src/exactlru.cpp"
"src/Generator.cpp"
"src/MayAnalysis/MayDomain.cpp"
"src/MayAnalysis/MayGeneratorsSet.cpp"
"src/MayAnalysis/MayAnalysis.cpp"
"src/MustAnalysis/MustDomain.cpp"
"src/MustAnalysis/MustGeneratorsSet.cpp"
"src/MustAnalysis/MustAnalysis.cpp"
"src/ClassificationBuilder.cpp"
"src/ZDD/ZDD.cpp"
......
......@@ -12,11 +12,13 @@ template <typename AbstractValuePolicy>
class GSAbstractValue : public AbstractValuePolicy
{
public:
friend AbstractValuePolicy;
using Block = Generator::Block;
using GeneratorsSet = std::set<Generator, LexicalOrder>;
using PartialOrder = typename AbstractValuePolicy::Comparator;
GeneratorsSet(const GeneratorsSet& g = {}) : _generators(g)
GSAbstractValue(const GeneratorsSet& g = {}) : _generators(g)
{
}
......@@ -28,21 +30,22 @@ public:
Generator newGenerator(g);
newGenerator.update(block);
insert(newGenerator);
}
}
void join(const GeneratorsSet& rhs)
void join(const GSAbstractValue& rhs)
{
for(const auto& g : rhs._generators) {
insert(g);
}
}
inline bool operator==(const GeneratorsSet& rhs) const
inline bool operator==(const GSAbstractValue& rhs) const
{
return _generators == rhs._generators;
}
inline bool operator!=(const GeneratorsSet& rhs) const
inline bool operator!=(const GSAbstractValue& rhs) const
{
return !(*this == rhs);
}
......
#ifndef MAY_GENERATORS_SET_H
#define MAY_GENERATORS_SET_H
#include <set>
#include <exactlru/Generator.h>
namespace exactlru
{
class MayComparator
{
public:
inline bool operator()(const Generator& lhs, const Generator& rhs) const
{
return rhs.contains(lhs);
}
};
class MayGeneratorsSet
{
public:
using Block = Generator::Block;
using GeneratorsSet = std::set<Generator, LexicalOrder>;
using PartialOrder = MayComparator;
MayGeneratorsSet(const GeneratorsSet& g = {});
void update(const Block* block);
void join(const MayGeneratorsSet& rhs);
bool isAlwaysMiss() const;
inline bool operator==(const MayGeneratorsSet& rhs) const
{
return _generators == rhs._generators;
}
inline bool operator!=(const MayGeneratorsSet& rhs) const
{
return !(*this == rhs);
}
private:
void insert(const Generator& generator)
{
// Check if "generator" is subsumed.
for(const auto& g : _generators)
if(_less(g, generator))
return;
// Remove old generators that are subsumed
typename GeneratorsSet::const_iterator it = _generators.begin();
while(it != _generators.end()) {
if(_less(generator, *it))
it = _generators.erase(it);
else
++it;
}
_generators.insert(generator);
}
GeneratorsSet _generators;
PartialOrder _less;
};
} // namespace exactlru
#endif // MAY_GENERATORS_SET_H
#ifndef EXACTLRU_MAY_MUST_TAG_H
#define EXACTLRU_MAY_MUST_TAG_H
struct MayTag {};
struct MustTag {};
#endif // EXACTLRU_MAY_MUST_TAG_H
#ifndef MUST_GENERATORS_SET_H
#define MUST_GENERATORS_SET_H
#include <set>
#include <exactlru/Generator.h>
namespace exactlru
{
class MustComparator
{
public:
inline bool operator()(const Generator& lhs, const Generator& rhs) const
{
return lhs.contains(rhs);
}
};
class MustGeneratorsSet
{
public:
using Block = Generator::Block;
using GeneratorsSet = std::set<Generator, LexicalOrder>;
using PartialOrder = MustComparator;
MustGeneratorsSet(const GeneratorsSet& g = {});
void update(const Block* block);
void join(const MustGeneratorsSet& rhs);
bool isAlwaysHit() const;
inline bool operator==(const MustGeneratorsSet& rhs) const
{
return _generators == rhs._generators;
}
inline bool operator!=(const MustGeneratorsSet& rhs) const
{
return !(*this == rhs);
}
private:
void insert(const Generator& generator)
{
// Check if "generator" is subsumed.
for(const auto& g : _generators)
if(_less(g, generator))
return;
// Remove old generators that are subsumed
typename GeneratorsSet::const_iterator it = _generators.begin();
while(it != _generators.end()) {
if(_less(generator, *it))
it = _generators.erase(it);
else
++it;
}
_generators.insert(generator);
}
GeneratorsSet _generators;
PartialOrder _less;
};
} // namespace exactlru
#endif // MUST_GENERATORS_SET_H
#ifndef MUST_GENERATORS_ZDD_H
#define MUST_GENERATORS_ZDD_H
#include <set>
namespace exactlru
{
class MustGeneratorsZDD
{
public:
using Block = Generator::Block;
MustGeneratorsZDD();
void update(const Block* block);
void join(const MustGeneratorsZDD& rhs);
bool isAlwaysHit() const;
inline bool operator==(const MustGeneratorsZDD& rhs) const
{
return _generators == rhs._generators;
}
inline bool operator!=(const MustGeneratorsZDD& rhs) const
{
return !(*this == rhs);
}
private:
ZDDNode _generators;
};
} // namespace exactlru
#endif // MUST_GENERATORS_ZDD_H
......@@ -4,7 +4,8 @@
#include <otawa/icat3/features.h>
#include <otawa/icache/features.h>
#include "ZDDAbstractValue.h"
#include "ZDD/ZDDAbstractValue.h"
#include <exactlru/GeneratorsSet.h>
namespace exactlru
{
......@@ -24,12 +25,12 @@ public:
const AbstractValue* init) :
DomainPolicy(focus, coll, set, init),
m_focus(focus),
m_bot(AbstractValue::Init::Bot),
m_top(AbstractValue::Init::Top),
m_bot(DomainPolicy::createBot(focus, coll, set)),
m_top(DomainPolicy::createTop(focus, coll, set)),
m_set(set),
m_coll(coll),
m_init(init ? *init : m_top),
m_tmp(AbstractValue::Init::Top)
m_tmp(DomainPolicy::createTop(focus, coll, set))
{
}
......@@ -91,6 +92,19 @@ public:
{
}
AbstractValue createBot(const otawa::icat3::LBlock*,
const otawa::icat3::LBlockCollection&,
int)
{
return AbstractValue(AbstractValue::Init::Bot);
}
AbstractValue createTop(const otawa::icat3::LBlock*,
const otawa::icat3::LBlockCollection&,
int)
{
return AbstractValue(AbstractValue::Init::Top);
}
void fetch(AbstractValue& a, const otawa::icat3::LBlock *lb, int k, const otawa::icat3::LBlock* focus)
{
a.update(m_manager, lb, k, focus);
......@@ -118,6 +132,19 @@ public:
{
}
AbstractValue createBot(const otawa::icat3::LBlock*,
const otawa::icat3::LBlockCollection&,
int)
{
return AbstractValue(AbstractValue::Init::Bot);
}
AbstractValue createTop(const otawa::icat3::LBlock*,
const otawa::icat3::LBlockCollection&,
int)
{
return AbstractValue(AbstractValue::Init::Top);
}
void fetch(AbstractValue& a, const otawa::icat3::LBlock *lb, int k, const otawa::icat3::LBlock* focus)
{
a.update(m_manager, lb, k, focus);
......@@ -131,6 +158,78 @@ private:
ManagerPtr m_manager;
};
class GSMayDomainPolicy
{
public:
using AbstractValue = GSAbstractValue<GSMayAbstractValuePolicy>;
GSMayDomainPolicy(const otawa::icat3::LBlock*,
const otawa::icat3::LBlockCollection&,
int,
const AbstractValue*)
{
}
AbstractValue createBot(const otawa::icat3::LBlock*,
const otawa::icat3::LBlockCollection&,
int)
{
return AbstractValue();
}
AbstractValue createTop(const otawa::icat3::LBlock* focus,
const otawa::icat3::LBlockCollection& coll,
int)
{
return AbstractValue({Generator(focus, coll.A(), false)});
}
void fetch(AbstractValue& a, const otawa::icat3::LBlock *lb, int, const otawa::icat3::LBlock*)
{
a.update(lb);
}
bool isAlwaysMiss(const AbstractValue& a) const
{
return a.isAlwaysMiss();
}
};
class GSMustDomainPolicy
{
public:
using AbstractValue = GSAbstractValue<GSMustAbstractValuePolicy>;
GSMustDomainPolicy(const otawa::icat3::LBlock*,
const otawa::icat3::LBlockCollection&,
int,
const AbstractValue*)
{
}
AbstractValue createBot(const otawa::icat3::LBlock*,
const otawa::icat3::LBlockCollection&,
int)
{
return AbstractValue();
}
AbstractValue createTop(const otawa::icat3::LBlock* focus,
const otawa::icat3::LBlockCollection& coll,
int)
{
return AbstractValue({Generator(focus, coll.A(), true)});
}
void fetch(AbstractValue& a, const otawa::icat3::LBlock *lb, int, const otawa::icat3::LBlock*)
{
a.update(lb);
}
bool isAlwaysHit(const AbstractValue& a) const
{
return a.isAlwaysHit();
}
};
} // namespace exactlru
#endif /* EXACTLRU_ZDD_DOMAIN_H_ */
......
......@@ -29,10 +29,9 @@
#include <otawa/icache/features.h>
#include <otawa/icat3/features.h>
#include <exactlru/features.h>
#include "MayDomain.h"
#include <exactlru/MayAnalysis/MayManager.h>
#include "../ZDD/Domain.h"
#include "../Domain.h"
using namespace otawa;
......@@ -42,8 +41,8 @@ namespace exactlru
class MayAdapter
{
public:
typedef Domain<ZDDMayDomainPolicy> domain_t;
//typedef MayDomain domain_t;
//typedef Domain<ZDDMayDomainPolicy> domain_t;
typedef Domain<GSMayDomainPolicy> domain_t;
typedef typename domain_t::t t;
typedef CompositeCFG graph_t;
typedef ai::ArrayStore<domain_t, graph_t> store_t;
......@@ -105,8 +104,8 @@ private:
class MayAnalysis : public Processor
{
public:
using domain_t = Domain<ZDDMayDomainPolicy>;
//using domain_t = MayDomain;
//using domain_t = Domain<ZDDMayDomainPolicy>;
using domain_t = Domain<GSMayDomainPolicy>;
static p::declare reg;
MayAnalysis(p::declare& r = reg) :
......
#include "MayDomain.h"
#include <exactlru/features.h>
#include <otawa/icat3/features.h>
using namespace otawa;
namespace exactlru
{
MayDomain::MayDomain(const icat3::LBlock* focus,
const icat3::LBlockCollection& coll,
int set,
const t* init) :
m_focus(focus),
m_bot(),
m_top({Generator(focus, coll.A(), false)}),
m_set(set),
m_coll(coll),
m_init(init ? *init : m_top),
m_tmp()
{
}
void MayDomain::join(t& d, const t& s) {
d.join(s);
}
void MayDomain::fetch(t& a, const icat3::LBlock *lb) {
a.update(lb);
}
void MayDomain::update(const icache::Access& access, t& a) {
switch(access.kind()) {
case icache::FETCH:
if(m_coll.cache()->set(access.address()) == m_set)
fetch(a, icat3::LBLOCK(access));
break;
case icache::PREFETCH:
if(m_coll.cache()->set(access.address()) == m_set) {
copy(m_tmp, a);
fetch(a, icat3::LBLOCK(access));
join(a, m_tmp);
}
break;
case icache::NONE:
break;
default:
ASSERT(false);
}
}
bool MayDomain::isAlwaysMiss(const t& a) const
{
return a.isAlwaysMiss();
}
} // namespace exactlru
/*
* ExactMustDomain class interface
* Copyright (c) 2017, IRIT UPS.
*
* This file is part of OTAWA
*
* OTAWA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* OTAWA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OTAWA; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifndef MAY_DOMAIN_H_
#define MAY_DOMAIN_H_
#include <exactlru/MayAnalysis/MayGeneratorsSet.h>
namespace exactlru
{
class MayDomain {
public:
using t = MayGeneratorsSet;
MayDomain(const otawa::icat3::LBlock* focus,
const otawa::icat3::LBlockCollection& coll,
int set,
const t *init);
inline const t& bot(void) const { return m_bot; }
inline const t& top(void) const { return m_top; }
inline const t& init(void) const { return m_init; }
inline void copy(t& d, const t& s) { d = s; }
inline bool equals(const t& a, const t& b) { return a == b; }
void join(t& d, const t& s);
void fetch(t& a, const otawa::icat3::LBlock *lb);
void update(const otawa::icache::Access& access, t& a);
bool isAlwaysMiss(const t& a) const;
private:
const otawa::icat3::LBlock* m_focus;
t m_bot, m_top;
otawa::hard::Cache::set_t m_set;
const otawa::icat3::LBlockCollection& m_coll;
const t& m_init;
t m_tmp;
};
} // namespace exactlru
#endif /* MAY_DOMAIN_H_ */
#include <exactlru/MayAnalysis/MayGeneratorsSet.h>
namespace exactlru
{
MayGeneratorsSet::MayGeneratorsSet(const GeneratorsSet& g) :
_generators(g)
{
}
void MayGeneratorsSet::update(const Block* block)
{
GeneratorsSet old(_generators);
_generators.clear();
for(const auto& g : old) {
Generator newGenerator(g);
newGenerator.update(block);
insert(newGenerator);
}
}
void MayGeneratorsSet::join(const MayGeneratorsSet& rhs)
{
for(const auto& g : rhs._generators) {
insert(g);
}
}
bool MayGeneratorsSet::isAlwaysMiss() const
{
for(const auto& g : _generators) {
if(!g.isFocusedBlockEvicted())
return false;
}
return true;
}
} // namespace exactlru
......@@ -27,10 +27,9 @@
#include <otawa/icache/features.h>
#include <otawa/icat3/features.h>
#include <exactlru/features.h>
#include "MustDomain.h"
#include <exactlru/MustAnalysis/MustManager.h>
#include "../ZDD/Domain.h"
#include "../Domain.h"
using namespace otawa;
......@@ -41,7 +40,7 @@ class MustAdapter
{
public:
//typedef Domain<ZDDMustDomainPolicy> domain_t;
typedef MustDomain domain_t;
typedef Domain<GSMustDomainPolicy> domain_t;
typedef typename domain_t::t t;
typedef CompositeCFG graph_t;
typedef ai::ArrayStore<domain_t, graph_t> store_t;
......@@ -104,7 +103,7 @@ class MustAnalysis : public Processor
{
public:
//using domain_t = Domain<ZDDMustDomainPolicy>;
using domain_t = MustDomain;
using domain_t = Domain<GSMustDomainPolicy>;
static p::declare reg;
MustAnalysis(p::declare& r = reg) :
......