-// A passport for a CMP site. We want to keep track of where the given CMP is
-// and how many times it is evaluated to true or false.
-struct CmpSitePassport {
- uintptr_t PC;
- size_t Counter[2];
-
- bool IsInterestingCmpTarget() {
- static const size_t kRareEnough = 50;
- size_t C0 = Counter[0];
- size_t C1 = Counter[1];
- return C0 > kRareEnough * (C1 + 1) || C1 > kRareEnough * (C0 + 1);
- }
-};
-
-// For now, just keep a simple imprecise hash table PC => CmpSitePassport.
-// Potentially, will need to have a compiler support to have a precise mapping
-// and also thread-safety.
-struct CmpSitePassportTable {
- static const size_t kSize = 99991; // Prime.
- CmpSitePassport Passports[kSize];
-
- CmpSitePassport *GetPassport(uintptr_t PC) {
- uintptr_t Idx = PC & kSize;
- CmpSitePassport *Res = &Passports[Idx];
- if (Res->PC == 0) // Not thread safe.
- Res->PC = PC;
- return Res->PC == PC ? Res : nullptr;
- }
-};
-
-static CmpSitePassportTable CSPTable; // Zero initialized.
-