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 Operand class and its |
| 11 // target-independent subclasses, primarily for the methods of the |
| 12 // Variable class. |
| 13 // |
| 14 //===----------------------------------------------------------------------===// |
| 15 |
| 16 #include "IceCfg.h" |
| 17 #include "IceInst.h" |
| 18 #include "IceOperand.h" |
| 19 |
| 20 namespace Ice { |
| 21 |
| 22 bool operator<(const RelocatableTuple &A, const RelocatableTuple &B) { |
| 23 if (A.Offset != B.Offset) |
| 24 return A.Offset < B.Offset; |
| 25 if (A.SuppressMangling != B.SuppressMangling) |
| 26 return A.SuppressMangling < B.SuppressMangling; |
| 27 return A.Name < B.Name; |
| 28 } |
| 29 |
| 30 void Variable::setUse(const Inst *Inst, const CfgNode *Node) { |
| 31 if (DefNode == NULL) |
| 32 return; |
| 33 if (llvm::isa<InstPhi>(Inst) || Node != DefNode) |
| 34 DefNode = NULL; |
| 35 } |
| 36 |
| 37 void Variable::setDefinition(Inst *Inst, const CfgNode *Node) { |
| 38 if (DefNode == NULL) |
| 39 return; |
| 40 // Can first check preexisting DefInst if we care about multi-def vars. |
| 41 DefInst = Inst; |
| 42 if (Node != DefNode) |
| 43 DefNode = NULL; |
| 44 } |
| 45 |
| 46 void Variable::replaceDefinition(Inst *Inst, const CfgNode *Node) { |
| 47 DefInst = NULL; |
| 48 setDefinition(Inst, Node); |
| 49 } |
| 50 |
| 51 void Variable::setIsArg(Cfg *Func) { |
| 52 IsArgument = true; |
| 53 if (DefNode == NULL) |
| 54 return; |
| 55 CfgNode *Entry = Func->getEntryNode(); |
| 56 if (DefNode == Entry) |
| 57 return; |
| 58 DefNode = NULL; |
| 59 } |
| 60 |
| 61 IceString Variable::getName() const { |
| 62 if (!Name.empty()) |
| 63 return Name; |
| 64 char buf[30]; |
| 65 snprintf(buf, llvm::array_lengthof(buf), "__%u", getIndex()); |
| 66 return buf; |
| 67 } |
| 68 |
| 69 // ======================== dump routines ======================== // |
| 70 |
| 71 void Variable::dump(const Cfg *Func) const { |
| 72 Ostream &Str = Func->getContext()->getStrDump(); |
| 73 const CfgNode *CurrentNode = Func->getCurrentNode(); |
| 74 (void)CurrentNode; // used only in assert() |
| 75 assert(CurrentNode == NULL || DefNode == NULL || DefNode == CurrentNode); |
| 76 Str << "%" << getName(); |
| 77 } |
| 78 |
| 79 void Operand::dump(const Cfg *Func) const { |
| 80 Ostream &Str = Func->getContext()->getStrDump(); |
| 81 Str << "Operand<?>"; |
| 82 } |
| 83 |
| 84 void ConstantRelocatable::dump(const Cfg *Func) const { |
| 85 Ostream &Str = Func->getContext()->getStrDump(); |
| 86 Str << "@" << Name; |
| 87 if (Offset) |
| 88 Str << "+" << Offset; |
| 89 } |
| 90 |
| 91 } // end of namespace Ice |
OLD | NEW |