@@ -650,16 +650,13 @@ unsigned CodeGenFunction::getAccessedFieldNo(unsigned Idx,
650
650
->getZExtValue ();
651
651
}
652
652
653
- // / Emit the hash_16_bytes function from include/llvm/ADT/Hashing.h.
654
- static llvm::Value *emitHash16Bytes (CGBuilderTy &Builder, llvm::Value *Low,
655
- llvm::Value *High) {
656
- llvm::Value *KMul = Builder.getInt64 (0x9ddfea08eb382d69ULL );
657
- llvm::Value *K47 = Builder.getInt64 (47 );
658
- llvm::Value *A0 = Builder.CreateMul (Builder.CreateXor (Low, High), KMul);
659
- llvm::Value *A1 = Builder.CreateXor (Builder.CreateLShr (A0, K47), A0);
660
- llvm::Value *B0 = Builder.CreateMul (Builder.CreateXor (High, A1), KMul);
661
- llvm::Value *B1 = Builder.CreateXor (Builder.CreateLShr (B0, K47), B0);
662
- return Builder.CreateMul (B1, KMul);
653
+ static llvm::Value *emitHashMix (CGBuilderTy &Builder, llvm::Value *Acc,
654
+ llvm::Value *Ptr ) {
655
+ llvm::Value *A0 =
656
+ Builder.CreateMul (Ptr , Builder.getInt64 (0xbf58476d1ce4e5b9u ));
657
+ llvm::Value *A1 =
658
+ Builder.CreateXor (A0, Builder.CreateLShr (A0, Builder.getInt64 (31 )));
659
+ return Builder.CreateXor (Acc, A1);
663
660
}
664
661
665
662
bool CodeGenFunction::isNullPointerAllowed (TypeCheckKind TCK) {
@@ -821,11 +818,7 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
821
818
EmitBlock (VptrNotNull);
822
819
}
823
820
824
- // Compute a hash of the mangled name of the type.
825
- //
826
- // FIXME: This is not guaranteed to be deterministic! Move to a
827
- // fingerprinting mechanism once LLVM provides one. For the time
828
- // being the implementation happens to be deterministic.
821
+ // Compute a deterministic hash of the mangled name of the type.
829
822
SmallString<64 > MangledName;
830
823
llvm::raw_svector_ostream Out (MangledName);
831
824
CGM.getCXXABI ().getMangleContext ().mangleCXXRTTI (Ty.getUnqualifiedType (),
@@ -834,15 +827,13 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
834
827
// Contained in NoSanitizeList based on the mangled type.
835
828
if (!CGM.getContext ().getNoSanitizeList ().containsType (SanitizerKind::Vptr,
836
829
Out.str ())) {
837
- llvm::hash_code TypeHash = hash_value (Out.str ());
838
-
839
- // Load the vptr, and compute hash_16_bytes(TypeHash, vptr).
840
- llvm::Value *Low = llvm::ConstantInt::get (Int64Ty, TypeHash);
830
+ // Load the vptr, and mix it with TypeHash.
831
+ llvm::Value *TypeHash =
832
+ llvm::ConstantInt::get (Int64Ty, xxh3_64bits (Out.str ()));
841
833
Address VPtrAddr (Ptr , IntPtrTy, getPointerAlign ());
842
834
llvm::Value *VPtrVal = Builder.CreateLoad (VPtrAddr);
843
- llvm::Value *High = Builder.CreateZExt (VPtrVal, Int64Ty);
844
-
845
- llvm::Value *Hash = emitHash16Bytes (Builder, Low, High);
835
+ llvm::Value *Hash =
836
+ emitHashMix (Builder, TypeHash, Builder.CreateZExt (VPtrVal, Int64Ty));
846
837
Hash = Builder.CreateTrunc (Hash, IntPtrTy);
847
838
848
839
// Look the hash up in our cache.
0 commit comments