-
Notifications
You must be signed in to change notification settings - Fork 3
/
gspin_patterns.h
140 lines (111 loc) · 5.39 KB
/
gspin_patterns.h
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
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <zlib.h>
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <string>
#include <exception>
#include "gs_patterns.h"
#include "gs_patterns_core.h"
#include "utils.h"
#if !defined(SYMBOLS_ONLY)
#define SYMBOLS_ONLY 1 //Filter out instructions that have no symbol
#endif
#if !defined(VBITS)
# define VBITS (512L)
# define VBYTES (VBITS/8)
#endif
namespace gs_patterns
{
namespace gspin_patterns
{
constexpr std::size_t MEMORY_ACCESS_SIZE = VBYTES;
//FROM DR SOURCE
//DR trace
struct _trace_entry_t {
unsigned short type; // 2 bytes: trace_type_t
unsigned short size;
union {
addr_t addr;
unsigned char length[sizeof(addr_t)];
};
} __attribute__((packed));
typedef struct _trace_entry_t trace_entry_t;
// An adapter for trace_entry_t
class InstrAddrAdapterForPin : public InstrAddrAdapter
{
public:
InstrAddrAdapterForPin(const trace_entry_t * te)
{
/// TODO: do we need to copy this, will we outlive trace_entry_t which is passed in ?
_te.type = te->type;
_te.size = te->size;
_te.addr = te->addr;
}
InstrAddrAdapterForPin(const trace_entry_t te) : _te(te) { }
virtual ~InstrAddrAdapterForPin() { }
virtual inline bool is_valid() const override { return !(0 == _te.type && 0 == _te.size); }
virtual inline bool is_mem_instr() const override { return ((_te.type == 0x0) || (_te.type == 0x1)); }
virtual inline bool is_other_instr() const override { return ((_te.type >= 0xa) && (_te.type <= 0x10)) || (_te.type == 0x1e); }
virtual mem_access_type get_mem_access_type() const override {
if (!is_mem_instr()) throw GSDataError("Not a Memory Instruction - unable to determine Access Type");
// Must be 0x0 or 0x1
if (_te.type == 0x0) return GATHER;
else return SCATTER;
}
virtual inline mem_instr_type get_mem_instr_type() const override { return VECTOR; }
virtual inline size_t get_size() const override { return _te.size; }
virtual inline addr_t get_base_addr() const override { return _te.addr; }
virtual inline addr_t get_address() const override { return _te.addr; }
virtual inline addr_t get_iaddr() const override { return _te.addr; }
virtual inline addr_t get_maddr() const override { return _te.addr / _te.size; }
virtual inline unsigned short get_type() const override { return _te.type; } // must be 0 for GATHER, 1 for SCATTER !!
virtual inline int64_t get_max_access_size() const override { return MEMORY_ACCESS_SIZE; }
virtual void output(std::ostream & os) const override {
os << "InstrAddrAdapterForPin: trace entry: type: [" << _te.type << "] size: [" << _te.size << "]";
}
private:
trace_entry_t _te;
};
class MemPatternsForPin : public MemPatterns<MEMORY_ACCESS_SIZE>
{
public:
MemPatternsForPin() : _metrics(GATHER, SCATTER),
_iinfo(GATHER, SCATTER) { }
virtual ~MemPatternsForPin() override { }
void handle_trace_entry(const InstrAddrAdapter & ia) override;
void generate_patterns() override;
Metrics & get_metrics(mem_access_type) override;
InstrInfo & get_iinfo(mem_access_type) override;
Metrics & get_gather_metrics() override { return _metrics.first; }
Metrics & get_scatter_metrics() override { return _metrics.second; }
InstrInfo & get_gather_iinfo () override { return _iinfo.first; }
InstrInfo & get_scatter_iinfo () override { return _iinfo.second; }
TraceInfo & get_trace_info() override { return _trace_info; }
InstrWindow<MEMORY_ACCESS_SIZE> &
get_instr_window() override { return _iw; }
void set_log_level(int8_t level) override { _log_level = level; }
int8_t get_log_level() override { return _log_level; }
void set_trace_file(const std::string & trace_file_name) { _trace_file_name = trace_file_name; }
const std::string & get_trace_file_name() { return _trace_file_name; }
void set_binary_file(const std::string & binary_file_name) { _binary_file_name = binary_file_name; }
const std::string & get_binary_file_name() { return _binary_file_name; }
void update_metrics();
std::string get_file_prefix ();
void process_traces();
void update_source_lines();
double update_source_lines_from_binary(mem_access_type);
void process_second_pass(gzFile & fp_drtrace);
private:
std::pair<Metrics, Metrics> _metrics;
std::pair<InstrInfo, InstrInfo> _iinfo;
TraceInfo _trace_info;
InstrWindow<MEMORY_ACCESS_SIZE> _iw;
int8_t _log_level = 0;
std::string _trace_file_name;
std::string _binary_file_name;
};
} // namespace gspin_patterns
} // namespace gs_patterns