-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[PGO] Test for inheritance relationships for instrprof
intrinsics
#89485
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
Conversation
Following up PR llvm#83511, added a test to cover the inheritance graph for these intrinsics.
@llvm/pr-subscribers-llvm-ir Author: Mircea Trofin (mtrofin) ChangesFollowing up PR #83511, added a test to cover the inheritance graph for these intrinsics. Full diff: https://github.com/llvm/llvm-project/pull/89485.diff 1 Files Affected:
diff --git a/llvm/unittests/IR/IntrinsicsTest.cpp b/llvm/unittests/IR/IntrinsicsTest.cpp
index a500346b66a5e4..715e7b9c6cdcd6 100644
--- a/llvm/unittests/IR/IntrinsicsTest.cpp
+++ b/llvm/unittests/IR/IntrinsicsTest.cpp
@@ -6,22 +6,57 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/IR/Intrinsics.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/IR/Constant.h"
+#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/SourceMgr.h"
#include "gtest/gtest.h"
+#include <algorithm>
+#include <cstdarg>
using namespace llvm;
namespace {
static const char *const NameTable1[] = {
- "llvm.foo",
- "llvm.foo.a",
- "llvm.foo.b",
- "llvm.foo.b.a",
- "llvm.foo.c",
+ "llvm.foo", "llvm.foo.a", "llvm.foo.b", "llvm.foo.b.a", "llvm.foo.c",
};
-TEST(IntrinNameLookup, Basic) {
+class IntrinsicsTest : public ::testing::Test {
+ LLVMContext Context;
+ std::unique_ptr<Module> M;
+ BasicBlock *BB = nullptr;
+
+ void TearDown() override { M.reset(); }
+
+ void SetUp() override {
+ M = std::make_unique<Module>("Test", Context);
+ auto F = M->getOrInsertFunction(
+ "test", FunctionType::get(Type::getVoidTy(Context), false));
+ BB = BasicBlock::Create(Context, "", cast<Function>(F.getCallee()));
+ EXPECT_NE(BB, nullptr);
+ }
+
+public:
+ Instruction *makeIntrinsic(Intrinsic::ID ID) const {
+ IRBuilder<> Builder(BB);
+ SmallVector<Value*, 4> ProcessedArgs;
+ auto *Decl = Intrinsic::getDeclaration(M.get(), ID);
+ for (auto *Ty : Decl->getFunctionType()->params()) {
+ auto *Val = Constant::getNullValue(Ty);
+ ProcessedArgs.push_back(Val);
+ }
+ return Builder.CreateCall(Decl, ProcessedArgs);
+ }
+ template <typename T> void checkIsa(const Instruction &I) {
+ EXPECT_TRUE(isa<T>(I));
+ }
+};
+
+TEST(IntrinsicNameLookup, Basic) {
int I = Intrinsic::lookupLLVMIntrinsicByName(NameTable1, "llvm.foo");
EXPECT_EQ(0, I);
I = Intrinsic::lookupLLVMIntrinsicByName(NameTable1, "llvm.foo.f64");
@@ -36,4 +71,45 @@ TEST(IntrinNameLookup, Basic) {
EXPECT_EQ(4, I);
}
+TEST_F(IntrinsicsTest, InstrProfInheritance) {
+ auto isInstrProfInstBase = [](const Instruction &I) {
+ return isa<InstrProfInstBase>(I);
+ };
+#define __ISA(TYPE, PARENT) \
+ auto is##TYPE = [&](const Instruction &I) -> bool { \
+ return isa<TYPE>(I) && is##PARENT(I); \
+ }
+ __ISA(InstrProfCntrInstBase, InstrProfInstBase);
+ __ISA(InstrProfMCDCCondBitmapUpdate, InstrProfInstBase);
+ __ISA(InstrProfCoverInst, InstrProfCntrInstBase);
+ __ISA(InstrProfIncrementInst, InstrProfCntrInstBase);
+ __ISA(InstrProfIncrementInstStep, InstrProfIncrementInst);
+ __ISA(InstrProfTimestampInst, InstrProfCntrInstBase);
+ __ISA(InstrProfValueProfileInst, InstrProfCntrInstBase);
+ __ISA(InstrProfMCDCBitmapInstBase, InstrProfInstBase);
+ __ISA(InstrProfMCDCBitmapParameters, InstrProfMCDCBitmapInstBase);
+ __ISA(InstrProfMCDCTVBitmapUpdate, InstrProfMCDCBitmapInstBase);
+#undef __ISA
+
+ std::vector<
+ std::pair<Intrinsic::ID, std::function<bool(const Instruction &)>>>
+ LeafIDs = {
+ {Intrinsic::instrprof_cover, isInstrProfCoverInst},
+ {Intrinsic::instrprof_increment, isInstrProfIncrementInst},
+ {Intrinsic::instrprof_increment_step, isInstrProfIncrementInstStep},
+ {Intrinsic::instrprof_mcdc_condbitmap_update,
+ isInstrProfMCDCCondBitmapUpdate},
+ {Intrinsic::instrprof_mcdc_parameters,
+ isInstrProfMCDCBitmapParameters},
+ {Intrinsic::instrprof_mcdc_tvbitmap_update,
+ isInstrProfMCDCTVBitmapUpdate},
+ {Intrinsic::instrprof_timestamp, isInstrProfTimestampInst},
+ {Intrinsic::instrprof_value_profile, isInstrProfValueProfileInst}};
+ for (const auto &[ID, Checker] : LeafIDs) {
+ auto *Intr = makeIntrinsic(ID);
+ EXPECT_TRUE(Checker(*Intr));
+ }
+
+#undef RULES
+}
} // end namespace
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
gentle reminder. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for adding the test!
Following up PR #83511, added a test to cover the inheritance graph for these intrinsics.