Chris Lattner | cf3056d | 2003-10-13 03:32:08 +0000 | [diff] [blame] | 1 | //===-- Instruction.cpp - Implement the Instruction class -----------------===// |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 9 | // |
Chandler Carruth | c2c50cd | 2013-01-02 09:10:48 +0000 | [diff] [blame] | 10 | // This file implements the Instruction class for the IR library. |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 508b19a | 2009-12-29 07:44:16 +0000 | [diff] [blame] | 14 | #include "llvm/Instruction.h" |
Eli Friedman | 0b79a77 | 2009-07-17 04:28:42 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 16 | #include "llvm/Instructions.h" |
Victor Hernandez | 88d9839 | 2009-09-18 19:20:02 +0000 | [diff] [blame] | 17 | #include "llvm/Module.h" |
Michael Ilseman | 125fc7f | 2012-11-27 00:41:22 +0000 | [diff] [blame] | 18 | #include "llvm/Operator.h" |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 19 | #include "llvm/Support/CallSite.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 20 | #include "llvm/Support/LeakDetector.h" |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 21 | #include "llvm/Type.h" |
Chris Lattner | 4b74c83 | 2003-11-20 17:45:12 +0000 | [diff] [blame] | 22 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 23 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 24 | Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 25 | Instruction *InsertBefore) |
Chris Lattner | 61336ae | 2010-04-01 05:23:13 +0000 | [diff] [blame] | 26 | : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) { |
Chris Lattner | d1e693f | 2002-09-08 18:59:35 +0000 | [diff] [blame] | 27 | // Make sure that we get added to a basicblock |
| 28 | LeakDetector::addGarbageObject(this); |
Chris Lattner | 2aa8311 | 2002-09-10 15:45:53 +0000 | [diff] [blame] | 29 | |
| 30 | // If requested, insert this instruction into a basic block... |
| 31 | if (InsertBefore) { |
| 32 | assert(InsertBefore->getParent() && |
| 33 | "Instruction to insert before is not in a basic block!"); |
| 34 | InsertBefore->getParent()->getInstList().insert(InsertBefore, this); |
| 35 | } |
Chris Lattner | 0095054 | 2001-06-06 20:29:01 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 38 | Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps, |
Chris Lattner | 910c80a | 2007-02-24 00:55:48 +0000 | [diff] [blame] | 39 | BasicBlock *InsertAtEnd) |
Chris Lattner | 61336ae | 2010-04-01 05:23:13 +0000 | [diff] [blame] | 40 | : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(0) { |
Chris Lattner | 96d83f6 | 2005-01-29 00:35:33 +0000 | [diff] [blame] | 41 | // Make sure that we get added to a basicblock |
| 42 | LeakDetector::addGarbageObject(this); |
Alkis Evlogimenos | e5828f1 | 2004-05-26 21:41:09 +0000 | [diff] [blame] | 43 | |
| 44 | // append this instruction into the basic block |
| 45 | assert(InsertAtEnd && "Basic block to append to may not be NULL!"); |
| 46 | InsertAtEnd->getInstList().push_back(this); |
Chris Lattner | f00042a | 2007-02-13 07:54:42 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | |
Chris Lattner | 70aa33e | 2006-06-21 16:53:47 +0000 | [diff] [blame] | 50 | // Out of line virtual method, so the vtable, etc has a home. |
Gordon Henriksen | afba8fe | 2007-12-10 02:14:30 +0000 | [diff] [blame] | 51 | Instruction::~Instruction() { |
Devang Patel | f9e0a22 | 2009-09-24 16:19:11 +0000 | [diff] [blame] | 52 | assert(Parent == 0 && "Instruction still linked in the program!"); |
Dan Gohman | 4f1be4a | 2010-07-20 22:25:04 +0000 | [diff] [blame] | 53 | if (hasMetadataHashEntry()) |
| 54 | clearMetadataHashEntries(); |
Chris Lattner | 70aa33e | 2006-06-21 16:53:47 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | |
Chris Lattner | bded132 | 2002-09-06 21:33:15 +0000 | [diff] [blame] | 58 | void Instruction::setParent(BasicBlock *P) { |
Chris Lattner | 786993c | 2004-02-04 01:06:38 +0000 | [diff] [blame] | 59 | if (getParent()) { |
| 60 | if (!P) LeakDetector::addGarbageObject(this); |
| 61 | } else { |
| 62 | if (P) LeakDetector::removeGarbageObject(this); |
| 63 | } |
Chris Lattner | d1e693f | 2002-09-08 18:59:35 +0000 | [diff] [blame] | 64 | |
Chris Lattner | bded132 | 2002-09-06 21:33:15 +0000 | [diff] [blame] | 65 | Parent = P; |
| 66 | } |
| 67 | |
Chris Lattner | 4b83380 | 2004-10-11 22:21:39 +0000 | [diff] [blame] | 68 | void Instruction::removeFromParent() { |
| 69 | getParent()->getInstList().remove(this); |
| 70 | } |
| 71 | |
| 72 | void Instruction::eraseFromParent() { |
| 73 | getParent()->getInstList().erase(this); |
| 74 | } |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 75 | |
Owen Anderson | 26bb50a | 2008-06-17 18:29:27 +0000 | [diff] [blame] | 76 | /// insertBefore - Insert an unlinked instructions into a basic block |
| 77 | /// immediately before the specified instruction. |
| 78 | void Instruction::insertBefore(Instruction *InsertPos) { |
| 79 | InsertPos->getParent()->getInstList().insert(InsertPos, this); |
| 80 | } |
| 81 | |
Chris Lattner | 3ff704f | 2009-01-13 07:43:51 +0000 | [diff] [blame] | 82 | /// insertAfter - Insert an unlinked instructions into a basic block |
| 83 | /// immediately after the specified instruction. |
| 84 | void Instruction::insertAfter(Instruction *InsertPos) { |
| 85 | InsertPos->getParent()->getInstList().insertAfter(InsertPos, this); |
| 86 | } |
| 87 | |
Chris Lattner | 0fe34d8 | 2005-08-08 05:21:50 +0000 | [diff] [blame] | 88 | /// moveBefore - Unlink this instruction from its current basic block and |
| 89 | /// insert it into the basic block that MovePos lives in, right before |
| 90 | /// MovePos. |
| 91 | void Instruction::moveBefore(Instruction *MovePos) { |
| 92 | MovePos->getParent()->getInstList().splice(MovePos,getParent()->getInstList(), |
| 93 | this); |
| 94 | } |
| 95 | |
Michael Ilseman | 125fc7f | 2012-11-27 00:41:22 +0000 | [diff] [blame] | 96 | /// Set or clear the unsafe-algebra flag on this instruction, which must be an |
| 97 | /// operator which supports this flag. See LangRef.html for the meaning of this |
| 98 | /// flag. |
| 99 | void Instruction::setHasUnsafeAlgebra(bool B) { |
| 100 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 101 | cast<FPMathOperator>(this)->setHasUnsafeAlgebra(B); |
| 102 | } |
| 103 | |
| 104 | /// Set or clear the NoNaNs flag on this instruction, which must be an operator |
| 105 | /// which supports this flag. See LangRef.html for the meaning of this flag. |
| 106 | void Instruction::setHasNoNaNs(bool B) { |
| 107 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 108 | cast<FPMathOperator>(this)->setHasNoNaNs(B); |
| 109 | } |
| 110 | |
| 111 | /// Set or clear the no-infs flag on this instruction, which must be an operator |
| 112 | /// which supports this flag. See LangRef.html for the meaning of this flag. |
| 113 | void Instruction::setHasNoInfs(bool B) { |
| 114 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 115 | cast<FPMathOperator>(this)->setHasNoInfs(B); |
| 116 | } |
| 117 | |
| 118 | /// Set or clear the no-signed-zeros flag on this instruction, which must be an |
| 119 | /// operator which supports this flag. See LangRef.html for the meaning of this |
| 120 | /// flag. |
| 121 | void Instruction::setHasNoSignedZeros(bool B) { |
| 122 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 123 | cast<FPMathOperator>(this)->setHasNoSignedZeros(B); |
| 124 | } |
| 125 | |
| 126 | /// Set or clear the allow-reciprocal flag on this instruction, which must be an |
| 127 | /// operator which supports this flag. See LangRef.html for the meaning of this |
| 128 | /// flag. |
| 129 | void Instruction::setHasAllowReciprocal(bool B) { |
| 130 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 131 | cast<FPMathOperator>(this)->setHasAllowReciprocal(B); |
| 132 | } |
| 133 | |
| 134 | /// Convenience function for setting all the fast-math flags on this |
| 135 | /// instruction, which must be an operator which supports these flags. See |
| 136 | /// LangRef.html for the meaning of these flats. |
| 137 | void Instruction::setFastMathFlags(FastMathFlags FMF) { |
| 138 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 139 | cast<FPMathOperator>(this)->setFastMathFlags(FMF); |
| 140 | } |
| 141 | |
| 142 | /// Determine whether the unsafe-algebra flag is set. |
| 143 | bool Instruction::hasUnsafeAlgebra() const { |
| 144 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 145 | return cast<FPMathOperator>(this)->hasUnsafeAlgebra(); |
| 146 | } |
| 147 | |
| 148 | /// Determine whether the no-NaNs flag is set. |
| 149 | bool Instruction::hasNoNaNs() const { |
| 150 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 151 | return cast<FPMathOperator>(this)->hasNoNaNs(); |
| 152 | } |
| 153 | |
| 154 | /// Determine whether the no-infs flag is set. |
| 155 | bool Instruction::hasNoInfs() const { |
| 156 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 157 | return cast<FPMathOperator>(this)->hasNoInfs(); |
| 158 | } |
| 159 | |
| 160 | /// Determine whether the no-signed-zeros flag is set. |
| 161 | bool Instruction::hasNoSignedZeros() const { |
| 162 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 163 | return cast<FPMathOperator>(this)->hasNoSignedZeros(); |
| 164 | } |
| 165 | |
| 166 | /// Determine whether the allow-reciprocal flag is set. |
| 167 | bool Instruction::hasAllowReciprocal() const { |
| 168 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 169 | return cast<FPMathOperator>(this)->hasAllowReciprocal(); |
| 170 | } |
| 171 | |
| 172 | /// Convenience function for getting all the fast-math flags, which must be an |
| 173 | /// operator which supports these flags. See LangRef.html for the meaning of |
| 174 | /// these flats. |
| 175 | FastMathFlags Instruction::getFastMathFlags() const { |
| 176 | assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op"); |
| 177 | return cast<FPMathOperator>(this)->getFastMathFlags(); |
| 178 | } |
Chris Lattner | 0fe34d8 | 2005-08-08 05:21:50 +0000 | [diff] [blame] | 179 | |
Michael Ilseman | 4b896dd | 2012-11-29 21:25:12 +0000 | [diff] [blame] | 180 | /// Copy I's fast-math flags |
| 181 | void Instruction::copyFastMathFlags(const Instruction *I) { |
| 182 | setFastMathFlags(I->getFastMathFlags()); |
| 183 | } |
| 184 | |
| 185 | |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 186 | const char *Instruction::getOpcodeName(unsigned OpCode) { |
| 187 | switch (OpCode) { |
| 188 | // Terminators |
Chris Lattner | 0513e9f | 2002-08-14 18:18:02 +0000 | [diff] [blame] | 189 | case Ret: return "ret"; |
| 190 | case Br: return "br"; |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 191 | case Switch: return "switch"; |
Chris Lattner | ab21db7 | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 192 | case IndirectBr: return "indirectbr"; |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 193 | case Invoke: return "invoke"; |
Bill Wendling | dccc03b | 2011-07-31 06:30:59 +0000 | [diff] [blame] | 194 | case Resume: return "resume"; |
Chris Lattner | b976e66 | 2004-10-16 18:08:06 +0000 | [diff] [blame] | 195 | case Unreachable: return "unreachable"; |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 196 | |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 197 | // Standard binary operators... |
| 198 | case Add: return "add"; |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 199 | case FAdd: return "fadd"; |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 200 | case Sub: return "sub"; |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 201 | case FSub: return "fsub"; |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 202 | case Mul: return "mul"; |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 203 | case FMul: return "fmul"; |
Reid Spencer | 1628cec | 2006-10-26 06:15:43 +0000 | [diff] [blame] | 204 | case UDiv: return "udiv"; |
| 205 | case SDiv: return "sdiv"; |
| 206 | case FDiv: return "fdiv"; |
Reid Spencer | 0a783f7 | 2006-11-02 01:53:59 +0000 | [diff] [blame] | 207 | case URem: return "urem"; |
| 208 | case SRem: return "srem"; |
| 209 | case FRem: return "frem"; |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 210 | |
| 211 | // Logical operators... |
| 212 | case And: return "and"; |
| 213 | case Or : return "or"; |
| 214 | case Xor: return "xor"; |
| 215 | |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 216 | // Memory instructions... |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 217 | case Alloca: return "alloca"; |
| 218 | case Load: return "load"; |
| 219 | case Store: return "store"; |
Eli Friedman | ff03048 | 2011-07-28 21:48:00 +0000 | [diff] [blame] | 220 | case AtomicCmpXchg: return "cmpxchg"; |
| 221 | case AtomicRMW: return "atomicrmw"; |
Eli Friedman | 47f3513 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 222 | case Fence: return "fence"; |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 223 | case GetElementPtr: return "getelementptr"; |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 224 | |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 225 | // Convert instructions... |
| 226 | case Trunc: return "trunc"; |
| 227 | case ZExt: return "zext"; |
| 228 | case SExt: return "sext"; |
| 229 | case FPTrunc: return "fptrunc"; |
| 230 | case FPExt: return "fpext"; |
| 231 | case FPToUI: return "fptoui"; |
| 232 | case FPToSI: return "fptosi"; |
| 233 | case UIToFP: return "uitofp"; |
| 234 | case SIToFP: return "sitofp"; |
| 235 | case IntToPtr: return "inttoptr"; |
| 236 | case PtrToInt: return "ptrtoint"; |
| 237 | case BitCast: return "bitcast"; |
| 238 | |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 239 | // Other instructions... |
Reid Spencer | 74f1642 | 2006-12-03 06:27:29 +0000 | [diff] [blame] | 240 | case ICmp: return "icmp"; |
| 241 | case FCmp: return "fcmp"; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 242 | case PHI: return "phi"; |
| 243 | case Select: return "select"; |
| 244 | case Call: return "call"; |
| 245 | case Shl: return "shl"; |
| 246 | case LShr: return "lshr"; |
| 247 | case AShr: return "ashr"; |
| 248 | case VAArg: return "va_arg"; |
Robert Bocchino | b52ee7f | 2006-01-10 19:05:34 +0000 | [diff] [blame] | 249 | case ExtractElement: return "extractelement"; |
Reid Spencer | 3da59db | 2006-11-27 01:05:10 +0000 | [diff] [blame] | 250 | case InsertElement: return "insertelement"; |
| 251 | case ShuffleVector: return "shufflevector"; |
Matthijs Kooijman | 74b5e07 | 2008-05-30 10:31:54 +0000 | [diff] [blame] | 252 | case ExtractValue: return "extractvalue"; |
| 253 | case InsertValue: return "insertvalue"; |
Bill Wendling | e6e8826 | 2011-08-12 20:24:12 +0000 | [diff] [blame] | 254 | case LandingPad: return "landingpad"; |
Chris Lattner | 8f77dae | 2003-05-08 02:44:12 +0000 | [diff] [blame] | 255 | |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 256 | default: return "<Invalid operator> "; |
| 257 | } |
Vikram S. Adve | c105645 | 2002-07-14 23:09:40 +0000 | [diff] [blame] | 258 | } |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 259 | |
Chris Lattner | 38f1455 | 2004-11-30 02:51:53 +0000 | [diff] [blame] | 260 | /// isIdenticalTo - Return true if the specified instruction is exactly |
| 261 | /// identical to the current one. This means that all operands match and any |
| 262 | /// extra information (e.g. load is volatile) agree. |
Chris Lattner | e3a0884 | 2008-11-27 08:39:18 +0000 | [diff] [blame] | 263 | bool Instruction::isIdenticalTo(const Instruction *I) const { |
Dan Gohman | 75b0eda | 2009-08-25 22:24:20 +0000 | [diff] [blame] | 264 | return isIdenticalToWhenDefined(I) && |
Dan Gohman | 58cfa3b | 2009-08-25 22:11:20 +0000 | [diff] [blame] | 265 | SubclassOptionalData == I->SubclassOptionalData; |
| 266 | } |
| 267 | |
Dan Gohman | 75b0eda | 2009-08-25 22:24:20 +0000 | [diff] [blame] | 268 | /// isIdenticalToWhenDefined - This is like isIdenticalTo, except that it |
Dan Gohman | 58cfa3b | 2009-08-25 22:11:20 +0000 | [diff] [blame] | 269 | /// ignores the SubclassOptionalData flags, which specify conditions |
| 270 | /// under which the instruction's result is undefined. |
| 271 | bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const { |
Chris Lattner | 38f1455 | 2004-11-30 02:51:53 +0000 | [diff] [blame] | 272 | if (getOpcode() != I->getOpcode() || |
| 273 | getNumOperands() != I->getNumOperands() || |
| 274 | getType() != I->getType()) |
| 275 | return false; |
| 276 | |
| 277 | // We have two instructions of identical opcode and #operands. Check to see |
| 278 | // if all operands are the same. |
| 279 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) |
| 280 | if (getOperand(i) != I->getOperand(i)) |
| 281 | return false; |
| 282 | |
| 283 | // Check special state that is a part of some instructions. |
| 284 | if (const LoadInst *LI = dyn_cast<LoadInst>(this)) |
Dan Gohman | 9a8af45 | 2008-10-16 01:24:45 +0000 | [diff] [blame] | 285 | return LI->isVolatile() == cast<LoadInst>(I)->isVolatile() && |
Eli Friedman | e5e7712 | 2011-08-15 21:00:18 +0000 | [diff] [blame] | 286 | LI->getAlignment() == cast<LoadInst>(I)->getAlignment() && |
| 287 | LI->getOrdering() == cast<LoadInst>(I)->getOrdering() && |
| 288 | LI->getSynchScope() == cast<LoadInst>(I)->getSynchScope(); |
Chris Lattner | 38f1455 | 2004-11-30 02:51:53 +0000 | [diff] [blame] | 289 | if (const StoreInst *SI = dyn_cast<StoreInst>(this)) |
Dan Gohman | 9a8af45 | 2008-10-16 01:24:45 +0000 | [diff] [blame] | 290 | return SI->isVolatile() == cast<StoreInst>(I)->isVolatile() && |
Eli Friedman | e5e7712 | 2011-08-15 21:00:18 +0000 | [diff] [blame] | 291 | SI->getAlignment() == cast<StoreInst>(I)->getAlignment() && |
| 292 | SI->getOrdering() == cast<StoreInst>(I)->getOrdering() && |
| 293 | SI->getSynchScope() == cast<StoreInst>(I)->getSynchScope(); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 294 | if (const CmpInst *CI = dyn_cast<CmpInst>(this)) |
| 295 | return CI->getPredicate() == cast<CmpInst>(I)->getPredicate(); |
Chris Lattner | ddb6db4 | 2005-05-06 05:51:46 +0000 | [diff] [blame] | 296 | if (const CallInst *CI = dyn_cast<CallInst>(this)) |
Dan Gohman | 9a8af45 | 2008-10-16 01:24:45 +0000 | [diff] [blame] | 297 | return CI->isTailCall() == cast<CallInst>(I)->isTailCall() && |
| 298 | CI->getCallingConv() == cast<CallInst>(I)->getCallingConv() && |
Nick Lewycky | f6c63c2 | 2011-01-26 09:23:19 +0000 | [diff] [blame] | 299 | CI->getAttributes() == cast<CallInst>(I)->getAttributes(); |
Dan Gohman | 9a8af45 | 2008-10-16 01:24:45 +0000 | [diff] [blame] | 300 | if (const InvokeInst *CI = dyn_cast<InvokeInst>(this)) |
Nick Lewycky | 41fe88b | 2008-10-27 07:28:44 +0000 | [diff] [blame] | 301 | return CI->getCallingConv() == cast<InvokeInst>(I)->getCallingConv() && |
Nick Lewycky | f6c63c2 | 2011-01-26 09:23:19 +0000 | [diff] [blame] | 302 | CI->getAttributes() == cast<InvokeInst>(I)->getAttributes(); |
Jay Foad | fc6d3a4 | 2011-07-13 10:26:04 +0000 | [diff] [blame] | 303 | if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(this)) |
| 304 | return IVI->getIndices() == cast<InsertValueInst>(I)->getIndices(); |
| 305 | if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(this)) |
| 306 | return EVI->getIndices() == cast<ExtractValueInst>(I)->getIndices(); |
Eli Friedman | 8a552bb | 2011-07-27 01:08:30 +0000 | [diff] [blame] | 307 | if (const FenceInst *FI = dyn_cast<FenceInst>(this)) |
| 308 | return FI->getOrdering() == cast<FenceInst>(FI)->getOrdering() && |
| 309 | FI->getSynchScope() == cast<FenceInst>(FI)->getSynchScope(); |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 310 | if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(this)) |
| 311 | return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I)->isVolatile() && |
| 312 | CXI->getOrdering() == cast<AtomicCmpXchgInst>(I)->getOrdering() && |
| 313 | CXI->getSynchScope() == cast<AtomicCmpXchgInst>(I)->getSynchScope(); |
| 314 | if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(this)) |
| 315 | return RMWI->getOperation() == cast<AtomicRMWInst>(I)->getOperation() && |
| 316 | RMWI->isVolatile() == cast<AtomicRMWInst>(I)->isVolatile() && |
| 317 | RMWI->getOrdering() == cast<AtomicRMWInst>(I)->getOrdering() && |
| 318 | RMWI->getSynchScope() == cast<AtomicRMWInst>(I)->getSynchScope(); |
Joel Jones | 9df72a9 | 2012-05-10 15:59:41 +0000 | [diff] [blame] | 319 | if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) { |
| 320 | const PHINode *otherPHI = cast<PHINode>(I); |
| 321 | for (unsigned i = 0, e = thisPHI->getNumOperands(); i != e; ++i) { |
| 322 | if (thisPHI->getIncomingBlock(i) != otherPHI->getIncomingBlock(i)) |
| 323 | return false; |
| 324 | } |
| 325 | return true; |
| 326 | } |
Chris Lattner | 38f1455 | 2004-11-30 02:51:53 +0000 | [diff] [blame] | 327 | return true; |
| 328 | } |
| 329 | |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 330 | // isSameOperationAs |
Dan Gohman | 194ae78 | 2009-06-12 19:03:05 +0000 | [diff] [blame] | 331 | // This should be kept in sync with isEquivalentOperation in |
| 332 | // lib/Transforms/IPO/MergeFunctions.cpp. |
Hal Finkel | ec4e85e | 2012-06-28 05:42:26 +0000 | [diff] [blame] | 333 | bool Instruction::isSameOperationAs(const Instruction *I, |
| 334 | unsigned flags) const { |
| 335 | bool IgnoreAlignment = flags & CompareIgnoringAlignment; |
| 336 | bool UseScalarTypes = flags & CompareUsingScalarTypes; |
| 337 | |
Dan Gohman | 194ae78 | 2009-06-12 19:03:05 +0000 | [diff] [blame] | 338 | if (getOpcode() != I->getOpcode() || |
| 339 | getNumOperands() != I->getNumOperands() || |
Hal Finkel | ec4e85e | 2012-06-28 05:42:26 +0000 | [diff] [blame] | 340 | (UseScalarTypes ? |
| 341 | getType()->getScalarType() != I->getType()->getScalarType() : |
| 342 | getType() != I->getType())) |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 343 | return false; |
| 344 | |
| 345 | // We have two instructions of identical opcode and #operands. Check to see |
| 346 | // if all operands are the same type |
| 347 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) |
Hal Finkel | ec4e85e | 2012-06-28 05:42:26 +0000 | [diff] [blame] | 348 | if (UseScalarTypes ? |
| 349 | getOperand(i)->getType()->getScalarType() != |
| 350 | I->getOperand(i)->getType()->getScalarType() : |
| 351 | getOperand(i)->getType() != I->getOperand(i)->getType()) |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 352 | return false; |
| 353 | |
| 354 | // Check special state that is a part of some instructions. |
| 355 | if (const LoadInst *LI = dyn_cast<LoadInst>(this)) |
Dan Gohman | 9a8af45 | 2008-10-16 01:24:45 +0000 | [diff] [blame] | 356 | return LI->isVolatile() == cast<LoadInst>(I)->isVolatile() && |
Hal Finkel | ec4e85e | 2012-06-28 05:42:26 +0000 | [diff] [blame] | 357 | (LI->getAlignment() == cast<LoadInst>(I)->getAlignment() || |
| 358 | IgnoreAlignment) && |
Eli Friedman | e5e7712 | 2011-08-15 21:00:18 +0000 | [diff] [blame] | 359 | LI->getOrdering() == cast<LoadInst>(I)->getOrdering() && |
| 360 | LI->getSynchScope() == cast<LoadInst>(I)->getSynchScope(); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 361 | if (const StoreInst *SI = dyn_cast<StoreInst>(this)) |
Dan Gohman | 9a8af45 | 2008-10-16 01:24:45 +0000 | [diff] [blame] | 362 | return SI->isVolatile() == cast<StoreInst>(I)->isVolatile() && |
Hal Finkel | ec4e85e | 2012-06-28 05:42:26 +0000 | [diff] [blame] | 363 | (SI->getAlignment() == cast<StoreInst>(I)->getAlignment() || |
| 364 | IgnoreAlignment) && |
Eli Friedman | e5e7712 | 2011-08-15 21:00:18 +0000 | [diff] [blame] | 365 | SI->getOrdering() == cast<StoreInst>(I)->getOrdering() && |
| 366 | SI->getSynchScope() == cast<StoreInst>(I)->getSynchScope(); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 367 | if (const CmpInst *CI = dyn_cast<CmpInst>(this)) |
| 368 | return CI->getPredicate() == cast<CmpInst>(I)->getPredicate(); |
| 369 | if (const CallInst *CI = dyn_cast<CallInst>(this)) |
Dan Gohman | 9a8af45 | 2008-10-16 01:24:45 +0000 | [diff] [blame] | 370 | return CI->isTailCall() == cast<CallInst>(I)->isTailCall() && |
| 371 | CI->getCallingConv() == cast<CallInst>(I)->getCallingConv() && |
Nick Lewycky | f6c63c2 | 2011-01-26 09:23:19 +0000 | [diff] [blame] | 372 | CI->getAttributes() == cast<CallInst>(I)->getAttributes(); |
Dan Gohman | 9a8af45 | 2008-10-16 01:24:45 +0000 | [diff] [blame] | 373 | if (const InvokeInst *CI = dyn_cast<InvokeInst>(this)) |
Nick Lewycky | 41fe88b | 2008-10-27 07:28:44 +0000 | [diff] [blame] | 374 | return CI->getCallingConv() == cast<InvokeInst>(I)->getCallingConv() && |
Nick Lewycky | f6c63c2 | 2011-01-26 09:23:19 +0000 | [diff] [blame] | 375 | CI->getAttributes() == |
| 376 | cast<InvokeInst>(I)->getAttributes(); |
Jay Foad | fc6d3a4 | 2011-07-13 10:26:04 +0000 | [diff] [blame] | 377 | if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(this)) |
| 378 | return IVI->getIndices() == cast<InsertValueInst>(I)->getIndices(); |
| 379 | if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(this)) |
| 380 | return EVI->getIndices() == cast<ExtractValueInst>(I)->getIndices(); |
Eli Friedman | 8a552bb | 2011-07-27 01:08:30 +0000 | [diff] [blame] | 381 | if (const FenceInst *FI = dyn_cast<FenceInst>(this)) |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 382 | return FI->getOrdering() == cast<FenceInst>(I)->getOrdering() && |
| 383 | FI->getSynchScope() == cast<FenceInst>(I)->getSynchScope(); |
| 384 | if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(this)) |
| 385 | return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I)->isVolatile() && |
| 386 | CXI->getOrdering() == cast<AtomicCmpXchgInst>(I)->getOrdering() && |
| 387 | CXI->getSynchScope() == cast<AtomicCmpXchgInst>(I)->getSynchScope(); |
| 388 | if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(this)) |
| 389 | return RMWI->getOperation() == cast<AtomicRMWInst>(I)->getOperation() && |
| 390 | RMWI->isVolatile() == cast<AtomicRMWInst>(I)->isVolatile() && |
| 391 | RMWI->getOrdering() == cast<AtomicRMWInst>(I)->getOrdering() && |
| 392 | RMWI->getSynchScope() == cast<AtomicRMWInst>(I)->getSynchScope(); |
Reid Spencer | e4d87aa | 2006-12-23 06:05:41 +0000 | [diff] [blame] | 393 | |
| 394 | return true; |
| 395 | } |
| 396 | |
Chris Lattner | 7ae40e7 | 2008-04-20 22:11:30 +0000 | [diff] [blame] | 397 | /// isUsedOutsideOfBlock - Return true if there are any uses of I outside of the |
| 398 | /// specified block. Note that PHI nodes are considered to evaluate their |
| 399 | /// operands in the corresponding predecessor block. |
| 400 | bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const { |
Gabor Greif | 60ad781 | 2010-03-25 23:06:16 +0000 | [diff] [blame] | 401 | for (const_use_iterator UI = use_begin(), E = use_end(); UI != E; ++UI) { |
Chris Lattner | 7ae40e7 | 2008-04-20 22:11:30 +0000 | [diff] [blame] | 402 | // PHI nodes uses values in the corresponding predecessor block. For other |
| 403 | // instructions, just check to see whether the parent of the use matches up. |
Gabor Greif | a8b9df7 | 2010-07-12 10:36:48 +0000 | [diff] [blame] | 404 | const User *U = *UI; |
| 405 | const PHINode *PN = dyn_cast<PHINode>(U); |
Chris Lattner | 7ae40e7 | 2008-04-20 22:11:30 +0000 | [diff] [blame] | 406 | if (PN == 0) { |
Gabor Greif | a8b9df7 | 2010-07-12 10:36:48 +0000 | [diff] [blame] | 407 | if (cast<Instruction>(U)->getParent() != BB) |
Chris Lattner | 7ae40e7 | 2008-04-20 22:11:30 +0000 | [diff] [blame] | 408 | return true; |
| 409 | continue; |
| 410 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 411 | |
Gabor Greif | a36791d | 2009-01-23 19:40:15 +0000 | [diff] [blame] | 412 | if (PN->getIncomingBlock(UI) != BB) |
Chris Lattner | 7ae40e7 | 2008-04-20 22:11:30 +0000 | [diff] [blame] | 413 | return true; |
| 414 | } |
Daniel Dunbar | a279bc3 | 2009-09-20 02:20:51 +0000 | [diff] [blame] | 415 | return false; |
Chris Lattner | 7ae40e7 | 2008-04-20 22:11:30 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Chris Lattner | d96288a | 2008-05-08 17:16:51 +0000 | [diff] [blame] | 418 | /// mayReadFromMemory - Return true if this instruction may read memory. |
| 419 | /// |
| 420 | bool Instruction::mayReadFromMemory() const { |
| 421 | switch (getOpcode()) { |
| 422 | default: return false; |
Chris Lattner | d96288a | 2008-05-08 17:16:51 +0000 | [diff] [blame] | 423 | case Instruction::VAArg: |
Chris Lattner | 748118d | 2008-05-08 21:58:49 +0000 | [diff] [blame] | 424 | case Instruction::Load: |
Eli Friedman | 8a552bb | 2011-07-27 01:08:30 +0000 | [diff] [blame] | 425 | case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 426 | case Instruction::AtomicCmpXchg: |
| 427 | case Instruction::AtomicRMW: |
Chris Lattner | d96288a | 2008-05-08 17:16:51 +0000 | [diff] [blame] | 428 | return true; |
| 429 | case Instruction::Call: |
| 430 | return !cast<CallInst>(this)->doesNotAccessMemory(); |
| 431 | case Instruction::Invoke: |
| 432 | return !cast<InvokeInst>(this)->doesNotAccessMemory(); |
Chris Lattner | 748118d | 2008-05-08 21:58:49 +0000 | [diff] [blame] | 433 | case Instruction::Store: |
Eli Friedman | e5e7712 | 2011-08-15 21:00:18 +0000 | [diff] [blame] | 434 | return !cast<StoreInst>(this)->isUnordered(); |
Chris Lattner | d96288a | 2008-05-08 17:16:51 +0000 | [diff] [blame] | 435 | } |
| 436 | } |
Chris Lattner | 7ae40e7 | 2008-04-20 22:11:30 +0000 | [diff] [blame] | 437 | |
Chris Lattner | bb5493d | 2007-02-15 23:15:00 +0000 | [diff] [blame] | 438 | /// mayWriteToMemory - Return true if this instruction may modify memory. |
| 439 | /// |
| 440 | bool Instruction::mayWriteToMemory() const { |
| 441 | switch (getOpcode()) { |
| 442 | default: return false; |
Eli Friedman | 8a552bb | 2011-07-27 01:08:30 +0000 | [diff] [blame] | 443 | case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 444 | case Instruction::Store: |
Chris Lattner | bb5493d | 2007-02-15 23:15:00 +0000 | [diff] [blame] | 445 | case Instruction::VAArg: |
Eli Friedman | 55ba816 | 2011-07-29 03:05:32 +0000 | [diff] [blame] | 446 | case Instruction::AtomicCmpXchg: |
| 447 | case Instruction::AtomicRMW: |
Chris Lattner | bb5493d | 2007-02-15 23:15:00 +0000 | [diff] [blame] | 448 | return true; |
| 449 | case Instruction::Call: |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 450 | return !cast<CallInst>(this)->onlyReadsMemory(); |
Chris Lattner | d96288a | 2008-05-08 17:16:51 +0000 | [diff] [blame] | 451 | case Instruction::Invoke: |
| 452 | return !cast<InvokeInst>(this)->onlyReadsMemory(); |
Chris Lattner | bb5493d | 2007-02-15 23:15:00 +0000 | [diff] [blame] | 453 | case Instruction::Load: |
Eli Friedman | e5e7712 | 2011-08-15 21:00:18 +0000 | [diff] [blame] | 454 | return !cast<LoadInst>(this)->isUnordered(); |
Chris Lattner | bb5493d | 2007-02-15 23:15:00 +0000 | [diff] [blame] | 455 | } |
| 456 | } |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 457 | |
Duncan Sands | 7af1c78 | 2009-05-06 06:49:50 +0000 | [diff] [blame] | 458 | /// mayThrow - Return true if this instruction may throw an exception. |
| 459 | /// |
| 460 | bool Instruction::mayThrow() const { |
| 461 | if (const CallInst *CI = dyn_cast<CallInst>(this)) |
| 462 | return !CI->doesNotThrow(); |
Bill Wendling | 55fdb4e | 2011-08-16 21:15:50 +0000 | [diff] [blame] | 463 | return isa<ResumeInst>(this); |
Duncan Sands | 7af1c78 | 2009-05-06 06:49:50 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 466 | /// isAssociative - Return true if the instruction is associative: |
| 467 | /// |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 468 | /// Associative operators satisfy: x op (y op z) === (x op y) op z |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 469 | /// |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 470 | /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative. |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 471 | /// |
Duncan Sands | 0d7ce5f | 2010-12-20 13:10:23 +0000 | [diff] [blame] | 472 | bool Instruction::isAssociative(unsigned Opcode) { |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 473 | return Opcode == And || Opcode == Or || Opcode == Xor || |
| 474 | Opcode == Add || Opcode == Mul; |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Shuxin Yang | 9b7f6f2 | 2012-11-29 01:47:31 +0000 | [diff] [blame] | 477 | bool Instruction::isAssociative() const { |
| 478 | unsigned Opcode = getOpcode(); |
| 479 | if (isAssociative(Opcode)) |
| 480 | return true; |
| 481 | |
| 482 | switch (Opcode) { |
| 483 | case FMul: |
| 484 | case FAdd: |
| 485 | return cast<FPMathOperator>(this)->hasUnsafeAlgebra(); |
| 486 | default: |
| 487 | return false; |
| 488 | } |
| 489 | } |
| 490 | |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 491 | /// isCommutative - Return true if the instruction is commutative: |
| 492 | /// |
Misha Brukman | 6b63452 | 2003-10-10 17:54:14 +0000 | [diff] [blame] | 493 | /// Commutative operators satisfy: (x op y) === (y op x) |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 494 | /// |
| 495 | /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when |
| 496 | /// applied to any type. |
| 497 | /// |
| 498 | bool Instruction::isCommutative(unsigned op) { |
| 499 | switch (op) { |
| 500 | case Add: |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 501 | case FAdd: |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 502 | case Mul: |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 503 | case FMul: |
Misha Brukman | fd93908 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 504 | case And: |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 505 | case Or: |
| 506 | case Xor: |
Chris Lattner | f2da724 | 2002-10-31 04:14:01 +0000 | [diff] [blame] | 507 | return true; |
| 508 | default: |
| 509 | return false; |
| 510 | } |
| 511 | } |
Tanya Lattner | 741bb00 | 2003-07-31 04:05:50 +0000 | [diff] [blame] | 512 | |
Duncan Sands | c038a78 | 2012-06-12 14:33:56 +0000 | [diff] [blame] | 513 | /// isIdempotent - Return true if the instruction is idempotent: |
| 514 | /// |
| 515 | /// Idempotent operators satisfy: x op x === x |
| 516 | /// |
| 517 | /// In LLVM, the And and Or operators are idempotent. |
| 518 | /// |
| 519 | bool Instruction::isIdempotent(unsigned Opcode) { |
| 520 | return Opcode == And || Opcode == Or; |
| 521 | } |
| 522 | |
| 523 | /// isNilpotent - Return true if the instruction is nilpotent: |
| 524 | /// |
| 525 | /// Nilpotent operators satisfy: x op x === Id, |
| 526 | /// |
| 527 | /// where Id is the identity for the operator, i.e. a constant such that |
| 528 | /// x op Id === x and Id op x === x for all x. |
| 529 | /// |
| 530 | /// In LLVM, the Xor operator is nilpotent. |
| 531 | /// |
| 532 | bool Instruction::isNilpotent(unsigned Opcode) { |
| 533 | return Opcode == Xor; |
| 534 | } |
| 535 | |
Devang Patel | 50b6e33 | 2009-10-27 22:16:29 +0000 | [diff] [blame] | 536 | Instruction *Instruction::clone() const { |
| 537 | Instruction *New = clone_impl(); |
| 538 | New->SubclassOptionalData = SubclassOptionalData; |
Chris Lattner | 508b19a | 2009-12-29 07:44:16 +0000 | [diff] [blame] | 539 | if (!hasMetadata()) |
| 540 | return New; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 541 | |
Chris Lattner | 508b19a | 2009-12-29 07:44:16 +0000 | [diff] [blame] | 542 | // Otherwise, enumerate and copy over metadata from the old instruction to the |
| 543 | // new one. |
| 544 | SmallVector<std::pair<unsigned, MDNode*>, 4> TheMDs; |
Chris Lattner | 4baa510 | 2011-07-14 18:57:51 +0000 | [diff] [blame] | 545 | getAllMetadataOtherThanDebugLoc(TheMDs); |
Chris Lattner | 508b19a | 2009-12-29 07:44:16 +0000 | [diff] [blame] | 546 | for (unsigned i = 0, e = TheMDs.size(); i != e; ++i) |
| 547 | New->setMetadata(TheMDs[i].first, TheMDs[i].second); |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 548 | |
Chris Lattner | 4baa510 | 2011-07-14 18:57:51 +0000 | [diff] [blame] | 549 | New->setDebugLoc(getDebugLoc()); |
Devang Patel | 50b6e33 | 2009-10-27 22:16:29 +0000 | [diff] [blame] | 550 | return New; |
| 551 | } |