[llvm] [DSE] Apply initializes attribute to DSE (PR #107282)
Haopeng Liu via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 14:23:15 PDT 2024
================
@@ -820,20 +828,126 @@ struct MemoryLocationWrapper {
const Value *UnderlyingObject;
MemoryDef *MemDef;
Instruction *DefInst;
+ bool DefByInitializesAttr = false;
};
// A memory def wrapper that represents a MemoryDef and the MemoryLocation(s)
// defined by this MemoryDef.
struct MemoryDefWrapper {
- MemoryDefWrapper(MemoryDef *MemDef, std::optional<MemoryLocation> MemLoc) {
+ MemoryDefWrapper(
+ MemoryDef *MemDef,
+ const SmallVectorImpl<std::pair<MemoryLocation, bool>> &MemLocations) {
DefInst = MemDef->getMemoryInst();
- if (MemLoc.has_value())
- DefinedLocation = MemoryLocationWrapper(*MemLoc, MemDef);
+ for (auto &[MemLoc, DefByInitializesAttr] : MemLocations)
+ DefinedLocations.push_back(
+ MemoryLocationWrapper(MemLoc, MemDef, DefByInitializesAttr));
}
Instruction *DefInst;
- std::optional<MemoryLocationWrapper> DefinedLocation = std::nullopt;
+ SmallVector<MemoryLocationWrapper, 1> DefinedLocations;
+};
+
+bool hasInitializesAttr(Instruction *I) {
+ CallBase *CB = dyn_cast<CallBase>(I);
+ if (!CB)
+ return false;
+
+ for (unsigned Idx = 0, Count = CB->arg_size(); Idx < Count; ++Idx)
+ if (CB->paramHasAttr(Idx, Attribute::Initializes))
----------------
haopliu wrote:
`CallBase::getArgOperandWithAttribute` is exactly what we need (call `AttributeList::.hasAttrSomewhere` with both the instruction attr and the called function attr). Used this API :-D
https://github.com/llvm/llvm-project/pull/107282
More information about the llvm-commits
mailing list