convert a bunch of std::strings to use StringRef. This should eliminate
[oota-llvm.git] / include / llvm / CodeGen / MachineInstr.h
index 0cdad848b9ac13a39511ae7934790d5d235c9436..79cb66f4c8e7dac1838986761810399bea53df73 100644 (file)
@@ -22,6 +22,7 @@
 #include "llvm/CodeGen/MachineOperand.h"
 #include "llvm/CodeGen/MachineMemOperand.h"
 #include "llvm/Target/TargetInstrDesc.h"
+#include "llvm/Support/DebugLoc.h"
 #include <list>
 #include <vector>
 
@@ -43,6 +44,7 @@ class MachineInstr : public ilist_node<MachineInstr> {
   std::vector<MachineOperand> Operands; // the operands
   std::list<MachineMemOperand> MemOperands; // information on memory references
   MachineBasicBlock *Parent;            // Pointer to the owning basic block.
+  DebugLoc debugLoc;                    // Source line information.
 
   // OperandComplete - Return true if it's illegal to add a new operand
   bool OperandsComplete() const;
@@ -53,7 +55,6 @@ class MachineInstr : public ilist_node<MachineInstr> {
   // Intrusive list support
   friend struct ilist_traits<MachineInstr>;
   friend struct ilist_traits<MachineBasicBlock>;
-  friend struct ilist_sentinel_traits<MachineInstr>;
   void setParent(MachineBasicBlock *P) { Parent = P; }
 
   /// MachineInstr ctor - This constructor creates a copy of the given
@@ -64,17 +65,34 @@ class MachineInstr : public ilist_node<MachineInstr> {
   /// TID NULL and no operands.
   MachineInstr();
 
+  // The next two constructors have DebugLoc and non-DebugLoc versions;
+  // over time, the non-DebugLoc versions should be phased out and eventually
+  // removed.
+
   /// MachineInstr ctor - This constructor create a MachineInstr and add the
   /// implicit operands.  It reserves space for number of operands specified by
-  /// TargetInstrDesc.
+  /// TargetInstrDesc.  The version with a DebugLoc should be preferred.
   explicit MachineInstr(const TargetInstrDesc &TID, bool NoImp = false);
 
   /// MachineInstr ctor - Work exactly the same as the ctor above, except that
   /// the MachineInstr is created and added to the end of the specified basic
-  /// block.
+  /// block.  The version with a DebugLoc should be preferred.
   ///
   MachineInstr(MachineBasicBlock *MBB, const TargetInstrDesc &TID);
 
+  /// MachineInstr ctor - This constructor create a MachineInstr and add the
+  /// implicit operands.  It reserves space for number of operands specified by
+  /// TargetInstrDesc.  An explicit DebugLoc is supplied.
+  explicit MachineInstr(const TargetInstrDesc &TID, const DebugLoc dl, 
+                        bool NoImp = false);
+
+  /// MachineInstr ctor - Work exactly the same as the ctor above, except that
+  /// the MachineInstr is created and added to the end of the specified basic
+  /// block.
+  ///
+  MachineInstr(MachineBasicBlock *MBB, const DebugLoc dl, 
+               const TargetInstrDesc &TID);
+
   ~MachineInstr();
 
   // MachineInstrs are pool-allocated and owned by MachineFunction.
@@ -83,6 +101,10 @@ class MachineInstr : public ilist_node<MachineInstr> {
 public:
   const MachineBasicBlock* getParent() const { return Parent; }
   MachineBasicBlock* getParent() { return Parent; }
+
+  /// getDebugLoc - Returns the debug location id of this MachineInstr.
+  ///
+  DebugLoc getDebugLoc() const { return debugLoc; }
   
   /// getDesc - Returns the target instruction descriptor of this
   /// MachineInstr.
@@ -186,7 +208,7 @@ public:
   }
 
   /// findRegisterUseOperandIdx() - Returns the operand index that is a use of
-  /// the specific register or -1 if it is not found. It further tightening
+  /// the specific register or -1 if it is not found. It further tightens
   /// the search criteria to a use that kills the register if isKill is true.
   int findRegisterUseOperandIdx(unsigned Reg, bool isKill = false,
                                 const TargetRegisterInfo *TRI = NULL) const;
@@ -208,7 +230,7 @@ public:
 
   /// findRegisterDefOperand - Wrapper for findRegisterDefOperandIdx, it returns
   /// a pointer to the MachineOperand rather than an index.
-  MachineOperand *findRegisterDefOperand(unsigned Reg,bool isDead = false,
+  MachineOperand *findRegisterDefOperand(unsigned Reg, bool isDead = false,
                                          const TargetRegisterInfo *TRI = NULL) {
     int Idx = findRegisterDefOperandIdx(Reg, isDead, TRI);
     return (Idx == -1) ? NULL : &getOperand(Idx);
@@ -219,9 +241,16 @@ public:
   /// none is found.
   int findFirstPredOperandIdx() const;
   
-  /// isRegReDefinedByTwoAddr - Given the defined register and the operand index,
-  /// check if the register def is a re-definition due to two addr elimination.
-  bool isRegReDefinedByTwoAddr(unsigned Reg, unsigned DefIdx) const;
+  /// isRegTiedToUseOperand - Given the index of a register def operand,
+  /// check if the register def is tied to a source operand, due to either
+  /// two-address elimination or inline assembly constraints. Returns the
+  /// first tied use operand index by reference is UseOpIdx is not null.
+  bool isRegTiedToUseOperand(unsigned DefOpIdx, unsigned *UseOpIdx = 0) const;
+
+  /// isRegTiedToDefOperand - Return true if the use operand of the specified
+  /// index is tied to an def operand. It also returns the def operand index by
+  /// reference if DefOpIdx is not null.
+  bool isRegTiedToDefOperand(unsigned UseOpIdx, unsigned *DefOpIdx = 0) const;
 
   /// copyKillDeadInfo - Copies kill / dead operand properties from MI.
   ///
@@ -263,16 +292,7 @@ public:
   //
   // Debugging support
   //
-  void print(std::ostream *OS, const TargetMachine *TM) const {
-    if (OS) print(*OS, TM);
-  }
-  void print(std::ostream &OS, const TargetMachine *TM = 0) const;
-  void print(std::ostream *OS) const { if (OS) print(*OS); }
-  void print(raw_ostream *OS, const TargetMachine *TM) const {
-    if (OS) print(*OS, TM);
-  }
   void print(raw_ostream &OS, const TargetMachine *TM = 0) const;
-  void print(raw_ostream *OS) const { if (OS) print(*OS); }
   void dump() const;
 
   //===--------------------------------------------------------------------===//
@@ -289,6 +309,11 @@ public:
   ///
   void setDesc(const TargetInstrDesc &tid) { TID = &tid; }
 
+  /// setDebugLoc - Replace current source information with new such.
+  /// Avoid using this, the constructor argument is preferable.
+  ///
+  void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
+
   /// RemoveOperand - Erase an operand  from an instruction, leaving it with one
   /// fewer operand than it started with.
   ///
@@ -326,11 +351,6 @@ private:
 //===----------------------------------------------------------------------===//
 // Debugging Support
 
-inline std::ostream& operator<<(std::ostream &OS, const MachineInstr &MI) {
-  MI.print(OS);
-  return OS;
-}
-
 inline raw_ostream& operator<<(raw_ostream &OS, const MachineInstr &MI) {
   MI.print(OS);
   return OS;