[PATCH] D103994: Annotate memcpy's of globals with info about the src/dst

Jon Roelofs via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 9 18:11:32 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGf8f1c9c38989: Annotate memcpy's of globals with info about the src/dst (authored by jroelofs).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103994/new/

https://reviews.llvm.org/D103994

Files:
  llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
  llvm/test/CodeGen/AArch64/memsize-remarks.ll


Index: llvm/test/CodeGen/AArch64/memsize-remarks.ll
===================================================================
--- llvm/test/CodeGen/AArch64/memsize-remarks.ll
+++ llvm/test/CodeGen/AArch64/memsize-remarks.ll
@@ -302,6 +302,19 @@
   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 }
Index: llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
===================================================================
--- llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
+++ llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
@@ -285,8 +285,23 @@
   }
 }
 
+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 @@
     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));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103994.351022.patch
Type: text/x-patch
Size: 2926 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210610/2f1b8189/attachment.bin>


More information about the llvm-commits mailing list