Author: Rahman Lavaee Date: 2026-11-17T12:09:24-08:00 New Revision: 8343b84ae86602faf0abfc8ce012b29b6574dafb
URL: https://github.com/llvm/llvm-project/commit/8343b84ae86602faf0abfc8ce012b29b6574dafb DIFF: https://github.com/llvm/llvm-project/commit/8343b84ae86602faf0abfc8ce012b29b6574dafb.diff LOG: [clang:codegen][Propeller] Supplement missing block weights using an AFDO profile (#236242) When generating basic block sections with Propeller CFG profiles, blocks that are cold in a non-representative load test can be split into cold sections even though they are warm in production. Add `-sample-profile-supplement` and `-sample-profile-supplement-remapping-file` to supplement the Propeller profile with a representative sample profile, ideally collected in production. `BasicBlockMatchingAndInference` reads the sample profile for each module and looks up block weights itself rather than calling SampleProfileLoader. Only line-based, non-context-sensitive sample profiles are currently supported, and a profile must be flow-sensitive exactly when `-enable-fs-discriminator` is set; unsupported or mismatched profiles are ignored with a warning. For each function, only blocks with zero Propeller samples are supplemented so blocks covered by Propeller keep their Propeller weights. Supplement block weights are scaled so that the supplement entry weight (entry-block body samples, falling back to head samples) matches the Propeller entry block weight; functions with neither entry-block samples nor head samples in the supplement are skipped since their scale is unknown. Blocks without supplement samples, or whose scaled weight rounds to zero, are left unchanged. `SampleProfileInference` then computes block and edge weights from the combined profile. Supplementation has shown up to 2% performance improvement on an internal binary with simulated load tests representing production workloads. For now, the supplement is only used with `-basic-block-section-match-infer` and `-propeller-match-bbid`. The options are not named after Propeller so that other profile consumers, such as FDO builds without Propeller, can use them later. Supplementation is not supported with a SampleFDO base profile. Reusing `-fprofile-sample-use` is not feasible as it currently collides with `-fprofile-use` (IR profile), which is primarily used for Propeller builds. Assisted by: Gemini-4-Carbon, Claude Opus 5.5 Added: clang/test/CodeGen/basic-block-sections-sample-profile-supplement.cpp llvm/test/CodeGen/X86/basic-block-sections-sample-profile-supplement.ll Modified: llvm/include/llvm/CodeGen/BasicBlockMatchingAndInference.h llvm/lib/CodeGen/BasicBlockMatchingAndInference.cpp llvm/lib/CodeGen/CodeGenOptions.td Removed: ################################################################################ diff --git a/clang/test/CodeGen/basic-block-sections-sample-profile-supplement.cpp b/clang/test/CodeGen/basic-block-sections-sample-profile-supplement.cpp new file mode 100644 index 0000000000000..3bcb37e1fd2da --- /dev/null +++ b/clang/test/CodeGen/basic-block-sections-sample-profile-supplement.cpp @@ -0,0 +1,80 @@ +// REQUIRES: x86-registered-target + +// Test that -sample-profile-supplement and +// -sample-profile-supplement-remapping-file read through LLVMContext's VFS +// (and thus comply with Clang's IO sandbox and respect -ivfsoverlay). + +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: sed -e "s@DIR@%{/t:regex_replacement}@g" %t/vfs.yaml.in > %t/vfs.yaml + +// Without a supplement, block #1 (`baz()`) has 0 Propeller samples and is +// placed in `.text.split._Z3foob`. +// RUN: %clang_cc1 -triple x86_64-pc-linux -S -O0 -debug-info-kind=line-tables-only \ +// RUN: -ffunction-sections -fbasic-block-sections=list=%t/propeller.txt \ +// RUN: -mllvm -basic-block-section-match-infer -mllvm -propeller-match-bbid \ +// RUN: %t/test.cpp -o - | FileCheck %s --check-prefixes=CHECK,WITHOUT-SUPPLEMENT + +// With a supplement and remapping file mapped only through the VFS overlay, +// `_Z3barb` remaps to `_Z3foob`, block #1's weight scales to 1, and `baz()` +// stays in `.text._Z3foob`. +// RUN: %clang_cc1 -triple x86_64-pc-linux -S -O0 -debug-info-kind=line-tables-only \ +// RUN: -ivfsoverlay %t/vfs.yaml \ +// RUN: -ffunction-sections -fbasic-block-sections=list=%t/propeller.txt \ +// RUN: -mllvm -basic-block-section-match-infer -mllvm -propeller-match-bbid \ +// RUN: -mllvm -sample-profile-supplement=%/t/virtual.prof \ +// RUN: -mllvm -sample-profile-supplement-remapping-file=%/t/virtual.remap \ +// RUN: %t/test.cpp -o - | FileCheck %s --check-prefixes=CHECK,WITH-SUPPLEMENT + +// CHECK: .section .text._Z3foob,"ax",@progbits +// CHECK-LABEL: _Z3foob: + +// WITHOUT-SUPPLEMENT: .section .text.split._Z3foob,"ax",@progbits +// WITHOUT-SUPPLEMENT-LABEL: _Z3foob.cold: +// WITHOUT-SUPPLEMENT: callq _Z3bazv + +// WITH-SUPPLEMENT: callq _Z3bazv +// WITH-SUPPLEMENT-NOT: .section .text.split._Z3foob + +//--- test.cpp +void baz(); + +void foo(bool cond) { + if (!cond) + baz(); +} + +//--- propeller.txt +v1 +f _Z3foob +g 0:100,1:0,2:100 1:0,2:0 2:100 + +//--- real.prof +_Z3barb:2000:1000 + 2: 5 + +//--- real.remap +name 3foo 3bar + +//--- vfs.yaml.in +{ + "version": 0, + "roots": [ + { + "name": "DIR", + "type": "directory", + "contents": [ + { + "name": "virtual.prof", + "type": "file", + "external-contents": "DIR/real.prof" + }, + { + "name": "virtual.remap", + "type": "file", + "external-contents": "DIR/real.remap" + } + ] + } + ] +} diff --git a/llvm/include/llvm/CodeGen/BasicBlockMatchingAndInference.h b/llvm/include/llvm/CodeGen/BasicBlockMatchingAndInference.h index cf6d901723a7b..56f95474bda13 100644 --- a/llvm/include/llvm/CodeGen/BasicBlockMatchingAndInference.h +++ b/llvm/include/llvm/CodeGen/BasicBlockMatchingAndInference.h @@ -16,9 +16,15 @@ #include "llvm/CodeGen/BasicBlockSectionsProfileReader.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Transforms/Utils/SampleProfileInference.h" +#include <memory> namespace llvm { +class Module; +namespace sampleprof { +class SampleProfileReader; +} // namespace sampleprof + class LLVM_ABI BasicBlockMatchingAndInference : public MachineFunctionPass { private: using Edge = std::pair<const MachineBasicBlock *, const MachineBasicBlock *>; @@ -37,6 +43,7 @@ class LLVM_ABI BasicBlockMatchingAndInference : public MachineFunctionPass { public: static char ID; BasicBlockMatchingAndInference(); + ~BasicBlockMatchingAndInference() override; StringRef getPassName() const override { return "Basic Block Matching and Inference"; @@ -44,12 +51,20 @@ class LLVM_ABI BasicBlockMatchingAndInference : public MachineFunctionPass { void getAnalysisUsage(AnalysisUsage &AU) const override; + bool doInitialization(Module &M) override; bool runOnMachineFunction(MachineFunction &F) override; + bool doFinalization(Module &M) override; std::optional<WeightInfo> getWeightInfo(StringRef FuncName) const; private: StringMap<WeightInfo> ProgramWeightInfo; + // The supplemental sample profile of the current module. Null if no + // supplemental sample profile is given or it fails to load. + std::unique_ptr<sampleprof::SampleProfileReader> SampleReader; + + void supplementWithSampleProfile(MachineFunction &MF, + WeightInfo &MatchWeight); WeightInfo initWeightInfoByMatching(MachineFunction &MF); WeightInfo initWeightInfoByBBID(MachineFunction &MF, const CFGProfile &CFG); diff --git a/llvm/lib/CodeGen/BasicBlockMatchingAndInference.cpp b/llvm/lib/CodeGen/BasicBlockMatchingAndInference.cpp index b49280b753200..f54ed897c403a 100644 --- a/llvm/lib/CodeGen/BasicBlockMatchingAndInference.cpp +++ b/llvm/lib/CodeGen/BasicBlockMatchingAndInference.cpp @@ -22,11 +22,19 @@ #include "CodeGenOptions.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/Analysis/ProfileSummaryInfo.h" #include "llvm/CodeGen/BasicBlockSectionsProfileReader.h" #include "llvm/CodeGen/MachineBlockHashInfo.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/IR/DebugInfoMetadata.h" +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/InitializePasses.h" +#include "llvm/ProfileData/SampleProf.h" +#include "llvm/ProfileData/SampleProfReader.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/MathExtras.h" using namespace llvm; @@ -83,9 +91,66 @@ INITIALIZE_PASS_END(BasicBlockMatchingAndInference, "machine-block-match-infer", char BasicBlockMatchingAndInference::ID = 0; +namespace { +/// Looks up the sampled weights of the instructions of one machine function in +/// a line-based sample profile. This is the lookup part of +/// SampleProfileLoaderBaseImpl without its weight propagation, remarks and +/// coverage tracking, which are not needed to supplement the Propeller profile. +class FunctionSamplesQuery { +public: + FunctionSamplesQuery(const FunctionSamples &Samples, + SampleProfileReaderItaniumRemapper *Remapper) + : Samples(Samples), Remapper(Remapper) {} + + /// Returns the weight of \p MI, or an error if it has no samples. + ErrorOr<uint64_t> getInstWeight(const MachineInstr &MI) { + const DILocation *DIL = MI.getDebugLoc(); + if (!DIL) + return std::error_code(); + // Find the samples of the inlined instance MI comes from. + auto [It, Inserted] = InlinedSamplesCache.try_emplace(DIL, nullptr); + if (Inserted) + It->second = Samples.findFunctionSamples(DIL, Remapper); + if (!It->second) + return std::error_code(); + uint32_t Discriminator = EnableFSDiscriminator + ? DIL->getDiscriminator() + : DIL->getBaseDiscriminator(); + return It->second->findSamplesAt(FunctionSamples::getOffset(DIL), + Discriminator); + } + + /// Returns the maximum weight among the non-meta instructions of \p MBB, or + /// an error if none of them has samples. + ErrorOr<uint64_t> getBlockWeight(const MachineBasicBlock &MBB) { + uint64_t Max = 0; + bool HasWeight = false; + for (const MachineInstr &MI : MBB) { + if (MI.isMetaInstruction()) + continue; + if (ErrorOr<uint64_t> W = getInstWeight(MI)) { + Max = std::max(Max, *W); + HasWeight = true; + } + } + if (!HasWeight) + return std::error_code(); + return Max; + } + +private: + const FunctionSamples &Samples; + SampleProfileReaderItaniumRemapper *Remapper; + // Samples of the inlined instance each location comes from. + DenseMap<const DILocation *, const FunctionSamples *> InlinedSamplesCache; +}; +} // namespace + BasicBlockMatchingAndInference::BasicBlockMatchingAndInference() : MachineFunctionPass(ID) {} +BasicBlockMatchingAndInference::~BasicBlockMatchingAndInference() = default; + void BasicBlockMatchingAndInference::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<MachineBlockHashInfo>(); AU.addRequired<BasicBlockSectionsProfileReaderWrapperPass>(); @@ -239,6 +304,121 @@ void BasicBlockMatchingAndInference::generateWeightInfoByInference( std::move(BlockWeights), std::move(EdgeWeights)}); } +bool BasicBlockMatchingAndInference::doInitialization(Module &M) { + const CodeGenOptions &Opts = getCodeGenOptions(M); + StringRef ProfileFile = Opts.sample_profile_supplement; + // Only the weights matched by BBIDs are supplemented. + if (ProfileFile.empty() || !Opts.propeller_match_bbid) + return false; + LLVMContext &Ctx = M.getContext(); + if (ProfileSummaryInfo(M).hasSampleProfile() || + !Opts.fs_profile_file.empty()) { + Ctx.diagnose(DiagnosticInfoSampleProfile( + ProfileFile, + "Supplemental sample profiles are not supported with SampleFDO", + DS_Warning)); + return false; + } + auto ReaderOrErr = SampleProfileReader::create( + ProfileFile, Ctx, Ctx.getVirtualFileSystem(), + EnableFSDiscriminator ? FSDiscriminatorPass::PassLast + : FSDiscriminatorPass::Base, + Opts.sample_profile_supplement_remapping_file); + if (std::error_code EC = ReaderOrErr.getError()) { + Ctx.diagnose(DiagnosticInfoSampleProfile( + ProfileFile, + "Could not open supplemental sample profile: " + EC.message())); + return false; + } + std::unique_ptr<SampleProfileReader> Reader = std::move(*ReaderOrErr); + Reader->setModule(&M); + if (Reader->read() != sampleprof_error::success) { + Ctx.diagnose(DiagnosticInfoSampleProfile( + ProfileFile, "Could not read supplemental sample profile")); + return false; + } + if (Reader->profileIsProbeBased()) { + Ctx.diagnose(DiagnosticInfoSampleProfile( + ProfileFile, + "Pseudo probe based supplemental sample profiles are not supported", + DS_Warning)); + return false; + } + if (Reader->profileIsCS()) { + Ctx.diagnose(DiagnosticInfoSampleProfile( + ProfileFile, + "Context-sensitive supplemental sample profiles are not supported", + DS_Warning)); + return false; + } + if (Reader->profileIsFS() && !EnableFSDiscriminator) { + Ctx.diagnose(DiagnosticInfoSampleProfile( + ProfileFile, + "Flow-sensitive supplemental sample profiles require " + "-enable-fs-discriminator", + DS_Warning)); + return false; + } + if (!Reader->profileIsFS() && EnableFSDiscriminator) { + Ctx.diagnose(DiagnosticInfoSampleProfile( + ProfileFile, + "Non-flow-sensitive supplemental sample profiles are not supported " + "with -enable-fs-discriminator", + DS_Warning)); + return false; + } + SampleReader = std::move(Reader); + return false; +} + +void BasicBlockMatchingAndInference::supplementWithSampleProfile( + MachineFunction &MF, WeightInfo &MatchWeight) { + if (!SampleReader) + return; + const FunctionSamples *Samples = + SampleReader->getSamplesFor(MF.getFunction()); + if (!Samples || Samples->empty()) + return; + FunctionSamplesQuery Query(*Samples, SampleReader->getRemapper()); + + // Scale the weights of the supplemental profile so that the entry block + // weights of both profiles agree. Skip functions with neither entry-block + // samples nor head samples, since their scale is unknown. + const MachineBasicBlock &EntryBB = MF.front(); + uint64_t PropellerEntryWeight = + std::max<uint64_t>(MatchWeight.BlockWeights.lookup(&EntryBB), 1); + uint64_t SampleEntryWeight = 0; + if (ErrorOr<uint64_t> W = Query.getBlockWeight(EntryBB)) + SampleEntryWeight = *W; + if (SampleEntryWeight == 0) + SampleEntryWeight = Samples->getHeadSamples(); + if (SampleEntryWeight == 0) + return; + + for (const MachineBasicBlock &MBB : MF) { + // Only supplement blocks that have no samples in the Propeller profile, so + // that code executed in production is not assumed cold prior to inference. + // Blocks that already have Propeller samples keep their Propeller weight. + if (MatchWeight.BlockWeights.lookup(&MBB) != 0) + continue; + ErrorOr<uint64_t> SampleWeight = Query.getBlockWeight(MBB); + if (!SampleWeight) + continue; + // Skip weights that round to zero, so that blocks missing from + // BlockWeights stay unknown to inference rather than known to be cold. + uint64_t Weight = + mulDivNearest(*SampleWeight, PropellerEntryWeight, SampleEntryWeight); + if (Weight != 0) + MatchWeight.BlockWeights[&MBB] = Weight; + } +} + +bool BasicBlockMatchingAndInference::doFinalization(Module &M) { + // The profile is read for each module. + SampleReader.reset(); + return false; +} + bool BasicBlockMatchingAndInference::runOnMachineFunction(MachineFunction &MF) { if (MF.empty()) return false; @@ -251,6 +431,7 @@ bool BasicBlockMatchingAndInference::runOnMachineFunction(MachineFunction &MF) { BasicBlockMatchingAndInference::WeightInfo MatchWeight; if (Opts.propeller_match_bbid) { MatchWeight = initWeightInfoByBBID(MF, *CFG); + supplementWithSampleProfile(MF, MatchWeight); } else { MatchWeight = initWeightInfoByMatching(MF); // If the ratio of the number of MBBs in matching to the total number of diff --git a/llvm/lib/CodeGen/CodeGenOptions.td b/llvm/lib/CodeGen/CodeGenOptions.td index 31d572a12a094..4a98cfdab0986 100644 --- a/llvm/lib/CodeGen/CodeGenOptions.td +++ b/llvm/lib/CodeGen/CodeGenOptions.td @@ -15,6 +15,13 @@ defm : ValueField<"propeller-infer-threshold", "float", "0.6f", "Threshold for infer stale profile">; defm : BoolField<"propeller-match-bbid", "false", "Match basic blocks using BBIDs instead of hashes for Propeller inference">; +let MetaVarName = "<filename>" in +defm : ValueField<"sample-profile-supplement", "StringRef", "", + "Sample profile used to supplement the weights of basic blocks without samples in another profile. " + "Currently used with basic-block-sections profile only.">; +let MetaVarName = "<filename>" in +defm : ValueField<"sample-profile-supplement-remapping-file", "StringRef", "", + "Symbol remapping file for -sample-profile-supplement">; // CodeGenPrepare.cpp defm : BoolField<"bbsections-guided-section-prefix", "true", diff --git a/llvm/test/CodeGen/X86/basic-block-sections-sample-profile-supplement.ll b/llvm/test/CodeGen/X86/basic-block-sections-sample-profile-supplement.ll new file mode 100644 index 0000000000000..98fbd7ccee1dc --- /dev/null +++ b/llvm/test/CodeGen/X86/basic-block-sections-sample-profile-supplement.ll @@ -0,0 +1,129 @@ +; RUN: echo 'v1' > %t.propeller +; RUN: echo 'f foo' >> %t.propeller +; RUN: echo 'g 0:100,1:0,2:100 1:0,2:0 2:100' >> %t.propeller +; RUN: echo 'foo:2000:1000' > %t.prof +; RUN: echo ' 3.1: 5' >> %t.prof +; RUN: echo 'foo:2000:1000' > %t.fs.prof +; RUN: echo ' 3.67108866: 5' >> %t.fs.prof +; RUN: echo 'foo:2000:1000' > %t.round_zero.prof +; RUN: echo ' 3.1: 4' >> %t.round_zero.prof +; RUN: echo 'foo:2000:1000' > %t.probe.prof +; RUN: echo ' 3.1: 5' >> %t.probe.prof +; RUN: echo ' !CFGChecksum: 123' >> %t.probe.prof + +; Case 1: Without a sample profile supplement, block 1 has 0 Propeller samples and is split into cold section. +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid | \ +; RUN: FileCheck %s --check-prefixes=CHECK,WITHOUT-SUPPLEMENT + +; Case 2: With a sample profile supplement (using a nonzero base discriminator), block 1 gets its samples scaled to the Propeller entry weight (5 * 100 / 1000 rounds to 1), and is kept in the main section even without even flow distribution. When the scaled weight rounds to 0 (4 * 100 / 1000), block 1 stays in the cold section. +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-supplement=%t.prof | \ +; RUN: FileCheck %s --check-prefixes=CHECK,WITH-SUPPLEMENT +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-even-flow-distribution=false -sample-profile-supplement=%t.prof | \ +; RUN: FileCheck %s --check-prefixes=CHECK,WITH-SUPPLEMENT +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-supplement=%t.round_zero.prof | \ +; RUN: FileCheck %s --check-prefixes=CHECK,WITHOUT-SUPPLEMENT + +; Case 3: A missing supplemental sample profile is diagnosed. +; RUN: not llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-supplement=%t.missing 2>&1 | \ +; RUN: FileCheck %s --check-prefix=MISSING +; MISSING: error: {{.*}}.missing: Could not open supplemental sample profile: + +; Case 4: The supplemental sample profile is not read without -basic-block-section-match-infer or -propeller-match-bbid. +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -propeller-match-bbid -sample-profile-supplement=%t.missing 2>&1 | \ +; RUN: FileCheck %s --check-prefix=UNUSED +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -sample-profile-supplement=%t.missing 2>&1 | \ +; RUN: FileCheck %s --check-prefix=UNUSED +; UNUSED-NOT: Could not open supplemental sample profile + +; Case 5: Supplemental sample profiles are ignored with a warning and not read when used with SampleFDO. +; The IR profile loader reads the primary profile in opt. Missing supplemental profile passed to llc is not read. +; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.prof | \ +; RUN: llc -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-supplement=%t.missing 2>&1 | \ +; RUN: FileCheck %s --check-prefixes=SAMPLEFDO,CHECK,WITHOUT-SUPPLEMENT +; The MIR profile loader reads the FS primary profile in llc. Pseudo-probe-based supplemental profile is not read. +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -enable-fs-discriminator -profile-isfs -fs-profile-file=%t.fs.prof -sample-profile-supplement=%t.probe.prof 2>&1 | \ +; RUN: FileCheck %s --check-prefixes=SAMPLEFDO,CHECK,WITHOUT-SUPPLEMENT +; SAMPLEFDO: warning: {{.*}}: Supplemental sample profiles are not supported with SampleFDO + +; Case 6: Flow-sensitive supplemental sample profiles and -enable-fs-discriminator must match. +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -profile-isfs -sample-profile-supplement=%t.fs.prof 2>&1 | \ +; RUN: FileCheck %s --check-prefixes=FS-WITHOUT-ENABLE,CHECK,WITHOUT-SUPPLEMENT +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -enable-fs-discriminator -sample-profile-supplement=%t.prof 2>&1 | \ +; RUN: FileCheck %s --check-prefixes=NON-FS-WITH-ENABLE,CHECK,WITHOUT-SUPPLEMENT +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -profile-isfs -enable-fs-discriminator -sample-profile-supplement=%t.fs.prof | \ +; RUN: FileCheck %s --check-prefixes=CHECK,WITH-SUPPLEMENT +; FS-WITHOUT-ENABLE: warning: {{.*}}.fs.prof: Flow-sensitive supplemental sample profiles require -enable-fs-discriminator +; NON-FS-WITH-ENABLE: warning: {{.*}}.prof: Non-flow-sensitive supplemental sample profiles are not supported with -enable-fs-discriminator + +; Case 7: Context-sensitive and pseudo-probe supplemental sample profiles are ignored with a warning. +; RUN: echo '[foo]:2000:1000' > %t.cs.prof +; RUN: echo ' 3.1: 5' >> %t.cs.prof +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-supplement=%t.cs.prof 2>&1 | \ +; RUN: FileCheck %s --check-prefixes=CS-PROF,CHECK,WITHOUT-SUPPLEMENT +; CS-PROF: warning: {{.*}}.cs.prof: Context-sensitive supplemental sample profiles are not supported +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-supplement=%t.probe.prof 2>&1 | \ +; RUN: FileCheck %s --check-prefixes=PROBE-PROF,CHECK,WITHOUT-SUPPLEMENT +; PROBE-PROF: warning: {{.*}}.probe.prof: Pseudo probe based supplemental sample profiles are not supported + +; Case 8: Functions with neither entry-block samples nor head samples in the supplement are skipped, while entry-block body samples suffice when head samples are 0. +; RUN: echo 'foo:2000:0' > %t.no_entry.prof +; RUN: echo ' 3.1: 5' >> %t.no_entry.prof +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-supplement=%t.no_entry.prof | \ +; RUN: FileCheck %s --check-prefixes=CHECK,WITHOUT-SUPPLEMENT +; RUN: echo 'foo:2000:0' > %t.entry_body.prof +; RUN: echo ' 0: 1000' >> %t.entry_body.prof +; RUN: echo ' 3.1: 5' >> %t.entry_body.prof +; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t.propeller -basic-block-section-match-infer -propeller-match-bbid -sample-profile-supplement=%t.entry_body.prof | \ +; RUN: FileCheck %s --check-prefixes=CHECK,WITH-SUPPLEMENT + +define void @foo(i1 zeroext %0) nounwind !dbg !4 { + %2 = alloca i8, align 1 + %3 = zext i1 %0 to i8 + store i8 %3, ptr %2, align 1, !dbg !10 + %4 = load i8, ptr %2, align 1, !dbg !11 + %5 = trunc i8 %4 to i1, !dbg !11 + br i1 %5, label %8, label %6, !dbg !12 + +6: ; preds = %1 + %7 = call i32 @baz(), !dbg !13 + br label %8, !dbg !14 + +8: ; preds = %6, %1 + ret void, !dbg !15 +} + +declare i32 @baz() + +; CHECK: .section .text.foo,"ax",@progbits +; CHECK-LABEL: foo: +; CHECK-LABEL: # %bb.0: +; CHECK-LABEL: .LBB0_2: +; CHECK: retq + +; WITHOUT-SUPPLEMENT: .section .text.split.foo,"ax",@progbits +; WITHOUT-SUPPLEMENT-LABEL: foo.cold: +; WITHOUT-SUPPLEMENT: callq baz@PLT + +; WITH-SUPPLEMENT-LABEL: .LBB0_1: +; WITH-SUPPLEMENT: callq baz@PLT +; WITH-SUPPLEMENT-NOT: .section .text.split.foo + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly) +!1 = !DIFile(filename: "test.cc", directory: "/tmp") +!2 = !{i32 2, !"Dwarf Version", i32 4} +!3 = !{i32 2, !"Debug Info Version", i32 3} +!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0) +!5 = !DISubroutineType(types: !6) +!6 = !{null} +; 67108866 = (1 << 26) | 2: non-FS prefix encoding decodes to base discriminator 1, +; while FS mode reads the full discriminator 67108866 (base 2 + PassLast bit 26). +!7 = distinct !DILexicalBlockFile(scope: !4, file: !1, discriminator: 67108866) +!10 = !DILocation(line: 1, column: 1, scope: !4) +!11 = !DILocation(line: 2, column: 1, scope: !4) +!12 = !DILocation(line: 3, column: 1, scope: !4) +!13 = !DILocation(line: 4, column: 1, scope: !7) +!14 = !DILocation(line: 5, column: 1, scope: !4) +!15 = !DILocation(line: 6, column: 1, scope: !4) _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
