1 //===-- Instruction.cpp - Implement the Instruction class -----------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
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 Instruction class for the IR library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "llvm/IR/Instruction.h"
15 #include "llvm/IR/CallSite.h"
16 #include "llvm/IR/Constants.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/IR/Operator.h"
20 #include "llvm/IR/Type.h"
21 using namespace llvm;
22 
23 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
24                          Instruction *InsertBefore)
25   : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
26 
27   // If requested, insert this instruction into a basic block...
28   if (InsertBefore) {
29     BasicBlock *BB = InsertBefore->getParent();
30     assert(BB && "Instruction to insert before is not in a basic block!");
31     BB->getInstList().insert(InsertBefore->getIterator(), this);
32   }
33 }
34 
35 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
36                          BasicBlock *InsertAtEnd)
37   : User(ty, Value::InstructionVal + it, Ops, NumOps), Parent(nullptr) {
38 
39   // append this instruction into the basic block
40   assert(InsertAtEnd && "Basic block to append to may not be NULL!");
41   InsertAtEnd->getInstList().push_back(this);
42 }
43 
44 
45 // Out of line virtual method, so the vtable, etc has a home.
46 Instruction::~Instruction() {
47   assert(!Parent && "Instruction still linked in the program!");
48   if (hasMetadataHashEntry())
49     clearMetadataHashEntries();
50 }
51 
52 
53 void Instruction::setParent(BasicBlock *P) {
54   Parent = P;
55 }
56 
57 const Module *Instruction::getModule() const {
58   return getParent()->getModule();
59 }
60 
61 Module *Instruction::getModule() {
62   return getParent()->getModule();
63 }
64 
65 Function *Instruction::getFunction() { return getParent()->getParent(); }
66 
67 const Function *Instruction::getFunction() const {
68   return getParent()->getParent();
69 }
70 
71 void Instruction::removeFromParent() {
72   getParent()->getInstList().remove(getIterator());
73 }
74 
75 iplist<Instruction>::iterator Instruction::eraseFromParent() {
76   return getParent()->getInstList().erase(getIterator());
77 }
78 
79 /// Insert an unlinked instruction into a basic block immediately before the
80 /// specified instruction.
81 void Instruction::insertBefore(Instruction *InsertPos) {
82   InsertPos->getParent()->getInstList().insert(InsertPos->getIterator(), this);
83 }
84 
85 /// Insert an unlinked instruction into a basic block immediately after the
86 /// specified instruction.
87 void Instruction::insertAfter(Instruction *InsertPos) {
88   InsertPos->getParent()->getInstList().insertAfter(InsertPos->getIterator(),
89                                                     this);
90 }
91 
92 /// Unlink this instruction from its current basic block and insert it into the
93 /// basic block that MovePos lives in, right before MovePos.
94 void Instruction::moveBefore(Instruction *MovePos) {
95   MovePos->getParent()->getInstList().splice(
96       MovePos->getIterator(), getParent()->getInstList(), getIterator());
97 }
98 
99 /// Set or clear the unsafe-algebra flag on this instruction, which must be an
100 /// operator which supports this flag. See LangRef.html for the meaning of this
101 /// flag.
102 void Instruction::setHasUnsafeAlgebra(bool B) {
103   assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
104   cast<FPMathOperator>(this)->setHasUnsafeAlgebra(B);
105 }
106 
107 /// Set or clear the NoNaNs flag on this instruction, which must be an operator
108 /// which supports this flag. See LangRef.html for the meaning of this flag.
109 void Instruction::setHasNoNaNs(bool B) {
110   assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
111   cast<FPMathOperator>(this)->setHasNoNaNs(B);
112 }
113 
114 /// Set or clear the no-infs flag on this instruction, which must be an operator
115 /// which supports this flag. See LangRef.html for the meaning of this flag.
116 void Instruction::setHasNoInfs(bool B) {
117   assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
118   cast<FPMathOperator>(this)->setHasNoInfs(B);
119 }
120 
121 /// Set or clear the no-signed-zeros flag on this instruction, which must be an
122 /// operator which supports this flag. See LangRef.html for the meaning of this
123 /// flag.
124 void Instruction::setHasNoSignedZeros(bool B) {
125   assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
126   cast<FPMathOperator>(this)->setHasNoSignedZeros(B);
127 }
128 
129 /// Set or clear the allow-reciprocal flag on this instruction, which must be an
130 /// operator which supports this flag. See LangRef.html for the meaning of this
131 /// flag.
132 void Instruction::setHasAllowReciprocal(bool B) {
133   assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
134   cast<FPMathOperator>(this)->setHasAllowReciprocal(B);
135 }
136 
137 /// Convenience function for setting all the fast-math flags on this
138 /// instruction, which must be an operator which supports these flags. See
139 /// LangRef.html for the meaning of these flats.
140 void Instruction::setFastMathFlags(FastMathFlags FMF) {
141   assert(isa<FPMathOperator>(this) && "setting fast-math flag on invalid op");
142   cast<FPMathOperator>(this)->setFastMathFlags(FMF);
143 }
144 
145 void Instruction::copyFastMathFlags(FastMathFlags FMF) {
146   assert(isa<FPMathOperator>(this) && "copying fast-math flag on invalid op");
147   cast<FPMathOperator>(this)->copyFastMathFlags(FMF);
148 }
149 
150 /// Determine whether the unsafe-algebra flag is set.
151 bool Instruction::hasUnsafeAlgebra() const {
152   assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
153   return cast<FPMathOperator>(this)->hasUnsafeAlgebra();
154 }
155 
156 /// Determine whether the no-NaNs flag is set.
157 bool Instruction::hasNoNaNs() const {
158   assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
159   return cast<FPMathOperator>(this)->hasNoNaNs();
160 }
161 
162 /// Determine whether the no-infs flag is set.
163 bool Instruction::hasNoInfs() const {
164   assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
165   return cast<FPMathOperator>(this)->hasNoInfs();
166 }
167 
168 /// Determine whether the no-signed-zeros flag is set.
169 bool Instruction::hasNoSignedZeros() const {
170   assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
171   return cast<FPMathOperator>(this)->hasNoSignedZeros();
172 }
173 
174 /// Determine whether the allow-reciprocal flag is set.
175 bool Instruction::hasAllowReciprocal() const {
176   assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
177   return cast<FPMathOperator>(this)->hasAllowReciprocal();
178 }
179 
180 /// Convenience function for getting all the fast-math flags, which must be an
181 /// operator which supports these flags. See LangRef.html for the meaning of
182 /// these flags.
183 FastMathFlags Instruction::getFastMathFlags() const {
184   assert(isa<FPMathOperator>(this) && "getting fast-math flag on invalid op");
185   return cast<FPMathOperator>(this)->getFastMathFlags();
186 }
187 
188 /// Copy I's fast-math flags
189 void Instruction::copyFastMathFlags(const Instruction *I) {
190   copyFastMathFlags(I->getFastMathFlags());
191 }
192 
193 
194 const char *Instruction::getOpcodeName(unsigned OpCode) {
195   switch (OpCode) {
196   // Terminators
197   case Ret:    return "ret";
198   case Br:     return "br";
199   case Switch: return "switch";
200   case IndirectBr: return "indirectbr";
201   case Invoke: return "invoke";
202   case Resume: return "resume";
203   case Unreachable: return "unreachable";
204   case CleanupRet: return "cleanupret";
205   case CatchRet: return "catchret";
206   case CatchPad: return "catchpad";
207   case CatchSwitch: return "catchswitch";
208 
209   // Standard binary operators...
210   case Add: return "add";
211   case FAdd: return "fadd";
212   case Sub: return "sub";
213   case FSub: return "fsub";
214   case Mul: return "mul";
215   case FMul: return "fmul";
216   case UDiv: return "udiv";
217   case SDiv: return "sdiv";
218   case FDiv: return "fdiv";
219   case URem: return "urem";
220   case SRem: return "srem";
221   case FRem: return "frem";
222 
223   // Logical operators...
224   case And: return "and";
225   case Or : return "or";
226   case Xor: return "xor";
227 
228   // Memory instructions...
229   case Alloca:        return "alloca";
230   case Load:          return "load";
231   case Store:         return "store";
232   case AtomicCmpXchg: return "cmpxchg";
233   case AtomicRMW:     return "atomicrmw";
234   case Fence:         return "fence";
235   case GetElementPtr: return "getelementptr";
236 
237   // Convert instructions...
238   case Trunc:         return "trunc";
239   case ZExt:          return "zext";
240   case SExt:          return "sext";
241   case FPTrunc:       return "fptrunc";
242   case FPExt:         return "fpext";
243   case FPToUI:        return "fptoui";
244   case FPToSI:        return "fptosi";
245   case UIToFP:        return "uitofp";
246   case SIToFP:        return "sitofp";
247   case IntToPtr:      return "inttoptr";
248   case PtrToInt:      return "ptrtoint";
249   case BitCast:       return "bitcast";
250   case AddrSpaceCast: return "addrspacecast";
251 
252   // Other instructions...
253   case ICmp:           return "icmp";
254   case FCmp:           return "fcmp";
255   case PHI:            return "phi";
256   case Select:         return "select";
257   case Call:           return "call";
258   case Shl:            return "shl";
259   case LShr:           return "lshr";
260   case AShr:           return "ashr";
261   case VAArg:          return "va_arg";
262   case ExtractElement: return "extractelement";
263   case InsertElement:  return "insertelement";
264   case ShuffleVector:  return "shufflevector";
265   case ExtractValue:   return "extractvalue";
266   case InsertValue:    return "insertvalue";
267   case LandingPad:     return "landingpad";
268   case CleanupPad:     return "cleanuppad";
269 
270   default: return "<Invalid operator> ";
271   }
272 }
273 
274 /// Return true if both instructions have the same special state This must be
275 /// kept in sync with FunctionComparator::cmpOperations in
276 /// lib/Transforms/IPO/MergeFunctions.cpp.
277 static bool haveSameSpecialState(const Instruction *I1, const Instruction *I2,
278                                  bool IgnoreAlignment = false) {
279   assert(I1->getOpcode() == I2->getOpcode() &&
280          "Can not compare special state of different instructions");
281 
282   if (const AllocaInst *AI = dyn_cast<AllocaInst>(I1))
283     return AI->getAllocatedType() == cast<AllocaInst>(I2)->getAllocatedType() &&
284            (AI->getAlignment() == cast<AllocaInst>(I2)->getAlignment() ||
285             IgnoreAlignment);
286   if (const LoadInst *LI = dyn_cast<LoadInst>(I1))
287     return LI->isVolatile() == cast<LoadInst>(I2)->isVolatile() &&
288            (LI->getAlignment() == cast<LoadInst>(I2)->getAlignment() ||
289             IgnoreAlignment) &&
290            LI->getOrdering() == cast<LoadInst>(I2)->getOrdering() &&
291            LI->getSynchScope() == cast<LoadInst>(I2)->getSynchScope();
292   if (const StoreInst *SI = dyn_cast<StoreInst>(I1))
293     return SI->isVolatile() == cast<StoreInst>(I2)->isVolatile() &&
294            (SI->getAlignment() == cast<StoreInst>(I2)->getAlignment() ||
295             IgnoreAlignment) &&
296            SI->getOrdering() == cast<StoreInst>(I2)->getOrdering() &&
297            SI->getSynchScope() == cast<StoreInst>(I2)->getSynchScope();
298   if (const CmpInst *CI = dyn_cast<CmpInst>(I1))
299     return CI->getPredicate() == cast<CmpInst>(I2)->getPredicate();
300   if (const CallInst *CI = dyn_cast<CallInst>(I1))
301     return CI->isTailCall() == cast<CallInst>(I2)->isTailCall() &&
302            CI->getCallingConv() == cast<CallInst>(I2)->getCallingConv() &&
303            CI->getAttributes() == cast<CallInst>(I2)->getAttributes() &&
304            CI->hasIdenticalOperandBundleSchema(*cast<CallInst>(I2));
305   if (const InvokeInst *CI = dyn_cast<InvokeInst>(I1))
306     return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
307            CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
308            CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
309   if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
310     return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
311   if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
312     return EVI->getIndices() == cast<ExtractValueInst>(I2)->getIndices();
313   if (const FenceInst *FI = dyn_cast<FenceInst>(I1))
314     return FI->getOrdering() == cast<FenceInst>(I2)->getOrdering() &&
315            FI->getSynchScope() == cast<FenceInst>(I2)->getSynchScope();
316   if (const AtomicCmpXchgInst *CXI = dyn_cast<AtomicCmpXchgInst>(I1))
317     return CXI->isVolatile() == cast<AtomicCmpXchgInst>(I2)->isVolatile() &&
318            CXI->isWeak() == cast<AtomicCmpXchgInst>(I2)->isWeak() &&
319            CXI->getSuccessOrdering() ==
320                cast<AtomicCmpXchgInst>(I2)->getSuccessOrdering() &&
321            CXI->getFailureOrdering() ==
322                cast<AtomicCmpXchgInst>(I2)->getFailureOrdering() &&
323            CXI->getSynchScope() == cast<AtomicCmpXchgInst>(I2)->getSynchScope();
324   if (const AtomicRMWInst *RMWI = dyn_cast<AtomicRMWInst>(I1))
325     return RMWI->getOperation() == cast<AtomicRMWInst>(I2)->getOperation() &&
326            RMWI->isVolatile() == cast<AtomicRMWInst>(I2)->isVolatile() &&
327            RMWI->getOrdering() == cast<AtomicRMWInst>(I2)->getOrdering() &&
328            RMWI->getSynchScope() == cast<AtomicRMWInst>(I2)->getSynchScope();
329 
330   return true;
331 }
332 
333 /// isIdenticalTo - Return true if the specified instruction is exactly
334 /// identical to the current one.  This means that all operands match and any
335 /// extra information (e.g. load is volatile) agree.
336 bool Instruction::isIdenticalTo(const Instruction *I) const {
337   return isIdenticalToWhenDefined(I) &&
338          SubclassOptionalData == I->SubclassOptionalData;
339 }
340 
341 /// isIdenticalToWhenDefined - This is like isIdenticalTo, except that it
342 /// ignores the SubclassOptionalData flags, which specify conditions
343 /// under which the instruction's result is undefined.
344 bool Instruction::isIdenticalToWhenDefined(const Instruction *I) const {
345   if (getOpcode() != I->getOpcode() ||
346       getNumOperands() != I->getNumOperands() ||
347       getType() != I->getType())
348     return false;
349 
350   // If both instructions have no operands, they are identical.
351   if (getNumOperands() == 0 && I->getNumOperands() == 0)
352     return haveSameSpecialState(this, I);
353 
354   // We have two instructions of identical opcode and #operands.  Check to see
355   // if all operands are the same.
356   if (!std::equal(op_begin(), op_end(), I->op_begin()))
357     return false;
358 
359   if (const PHINode *thisPHI = dyn_cast<PHINode>(this)) {
360     const PHINode *otherPHI = cast<PHINode>(I);
361     return std::equal(thisPHI->block_begin(), thisPHI->block_end(),
362                       otherPHI->block_begin());
363   }
364 
365   return haveSameSpecialState(this, I);
366 }
367 
368 // Keep this in sync with FunctionComparator::cmpOperations in
369 // lib/Transforms/IPO/MergeFunctions.cpp.
370 bool Instruction::isSameOperationAs(const Instruction *I,
371                                     unsigned flags) const {
372   bool IgnoreAlignment = flags & CompareIgnoringAlignment;
373   bool UseScalarTypes  = flags & CompareUsingScalarTypes;
374 
375   if (getOpcode() != I->getOpcode() ||
376       getNumOperands() != I->getNumOperands() ||
377       (UseScalarTypes ?
378        getType()->getScalarType() != I->getType()->getScalarType() :
379        getType() != I->getType()))
380     return false;
381 
382   // We have two instructions of identical opcode and #operands.  Check to see
383   // if all operands are the same type
384   for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
385     if (UseScalarTypes ?
386         getOperand(i)->getType()->getScalarType() !=
387           I->getOperand(i)->getType()->getScalarType() :
388         getOperand(i)->getType() != I->getOperand(i)->getType())
389       return false;
390 
391   return haveSameSpecialState(this, I, IgnoreAlignment);
392 }
393 
394 /// isUsedOutsideOfBlock - Return true if there are any uses of I outside of the
395 /// specified block.  Note that PHI nodes are considered to evaluate their
396 /// operands in the corresponding predecessor block.
397 bool Instruction::isUsedOutsideOfBlock(const BasicBlock *BB) const {
398   for (const Use &U : uses()) {
399     // PHI nodes uses values in the corresponding predecessor block.  For other
400     // instructions, just check to see whether the parent of the use matches up.
401     const Instruction *I = cast<Instruction>(U.getUser());
402     const PHINode *PN = dyn_cast<PHINode>(I);
403     if (!PN) {
404       if (I->getParent() != BB)
405         return true;
406       continue;
407     }
408 
409     if (PN->getIncomingBlock(U) != BB)
410       return true;
411   }
412   return false;
413 }
414 
415 /// mayReadFromMemory - Return true if this instruction may read memory.
416 ///
417 bool Instruction::mayReadFromMemory() const {
418   switch (getOpcode()) {
419   default: return false;
420   case Instruction::VAArg:
421   case Instruction::Load:
422   case Instruction::Fence: // FIXME: refine definition of mayReadFromMemory
423   case Instruction::AtomicCmpXchg:
424   case Instruction::AtomicRMW:
425   case Instruction::CatchPad:
426   case Instruction::CatchRet:
427     return true;
428   case Instruction::Call:
429     return !cast<CallInst>(this)->doesNotAccessMemory();
430   case Instruction::Invoke:
431     return !cast<InvokeInst>(this)->doesNotAccessMemory();
432   case Instruction::Store:
433     return !cast<StoreInst>(this)->isUnordered();
434   }
435 }
436 
437 /// mayWriteToMemory - Return true if this instruction may modify memory.
438 ///
439 bool Instruction::mayWriteToMemory() const {
440   switch (getOpcode()) {
441   default: return false;
442   case Instruction::Fence: // FIXME: refine definition of mayWriteToMemory
443   case Instruction::Store:
444   case Instruction::VAArg:
445   case Instruction::AtomicCmpXchg:
446   case Instruction::AtomicRMW:
447   case Instruction::CatchPad:
448   case Instruction::CatchRet:
449     return true;
450   case Instruction::Call:
451     return !cast<CallInst>(this)->onlyReadsMemory();
452   case Instruction::Invoke:
453     return !cast<InvokeInst>(this)->onlyReadsMemory();
454   case Instruction::Load:
455     return !cast<LoadInst>(this)->isUnordered();
456   }
457 }
458 
459 bool Instruction::isAtomic() const {
460   switch (getOpcode()) {
461   default:
462     return false;
463   case Instruction::AtomicCmpXchg:
464   case Instruction::AtomicRMW:
465   case Instruction::Fence:
466     return true;
467   case Instruction::Load:
468     return cast<LoadInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
469   case Instruction::Store:
470     return cast<StoreInst>(this)->getOrdering() != AtomicOrdering::NotAtomic;
471   }
472 }
473 
474 bool Instruction::mayThrow() const {
475   if (const CallInst *CI = dyn_cast<CallInst>(this))
476     return !CI->doesNotThrow();
477   if (const auto *CRI = dyn_cast<CleanupReturnInst>(this))
478     return CRI->unwindsToCaller();
479   if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(this))
480     return CatchSwitch->unwindsToCaller();
481   return isa<ResumeInst>(this);
482 }
483 
484 bool Instruction::mayReturn() const {
485   if (const CallInst *CI = dyn_cast<CallInst>(this))
486     return !CI->doesNotReturn();
487   return true;
488 }
489 
490 /// isAssociative - Return true if the instruction is associative:
491 ///
492 ///   Associative operators satisfy:  x op (y op z) === (x op y) op z
493 ///
494 /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
495 ///
496 bool Instruction::isAssociative(unsigned Opcode) {
497   return Opcode == And || Opcode == Or || Opcode == Xor ||
498          Opcode == Add || Opcode == Mul;
499 }
500 
501 bool Instruction::isAssociative() const {
502   unsigned Opcode = getOpcode();
503   if (isAssociative(Opcode))
504     return true;
505 
506   switch (Opcode) {
507   case FMul:
508   case FAdd:
509     return cast<FPMathOperator>(this)->hasUnsafeAlgebra();
510   default:
511     return false;
512   }
513 }
514 
515 /// isCommutative - Return true if the instruction is commutative:
516 ///
517 ///   Commutative operators satisfy: (x op y) === (y op x)
518 ///
519 /// In LLVM, these are the associative operators, plus SetEQ and SetNE, when
520 /// applied to any type.
521 ///
522 bool Instruction::isCommutative(unsigned op) {
523   switch (op) {
524   case Add:
525   case FAdd:
526   case Mul:
527   case FMul:
528   case And:
529   case Or:
530   case Xor:
531     return true;
532   default:
533     return false;
534   }
535 }
536 
537 /// isIdempotent - Return true if the instruction is idempotent:
538 ///
539 ///   Idempotent operators satisfy:  x op x === x
540 ///
541 /// In LLVM, the And and Or operators are idempotent.
542 ///
543 bool Instruction::isIdempotent(unsigned Opcode) {
544   return Opcode == And || Opcode == Or;
545 }
546 
547 /// isNilpotent - Return true if the instruction is nilpotent:
548 ///
549 ///   Nilpotent operators satisfy:  x op x === Id,
550 ///
551 ///   where Id is the identity for the operator, i.e. a constant such that
552 ///     x op Id === x and Id op x === x for all x.
553 ///
554 /// In LLVM, the Xor operator is nilpotent.
555 ///
556 bool Instruction::isNilpotent(unsigned Opcode) {
557   return Opcode == Xor;
558 }
559 
560 Instruction *Instruction::cloneImpl() const {
561   llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
562 }
563 
564 Instruction *Instruction::clone() const {
565   Instruction *New = nullptr;
566   switch (getOpcode()) {
567   default:
568     llvm_unreachable("Unhandled Opcode.");
569 #define HANDLE_INST(num, opc, clas)                                            \
570   case Instruction::opc:                                                       \
571     New = cast<clas>(this)->cloneImpl();                                       \
572     break;
573 #include "llvm/IR/Instruction.def"
574 #undef HANDLE_INST
575   }
576 
577   New->SubclassOptionalData = SubclassOptionalData;
578   if (!hasMetadata())
579     return New;
580 
581   // Otherwise, enumerate and copy over metadata from the old instruction to the
582   // new one.
583   SmallVector<std::pair<unsigned, MDNode *>, 4> TheMDs;
584   getAllMetadataOtherThanDebugLoc(TheMDs);
585   for (const auto &MD : TheMDs)
586     New->setMetadata(MD.first, MD.second);
587 
588   New->setDebugLoc(getDebugLoc());
589   return New;
590 }
591