================ @@ -149,14 +157,44 @@ class SourceLocationSequence::State { operator SourceLocationSequence *() { return &Seq; } }; -inline uint64_t SourceLocationEncoding::encode(SourceLocation Loc, - SourceLocationSequence *Seq) { - return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding()); +inline SourceLocationEncoding::RawLocEncoding +SourceLocationEncoding::encode(SourceLocation Loc, UIntTy BaseOffset, + unsigned BaseModuleFileIndex, + SourceLocationSequence *Seq) { + // If the source location is a local source location, we can try to optimize + // the similar sequences to only record the differences. + if (!BaseOffset) + return Seq ? Seq->encode(Loc) : encodeRaw(Loc.getRawEncoding()); + + if (Loc.isInvalid()) + return 0; + + // Otherwise, the higher bits are used to store the module file index, + // so it is meaningless to optimize the source locations into small + // integers. Let's try to always use the raw encodings. + assert(Loc.getOffset() >= BaseOffset); + Loc = Loc.getLocWithOffset(-BaseOffset); + RawLocEncoding Encoded = encodeRaw(Loc.getRawEncoding()); + assert(Encoded < ((RawLocEncoding)1 << 32)); + + assert(BaseModuleFileIndex < ((RawLocEncoding)1 << 32)); + Encoded |= (RawLocEncoding)BaseModuleFileIndex << 32; + return Encoded; } -inline SourceLocation -SourceLocationEncoding::decode(uint64_t Encoded, SourceLocationSequence *Seq) { - return Seq ? Seq->decode(Encoded) - : SourceLocation::getFromRawEncoding(decodeRaw(Encoded)); +inline std::pair<SourceLocation, unsigned> +SourceLocationEncoding::decode(RawLocEncoding Encoded, + SourceLocationSequence *Seq) { + unsigned ModuleFileIndex = Encoded >> 32; + + if (!ModuleFileIndex) + return {Seq ? Seq->decode(Encoded) + : SourceLocation::getFromRawEncoding(decodeRaw(Encoded)), + ModuleFileIndex}; + + Encoded &= ((RawLocEncoding)1 << 33) - 1; ---------------- Bigcheese wrote:
We have `maskTrailingOnes<RawLocEncoding>(32)` which is a bit clearer than raw bit math. https://github.com/llvm/llvm-project/pull/86912 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits