[llvm] [NFC] Move ModRef/MemoryEffects printers to their own file (PR #105367)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 13:56:53 PDT 2024


https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/105367

>From 1b4463b537f0840941be9db4e3994e4ebea9c09e Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 20 Aug 2024 13:46:38 -0700
Subject: [PATCH] [NFC] Move ModRef/MemoryEffects printers to their own file

- Move << operators for ModRef and MemoryEffects to a new ModRef.cpp
  file under llvm/Support (instead of AliasAnalysis.cpp)

- This enabled calling these operators from `Core` files like
  Instructions.cpp (for debugging). Currently, they live in
   `LLVMAnalysis` which cannot be linked with `Core`.
---
 llvm/include/llvm/Support/ModRef.h  |  2 +-
 llvm/lib/Analysis/AliasAnalysis.cpp | 36 --------------------
 llvm/lib/Support/CMakeLists.txt     |  1 +
 llvm/lib/Support/ModRef.cpp         | 51 +++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 37 deletions(-)
 create mode 100644 llvm/lib/Support/ModRef.cpp

diff --git a/llvm/include/llvm/Support/ModRef.h b/llvm/include/llvm/Support/ModRef.h
index 7687280111a1f8..5a9d80c87ae27a 100644
--- a/llvm/include/llvm/Support/ModRef.h
+++ b/llvm/include/llvm/Support/ModRef.h
@@ -1,4 +1,4 @@
-//===--- ModRef.h - Memory effect modelling ---------------------*- C++ -*-===//
+//===--- ModRef.h - Memory effect modeling ----------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp
index 6eaaad5f332eb9..9f529fde55c20f 100644
--- a/llvm/lib/Analysis/AliasAnalysis.cpp
+++ b/llvm/lib/Analysis/AliasAnalysis.cpp
@@ -423,42 +423,6 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, AliasResult AR) {
   return OS;
 }
 
-raw_ostream &llvm::operator<<(raw_ostream &OS, ModRefInfo MR) {
-  switch (MR) {
-  case ModRefInfo::NoModRef:
-    OS << "NoModRef";
-    break;
-  case ModRefInfo::Ref:
-    OS << "Ref";
-    break;
-  case ModRefInfo::Mod:
-    OS << "Mod";
-    break;
-  case ModRefInfo::ModRef:
-    OS << "ModRef";
-    break;
-  }
-  return OS;
-}
-
-raw_ostream &llvm::operator<<(raw_ostream &OS, MemoryEffects ME) {
-  for (IRMemLocation Loc : MemoryEffects::locations()) {
-    switch (Loc) {
-    case IRMemLocation::ArgMem:
-      OS << "ArgMem: ";
-      break;
-    case IRMemLocation::InaccessibleMem:
-      OS << "InaccessibleMem: ";
-      break;
-    case IRMemLocation::Other:
-      OS << "Other: ";
-      break;
-    }
-    OS << ME.getModRef(Loc) << ", ";
-  }
-  return OS;
-}
-
 //===----------------------------------------------------------------------===//
 // Helper method implementation
 //===----------------------------------------------------------------------===//
diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt
index a73ac54a01c5a5..c55c17fae189f5 100644
--- a/llvm/lib/Support/CMakeLists.txt
+++ b/llvm/lib/Support/CMakeLists.txt
@@ -205,6 +205,7 @@ add_llvm_component_library(LLVMSupport
   MemAlloc.cpp
   MemoryBuffer.cpp
   MemoryBufferRef.cpp
+  ModRef.cpp
   MD5.cpp
   MSP430Attributes.cpp
   MSP430AttributeParser.cpp
diff --git a/llvm/lib/Support/ModRef.cpp b/llvm/lib/Support/ModRef.cpp
new file mode 100644
index 00000000000000..c5978296e97f0c
--- /dev/null
+++ b/llvm/lib/Support/ModRef.cpp
@@ -0,0 +1,51 @@
+//===--- ModRef.cpp - Memory effect modeling --------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file implements ModRef and MemoryEffects misc functions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Support/ModRef.h"
+
+using namespace llvm;
+
+raw_ostream &llvm::operator<<(raw_ostream &OS, ModRefInfo MR) {
+  switch (MR) {
+  case ModRefInfo::NoModRef:
+    OS << "NoModRef";
+    break;
+  case ModRefInfo::Ref:
+    OS << "Ref";
+    break;
+  case ModRefInfo::Mod:
+    OS << "Mod";
+    break;
+  case ModRefInfo::ModRef:
+    OS << "ModRef";
+    break;
+  }
+  return OS;
+}
+
+raw_ostream &llvm::operator<<(raw_ostream &OS, MemoryEffects ME) {
+  for (IRMemLocation Loc : MemoryEffects::locations()) {
+    switch (Loc) {
+    case IRMemLocation::ArgMem:
+      OS << "ArgMem: ";
+      break;
+    case IRMemLocation::InaccessibleMem:
+      OS << "InaccessibleMem: ";
+      break;
+    case IRMemLocation::Other:
+      OS << "Other: ";
+      break;
+    }
+    OS << ME.getModRef(Loc) << ", ";
+  }
+  return OS;
+}



More information about the llvm-commits mailing list