|
44 | 44 | #include "lldb/lldb-private-enumerations.h" |
45 | 45 | #include "lldb/lldb-private-interfaces.h" |
46 | 46 | #include "lldb/lldb-private-types.h" |
| 47 | +#include "llvm/ADT/DenseMap.h" |
47 | 48 | #include "llvm/Support/Compiler.h" |
48 | 49 | #include "llvm/TargetParser/Triple.h" |
49 | 50 |
|
| 51 | + |
50 | 52 | #include <cstdint> |
51 | 53 | #include <cstring> |
52 | | -#include <unordered_map> |
53 | 54 | #include <utility> |
54 | 55 |
|
55 | 56 | #include <cassert> |
@@ -403,7 +404,7 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch, |
403 | 404 | }; |
404 | 405 |
|
405 | 406 | // Track live variables across instructions (keyed by stable LLDB user_id_t) |
406 | | - std::unordered_map<lldb::user_id_t, VarState> live_vars; |
| 407 | + llvm::SmallDenseMap<lldb::user_id_t, VarState, 8> live_vars; // 8 is a good small-buffer guess |
407 | 408 |
|
408 | 409 | // Stateful annotator: updates live_vars and returns only what should be |
409 | 410 | // printed for THIS instruction. |
@@ -432,9 +433,10 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch, |
432 | 433 | VariableListSP var_list_sp = frame->GetInScopeVariableList(true); |
433 | 434 | if (!var_list_sp) { |
434 | 435 | // No variables in scope: everything previously live becomes <undef> |
435 | | - for (auto it = live_vars.begin(); it != live_vars.end();) { |
436 | | - events.push_back(llvm::formatv("{0} = <undef>", it->second.name).str()); |
437 | | - it = live_vars.erase(it); |
| 436 | + for (auto I = live_vars.begin(), E = live_vars.end(); I != E; ) { |
| 437 | + auto Cur = I++; |
| 438 | + events.push_back(llvm::formatv("{0} = <undef>", Cur->second.name).str()); |
| 439 | + live_vars.erase(Cur); |
438 | 440 | } |
439 | 441 | frame->ChangePC(original_pc); |
440 | 442 | return events; |
@@ -484,31 +486,31 @@ void Disassembler::PrintInstructions(Debugger &debugger, const ArchSpec &arch, |
484 | 486 | if (loc_clean.empty()) |
485 | 487 | continue; |
486 | 488 |
|
487 | | - // Update map + decide if we print |
488 | | - auto it = live_vars.find(var_id); |
489 | | - if (it == live_vars.end()) { |
490 | | - // New var → print |
491 | | - live_vars.emplace(var_id, |
492 | | - VarState{std::string(name), loc_clean.str(), true}); |
| 489 | + auto insert_res = live_vars.insert({var_id, |
| 490 | + VarState{std::string(name), |
| 491 | + loc_clean.str(), |
| 492 | + /*seen_this_inst*/ true}}); |
| 493 | + if (insert_res.second) { |
| 494 | + // Newly inserted → print |
493 | 495 | events.push_back(llvm::formatv("{0} = {1}", name, loc_clean).str()); |
494 | 496 | } else { |
495 | | - it->second.seen_this_inst = true; |
496 | | - if (it->second.last_loc != loc_clean) { |
497 | | - it->second.last_loc = loc_clean.str(); |
498 | | - events.push_back( |
499 | | - llvm::formatv("{0} = {1}", it->second.name, loc_clean).str()); |
| 497 | + // Already present |
| 498 | + VarState &vs = insert_res.first->second; |
| 499 | + vs.seen_this_inst = true; |
| 500 | + if (vs.last_loc != loc_clean) { |
| 501 | + vs.last_loc = loc_clean.str(); |
| 502 | + events.push_back(llvm::formatv("{0} = {1}", vs.name, loc_clean).str()); |
500 | 503 | } |
501 | 504 | } |
502 | 505 | } |
503 | 506 |
|
504 | 507 | // Anything previously live that we didn't see a location for at this inst |
505 | 508 | // is now <undef> |
506 | | - for (auto it = live_vars.begin(); it != live_vars.end();) { |
507 | | - if (!it->second.seen_this_inst) { |
508 | | - events.push_back(llvm::formatv("{0} = <undef>", it->second.name).str()); |
509 | | - it = live_vars.erase(it); |
510 | | - } else { |
511 | | - ++it; |
| 509 | + for (auto I = live_vars.begin(), E = live_vars.end(); I != E; ) { |
| 510 | + auto Cur = I++; |
| 511 | + if (!Cur->second.seen_this_inst) { |
| 512 | + events.push_back(llvm::formatv("{0} = <undef>", Cur->second.name).str()); |
| 513 | + live_vars.erase(Cur); |
512 | 514 | } |
513 | 515 | } |
514 | 516 |
|
|
0 commit comments