Only break Profile translations on existing SrcRecs
[hiphop-php.git] / hphp / tools / tc-print / mappers.h
blob3a262b23af527f48a8ac185338222f472eea49b6
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_ADDR_TO_BC_MAPPER_
18 #define incl_HPHP_ADDR_TO_BC_MAPPER_
20 #include <vector>
21 #include <string>
23 #include "hphp/runtime/vm/hhbc.h"
24 #include "hphp/runtime/vm/jit/types.h"
26 #include "hphp/tools/tc-print/perf-events.h"
27 #include "hphp/tools/tc-print/offline-trans-data.h"
28 #include "hphp/tools/tc-print/offline-code.h"
29 #include "hphp/tools/tc-print/repo-wrapper.h"
31 namespace HPHP { namespace jit {
33 typedef uint16_t ExtOpcode;
35 /* Utilities */
37 std::string extOpcodeToString(ExtOpcode eOpcode);
38 std::vector<std::pair<std::string, ExtOpcode> > getValidOpcodeNames();
39 ExtOpcode stringToExtOpcode(std::string s);
40 std::string tcRegionToString(TCRegion tcr);
42 /* AddrToBcMapper */
44 struct AddrToBcMapper : Mapper<TCA, ExtOpcode> {
45 explicit AddrToBcMapper(const OfflineTransData* _transData) :
46 transData(_transData) {}
48 folly::Optional<ExtOpcode> operator()(const TCA& addr) override;
50 private:
51 const OfflineTransData* transData;
54 /* AddrToTransMapper */
56 struct AddrToTransMapper : Mapper<TCA, TransID> {
57 explicit AddrToTransMapper(const OfflineTransData* _tdata) : tdata(_tdata) {}
59 folly::Optional<TransID> operator()(const TCA& addr) override {
60 always_assert(tdata);
61 TransID tid = tdata->getTransContaining(addr);
62 if (tid != INVALID_ID) return tid;
63 return folly::none;
66 private:
67 const OfflineTransData* tdata;
70 /* AddrToTransFragmentMapper */
72 struct TransFragment {
73 TransID tid;
74 TCA aStart;
75 TCA acoldStart;
76 TCA afrozenStart;
77 uint32_t aLen;
78 uint32_t acoldLen;
79 uint32_t afrozenLen;
81 // Since it's going into an ordered map...
82 bool operator<(const TransFragment& other) const {
83 return aStart < other.aStart;
87 struct AddrToTransFragmentMapper : Mapper<TCA, TransFragment> {
88 AddrToTransFragmentMapper(const OfflineTransData* _tdata,
89 ExtOpcode _filterBy) :
90 tdata(_tdata), filterBy(_filterBy) {}
92 folly::Optional<TransFragment> operator()(const TCA& addr) override;
94 private:
95 TransFragment extractTransFragment(TCA addr, ExtOpcode opcode);
97 private:
98 const OfflineTransData* tdata;
99 ExtOpcode filterBy;
102 /* TransToFuncMapper */
104 struct TransToFuncMapper : Mapper<TransID, FuncId> {
105 explicit TransToFuncMapper(const OfflineTransData* _tdata) : tdata(_tdata) {}
107 folly::Optional<FuncId> operator()(const TransID& tid) override {
108 always_assert(tdata);
109 return tdata->getTransRec(tid)->src.funcID();
112 private:
113 const OfflineTransData* tdata;
118 #endif