[llvm] f8f1c9c - Annotate memcpy's of globals with info about the src/dst
Jon Roelofs via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 9 18:11:29 PDT 2021
Author: Jon Roelofs
Date: 2021-06-09T18:11:08-07:00
New Revision: f8f1c9c38989e804946697b301a6e064e43b5e52
URL: https://github.com/llvm/llvm-project/commit/f8f1c9c38989e804946697b301a6e064e43b5e52
DIFF: https://github.com/llvm/llvm-project/commit/f8f1c9c38989e804946697b301a6e064e43b5e52.diff
LOG: Annotate memcpy's of globals with info about the src/dst
Differential revision: https://reviews.llvm.org/D103994
Added:
Modified:
llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
llvm/test/CodeGen/AArch64/memsize-remarks.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
index 1ad75f716abc..8ee7e0cb5e4a 100644
--- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
@@ -285,8 +285,23 @@ void MemoryOpRemark::visitSizeOperand(Value *V, OptimizationRemarkMissed &R) {
}
}
+static Optional<StringRef> nameOrNone(const Value *V) {
+ if (V->hasName())
+ return V->getName();
+ return None;
+}
+
void MemoryOpRemark::visitVariable(const Value *V,
SmallVectorImpl<VariableInfo> &Result) {
+ if (auto *GV = dyn_cast<GlobalVariable>(V)) {
+ auto *Ty = cast<PointerType>(GV->getType())->getElementType();
+ int64_t Size = DL.getTypeSizeInBits(Ty).getFixedSize();
+ VariableInfo Var{nameOrNone(GV), Size};
+ if (!Var.isEmpty())
+ Result.push_back(std::move(Var));
+ return;
+ }
+
// If we find some information in the debug info, take that.
bool FoundDI = false;
// Try to get an llvm.dbg.declare, which has a DILocalVariable giving us the
@@ -312,12 +327,10 @@ void MemoryOpRemark::visitVariable(const Value *V,
return;
// If not, get it from the alloca.
- Optional<StringRef> Name = AI->hasName() ? Optional<StringRef>(AI->getName())
- : Optional<StringRef>(None);
Optional<TypeSize> TySize = AI->getAllocationSizeInBits(DL);
Optional<uint64_t> Size =
TySize ? getSizeInBytes(TySize->getFixedSize()) : None;
- VariableInfo Var{Name, Size};
+ VariableInfo Var{nameOrNone(AI), Size};
if (!Var.isEmpty())
Result.push_back(std::move(Var));
}
diff --git a/llvm/test/CodeGen/AArch64/memsize-remarks.ll b/llvm/test/CodeGen/AArch64/memsize-remarks.ll
index 10af36c01d1e..d505c75c0776 100644
--- a/llvm/test/CodeGen/AArch64/memsize-remarks.ll
+++ b/llvm/test/CodeGen/AArch64/memsize-remarks.ll
@@ -302,6 +302,19 @@ define void @known_call_with_dereferenceable_bytes(i8* dereferenceable(42) %dst,
ret void
}
+ at dropbear = external unnamed_addr constant [3 x i8], align 1
+ at koala = external unnamed_addr constant [7 x i8], align 1
+
+define void @slicePun() {
+bb:
+; GISEL: remark: <unknown>:0:0: Call to memcpy. Memory operation size: 24 bytes.{{$}}
+; GISEL-NEXT: Read Variables: koala (56 bytes).
+; GISEL-NEXT: Written Variables: dropbear (24 bytes).
+ tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 getelementptr inbounds ([3 x i8], [3 x i8]* @dropbear, i64 0, i64 0),
+ i8* getelementptr inbounds ([7 x i8], [7 x i8]* @koala, i64 0, i64 0), i64 24, i1 false)
+ ret void
+}
+
attributes #0 = { noinline nounwind ssp uwtable "frame-pointer"="non-leaf" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-a7" "target-features"="+aes,+crypto,+fp-armv8,+neon,+sha2,+zcm,+zcz" }
attributes #1 = { nounwind "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-a7" "target-features"="+aes,+crypto,+fp-armv8,+neon,+sha2,+zcm,+zcz" }
attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }
More information about the llvm-commits
mailing list