[llvm] 8c68eb8 - [SampleFDO] Make FSDiscriminator flag part of function parameters
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 21 14:38:34 PDT 2021
Author: Rong Xu
Date: 2021-06-21T14:37:45-07:00
New Revision: 8c68eb83065cc531fde28fc743a7278190f9eb65
URL: https://github.com/llvm/llvm-project/commit/8c68eb83065cc531fde28fc743a7278190f9eb65
DIFF: https://github.com/llvm/llvm-project/commit/8c68eb83065cc531fde28fc743a7278190f9eb65.diff
LOG: [SampleFDO] Make FSDiscriminator flag part of function parameters
Add a parameter of IsFSDiscriminator to function
getBaseDiscriminatorFromDiscriminator().
This function currently checks the internal flag of
--enable-fs-discriminator. This is not good because we might
change the default value of the internal flag.
Note that we have a default parameter. This is just
because create_afdo_tool has a call-site to it.
I will remove the default parameter in a later patch.
Differential Revision: https://reviews.llvm.org/D104584
Added:
Modified:
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
llvm/tools/llvm-profgen/ProfiledBinary.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index e5d4c29ad228..e5e41e288411 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1744,8 +1744,10 @@ class DILocation : public MDNode {
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 +2200,8 @@ DILocation::cloneWithDiscriminator(unsigned Discriminator) const {
}
unsigned DILocation::getBaseDiscriminator() const {
- return getBaseDiscriminatorFromDiscriminator(getDiscriminator());
+ return getBaseDiscriminatorFromDiscriminator(getDiscriminator(),
+ EnableFSDiscriminator);
}
unsigned DILocation::getDuplicationFactor() const {
diff --git a/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h b/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
index d29f3bf91a70..e0759d359dbe 100644
--- a/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
+++ b/llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
@@ -279,7 +279,12 @@ SampleProfileLoaderBaseImpl<BT>::getInstWeightImpl(const InstructionT &Inst) {
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();
+
ErrorOr<uint64_t> R = FS->findSamplesAt(LineOffset, Discriminator);
if (R) {
bool FirstMark =
@@ -298,11 +303,9 @@ SampleProfileLoaderBaseImpl<BT>::getInstWeightImpl(const InstructionT &Inst) {
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;
}
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 464616f6059a..afca9eab1da0 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -440,7 +440,8 @@ FrameLocationStack ProfiledBinary::symbolize(const InstructionPointer &IP,
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);
}
More information about the llvm-commits
mailing list