melver created this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
- Avoid bit operations to compute Offset by removing bitfields. On 64-bit architectures, SLocEntry's size is unchanged. - Provide branch-prediction hints to compiler to generate better code. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D80428 Files: clang/include/clang/Basic/SourceManager.h clang/lib/Basic/SourceManager.cpp Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -885,14 +885,14 @@ bool Invalid = false; unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex; unsigned MidOffset = getLocalSLocEntry(MiddleIndex, &Invalid).getOffset(); - if (Invalid) + if (LLVM_UNLIKELY(Invalid)) return FileID::get(0); ++NumProbes; // If the offset of the midpoint is too large, chop the high side of the // range to the midpoint. - if (MidOffset > SLocOffset) { + if (LLVM_LIKELY(MidOffset > SLocOffset)) { GreaterIndex = MiddleIndex; continue; } Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -439,8 +439,8 @@ /// SourceManager keeps an array of these objects, and they are uniquely /// identified by the FileID datatype. class SLocEntry { - unsigned Offset : 31; - unsigned IsExpansion : 1; + unsigned Offset; + bool IsExpansion; union { FileInfo File; ExpansionInfo Expansion; @@ -465,7 +465,6 @@ } static SLocEntry get(unsigned Offset, const FileInfo &FI) { - assert(!(Offset & (1u << 31)) && "Offset is too large"); SLocEntry E; E.Offset = Offset; E.IsExpansion = false; @@ -474,7 +473,6 @@ } static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) { - assert(!(Offset & (1u << 31)) && "Offset is too large"); SLocEntry E; E.Offset = Offset; E.IsExpansion = true;
Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -885,14 +885,14 @@ bool Invalid = false; unsigned MiddleIndex = (GreaterIndex-LessIndex)/2+LessIndex; unsigned MidOffset = getLocalSLocEntry(MiddleIndex, &Invalid).getOffset(); - if (Invalid) + if (LLVM_UNLIKELY(Invalid)) return FileID::get(0); ++NumProbes; // If the offset of the midpoint is too large, chop the high side of the // range to the midpoint. - if (MidOffset > SLocOffset) { + if (LLVM_LIKELY(MidOffset > SLocOffset)) { GreaterIndex = MiddleIndex; continue; } Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -439,8 +439,8 @@ /// SourceManager keeps an array of these objects, and they are uniquely /// identified by the FileID datatype. class SLocEntry { - unsigned Offset : 31; - unsigned IsExpansion : 1; + unsigned Offset; + bool IsExpansion; union { FileInfo File; ExpansionInfo Expansion; @@ -465,7 +465,6 @@ } static SLocEntry get(unsigned Offset, const FileInfo &FI) { - assert(!(Offset & (1u << 31)) && "Offset is too large"); SLocEntry E; E.Offset = Offset; E.IsExpansion = false; @@ -474,7 +473,6 @@ } static SLocEntry get(unsigned Offset, const ExpansionInfo &Expansion) { - assert(!(Offset & (1u << 31)) && "Offset is too large"); SLocEntry E; E.Offset = Offset; E.IsExpansion = true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits