[llvm] [VPlan] Manage instruction medata in VPlan. (PR #135272)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 20 11:48:45 PDT 2025


================
@@ -1190,28 +1190,49 @@ struct VPIRPhi : public VPIRInstruction {
 #endif
 };
 
+using MDArrayRef = ArrayRef<std::pair<unsigned, MDNode *>>;
+
+/// Helper to manage IR metadata for recipes. It filters out metadata that
+/// cannot be proagated.
+class VPIRMetadata {
+  SmallVector<std::pair<unsigned, MDNode *>> Metadata;
+
+protected:
+  VPIRMetadata(MDArrayRef Metadata) : Metadata(Metadata) {}
+
+public:
+  /// Add all metadata to \p V if it is an instruction.
+  void applyMetadata(Value *V) const;
----------------
ayalz wrote:

(original post outdated as it referred to `setMetadata()`, resurrecting here)

>> Better have the caller dyn_cast to Instruction (and realize metadata may be lost for non Instruction Values) than pretend this can set metadata to any Value?

> Could do if preferred, but then we would need to update every caller?

Yes, admittedly, consistent with `setFlags()`.
In some cases an assert/cast may be appropriate rather than a dyn_cast, when value is expected to be an instruction (otherwise cost may be inaccurate?)

https://github.com/llvm/llvm-project/pull/135272


More information about the llvm-commits mailing list