diff options
Diffstat (limited to 'llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp')
-rw-r--r-- | llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp | 42 |
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 |