[PATCH] D157040: [OpenMP][IR] Set correct alignment for internal variables
Hao Jin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 3 21:36:48 PDT 2023
erjin updated this revision to Diff 547100.
erjin retitled this revision from "[OpenMP][IR] Set correct alignment for critical region lock" to "[OpenMP][IR] Set correct alignment for internal variables".
erjin added a comment.
Thanks for the review! I have made changes based on the comment. Specify the alignment while making these internal variables.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157040/new/
https://reviews.llvm.org/D157040
Files:
clang/lib/CodeGen/CGOpenMPRuntime.cpp
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===================================================================
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -2744,7 +2744,14 @@
PointerType *CriticalNamePtrTy =
PointerType::getUnqual(ArrayType::get(Type::getInt32Ty(Ctx), 8));
EXPECT_EQ(CriticalEndCI->getArgOperand(2), CriticalEntryCI->getArgOperand(2));
- EXPECT_EQ(CriticalEndCI->getArgOperand(2)->getType(), CriticalNamePtrTy);
+ GlobalVariable *GV =
+ dyn_cast<GlobalVariable>(CriticalEndCI->getArgOperand(2));
+ ASSERT_NE(GV, nullptr);
+ EXPECT_EQ(GV->getType(), CriticalNamePtrTy);
+ llvm::Align PtrAlign =
+ M->getDataLayout().getPointerABIAlignment(GV->getAddressSpace());
+ if (PtrAlign.value() > GV->getAlignment())
+ EXPECT_EQ(GV->getAlignment(), PtrAlign.value());
}
TEST_F(OpenMPIRBuilderTest, OrderedDirectiveDependSource) {
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===================================================================
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4493,7 +4493,11 @@
M, Ty, /*IsConstant=*/false, GlobalValue::CommonLinkage,
Constant::getNullValue(Ty), Elem.first(),
/*InsertBefore=*/nullptr, GlobalValue::NotThreadLocal, AddressSpace);
- GV->setAlignment(M.getDataLayout().getABITypeAlign(Ty));
+ llvm::Align TypeAlign = M.getDataLayout().getABITypeAlign(Ty);
+ llvm::Align PtrAlign =
+ M.getDataLayout().getPointerABIAlignment(GV->getAddressSpace());
+ TypeAlign = PtrAlign > TypeAlign ? PtrAlign : TypeAlign;
+ GV->setAlignment(TypeAlign);
Elem.second = GV;
}
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2161,11 +2161,7 @@
llvm::Value *CGOpenMPRuntime::getCriticalRegionLock(StringRef CriticalName) {
std::string Prefix = Twine("gomp_critical_user_", CriticalName).str();
std::string Name = getName({Prefix, "var"});
- llvm::GlobalVariable *G = OMPBuilder.getOrCreateInternalVariable(KmpCriticalNameTy, Name);
- llvm::Align PtrAlign = OMPBuilder.M.getDataLayout().getPointerABIAlignment(G->getAddressSpace());
- if (PtrAlign > llvm::Align(G->getAlignment()))
- G->setAlignment(PtrAlign);
- return G;
+ return OMPBuilder.getOrCreateInternalVariable(KmpCriticalNameTy, Name);
}
namespace {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157040.547100.patch
Type: text/x-patch
Size: 2538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230804/6514eec2/attachment.bin>
More information about the llvm-commits
mailing list