[PATCH] D127892: [LoopIdiom] Set `elementtype` attribute for generated memory intrinsic if required.
Denis Antrushin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 15 12:08:18 PDT 2022
dantrushin created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
dantrushin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Some garbage collectors require load and/or store barriers when
reading/storing object pointers. The only way to differentiate object
pointer from scalar type of the same size when using memory intrinsics
is `elementtype` attribute. Set it when we created new memcpy call
in function which has GCStrategy requiring barriers.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D127892
Files:
llvm/include/llvm/IR/GCStrategy.h
llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
Index: llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
+++ llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp
@@ -68,6 +68,7 @@
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
+#include "llvm/IR/GCStrategy.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
@@ -1503,6 +1504,16 @@
}
NewCall->setDebugLoc(TheStore->getDebugLoc());
+ const auto *F = TheStore->getFunction();
+ if (F->hasGC())
+ if (auto GC = llvm::getGCStrategy(F->getGC()))
+ if (GC->requiresBarriers()) {
+ LLVMContext &Ctx = NewCall->getContext();
+ Type *ET = TheLoad->getType();
+ NewCall->addParamAttr(0, Attribute::get(Ctx, Attribute::ElementType, ET));
+ NewCall->addParamAttr(1, Attribute::get(Ctx, Attribute::ElementType, ET));
+ }
+
if (MSSAU) {
MemoryAccess *NewMemAcc = MSSAU->createMemoryAccessInBB(
NewCall, nullptr, NewCall->getParent(), MemorySSA::BeforeTerminator);
Index: llvm/include/llvm/IR/GCStrategy.h
===================================================================
--- llvm/include/llvm/IR/GCStrategy.h
+++ llvm/include/llvm/IR/GCStrategy.h
@@ -74,6 +74,10 @@
bool NeededSafePoints = false; ///< if set, calls are inferred to be safepoints
bool UsesMetadata = false; ///< If set, backend must emit metadata tables.
+ bool RequiresLoadBarriers = false; ///< If set, GC requires read barriers on object
+ /// pointer loads
+ bool RequiresStoreBarriers = false; ///< If set, GC requires store barriers on object
+ /// pointer stores.
public:
GCStrategy();
@@ -87,6 +91,17 @@
/// and false otherwise.
bool useStatepoints() const { return UseStatepoints; }
+ /// Returns true if GC requires load barriers on object pointers.
+ bool requiresLoadBarriers() const { return RequiresLoadBarriers; }
+
+ /// Returns true if GC requires store barriers on object pointers.
+ bool requiresStoreBarriers() const { return RequiresStoreBarriers; }
+
+ /// Returns true if GC requires load and/or store barriers on object pointers.
+ bool requiresBarriers() const {
+ return RequiresLoadBarriers || RequiresStoreBarriers;
+ }
+
/** @name Statepoint Specific Properties */
///@{
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127892.437284.patch
Type: text/x-patch
Size: 2473 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220615/1a797f4e/attachment.bin>
More information about the llvm-commits
mailing list