-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[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
base: main
Are you sure you want to change the base?
Changes from all commits
13d1fbb
db5920a
47fbe85
f8097fb
7b27203
4c4669a
0f40efd
2791a1c
6148922
3a49b43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super-nitty, but can it be a loop pass? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that. I found it then automatically inserted LoopSimplifyPass and LCSSAPass before PGOEstimateTripCountsPass. Is that expected? It seems like PGOEstimateTripCountsPass shouldn't have such side effects. |
||
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(); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.