22 #ifndef OTAWA_GRAPH_BBTIME_H
23 #define OTAWA_GRAPH_BBTIME_H
32 #include <elm/io/OutFileStream.h>
39 extern Identifier<int>
TIME;
56 if(i < lbs->count() &&
lbs->get(
i)->address() == inst->
address()) {
77 using namespace elm::genstruct;
89 _bb_list.addFirst(bb);
97 _bb_list.addLast(block);
107 _bb_list.addFirst(new_bb);
116 {
return _num_insts;}
120 {
return _bb_list.last();}
127 output <<
"b" <<
bb->number() <<
"-";
160 virtual int cacheMissPenalty(
Address addr)
const;
161 virtual int memoryLatency(
Address addr)
const;
165 virtual void BuildVectorOfHwResources();
168 _do_consider_icache = icache;
176 virtual void configure(
const PropList& props);
185 void analyzePathContext(
PathContext *ctxt,
int context_index);
187 void outputGraph(G* graph,
int bb_number,
int context_number,
int case_number,
const string& info =
"");
195 ASSERTP(bank,
"no bank for memory access at " << addr);
250 if(!_graphs_dir_name.isEmpty())
251 _do_output_graphs =
true;
253 _do_output_graphs =
false;
256 _do_consider_icache =
true;
259 _do_consider_icache =
false;
276 BuildVectorOfHwResources();
289 int resource_index = 0;
290 bool is_ooo_proc =
false;
294 _hw_resources.add(new_resource);
299 for (
int i=0 ; i<stage->width() ; i++) {
301 buffer << stage->name() <<
"[" << i <<
"]";
303 _hw_resources.add(new_resource);
308 for (
int i=0 ; i<stage->numFus() ; i++) {
311 for (
int j=0 ; j<fu_stage->
width() ; j++) {
313 buffer << fu_stage->
name() <<
"[" << j <<
"]";
315 _hw_resources.add(new_resource);
326 int num = queue->size();
327 for (
int i=0 ; i<num ; i++) {
329 buffer << queue->name() <<
"[" << i <<
"]";
333 if (((
StageResource *)(*resource))->stage() == queue->emptyingStage()) {
350 _hw_resources.add(new_resource);
378 int last_stage_cap = _microprocessor->lastStage()->width();
386 if ( (new_ctxt->
numInsts() >= last_stage_cap)
389 context_list->
addLast(new_ctxt);
391 FillSequence(new_ctxt, context_list, depth);
410 FillSequence(ctxt, context_list, depth);
438 buffer << _graphs_dir_name <<
"/";
439 buffer <<
"b" << bb_number <<
"-ctxt" << context_index <<
"-case" << case_index <<
".dot";
442 graph->dump(dotFile, info);
506 if (header0 == NULL){
512 if (header0 != header){
513 if (header1 == NULL){
526 if (header1 != header) {
528 ASSERTP(0,
"this sequence has more than 2 headers for cache categories: this is not supported so far\n");
543 if (num_headers == 1){
566 list->
addLast(tctxt_first_first);
569 list->
addLast(tctxt_others_first);
572 list->
addLast(tctxt_first_others);
582 if (header == header0){
616 graph->restoreDefaultLatencies();
618 graph->setLatencies(NC_ctxt);
620 graph->setLatencies(FM_ctxt);
621 int cost = graph->analyze();
636 G *execution_graph =
new G(_ws,_microprocessor, &_hw_resources, sequence, _props);
637 execution_graph->build();
640 if(!_do_consider_icache)
641 for(
typename G::InstIterator
inst(execution_graph);
inst;
inst++)
642 inst->fetchNode()->setLatency(memoryLatency(
inst->
inst()->address()));
645 int reference_cost = execution_graph->analyze();
647 log <<
"\t\treference cost = " << reference_cost <<
"\n\n";
648 if (_do_output_graphs){
649 outputGraph(execution_graph, bb->
number(), context_index, case_index++,
650 _ <<
"reference cost = " << reference_cost);
654 if (_do_consider_icache){
662 log <<
"\t\t\tcategory of I" <<
inst->index() <<
" is ";
665 log <<
"ALWAYS_HIT\n";
668 log <<
"ALWAYS_MISS\n";
671 log <<
"FIRST_MISS (with header b" << lbm.
header()->
number() <<
")\n";
674 log <<
"NOT_CLASSIFIED\n";
677 log <<
"unknown !!!\n";
686 computeDefaultTimingContextForICache(&default_timing_context, sequence);
687 int default_icache_cost = reference_cost;
688 if (!default_timing_context.
isEmpty()){
690 log <<
"\t\t\t\tdefault timing context: misses for";
692 log <<
"I" << nl->node()->inst()->index() <<
", ";
696 execution_graph->setDefaultLatencies(&default_timing_context);
697 default_icache_cost = execution_graph->analyze();
698 if (_do_output_graphs) {
700 buf <<
"cost with AM = " << default_icache_cost <<
"\\lAM (";
702 buf <<
"I" << nl->node()->inst()->index() <<
", ";
704 outputGraph(execution_graph, bb->
number(), context_index, case_index++, buf.
toString());
707 log <<
"cost = " << default_icache_cost <<
" (only accounting for fixed latencies)\n\n";
708 if (default_icache_cost > reference_cost)
709 reference_cost = default_icache_cost;
715 buildNCTimingContextListForICache(&NC_timing_context_list, sequence);
716 buildFMTimingContextListForICache(&FM_timing_context_list, sequence);
722 if (!FM_timing_context_list.
isEmpty()){
725 cache_penalty->
setHeader(0, FM_tctxt->header(0));
726 cache_penalty->
setHeader(1, FM_tctxt->header(1));
729 if (!NC_timing_context_list.
isEmpty()){
731 int NC_cost = analyzeTimingContext(execution_graph, NC_tctxt.item(), NULL);
732 if (NC_cost > reference_cost)
733 reference_cost = NC_cost;
734 int cost = analyzeTimingContext(execution_graph, NC_tctxt.item(), FM_tctxt.item());
736 log <<
"\n\t\tcontext " << index <<
": ";
738 log <<
"I" << (nl.item())->node()->inst()->index() <<
",";
741 log <<
"I" << (nl.item())->node()->inst()->index() <<
",";
744 log <<
"cost=" << cost;
745 log <<
" - NC_cost=" << NC_cost <<
"\n";
748 int penalty = cost - reference_cost;
752 if (penalty > cache_penalty->
penalty(FM_tctxt->type()))
753 cache_penalty->
setPenalty(FM_tctxt->type(), penalty);
757 if (_do_output_graphs) {
759 buf <<
"FM-NC cost = " << cost <<
"\\lfirst(";
761 buf <<
"I" << (nl.item())->node()->inst()->index() <<
",";
764 buf <<
"I" << (nl.item())->node()->inst()->index() <<
",";
766 outputGraph(execution_graph, bb->
number(), context_index, case_index++, buf.
toString());
771 int cost = analyzeTimingContext(execution_graph, NULL, FM_tctxt.item());
773 log <<
"\t\tcontext " << index <<
": ";
775 log <<
"I" << (nl.item())->node()->inst()->index() <<
",";
778 log <<
"cost=" << cost <<
"\n";
780 int penalty = cost - reference_cost;
783 if (penalty > cache_penalty->
penalty(FM_tctxt->type()))
784 cache_penalty->
setPenalty(FM_tctxt->type(), penalty);
788 if (_do_output_graphs){
790 buf <<
"NC cost = " << cost <<
"\\lNC (";
792 buf <<
"I" << (nl.item())->node()->inst()->index() <<
",";
794 outputGraph(execution_graph, bb->
number(), context_index, case_index++, buf.
toString());
802 int NC_cost = analyzeTimingContext(execution_graph, NC_tctxt.item(), NULL);
804 log <<
"\t\tcontext " << index <<
": ";
806 log <<
"I" << (nl.item())->node()->inst()->index() <<
",";
809 log <<
"cost=" << NC_cost <<
"\n";
811 if (NC_cost > reference_cost)
812 reference_cost = NC_cost;
813 if (_do_output_graphs){
815 buf <<
"NC cost = " << NC_cost <<
"\\l NC (";
817 buf <<
"I" << (nl.item())->node()->inst()->index() <<
",";
819 outputGraph(execution_graph, bb->
number(), context_index, case_index++, buf.
toString());
825 if (cache_penalty->
header(0)){
830 log <<
"\t\tcache penalty: ";
831 cache_penalty->
dump(log);
840 log <<
"\t\tReference cost: " << reference_cost <<
"\n";
850 delete execution_graph;
864 log <<
"\n\t\t================================================================\n";
868 int context_index = 0;
874 log <<
"\n\t\t----- Considering context: ";
878 analyzePathContext(ctxt, context_index);
886 #endif // OTAWA_GRAPH_BBTIME_H
const hard::Cache * icache
Definition: GraphBBTime.h:156
int _num_insts
Definition: GraphBBTime.h:83
elm::genstruct::SLList< PathContext * > * buildListOfPathContexts(BasicBlock *bb, int depth=1)
Definition: GraphBBTime.h:405
Definition: categories.h:39
struct otawa::sem::inst inst
Identifier< const Processor * > PROCESSOR
Current memory.
int _prologue_depth
Definition: GraphBBTime.h:147
This processor is dedicated to the basic block process thru proccessBB() method.
Definition: BBProcessor.h:72
Iterator for the instruction queues.
Definition: ParExeProc.h:227
Representation of a pipeline stage to be used to build a ParExeGraph.
Definition: ParExeProc.h:86
Definition: ParExeProc.h:88
dtd::Element edge(dtd::make("edge", _EDGE).attr(source).attr(target).attr(called))
static const Processor null
Definition: Processor.h:151
elm::genstruct::SLList< BasicBlock * > _bb_list
Definition: GraphBBTime.h:82
Identifier< const Memory * > MEMORY
Current memory.
category_t next(BasicBlock *ibb, Inst *inst)
Definition: GraphBBTime.h:46
virtual void buildNCTimingContextListForICache(elm::genstruct::SLList< TimingContext * > *list, ParExeSequence *seq)
Definition: GraphBBTime.h:449
int analyzeTimingContext(G *graph, TimingContext *NC_ctxt, TimingContext *FM_ctxt)
Definition: GraphBBTime.h:615
void FillSequence(PathContext *ctxt, elm::genstruct::SLList< PathContext * > *context_list, int depth)
Definition: GraphBBTime.h:373
Definition: categories.h:38
virtual void configure(const PropList &props)
Configure the current processor.
Definition: GraphBBTime.h:247
PathContext(const PathContext &ctxt)
Definition: GraphBBTime.h:95
BasicBlock * mainBlock()
Definition: GraphBBTime.h:121
GraphBBTime(AbstractRegistration &_reg=reg)
Definition: GraphBBTime.h:228
BasicBlock * header(void) const
Definition: GraphBBTime.h:67
String _graphs_dir_name
Definition: GraphBBTime.h:150
Abstract class to represent the registered processors.
Definition: Registration.h:80
Représentation of a processor (to be used to build a ParExeGraph).
Definition: ParExeProc.h:195
elm::io::Output * _output
Definition: GraphBBTime.h:149
Definition: Registration.h:138
const int end
Definition: Registration.h:42
elm::genstruct::Vector< Resource * > _hw_resources
Definition: GraphBBTime.h:158
elm::String name(void)
Definition: ParExeProc.h:115
~PathContext()
Definition: GraphBBTime.h:103
void setPenalty(cache_penalty_type_t type, int value)
Definition: CachePenalty.h:50
genstruct::AllocatedTable< LBlock * > * lbs
Definition: GraphBBTime.h:71
Definition: ParExeGraph.h:128
ParExeSequence * buildSequence(PathContext *ctxt)
Definition: GraphBBTime.h:418
Definition: categories.h:41
Description of a processor pipeline.
Definition: Processor.h:136
Definition: Resource.h:61
BasicBlock * hd
Definition: GraphBBTime.h:72
Identifier< CachePenalty * > ICACHE_PENALTY
Edge * _edge
Definition: GraphBBTime.h:86
virtual void configureMem(WorkSpace *ws)
Definition: GraphBBTime.h:166
code_part_t
Definition: ParExeGraph.h:50
WorkSpace * _ws
Definition: GraphBBTime.h:145
dtd::Element bb(dtd::make("bb", _BB).attr(id).attr(address).attr(size))
int countInstructions(void) const
Definition: BasicBlock.h:182
void addLast(const T &value)
const int provide
Definition: Registration.h:44
Control Flow Graph representation.
Definition: CFG.h:42
Class to represent the whole memory of the platform.
Definition: Memory.h:173
void addBlock(BasicBlock *new_bb, Edge *edge)
Definition: GraphBBTime.h:106
StringOption proc(command, 'p',"processor","used processor","path","")
void dump(elm::io::Output &out)
Definition: CachePenalty.h:55
bool isEntry(void) const
Test if the basic block is the CFG entry.
Definition: BasicBlock.h:136
Definition: ParExeProc.h:171
Definition: Resource.h:56
virtual void computeDefaultTimingContextForICache(TimingContext *dtctxt, ParExeSequence *seq)
Definition: GraphBBTime.h:598
BasicBlock * _bb
Definition: GraphBBTime.h:85
Definition: GraphBBTime.h:41
Definition: categories.h:43
void analyzePathContext(PathContext *ctxt, int context_index)
Definition: GraphBBTime.h:628
void outputGraph(G *graph, int bb_number, int context_number, int case_number, const string &info="")
Output the given graph in the directory configured by GRAPHS_OUTPUT_DIRECTORY.
Definition: GraphBBTime.h:436
Identifier< elm::system::Path > CACHE_CONFIG_PATH
Gives the path of file containing the cache configuration.
bool isExit(void) const
Test if the basic block is the CFG exit.
Definition: BasicBlock.h:137
const category_t INVALID_CATEGORY
Definition: categories.h:78
elm::StringBuffer buf
Definition: util_fft_lexer.cc:640
Identifier< String > GRAPHS_OUTPUT_DIRECTORY
int numBlocks()
Definition: GraphBBTime.h:117
int numInsts()
Definition: GraphBBTime.h:115
int i
Definition: GraphBBTime.h:73
virtual void processWorkSpace(WorkSpace *fw)
Process the given framework.
Definition: proc_CFGProcessor.cpp:80
bool _do_consider_icache
Definition: GraphBBTime.h:154
const hard::Memory * mem
Definition: GraphBBTime.h:155
Definition: ParExeGraph.h:169
A workspace represents a program, its run-time and all information about WCET computation or any othe...
Definition: WorkSpace.h:67
void processWorkSpace(WorkSpace *ws)
Process the given framework.
Definition: GraphBBTime.h:268
This class contains the configuration of a level of cache of processor.
Definition: Cache.h:34
Definition: Resource.h:71
Definition: CachePenalty.h:33
static bool dominates(BasicBlock *bb1, BasicBlock *bb2)
Test if the first basic block dominates the second one.
Definition: util_Dominance.cpp:164
The representation of an address in OTAWA.
Definition: base.h:54
category_t
Definition: categories.h:37
BasicBlock * bb
Definition: GraphBBTime.h:70
int number(void) const
Get the number hooked on this basic block, that is, value of ID_Index property.
Definition: BasicBlock.h:146
const int require
Definition: Registration.h:43
virtual address_t address(void) const =0
Get the address of the item .
inst(void)
Definition: inst.h:118
virtual int memoryLatency(Address addr) const
Definition: GraphBBTime.h:200
const category_t FIRST_MISS
Definition: categories.h:81
bool isEmpty()
Definition: ParExeGraph.h:193
int _num_bbs
Definition: GraphBBTime.h:84
static Registration< GraphBBTime< G > > reg
Definition: GraphBBTime.h:174
ParExeStage * firstStage()
Definition: ParExeProc.h:167
A sequence of ParExeInstruction for which a ParExeGraph will be built.
Definition: ParExeGraph.h:125
Definition: ParExeProc.h:89
Representation of a pipeline (list of stages).
Definition: ParExeProc.h:157
Definition: ParExeGraph.h:52
BasicBlockIterator(const PathContext &ctxt)
Definition: GraphBBTime.h:133
Definition: BasicBlock.h:160
SilentFeature MEMORY_FEATURE
This feature ensures we have obtained the memory configuration of the system.
Definition: ParExeGraph.h:142
This class represents edges in the CFG representation.
Definition: Edge.h:33
Identifier< category_t > & CATEGORY
Definition: cache_categories.cpp:160
dtd::Element cfg(dtd::make("cfg", _CFG).attr(id).content((entry,*bb, exit,*edge)))
This basic block processor computes the basic block execution time using the execution graph method d...
Definition: GraphBBTime.h:143
Definition: CachePenalty.h:33
Identifier< genstruct::AllocatedTable< LBlock * > * > BB_LBLOCKS
This property is used for storing the list of L-Blocks of a BasicBlock.
void addNodeLatency(NodeLatency *nl)
Definition: ParExeGraph.h:191
This is the minimal definition of a basic block.
Definition: BasicBlock.h:43
Definition: Resource.h:37
BasicBlock * lastBlock()
Definition: GraphBBTime.h:119
A bank in the memory.
Definition: Memory.h:86
int latency(void) const
Get the default latency for accessing this bank.
Definition: Memory.h:120
void dump(io::Output &output)
Definition: GraphBBTime.h:125
Definition: categories.h:42
This class represents assembly instruction of a piece of code.
Definition: Inst.h:62
const int base
Definition: Registration.h:47
LBlockManager(void)
Definition: GraphBBTime.h:44
BasicBlock * header(int index)
Definition: CachePenalty.h:47
Instruction as presented in the ParExeGraph.
Definition: ParExeGraph.h:63
PathContext(BasicBlock *bb)
Definition: GraphBBTime.h:88
int penalty(cache_penalty_type_t type)
Definition: CachePenalty.h:52
This a list of properties.
Definition: PropList.h:63
OutStream * _output_stream
Definition: GraphBBTime.h:148
ParExeProc * _microprocessor
Definition: GraphBBTime.h:157
This class is used for returning exceptions from the processors.
Definition: ProcessorException.h:17
Identifier< ot::time > TIME
This identifier is used for storing the time of execution in cycles (int) of the program area it appl...
virtual void BuildVectorOfHwResources()
Definition: GraphBBTime.h:287
This class can be used to express the penalties due to the instruction cache.
Definition: CachePenalty.h:31
Identifier< const CacheConfiguration * > CACHE_CONFIGURATION
Current configuration.
int width(void) const
Definition: ParExeProc.h:114
void addLast(const T &value)
virtual void configure(const PropList &props)
Configure the current processor.
Definition: proc_CFGProcessor.cpp:151
PropList _props
Definition: GraphBBTime.h:146
void setHeader(int index, BasicBlock *bb)
Definition: CachePenalty.h:45
Definition: CachePenalty.h:33
void setType(CachePenalty::cache_penalty_type_t type)
Definition: ParExeGraph.h:201
Edge * edge()
Definition: GraphBBTime.h:123
bool _do_output_graphs
Definition: GraphBBTime.h:153
Definition: ParExeGraph.h:51
static MetaRegistration reg
Definition: CFGProcessor.h:43
Definition: GraphBBTime.h:131
Definition: ParExeGraph.h:154
Identifier< BasicBlock * > CATEGORY_HEADER
In the case of a FIRST_HIT (or FIRST_MISS) property, contains the header of the loop causing the HIT ...
SilentFeature PROCESSOR_FEATURE
This feature ensures we have obtained the memory configuration of the system.
virtual void buildFMTimingContextListForICache(elm::genstruct::SLList< TimingContext * > *list, ParExeSequence *seq)
Definition: GraphBBTime.h:490
Definition: CachePenalty.h:33
Address address(void) const
Definition: BasicBlock.h:140
virtual int cacheMissPenalty(Address addr) const
Definition: GraphBBTime.h:193
SilentFeature BB_TIME_FEATURE
This feature ensures that the execution time of each basic block has been computed.
void processBB(WorkSpace *ws, CFG *cfg, BasicBlock *bb)
Perform the work of the given basic block.
Definition: GraphBBTime.h:857
Iterator for instructions in the basic block.
Definition: BasicBlock.h:70
Definition: GraphBBTime.h:80