[llvm] CodeGenPrepare: Null check pointers (PR #142350)
Akshat Oke via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 2 02:01:51 PDT 2025
https://github.com/optimisan updated https://github.com/llvm/llvm-project/pull/142350
>From a313c87fe132fc576304a7334ee7153acfb5433a Mon Sep 17 00:00:00 2001
From: Akshat Oke <Akshat.Oke at amd.com>
Date: Mon, 2 Jun 2025 09:00:13 +0000
Subject: [PATCH] CodeGenPrepare: Null check pointers
---
llvm/lib/CodeGen/CodeGenPrepare.cpp | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 76f27623c8656..a191dce96be27 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -559,6 +559,7 @@ PreservedAnalyses CodeGenPreparePass::run(Function &F,
}
bool CodeGenPrepare::run(Function &F, FunctionAnalysisManager &AM) {
+ assert(TM && "TargetMachine is required for CodeGenPrepare");
DL = &F.getDataLayout();
SubtargetInfo = TM->getSubtargetImpl(F);
TLI = SubtargetInfo->getTargetLowering();
@@ -589,16 +590,16 @@ bool CodeGenPrepare::_run(Function &F) {
// counts based hotness overwrite the cold attribute.
// This is a conservative behabvior.
if (F.hasFnAttribute(Attribute::Hot) ||
- PSI->isFunctionHotInCallGraph(&F, *BFI))
+ (PSI && PSI->isFunctionHotInCallGraph(&F, *BFI)))
F.setSectionPrefix("hot");
// If PSI shows this function is not hot, we will placed the function
// into unlikely section if (1) PSI shows this is a cold function, or
// (2) the function has a attribute of cold.
- else if (PSI->isFunctionColdInCallGraph(&F, *BFI) ||
+ else if ((PSI && PSI->isFunctionColdInCallGraph(&F, *BFI)) ||
F.hasFnAttribute(Attribute::Cold))
F.setSectionPrefix("unlikely");
- else if (ProfileUnknownInSpecialSection && PSI->hasPartialSampleProfile() &&
- PSI->isFunctionHotnessUnknown(F))
+ else if (ProfileUnknownInSpecialSection && PSI &&
+ PSI->hasPartialSampleProfile() && PSI->isFunctionHotnessUnknown(F))
F.setSectionPrefix("unknown");
}
More information about the llvm-commits
mailing list