[PATCH] D52414: IR: Move AtomicRMW string names into class

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 24 07:21:40 PDT 2018


arsenm created this revision.
Herald added subscribers: jfb, wdng.
arsenm added a dependent revision: D52415: Add atomicrmw operation to error messages.

This will be used to improve error messages in a future commit


https://reviews.llvm.org/D52414

Files:
  include/llvm/IR/Instructions.h
  lib/IR/AsmWriter.cpp


Index: lib/IR/AsmWriter.cpp
===================================================================
--- lib/IR/AsmWriter.cpp
+++ lib/IR/AsmWriter.cpp
@@ -1217,24 +1217,6 @@
                                    SlotTracker *Machine, const Module *Context,
                                    bool FromValue = false);
 
-static void writeAtomicRMWOperation(raw_ostream &Out,
-                                    AtomicRMWInst::BinOp Op) {
-  switch (Op) {
-  default: Out << " <unknown operation " << Op << ">"; break;
-  case AtomicRMWInst::Xchg: Out << " xchg"; break;
-  case AtomicRMWInst::Add:  Out << " add"; break;
-  case AtomicRMWInst::Sub:  Out << " sub"; break;
-  case AtomicRMWInst::And:  Out << " and"; break;
-  case AtomicRMWInst::Nand: Out << " nand"; break;
-  case AtomicRMWInst::Or:   Out << " or"; break;
-  case AtomicRMWInst::Xor:  Out << " xor"; break;
-  case AtomicRMWInst::Max:  Out << " max"; break;
-  case AtomicRMWInst::Min:  Out << " min"; break;
-  case AtomicRMWInst::UMax: Out << " umax"; break;
-  case AtomicRMWInst::UMin: Out << " umin"; break;
-  }
-}
-
 static void WriteOptimizationInfo(raw_ostream &Out, const User *U) {
   if (const FPMathOperator *FPO = dyn_cast<const FPMathOperator>(U)) {
     // 'Fast' is an abbreviation for all fast-math-flags.
@@ -3568,7 +3550,7 @@
 
   // Print out the atomicrmw operation
   if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(&I))
-    writeAtomicRMWOperation(Out, RMWI->getOperation());
+    Out << ' ' << AtomicRMWInst::getOperationName(RMWI->getOperation());
 
   // Print out the type of the operands...
   const Value *Operand = I.getNumOperands() ? I.getOperand(0) : nullptr;
Index: include/llvm/IR/Instructions.h
===================================================================
--- include/llvm/IR/Instructions.h
+++ include/llvm/IR/Instructions.h
@@ -735,6 +735,37 @@
     return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
   }
 
+  static StringRef getOperationName(BinOp Op) {
+    switch (Op) {
+    case AtomicRMWInst::Xchg:
+      return "xchg";
+    case AtomicRMWInst::Add:
+      return "add";
+    case AtomicRMWInst::Sub:
+      return "sub";
+    case AtomicRMWInst::And:
+      return "and";
+    case AtomicRMWInst::Nand:
+      return "nand";
+    case AtomicRMWInst::Or:
+      return "or";
+    case AtomicRMWInst::Xor:
+      return "xor";
+    case AtomicRMWInst::Max:
+      return "max";
+    case AtomicRMWInst::Min:
+      return "min";
+    case AtomicRMWInst::UMax:
+      return "umax";
+    case AtomicRMWInst::UMin:
+      return "umin";
+    case AtomicRMWInst::BAD_BINOP:
+      return "<invalid operation>";
+    }
+
+    llvm_unreachable("invalid atomicrmw operation");
+  }
+
   void setOperation(BinOp Operation) {
     unsigned short SubclassData = getSubclassDataFromInstruction();
     setInstructionSubclassData((SubclassData & 31) |


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52414.166659.patch
Type: text/x-patch
Size: 2882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180924/3a0981e8/attachment.bin>


More information about the llvm-commits mailing list