@@ -128,26 +128,40 @@ class VivisectBroker : public Broker {
128128
129129 MCIS[i] = &MCI; // return a pointer into our MCI_Pool
130130
131- if (MDE && insn.has_memory_access ()) {
132- auto MemAccess = insn.memory_access ();
133- auto &Registry = MDE->MDRegistry ;
134- auto &IndexMap = MDE->IndexMap ;
135- auto &MemAccessCat = Registry[MD_LSUnit_MemAccess];
136- IndexMap[i] = TotalNumTraces;
137- MemAccessCat[TotalNumTraces] = std::move (MDMemoryAccess{
138- MemAccess.is_store (),
139- MemAccess.vaddr (),
140- MemAccess.size (),
141- });
142- }
131+ // Add metadata to the fetched instruction if metadata exchanger
132+ // is available
133+ if (MDE) {
134+
135+ // The registry stores the metadata
136+ auto &Registry = MDE->MDRegistry ;
137+
138+ // The IndexMap maps instruction index (within this region) to
139+ // the identifier we chose for our metadata. We chose a
140+ // monotonically increasing counter as the identifier for each
141+ // metadata entry.
142+ auto &IndexMap = MDE->IndexMap ;
143+ IndexMap[i] = TotalNumTraces;
144+
145+ auto &InstrAddrCat = Registry[MD_InstrAddr];
146+ InstrAddrCat[TotalNumTraces] = insn.addr ();
147+
148+ if (insn.has_memory_access ()) {
149+ auto MemAccess = insn.memory_access ();
150+ auto &MemAccessCat = Registry[MD_LSUnit_MemAccess];
151+ MemAccessCat[TotalNumTraces] = std::move (MDMemoryAccess{
152+ MemAccess.is_store (),
153+ MemAccess.vaddr (),
154+ MemAccess.size (),
155+ });
156+ }
157+
158+ if (insn.has_branch_flow ()) {
159+ auto BranchFlow = insn.branch_flow ();
160+ auto &Registry = MDE->MDRegistry ;
161+ auto &BranchFlowCat = Registry[MD_FrontEnd_BranchFlow];
162+ BranchFlowCat[TotalNumTraces] = BranchFlow.is_mispredict ();
163+ }
143164
144- if (MDE && insn.has_branch_flow ()) {
145- auto BranchFlow = insn.branch_flow ();
146- auto &Registry = MDE->MDRegistry ;
147- auto &IndexMap = MDE->IndexMap ;
148- auto &BranchFlowCat = Registry[MD_FrontEnd_BranchFlow];
149- IndexMap[i] = TotalNumTraces;
150- BranchFlowCat[TotalNumTraces] = BranchFlow.is_mispredict ();
151165 }
152166
153167 ++TotalNumTraces;
0 commit comments