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
This commit is contained in:
Dan Gohman
2009-09-23 01:33:16 +00:00
parent 00133a7d52
commit cd26ec5f3c
7 changed files with 74 additions and 47 deletions

View File

@ -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 << "<unknown>";
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<MachineMemOperand>::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 << "<unknown>";
else if (!V->getName().empty())
OS << V->getName();
else if (const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V)) {
PSV->print(OS);
} else
OS << V;
OS << " + " << MRO.getOffset() << "]";
OS << *i;
if (next(i) != e)
OS << " ";
}
}