OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceOperand.cpp - High-level operand implementation -----===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // This file implements the IceOperand class and its |
| 11 // target-independent subclasses, primarily for the methods of the |
| 12 // IceVariable class. |
| 13 // |
| 14 //===----------------------------------------------------------------------===// |
| 15 |
| 16 #include "IceCfg.h" |
| 17 #include "IceInst.h" |
| 18 #include "IceOperand.h" |
| 19 |
| 20 void IceVariable::setUse(const IceInst *Inst, const IceCfgNode *Node) { |
| 21 if (DefNode == NULL) |
| 22 return; |
| 23 if (llvm::isa<IceInstPhi>(Inst) || Node != DefNode) |
| 24 DefNode = NULL; |
| 25 } |
| 26 |
| 27 void IceVariable::setDefinition(IceInst *Inst, const IceCfgNode *Node) { |
| 28 if (DefNode == NULL) |
| 29 return; |
| 30 // Can first check preexisting DefInst if we care about multi-def vars. |
| 31 DefInst = Inst; |
| 32 if (Node != DefNode) |
| 33 DefNode = NULL; |
| 34 } |
| 35 |
| 36 void IceVariable::replaceDefinition(IceInst *Inst, const IceCfgNode *Node) { |
| 37 DefInst = NULL; |
| 38 setDefinition(Inst, Node); |
| 39 } |
| 40 |
| 41 void IceVariable::setIsArg(IceCfg *Cfg) { |
| 42 IsArgument = true; |
| 43 if (DefNode == NULL) |
| 44 return; |
| 45 IceCfgNode *Entry = Cfg->getEntryNode(); |
| 46 if (DefNode == Entry) |
| 47 return; |
| 48 DefNode = NULL; |
| 49 } |
| 50 |
| 51 IceString IceVariable::getName() const { |
| 52 if (Name != "") |
| 53 return Name; |
| 54 char buf[30]; |
| 55 sprintf(buf, "__%u", getIndex()); |
| 56 return buf; |
| 57 } |
| 58 |
| 59 // ======================== dump routines ======================== // |
| 60 |
| 61 IceOstream &operator<<(IceOstream &Str, const IceOperand *O) { |
| 62 if (O) |
| 63 O->dump(Str); |
| 64 else |
| 65 Str << "<NULL>"; |
| 66 return Str; |
| 67 } |
| 68 |
| 69 void IceVariable::dump(IceOstream &Str) const { |
| 70 const IceCfgNode *CurrentNode = Str.getCurrentNode(); |
| 71 (void)CurrentNode; // used only in assert() |
| 72 assert(CurrentNode == NULL || DefNode == NULL || DefNode == CurrentNode); |
| 73 Str << "%" << getName(); |
| 74 } |
| 75 |
| 76 void IceOperand::dump(IceOstream &Str) const { Str << "IceOperand<?>"; } |
| 77 |
| 78 void IceConstantRelocatable::dump(IceOstream &Str) const { |
| 79 Str << "@" << Name; |
| 80 if (Offset) |
| 81 Str << "+" << Offset; |
| 82 } |
OLD | NEW |