forked from chipsalliance/VeeR-ISS
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathInstProfile.hpp
88 lines (69 loc) · 2.82 KB
/
InstProfile.hpp
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
// Copyright 2020 Western Digital Corporation or its affiliates.
//
// 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.
#pragma once
#include <vector>
#include "InstId.hpp"
#include "VecRegs.hpp"
namespace WdRiscv
{
struct InstProfile
{
InstId id_ = InstId::illegal;
uintmax_t freq_ = 0; // Number of times instruction was executed
uintmax_t user_ = 0; // Number of times exeuted in user mode.
uintmax_t supervisor_ = 0; // Number of times exeuted in supervisor mode.
uintmax_t machine_ = 0; // Number of times exeuted in machine mode.
ElementWidth elemWidth_ = ElementWidth::Byte; // For vector instructions.
// One entry per integer register: Count of times register was used
// by instruction as destination register.
std::vector<uintmax_t> destRegFreq_;
// SrcRegFreq_[0] corresponds to the 1st source register operand,
// srcRegFreq_[1] to the second and srcRegFreq_[3] to the
// 3rd/immediate operand. Each entry of srcRegFreq_[i] is a vector
// with one entry per integer/fp register indicating the count of
// times that register was used by the instruction as a source
// operand.
std::vector< std::vector<uintmax_t> > srcRegFreq_;
std::vector< std::vector<uintmax_t> > srcHisto_;
bool hasImm_ = false;
int32_t minImm_ = 0; // Minimum immediate operand value.
int32_t maxImm_ = 0; // Maximum immediate operand value.
};
class InstProfiles
{
public:
InstProfiles() = default;
void configure();
InstProfile* find(InstId id)
{ return size_t(id) < vec_.size()? &vec_.at(size_t(id)) : nullptr; }
InstProfile* find(InstId id, ElementWidth width)
{
size_t base = unsigned(InstId::maxId) + 1;
size_t multiplier = unsigned(width);
size_t ix = base*multiplier + size_t(id);
return ix < vec_.size()? &vec_.at(ix) : nullptr;
}
/// Set the elements of the given vector to the indices of the
/// instruction records sorted by frequency.
void sort(std::vector<size_t>& indices) const;
/// Return number of records in this container.
size_t size();
/// Return the ith entry in this container or null if i is out of
/// bounds.
const InstProfile* ithEntry(size_t i) const
{ return i < vec_.size() ? &vec_.at(i) : nullptr; }
private:
std::vector<InstProfile> vec_;
};
}