[llvm] [RFC] Memory Model Relaxation Annotations (PR #78569)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 00:20:44 PDT 2024


================
@@ -0,0 +1,185 @@
+//===- MemoryModelRelaxationAnnotations.cpp ---------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+// FIXME: Only needed for canInstructionHaveMMRAs, should it move to another
+// file?
+#include "llvm/IR/Instructions.h"
+
+using namespace llvm;
+
+static bool isTagMD(const MDNode *MD) {
+  return isa<MDTuple>(MD) && MD->getNumOperands() == 2 &&
+         isa<MDString>(MD->getOperand(0)) && isa<MDString>(MD->getOperand(1));
+}
+
+MMRAMetadata::MMRAMetadata(const Instruction &I)
+    : MMRAMetadata(I.getMetadata(LLVMContext::MD_mmra)) {}
+
+MMRAMetadata::MMRAMetadata(MDNode *MD) {
+  if (!MD)
+    return;
+
+  // TODO: Split this into a "tryParse" function that can return an err.
+  // CTor can use the tryParse & just fatal on err.
+
+  MDTuple *Tuple = dyn_cast<MDTuple>(MD);
+  if (!Tuple)
+    report_fatal_error("MMRAs should always be MDTuples!");
----------------
arsenm wrote:

All of these report_fatal_errors should be moved to IR verifier checks; the actual code should then rely on those enforced assumptions 

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


More information about the llvm-commits mailing list