From bec02cb2e52a712b3da7ee1c5098a4bb9e154c77 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Tue, 2 Oct 2018 23:44:11 +0000 Subject: [PATCH] IR: Move AtomicRMW string names into class This will be used to improve error messages in a future commit. llvm-svn: 343647 --- include/llvm/IR/Instructions.h | 2 ++ lib/IR/AsmWriter.cpp | 20 +------------------- lib/IR/Instructions.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/include/llvm/IR/Instructions.h b/include/llvm/IR/Instructions.h index 476c412fd52..8bdc935425d 100644 --- a/include/llvm/IR/Instructions.h +++ b/include/llvm/IR/Instructions.h @@ -735,6 +735,8 @@ public: return static_cast(getSubclassDataFromInstruction() >> 5); } + static StringRef getOperationName(BinOp Op); + void setOperation(BinOp Operation) { unsigned short SubclassData = getSubclassDataFromInstruction(); setInstructionSubclassData((SubclassData & 31) | diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 7f3a6bee6b9..33863da468d 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -1241,24 +1241,6 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Metadata *MD, SlotTracker *Machine, const Module *Context, bool FromValue = false); -static void writeAtomicRMWOperation(raw_ostream &Out, - AtomicRMWInst::BinOp Op) { - switch (Op) { - default: Out << " "; 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(U)) { // 'Fast' is an abbreviation for all fast-math-flags. @@ -3612,7 +3594,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) { // Print out the atomicrmw operation if (const AtomicRMWInst *RMWI = dyn_cast(&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; diff --git a/lib/IR/Instructions.cpp b/lib/IR/Instructions.cpp index 8ade6f508a3..126a96635ee 100644 --- a/lib/IR/Instructions.cpp +++ b/lib/IR/Instructions.cpp @@ -1336,6 +1336,37 @@ AtomicRMWInst::AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val, Init(Operation, Ptr, Val, Ordering, SSID); } +StringRef AtomicRMWInst::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 ""; + } + + llvm_unreachable("invalid atomicrmw operation"); +} + //===----------------------------------------------------------------------===// // FenceInst Implementation //===----------------------------------------------------------------------===//