[PATCH] D107354: [MachineMemOperand] learn about ptr_provenance

Jeroen Dobbelaere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 3 07:47:28 PDT 2021


jeroen.dobbelaere created this revision.
jeroen.dobbelaere added reviewers: jdoerfert, nikic.
Herald added a subscriber: hiraditya.
jeroen.dobbelaere requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

For the machine instructions, MachineMemOperand is the better place to track the ptr_provenance.


https://reviews.llvm.org/D107354

Files:
  llvm/include/llvm/CodeGen/MachineMemOperand.h
  llvm/lib/CodeGen/MachineOperand.cpp


Index: llvm/lib/CodeGen/MachineOperand.cpp
===================================================================
--- llvm/lib/CodeGen/MachineOperand.cpp
+++ llvm/lib/CodeGen/MachineOperand.cpp
@@ -1180,6 +1180,10 @@
        << "unknown-address";
   }
   MachineOperand::printOperandOffset(OS, getOffset());
+  if (getPtrProvenance()) {
+    OS << ", ptr_provenance ";
+    MIRFormatter::printIRValue(OS, *getPtrProvenance(), MST);
+  }
   if (getSize() > 0 && getAlign() != getSize())
     OS << ", align " << getAlign().value();
   if (getAlign() != getBaseAlign())
Index: llvm/include/llvm/CodeGen/MachineMemOperand.h
===================================================================
--- llvm/include/llvm/CodeGen/MachineMemOperand.h
+++ llvm/include/llvm/CodeGen/MachineMemOperand.h
@@ -41,6 +41,12 @@
   /// space.
   PointerUnion<const Value *, const PseudoSourceValue *> V;
 
+  /// The provenance of the pointer. When ConstantPointerNull, the provenance
+  /// can be any object.
+  /// FIXME: nullptr here means : use V as provenance. This will change in
+  /// future.
+  const Value *PtrProvenance = nullptr;
+
   /// Offset - This is an offset from the base Value*.
   int64_t Offset;
 
@@ -49,8 +55,9 @@
   uint8_t StackID;
 
   explicit MachinePointerInfo(const Value *v, int64_t offset = 0,
-                              uint8_t ID = 0)
-      : V(v), Offset(offset), StackID(ID) {
+                              uint8_t ID = 0,
+                              const Value *ptrProvenance = nullptr)
+      : V(v), PtrProvenance(ptrProvenance), Offset(offset), StackID(ID) {
     AddrSpace = v ? v->getType()->getPointerAddressSpace() : 0;
   }
 
@@ -60,15 +67,16 @@
     AddrSpace = v ? v->getAddressSpace() : 0;
   }
 
-  explicit MachinePointerInfo(unsigned AddressSpace = 0, int64_t offset = 0)
-      : V((const Value *)nullptr), Offset(offset), AddrSpace(AddressSpace),
-        StackID(0) {}
+  explicit MachinePointerInfo(unsigned AddressSpace = 0, int64_t offset = 0,
+                              const Value *ptrProvenance = nullptr)
+      : V((const Value *)nullptr), PtrProvenance(ptrProvenance), Offset(offset),
+        AddrSpace(AddressSpace), StackID(0) {}
 
   explicit MachinePointerInfo(
     PointerUnion<const Value *, const PseudoSourceValue *> v,
     int64_t offset = 0,
-    uint8_t ID = 0)
-    : V(v), Offset(offset), StackID(ID) {
+    uint8_t ID = 0, const Value *ptrProvenance = nullptr)
+    : V(v), PtrProvenance(ptrProvenance), Offset(offset), StackID(ID) {
     if (V) {
       if (const auto *ValPtr = V.dyn_cast<const Value*>())
         AddrSpace = ValPtr->getType()->getPointerAddressSpace();
@@ -216,6 +224,8 @@
 
   const void *getOpaqueValue() const { return PtrInfo.V.getOpaqueValue(); }
 
+  const Value *getPtrProvenance() const { return PtrInfo.PtrProvenance; }
+
   /// Return the raw flags of the source value, \see Flags.
   Flags getFlags() const { return FlagVals; }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107354.363739.patch
Type: text/x-patch
Size: 2935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210803/b8d05906/attachment.bin>


More information about the llvm-commits mailing list