Index: llvm/include/llvm/IR/DebugInfoMetadata.h =================================================================== --- llvm/include/llvm/IR/DebugInfoMetadata.h +++ llvm/include/llvm/IR/DebugInfoMetadata.h @@ -1702,6 +1702,7 @@ /// Returns the base discriminator stored in the discriminator. inline unsigned getBaseDiscriminator() const; + inline unsigned getBaseDiscriminator(bool IsFSDiscriminator) const; /// Returns a new DILocation with duplication factor \p DF * current /// duplication factor encoded in the discriminator. The current duplication @@ -1744,8 +1745,10 @@ static unsigned getBaseDiscriminatorBits() { return getBaseFSBitEnd(); } /// Returns the base discriminator for a given encoded discriminator \p D. - static unsigned getBaseDiscriminatorFromDiscriminator(unsigned D) { - if (EnableFSDiscriminator) + static unsigned + getBaseDiscriminatorFromDiscriminator(unsigned D, + bool IsFSDiscriminator = false) { + if (IsFSDiscriminator) return getMaskedDiscriminator(D, getBaseDiscriminatorBits()); return getUnsignedFromPrefixEncoding(D); } @@ -2198,7 +2201,12 @@ } unsigned DILocation::getBaseDiscriminator() const { - return getBaseDiscriminatorFromDiscriminator(getDiscriminator()); + return getBaseDiscriminatorFromDiscriminator(getDiscriminator(), + EnableFSDiscriminator); +} +unsigned DILocation::getBaseDiscriminator(bool IsFSDiscriminator) const { + return getBaseDiscriminatorFromDiscriminator(getDiscriminator(), + IsFSDiscriminator); } unsigned DILocation::getDuplicationFactor() const { @@ -2213,7 +2221,7 @@ unsigned BD, DF, CI; if (EnableFSDiscriminator) { - BD = getBaseDiscriminator(); + BD = getBaseDiscriminator(/* IsFSDiscriminator */ true); if (D == BD) return this; return cloneWithDiscriminator(D); @@ -2234,7 +2242,7 @@ if (DF <= 1) return this; - unsigned BD = getBaseDiscriminator(); + unsigned BD = getBaseDiscriminator(/* IsFSDiscriminator */ false); unsigned CI = getCopyIdentifier(); if (Optional D = encodeDiscriminator(BD, DF, CI)) return cloneWithDiscriminator(*D); Index: llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h =================================================================== --- llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h +++ llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h @@ -279,7 +279,12 @@ const DILocation *DIL = DLoc; uint32_t LineOffset = FunctionSamples::getOffset(DIL); - uint32_t Discriminator = DIL->getBaseDiscriminator(); + uint32_t Discriminator; + if (EnableFSDiscriminator) + Discriminator = DIL->getDiscriminator(); + else + Discriminator = DIL->getBaseDiscriminator(/* IsFSDiscriminator */ false); + ErrorOr R = FS->findSamplesAt(LineOffset, Discriminator); if (R) { bool FirstMark = @@ -298,11 +303,9 @@ return Remark; }); } - LLVM_DEBUG(dbgs() << " " << DLoc.getLine() << "." - << DIL->getBaseDiscriminator() << ":" << Inst - << " (line offset: " << LineOffset << "." - << DIL->getBaseDiscriminator() << " - weight: " << R.get() - << ")\n"); + LLVM_DEBUG(dbgs() << " " << DLoc.getLine() << "." << Discriminator << ":" + << Inst << " (line offset: " << LineOffset << "." + << Discriminator << " - weight: " << R.get() << ")\n"); } return R; } Index: llvm/tools/llvm-profgen/ProfiledBinary.cpp =================================================================== --- llvm/tools/llvm-profgen/ProfiledBinary.cpp +++ llvm/tools/llvm-profgen/ProfiledBinary.cpp @@ -440,7 +440,8 @@ FunctionName = FunctionSamples::getCanonicalFnName(FunctionName); LineLocation Line(CallerFrame.Line - CallerFrame.StartLine, DILocation::getBaseDiscriminatorFromDiscriminator( - CallerFrame.Discriminator)); + CallerFrame.Discriminator, + /* IsFSDiscriminator */ false)); FrameLocation Callsite(FunctionName.str(), Line); CallStack.push_back(Callsite); }