aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
diff options
context:
space:
mode:
authorSergio Afonso <safonsof@amd.com>2023-06-01 17:38:33 +0100
committerSergio Afonso <safonsof@amd.com>2023-07-20 15:07:50 +0100
commit40340cf91ab9c61ec8c77c0a5063d4e5894e9d07 (patch)
treea1382b8cf47b7d5664f70ae8fe111141bc0a31d1 /llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
parenta1c0e3be6f09be1315c21911b646eb9ddc5048c4 (diff)
downloadllvm-40340cf91ab9c61ec8c77c0a5063d4e5894e9d07.zip
llvm-40340cf91ab9c61ec8c77c0a5063d4e5894e9d07.tar.gz
llvm-40340cf91ab9c61ec8c77c0a5063d4e5894e9d07.tar.bz2
[MLIR][OpenMP][OMPIRBuilder] Use target triple to initialize `IsGPU` flag
This patch modifies the construction of the `OpenMPIRBuilder` in MLIR to initialize the `IsGPU` flag using target triple information passed down from the Flang frontend. If not present, it will default to `false`. This replicates the behavior currently implemented in Clang, where the `CodeGenModule::createOpenMPRuntime()` method creates a different `CGOpenMPRuntime` instance depending on the target triple, which in turn has an effect on the `IsGPU` flag of the `OpenMPIRBuilderConfig` object. Differential Revision: https://reviews.llvm.org/D151903
Diffstat (limited to 'llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp')
-rw-r--r--llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
index b15b30a..f6889cd 100644
--- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -5871,4 +5871,46 @@ TEST_F(OpenMPIRBuilderTest, registerTargetGlobalVariable) {
}
}
+TEST_F(OpenMPIRBuilderTest, createGPUOffloadEntry) {
+ OpenMPIRBuilder OMPBuilder(*M);
+ OMPBuilder.initialize();
+ OpenMPIRBuilderConfig Config(/* IsTargetDevice = */ true,
+ /* IsGPU = */ true,
+ /* HasRequiresUnifiedSharedMemory = */ false,
+ /* OpenMPOffloadMandatory = */ false);
+ OMPBuilder.setConfig(Config);
+
+ FunctionCallee FnTypeAndCallee =
+ M->getOrInsertFunction("test_kernel", Type::getVoidTy(Ctx));
+
+ auto *Fn = cast<Function>(FnTypeAndCallee.getCallee());
+ OMPBuilder.createOffloadEntry(/* ID = */ nullptr, Fn,
+ /* Size = */ 0,
+ /* Flags = */ 0, GlobalValue::WeakAnyLinkage);
+
+ // Check nvvm.annotations only created for GPU kernels
+ NamedMDNode *MD = M->getNamedMetadata("nvvm.annotations");
+ EXPECT_NE(MD, nullptr);
+ EXPECT_EQ(MD->getNumOperands(), 1u);
+
+ MDNode *Annotations = MD->getOperand(0);
+ EXPECT_EQ(Annotations->getNumOperands(), 3u);
+
+ Constant *ConstVal =
+ dyn_cast<ConstantAsMetadata>(Annotations->getOperand(0))->getValue();
+ EXPECT_TRUE(isa<Function>(Fn));
+ EXPECT_EQ(ConstVal, cast<Function>(Fn));
+
+ EXPECT_TRUE(Annotations->getOperand(1).equalsStr("kernel"));
+
+ EXPECT_TRUE(mdconst::hasa<ConstantInt>(Annotations->getOperand(2)));
+ APInt IntVal =
+ mdconst::extract<ConstantInt>(Annotations->getOperand(2))->getValue();
+ EXPECT_EQ(IntVal, 1);
+
+ // Check kernel attributes
+ EXPECT_TRUE(Fn->hasFnAttribute("kernel"));
+ EXPECT_TRUE(Fn->hasFnAttribute(Attribute::MustProgress));
+}
+
} // namespace