[llvm] [ProfCheck][NFC] Make Function argument from branch weight setter optional (PR #166032)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 2 00:12:05 PDT 2025
================
@@ -274,9 +274,10 @@ void llvm::setExplicitlyUnknownBranchWeights(Instruction &I,
}
void llvm::setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I,
- Function &F,
- StringRef PassName) {
- if (std::optional<Function::ProfileCount> EC = F.getEntryCount();
+ StringRef PassName,
+ const Function *F) {
+ F = F ? F : I.getFunction();
+ if (std::optional<Function::ProfileCount> EC = F->getEntryCount();
----------------
boomanaiden154 wrote:
Do we want to add an assert here that `F` is not `nullptr`?
This refactoring does add a footgun in that if you have an Instruction that is not attached to a function, but forget to pass in the function explicitly, we then try to call `getEntryCount` on `nullptr`. I guess there ends up being a tradeoff on callsite complexity in the normal place (where I is attached to a function) versus ensuring we correctly handle the edge case in all circumstances. No real opinion on my end on what is better.
https://github.com/llvm/llvm-project/pull/166032
More information about the llvm-commits
mailing list