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/

lrusecurity_Displayer.cpp 3.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <lrupreanalysis/features.h>

#include <elm/sys/Path.h>
#include <elm/sys/System.h>

#include <otawa/proc/BBProcessor.h>
#include <otawa/prog/Process.h>
#include <otawa/icat3/features.h>
#include <otawa/icache/features.h>

using namespace otawa;

namespace lrupreanalysis
{

class ClassificationDisplayer : public BBProcessor
{
public:
	static otawa::p::declare reg;

	ClassificationDisplayer() :
		otawa::BBProcessor(reg),
		_path(""),
		_toFile(false),
		_stream(nullptr),
		_line(false)
	{
	}

	virtual void configure(const PropList& props) override
	{
		otawa::BBProcessor::configure(props);
		if(props.hasProp(CLASSIFICATION_PATH))
			_path = CLASSIFICATION_PATH(props);
		if(props.hasProp(CLASSIFICATION_TO_FILE))
			_toFile = CLASSIFICATION_TO_FILE(props);
	}
protected:

	virtual void setup(WorkSpace *ws) override
	{
		// Check if source is available
		if(ws->isProvided(SOURCE_LINE_FEATURE))
			_line = true;
		if(logFor(LOG_PROC))
			log << "\tsource/line information " << (_line ? "" : "not ") << "available\n";

		if(!_path && _toFile)
			_path = _ << "access_classification.txt";

		if(_path) {
			try {
				_stream = elm::sys::System::createFile(_path);
			}
			catch(elm::sys::SystemException& e) {
				throw ProcessorException(*this, _ << "cannot open \"" << _path << "\"");
			}

			_out.setStream(*_stream);
		}
		_out << "ACCESS\t\tKIND\tCATEGORY\tBB\t";
		if(_line)
			_out << "\tLINE";

		_out << io::endl;
	}

	virtual void processCFG(WorkSpace* ws, CFG* cfg) override
	{
		_out << "FUNCTION " << cfg->label() << io::endl;
		BBProcessor::processCFG(ws, cfg);
	}

	virtual void processBB(WorkSpace* ws, CFG* cfg, Block* b) override
	{
		if(!b->isBasic())
			return;

		BasicBlock* bb = b->toBasic();

		for(Block::EdgeIter edgeIter(bb->ins()); edgeIter; ++edgeIter) {
			const Edge* e = *edgeIter;
			const Bag<icache::Access>& bag = icache::ACCESSES(e);
			processBag(ws, cfg, bag, bb);
		}

		const Bag<icache::Access>& bag = icache::ACCESSES(bb);
		processBag(ws, cfg, bag, bb);
	}

	void processBag(WorkSpace* ws, CFG* cfg, const Bag<icache::Access>& bag, BasicBlock* bb)
	{
		for(int i = 0; i < bag.size(); ++i)
			processAccess(ws, cfg, &bag[i], bb);
	}

	void processAccess(WorkSpace* ws, CFG*, const icache::Access* access, BasicBlock* bb)
	{
		_out << access->address() << "\t";
		switch(access->kind()){
			case icache::NONE: _out << "NONE\t"; break;
			case icache::FETCH: _out << "FETCH\t"; break;
			case icache::PREFETCH: _out << "PREFETCH\t"; break;
		}
		ExactCategory cat = EXACT_CATEGORY(access);

		if(cat == ExactCategory::AH)
			_out << "AH\t\t";
		else if(cat == ExactCategory::AM)
			_out << "AM\t\t";
		else if(cat == ExactCategory::DU)
			_out << "DU\t\t";
		else
			_out << "NC\t\t";
		_out << "BB " << bb->index() << "\t\t";
		printLine(ws, bb->address(), bb->topAddress().offset());
		_out << io::endl;
	}

	void printLine(WorkSpace* ws, Address begin, Address::offset_t offset)
	{

		// Display line
		if(_line) {
			bool one = false;
			Pair<cstring, int> old = pair(cstring(""), 0);
			for(Address addr = begin; addr.offset() < offset; addr = addr + 1) {
				Option<Pair<cstring, int> > res = ws->process()->getSourceLine(addr);
				if(res) {
					if((*res).fst != old.fst) {
						old = *res;
			 			if(one)
			 				_out << ", ";
			 			else
			 				one = true;
			 			_out << old.fst << ':' << old.snd;
					}
					else if((*res).snd != old.snd) {
						old = *res;
						_out << ',' << old.snd;
					}
				}
			}
		}
	}

	virtual void cleanup(WorkSpace*) override
	{
		if(_stream)
			delete _stream;
	}

	elm::io::Output _out;
	elm::sys::Path _path;
	bool _toFile;
	elm::io::OutStream* _stream;
	bool _line;
	bool _mcAnalysis;
};

p::declare ClassificationDisplayer::reg = p::init("lrupreanalysis::ClassificationDisplayer", Version(1, 0, 0))
	.require(LRU_CLASSIFICATION_FEATURE)
	.make<ClassificationDisplayer>();


p::id<bool> CLASSIFICATION_TO_FILE("lruperanalysis::CLASSIFICATION_TO_FILE", false);
p::id<elm::sys::Path> CLASSIFICATION_PATH("lrupreanalysis::CLASSIFICATION_PATH", "/tmp/");

} // namespace lrupreanalysis