[clang] [Modules] No transitive source location change (PR #86912)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 15 01:06:17 PDT 2024
================
@@ -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;
----------------
ChuanqiXu9 wrote:
Done.
https://github.com/llvm/llvm-project/pull/86912
More information about the cfe-commits
mailing list