-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[PGO] Add llvm.loop.estimated_trip_count
metadata
#148758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jdenny-ornl
merged 11 commits into
main
from
users/jdenny-ornl/pgo-estimated-trip-count
Jul 31, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
13d1fbb
[PGO] Add `llvm.loop.estimated_trip_count` metadata
jdenny-ornl db5920a
Merge branch 'main' into pgo-estimated-trip-count
jdenny-ornl 47fbe85
Add PGOEstimateTripCounts in more cases
jdenny-ornl f8097fb
Add unused initialization
jdenny-ornl 7b27203
Simplify some test changes
jdenny-ornl 4c4669a
Extend verify pass to cover new metadata
jdenny-ornl 0f40efd
Fix test for some builds
jdenny-ornl 2791a1c
Merge branch 'main' into pgo-estimated-trip-count
jdenny-ornl 6148922
Apply some small reviewer suggestions
jdenny-ornl 3a49b43
Attempt to fix windows pre-commit CI
jdenny-ornl 2f7daa8
Merge branch 'main' into pgo-estimated-trip-count
jdenny-ornl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
llvm/include/llvm/Transforms/Instrumentation/PGOEstimateTripCounts.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===- PGOEstimateTripCounts.h ----------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_PGOESTIMATETRIPCOUNTS_H | ||
#define LLVM_TRANSFORMS_INSTRUMENTATION_PGOESTIMATETRIPCOUNTS_H | ||
|
||
#include "llvm/IR/PassManager.h" | ||
|
||
namespace llvm { | ||
|
||
struct PGOEstimateTripCountsPass | ||
: public PassInfoMixin<PGOEstimateTripCountsPass> { | ||
PGOEstimateTripCountsPass() {} | ||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_PGOESTIMATETRIPCOUNTS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
llvm/lib/Transforms/Instrumentation/PGOEstimateTripCounts.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/Transforms/Instrumentation/PGOEstimateTripCounts.h" | ||
#include "llvm/Analysis/LoopInfo.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/Transforms/Utils/LoopUtils.h" | ||
|
||
using namespace llvm; | ||
|
||
#define DEBUG_TYPE "pgo-estimate-trip-counts" | ||
|
||
static bool runOnLoop(Loop *L) { | ||
bool MadeChange = false; | ||
std::optional<unsigned> TC = getLoopEstimatedTripCount( | ||
L, /*EstimatedLoopInvocationWeight=*/nullptr, /*DbgForInit=*/true); | ||
MadeChange |= setLoopEstimatedTripCount(L, TC); | ||
jdenny-ornl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for (Loop *SL : *L) | ||
MadeChange |= runOnLoop(SL); | ||
return MadeChange; | ||
} | ||
|
||
PreservedAnalyses PGOEstimateTripCountsPass::run(Module &M, | ||
jdenny-ornl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ModuleAnalysisManager &AM) { | ||
FunctionAnalysisManager &FAM = | ||
AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); | ||
bool MadeChange = false; | ||
LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": start\n"); | ||
for (Function &F : M) { | ||
if (F.isDeclaration()) | ||
continue; | ||
LoopInfo *LI = &FAM.getResult<LoopAnalysis>(F); | ||
if (!LI) | ||
continue; | ||
for (Loop *L : *LI) | ||
MadeChange |= runOnLoop(L); | ||
} | ||
LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": end\n"); | ||
return MadeChange ? PreservedAnalyses::none() : PreservedAnalyses::all(); | ||
jdenny-ornl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.