diff options
author | Dan Gohman <gohman@apple.com> | 2009-09-23 01:33:16 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-09-23 01:33:16 +0000 |
commit | cd26ec5f3c089b3b24f80ff200e94e681eb9e1ee (patch) | |
tree | 62e9a6dbafa4d84a1045809ed86ea3c1396ccb69 /lib | |
parent | 00133a7d52f32ab9c9ac53e964a5cc68fc626b4d (diff) | |
download | external_llvm-cd26ec5f3c089b3b24f80ff200e94e681eb9e1ee.zip external_llvm-cd26ec5f3c089b3b24f80ff200e94e681eb9e1ee.tar.gz external_llvm-cd26ec5f3c089b3b24f80ff200e94e681eb9e1ee.tar.bz2 |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/MachineInstr.cpp | 68 | ||||
-rw-r--r-- | lib/CodeGen/PseudoSourceValue.cpp | 10 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 5 | ||||
-rw-r--r-- | lib/VMCore/AsmWriter.cpp | 14 |
4 files changed, 59 insertions, 38 deletions
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp index 2f5964f..baab120 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 << "<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 << " "; } } diff --git a/lib/CodeGen/PseudoSourceValue.cpp b/lib/CodeGen/PseudoSourceValue.cpp index c440936..3728b7f 100644 --- a/lib/CodeGen/PseudoSourceValue.cpp +++ b/lib/CodeGen/PseudoSourceValue.cpp @@ -47,12 +47,8 @@ PseudoSourceValue::PseudoSourceValue() : Value(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext())), PseudoSourceValueVal) {} -void PseudoSourceValue::dump() const { - print(errs()); errs() << '\n'; -} - -void PseudoSourceValue::print(raw_ostream &OS) const { - OS << PSVNames[this - *PSVs]; +void PseudoSourceValue::printCustom(raw_ostream &O) const { + O << PSVNames[this - *PSVs]; } namespace { @@ -67,7 +63,7 @@ namespace { virtual bool isConstant(const MachineFrameInfo *MFI) const; - virtual void print(raw_ostream &OS) const { + virtual void printCustom(raw_ostream &OS) const { OS << "FixedStack" << FI; } }; diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 87ea19b..e238b6e 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -5580,10 +5580,7 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const { else OS << "<null>"; } else if (const MemOperandSDNode *M = dyn_cast<MemOperandSDNode>(this)) { - if (M->MO.getValue()) - OS << "<" << M->MO.getValue() << ":" << M->MO.getOffset() << ">"; - else - OS << "<null:" << M->MO.getOffset() << ">"; + OS << ": " << M->MO; } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) { OS << ":" << N->getVT().getEVTString(); } diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 0d52e1f..219fe09 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -1198,6 +1198,11 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V, return; } + if (V->getValueID() == Value::PseudoSourceValueVal) { + V->print(Out); + return; + } + char Prefix = '%'; int Slot; if (Machine) { @@ -2076,10 +2081,17 @@ void Value::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW) const { } else if (isa<InlineAsm>(this)) { WriteAsOperand(OS, this, true, 0); } else { - llvm_unreachable("Unknown value to print out!"); + // Otherwise we don't know what it is. Call the virtual function to + // allow a subclass to print itself. + printCustom(OS); } } +// Value::printCustom - subclasses should override this to implement printing. +void Value::printCustom(raw_ostream &OS) const { + llvm_unreachable("Unknown value to print out!"); +} + // Value::dump - allow easy printing of Values from the debugger. void Value::dump() const { print(errs()); errs() << '\n'; } |