diff options
author | Sergio Afonso <safonsof@amd.com> | 2025-01-14 12:35:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-14 12:35:50 +0000 |
commit | d0b641b7e2a9b4120c11fc60b111a657b0420176 (patch) | |
tree | ea60b1eac7d77a4489c17ad07bf0f2b1ba8dc995 /llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp | |
parent | fabc443e9394e460d328984d75570d9f017fe709 (diff) | |
download | llvm-d0b641b7e2a9b4120c11fc60b111a657b0420176.zip llvm-d0b641b7e2a9b4120c11fc60b111a657b0420176.tar.gz llvm-d0b641b7e2a9b4120c11fc60b111a657b0420176.tar.bz2 |
[OMPIRBuilder] Propagate attributes to outlined target regions (#117875)
This patch copies the target-cpu and target-features attributes of
functions containing target regions into the corresponding outlined
function holding the target region.
This mirrors what is currently being done for all other outlined
functions through the `CodeExtractor` in `OpenMPIRBuilder::finalize()`.
Diffstat (limited to 'llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp')
-rw-r--r-- | llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp index 11f13be..3b571cc 100644 --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -6169,6 +6169,8 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) { OpenMPIRBuilderConfig Config(false, false, false, false, false, false, false); OMPBuilder.setConfig(Config); F->setName("func"); + F->addFnAttr("target-cpu", "x86-64"); + F->addFnAttr("target-features", "+mmx,+sse"); IRBuilder<> Builder(BB); auto *Int32Ty = Builder.getInt32Ty(); @@ -6320,6 +6322,13 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) { StringRef FunctionName2 = OutlinedFunc->getName(); EXPECT_TRUE(FunctionName2.starts_with("__omp_offloading")); + // Check that target-cpu and target-features were propagated to the outlined + // function + EXPECT_EQ(OutlinedFunc->getFnAttribute("target-cpu"), + F->getFnAttribute("target-cpu")); + EXPECT_EQ(OutlinedFunc->getFnAttribute("target-features"), + F->getFnAttribute("target-features")); + EXPECT_FALSE(verifyModule(*M, &errs())); } @@ -6330,6 +6339,8 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) { OMPBuilder.initialize(); F->setName("func"); + F->addFnAttr("target-cpu", "gfx90a"); + F->addFnAttr("target-features", "+gfx9-insts,+wavefrontsize64"); IRBuilder<> Builder(BB); OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); @@ -6407,6 +6418,13 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) { Function *OutlinedFn = TargetStore->getFunction(); EXPECT_NE(F, OutlinedFn); + // Check that target-cpu and target-features were propagated to the outlined + // function + EXPECT_EQ(OutlinedFn->getFnAttribute("target-cpu"), + F->getFnAttribute("target-cpu")); + EXPECT_EQ(OutlinedFn->getFnAttribute("target-features"), + F->getFnAttribute("target-features")); + EXPECT_TRUE(OutlinedFn->hasWeakODRLinkage()); // Account for the "implicit" first argument. EXPECT_EQ(OutlinedFn->getName(), "__omp_offloading_1_2_parent_l3"); @@ -6657,6 +6675,13 @@ TEST_F(OpenMPIRBuilderTest, TargetRegionDeviceSPMD) { EXPECT_NE(OutlinedFn, nullptr); EXPECT_NE(F, OutlinedFn); + // Check that target-cpu and target-features were propagated to the outlined + // function + EXPECT_EQ(OutlinedFn->getFnAttribute("target-cpu"), + F->getFnAttribute("target-cpu")); + EXPECT_EQ(OutlinedFn->getFnAttribute("target-features"), + F->getFnAttribute("target-features")); + EXPECT_TRUE(OutlinedFn->hasWeakODRLinkage()); // Account for the "implicit" first argument. EXPECT_EQ(OutlinedFn->getName(), "__omp_offloading_1_2_parent_l3"); |