@@ -40,6 +40,7 @@ class ReplayCacheIntrinsics : public HookCode {
4040
4141 bool is_region_active = false ;
4242 unsigned int region_instruction_count = 0 ;
43+ unsigned int store_count_after_fence = 0 ;
4344 std::vector<insn_t > replay_instructions;
4445 arch_addr_t last_region_register_value = 0 ;
4546 arch_addr_t last_store_address = 0 ;
@@ -203,6 +204,11 @@ class ReplayCacheIntrinsics : public HookCode {
203204 case RISCV_INS_C_SWSP: {
204205 recordLastStore (insn);
205206 if (is_region_active) {
207+ // Increase the store counter.
208+ // Only when a region is active, to exclude stores that occurred before the first
209+ // region was activated
210+ ++store_count_after_fence;
211+
206212 // Store the instruction for replay
207213 replay_instructions.emplace_back (std::move (insn));
208214 p_debug << printLeader () << " stored instruction for replay" << std::endl;
@@ -248,6 +254,11 @@ class ReplayCacheIntrinsics : public HookCode {
248254
249255 is_region_active = true ;
250256 assert (replay_instructions.empty ());
257+
258+ // Sanity check for compiler-generated code.
259+ // Any ReplayCache region can only safely be started when no stores have been
260+ // performed since the last FENCE instruction
261+ assert (store_count_after_fence == 0 );
251262 }
252263
253264 void executeCLWB () {
@@ -260,6 +271,7 @@ class ReplayCacheIntrinsics : public HookCode {
260271 const auto fence_cycles = cache->fence ();
261272 p_debug << printLeader () << " FENCE cycles: " << fence_cycles << std::endl;
262273 pipeline.addToCycles (fence_cycles);
274+ store_count_after_fence = 0 ;
263275 }
264276
265277 void createCheckpoint () {
0 commit comments