[llvm] [DSE] Apply initializes attribute to DSE (PR #107282)
Jan Voung via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 07:56:54 PDT 2024
================
@@ -820,20 +828,121 @@ 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 (size_t Idx = 0; Idx < CB->arg_size(); Idx++)
----------------
jvoung wrote:
nit: some of the "size_t" can be "unsigned" for arg_size()
(for example https://github.com/llvm/llvm-project/blob/80cd2141eb7f6e7be738a01348bc2ccd08b41cd6/llvm/lib/IR/Verifier.cpp#L3625)
https://github.com/llvm/llvm-project/pull/107282
More information about the llvm-commits
mailing list