================ @@ -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; ---------------- Bigcheese wrote:
Were you going to change this to only reserve 16 bits for module index? 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