From cd26ec5f3c089b3b24f80ff200e94e681eb9e1ee Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 23 Sep 2009 01:33:16 +0000 Subject: Give MachineMemOperand an operator<<, factoring out code from two different places for printing MachineMemOperands. Drop the virtual from Value::dump and instead give Value a protected virtual hook that can be overridden by subclasses to implement custom printing. This lets printing be more consistent, and simplifies printing of PseudoSourceValue values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82599 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineInstr.cpp | 68 +++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 26 deletions(-) (limited to 'lib/CodeGen/MachineInstr.cpp') diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 2f5964f140..baab1203df 100644 --- a/lib/CodeGen/MachineInstr.cpp +++ b/lib/CodeGen/MachineInstr.cpp @@ -15,6 +15,7 @@ #include "llvm/Constants.h" #include "llvm/InlineAsm.h" #include "llvm/Value.h" +#include "llvm/Assembly/Writer.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/CodeGen/PseudoSourceValue.h" @@ -297,6 +298,44 @@ void MachineMemOperand::Profile(FoldingSetNodeID &ID) const { ID.AddInteger(Flags); } +raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineMemOperand &MRO) { + assert((MRO.isLoad() || MRO.isStore()) && + "SV has to be a load, store or both."); + + if (MRO.isVolatile()) + OS << "Volatile "; + + if (MRO.isLoad()) + OS << "LD"; + if (MRO.isStore()) + OS << "ST"; + OS << MRO.getSize(); + + // Print the address information. + OS << "["; + if (!MRO.getValue()) + OS << ""; + else + WriteAsOperand(OS, MRO.getValue(), /*PrintType=*/false); + + // If the alignment of the memory reference itself differs from the alignment + // of the base pointer, print the base alignment explicitly, next to the base + // pointer. + if (MRO.getBaseAlignment() != MRO.getAlignment()) + OS << "(align=" << MRO.getBaseAlignment() << ")"; + + if (MRO.getOffset() != 0) + OS << "+" << MRO.getOffset(); + OS << "]"; + + // Print the alignment of the reference. + if (MRO.getBaseAlignment() != MRO.getAlignment() || + MRO.getBaseAlignment() != MRO.getSize()) + OS << "(align=" << MRO.getAlignment() << ")"; + + return OS; +} + //===----------------------------------------------------------------------===// // MachineInstr Implementation //===----------------------------------------------------------------------===// @@ -967,32 +1006,9 @@ void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM) const { OS << ", Mem:"; for (std::list::const_iterator i = memoperands_begin(), e = memoperands_end(); i != e; ++i) { - const MachineMemOperand &MRO = *i; - const Value *V = MRO.getValue(); - - assert((MRO.isLoad() || MRO.isStore()) && - "SV has to be a load, store or both."); - - if (MRO.isVolatile()) - OS << "Volatile "; - - if (MRO.isLoad()) - OS << "LD"; - if (MRO.isStore()) - OS << "ST"; - - OS << "(" << MRO.getSize() << "," << MRO.getAlignment() << ") ["; - - if (!V) - OS << ""; - else if (!V->getName().empty()) - OS << V->getName(); - else if (const PseudoSourceValue *PSV = dyn_cast(V)) { - PSV->print(OS); - } else - OS << V; - - OS << " + " << MRO.getOffset() << "]"; + OS << *i; + if (next(i) != e) + OS << " "; } } -- cgit v1.2.3-18-g5258