llvm.org GIT mirror llvm / cd26ec5
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 Dan Gohman 10 years ago
7 changed file(s) with 75 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
2121
2222 class Value;
2323 class FoldingSetNodeID;
24 class raw_ostream;
2425
2526 //===----------------------------------------------------------------------===//
2627 /// MachineMemOperand - A description of a memory reference used in the backend.
9192 void Profile(FoldingSetNodeID &ID) const;
9293 };
9394
95 raw_ostream &operator<<(raw_ostream &OS, const MachineMemOperand &MRO);
96
9497 } // End llvm namespace
9598
9699 #endif
2424 /// stack frame (e.g., a spill slot), below the stack frame (e.g., argument
2525 /// space), or constant pool.
2626 class PseudoSourceValue : public Value {
27 private:
28 /// printCustom - Implement printing for PseudoSourceValue. This is called
29 /// from Value::print or Value's operator<<.
30 ///
31 virtual void printCustom(raw_ostream &O) const;
32
2733 public:
2834 PseudoSourceValue();
29
30 /// dump - Support for debugging, callable in GDB: V->dump()
31 //
32 virtual void dump() const;
33
34 /// print - Implement operator<< on PseudoSourceValue.
35 ///
36 virtual void print(raw_ostream &OS) const;
3735
3836 /// isConstant - Test whether this PseudoSourceValue has a constant value.
3937 ///
8989 void operator=(const Value &); // Do not implement
9090 Value(const Value &); // Do not implement
9191
92 protected:
93 /// printCustom - Value subclasses can override this to implement custom
94 /// printing behavior.
95 virtual void printCustom(raw_ostream &O) const;
96
9297 public:
9398 Value(const Type *Ty, unsigned scid);
9499 virtual ~Value();
95100
96101 /// dump - Support for debugging, callable in GDB: V->dump()
97102 //
98 virtual void dump() const;
103 void dump() const;
99104
100105 /// print - Implement operator<< on Value.
101106 ///
1414 #include "llvm/Constants.h"
1515 #include "llvm/InlineAsm.h"
1616 #include "llvm/Value.h"
17 #include "llvm/Assembly/Writer.h"
1718 #include "llvm/CodeGen/MachineFunction.h"
1819 #include "llvm/CodeGen/MachineRegisterInfo.h"
1920 #include "llvm/CodeGen/PseudoSourceValue.h"
296297 ID.AddInteger(Flags);
297298 }
298299
300 raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineMemOperand &MRO) {
301 assert((MRO.isLoad() || MRO.isStore()) &&
302 "SV has to be a load, store or both.");
303
304 if (MRO.isVolatile())
305 OS << "Volatile ";
306
307 if (MRO.isLoad())
308 OS << "LD";
309 if (MRO.isStore())
310 OS << "ST";
311 OS << MRO.getSize();
312
313 // Print the address information.
314 OS << "[";
315 if (!MRO.getValue())
316 OS << "";
317 else
318 WriteAsOperand(OS, MRO.getValue(), /*PrintType=*/false);
319
320 // If the alignment of the memory reference itself differs from the alignment
321 // of the base pointer, print the base alignment explicitly, next to the base
322 // pointer.
323 if (MRO.getBaseAlignment() != MRO.getAlignment())
324 OS << "(align=" << MRO.getBaseAlignment() << ")";
325
326 if (MRO.getOffset() != 0)
327 OS << "+" << MRO.getOffset();
328 OS << "]";
329
330 // Print the alignment of the reference.
331 if (MRO.getBaseAlignment() != MRO.getAlignment() ||
332 MRO.getBaseAlignment() != MRO.getSize())
333 OS << "(align=" << MRO.getAlignment() << ")";
334
335 return OS;
336 }
337
299338 //===----------------------------------------------------------------------===//
300339 // MachineInstr Implementation
301340 //===----------------------------------------------------------------------===//
9661005 OS << ", Mem:";
9671006 for (std::list::const_iterator i = memoperands_begin(),
9681007 e = memoperands_end(); i != e; ++i) {
969 const MachineMemOperand &MRO = *i;
970 const Value *V = MRO.getValue();
971
972 assert((MRO.isLoad() || MRO.isStore()) &&
973 "SV has to be a load, store or both.");
974
975 if (MRO.isVolatile())
976 OS << "Volatile ";
977
978 if (MRO.isLoad())
979 OS << "LD";
980 if (MRO.isStore())
981 OS << "ST";
982
983 OS << "(" << MRO.getSize() << "," << MRO.getAlignment() << ") [";
984
985 if (!V)
986 OS << "";
987 else if (!V->getName().empty())
988 OS << V->getName();
989 else if (const PseudoSourceValue *PSV = dyn_cast(V)) {
990 PSV->print(OS);
991 } else
992 OS << V;
993
994 OS << " + " << MRO.getOffset() << "]";
1008 OS << *i;
1009 if (next(i) != e)
1010 OS << " ";
9951011 }
9961012 }
9971013
4646 Value(PointerType::getUnqual(Type::getInt8Ty(getGlobalContext())),
4747 PseudoSourceValueVal) {}
4848
49 void PseudoSourceValue::dump() const {
50 print(errs()); errs() << '\n';
51 }
52
53 void PseudoSourceValue::print(raw_ostream &OS) const {
54 OS << PSVNames[this - *PSVs];
49 void PseudoSourceValue::printCustom(raw_ostream &O) const {
50 O << PSVNames[this - *PSVs];
5551 }
5652
5753 namespace {
6662
6763 virtual bool isConstant(const MachineFrameInfo *MFI) const;
6864
69 virtual void print(raw_ostream &OS) const {
65 virtual void printCustom(raw_ostream &OS) const {
7066 OS << "FixedStack" << FI;
7167 }
7268 };
55795579 else
55805580 OS << "";
55815581 } else if (const MemOperandSDNode *M = dyn_cast(this)) {
5582 if (M->MO.getValue())
5583 OS << "<" << M->MO.getValue() << ":" << M->MO.getOffset() << ">";
5584 else
5585 OS << "MO.getOffset() << ">";
5582 OS << ": " << M->MO;
55865583 } else if (const VTSDNode *N = dyn_cast(this)) {
55875584 OS << ":" << N->getVT().getEVTString();
55885585 }
11971197 return;
11981198 }
11991199
1200 if (V->getValueID() == Value::PseudoSourceValueVal) {
1201 V->print(Out);
1202 return;
1203 }
1204
12001205 char Prefix = '%';
12011206 int Slot;
12021207 if (Machine) {
20752080 } else if (isa(this)) {
20762081 WriteAsOperand(OS, this, true, 0);
20772082 } else {
2078 llvm_unreachable("Unknown value to print out!");
2079 }
2083 // Otherwise we don't know what it is. Call the virtual function to
2084 // allow a subclass to print itself.
2085 printCustom(OS);
2086 }
2087 }
2088
2089 // Value::printCustom - subclasses should override this to implement printing.
2090 void Value::printCustom(raw_ostream &OS) const {
2091 llvm_unreachable("Unknown value to print out!");
20802092 }
20812093
20822094 // Value::dump - allow easy printing of Values from the debugger.