[llvm] [MemProf] Prune unneeded non-cold contexts (PR #124823)
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 10:30:01 PST 2025
================
@@ -220,6 +221,48 @@ declare dso_local noalias noundef i8* @malloc(i64 noundef)
EXPECT_EQ(Call4->getFnAttr("memprof").getValueAsString(), "notcold");
}
+// TODO: Use this matcher in existing tests.
+// ExpectedVals should be a vector of expected MIBs and their allocation type
+// and stack id contents in order, of type:
+// std::vector<std::pair<AllocationType, std::vector<unsigned>>>
+MATCHER_P(MemprofMetadataEquals, ExpectedVals, "Matching !memprof contents") {
+ auto PrintAndFail = [&]() {
+ std::string Buffer;
+ llvm::raw_string_ostream OS(Buffer);
+ OS << "Expected:\n";
+ for (auto &[ExpectedAllocType, ExpectedStackIds] : ExpectedVals) {
+ OS << "\t" << getAllocTypeAttributeString(ExpectedAllocType) << " { ";
+ for (auto Id : ExpectedStackIds)
+ OS << Id << " ";
+ OS << "}\n";
+ }
+ OS << "Got:\n";
+ arg->printTree(OS);
+ *result_listener << "!memprof metadata differs!\n" << Buffer;
+ return false;
+ };
+
+ if (ExpectedVals.size() != arg->getNumOperands())
+ return PrintAndFail();
+
+ for (size_t I = 0; I < ExpectedVals.size(); I++) {
+ const auto &[ExpectedAllocType, ExpectedStackIds] = ExpectedVals[I];
+ MDNode *MIB = dyn_cast<MDNode>(arg->getOperand(I));
+ if (getMIBAllocType(MIB) != ExpectedAllocType)
+ return PrintAndFail();
+ MDNode *StackMD = getMIBStackNode(MIB);
+ EXPECT_NE(StackMD, nullptr);
----------------
teresajohnson wrote:
I had ASSERT_NE here first but I get a compiler error:
llvm/unittests/Analysis/MemoryProfileInfoTest.cpp:254:5: error: cannot initialize return object of type 'bool' with an rvalue of type 'void'
ASSERT_NE(StackMD, nullptr);
https://github.com/llvm/llvm-project/pull/124823
More information about the llvm-commits
mailing list