aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/MachineInstr.cpp
diff options
context:
space:
mode:
authorVikram S. Adve <vadve@cs.uiuc.edu>2002-08-14 16:52:58 +0000
committerVikram S. Adve <vadve@cs.uiuc.edu>2002-08-14 16:52:58 +0000
commite2a78e31862c2b6142491db5a67065756d6870be (patch)
tree8c41b3c0f5cbf4c88187d04e09474ee1d9e63492 /lib/CodeGen/MachineInstr.cpp
parentcefbd32637cdd1c7738ee8331c4242d924e983f4 (diff)
Add method MachineInstr::substituteValue() which substitutes
one Value with another one in all operands and implicit references of the machine instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3306 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineInstr.cpp')
-rw-r--r--lib/CodeGen/MachineInstr.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/CodeGen/MachineInstr.cpp b/lib/CodeGen/MachineInstr.cpp
index 79034113fc..d3608c1320 100644
--- a/lib/CodeGen/MachineInstr.cpp
+++ b/lib/CodeGen/MachineInstr.cpp
@@ -77,6 +77,35 @@ MachineInstr::SetRegForOperand(unsigned i, int regNum)
}
+// Subsitute all occurrences of Value* oldVal with newVal in all operands
+// and all implicit refs. If defsOnly == true, substitute defs only.
+unsigned
+MachineInstr::substituteValue(const Value* oldVal, Value* newVal, bool defsOnly)
+{
+ unsigned numSubst = 0;
+
+ // Subsitute operands
+ for (MachineInstr::val_op_iterator O = begin(), E = end(); O != E; ++O)
+ if (*O == oldVal)
+ if (!defsOnly || O.isDef())
+ {
+ O.getMachineOperand().value = newVal;
+ ++numSubst;
+ }
+
+ // Subsitute implicit refs
+ for (unsigned i=0, N=implicitRefs.size(); i < N; ++i)
+ if (implicitRefs[i] == oldVal)
+ if (!defsOnly || implicitRefIsDefined(i))
+ {
+ implicitRefs[i] = newVal;
+ ++numSubst;
+ }
+
+ return numSubst;
+}
+
+
void
MachineInstr::dump() const
{