Chris Lattner | e4dbb1a | 2002-11-20 20:47:41 +0000 | [diff] [blame] | 1 | //===- ValueMapper.cpp - Interface shared by lib/Transforms/Utils ---------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 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 | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | e4dbb1a | 2002-11-20 20:47:41 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines the MapValue function, which is shared by various parts of |
| 11 | // the lib/Transforms/Utils library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Dan Gohman | a209503 | 2010-08-24 18:50:07 +0000 | [diff] [blame] | 15 | #include "llvm/Transforms/Utils/ValueMapper.h" |
David Blaikie | 348de69 | 2015-04-23 21:36:23 +0000 | [diff] [blame] | 16 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Constants.h" |
| 18 | #include "llvm/IR/Function.h" |
| 19 | #include "llvm/IR/InlineAsm.h" |
| 20 | #include "llvm/IR/Instructions.h" |
| 21 | #include "llvm/IR/Metadata.h" |
David Blaikie | 8820884 | 2015-08-21 20:16:51 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Operator.h" |
Chris Lattner | df3c342 | 2004-01-09 06:12:26 +0000 | [diff] [blame] | 23 | using namespace llvm; |
Chris Lattner | e4dbb1a | 2002-11-20 20:47:41 +0000 | [diff] [blame] | 24 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 25 | // Out of line method to get vtable etc for class. |
Craig Topper | 2a6a08b | 2012-09-26 06:36:36 +0000 | [diff] [blame] | 26 | void ValueMapTypeRemapper::anchor() {} |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 27 | void ValueMaterializer::anchor() {} |
Rafael Espindola | 19b5238 | 2015-11-27 20:28:19 +0000 | [diff] [blame] | 28 | void ValueMaterializer::materializeInitFor(GlobalValue *New, GlobalValue *Old) { |
| 29 | } |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 30 | |
| 31 | Value *llvm::MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags, |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 32 | ValueMapTypeRemapper *TypeMapper, |
| 33 | ValueMaterializer *Materializer) { |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 34 | ValueToValueMapTy::iterator I = VM.find(V); |
Chris Lattner | 1bfc7ab | 2007-02-03 00:08:31 +0000 | [diff] [blame] | 35 | |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 36 | // If the value already exists in the map, use it. |
| 37 | if (I != VM.end() && I->second) return I->second; |
| 38 | |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 39 | // If we have a materializer and it can materialize a value, use that. |
| 40 | if (Materializer) { |
Rafael Espindola | 19b5238 | 2015-11-27 20:28:19 +0000 | [diff] [blame] | 41 | if (Value *NewV = |
| 42 | Materializer->materializeDeclFor(const_cast<Value *>(V))) { |
| 43 | VM[V] = NewV; |
Rafael Espindola | baa3bf8 | 2015-12-01 15:19:48 +0000 | [diff] [blame] | 44 | if (auto *NewGV = dyn_cast<GlobalValue>(NewV)) |
| 45 | Materializer->materializeInitFor( |
| 46 | NewGV, const_cast<GlobalValue *>(cast<GlobalValue>(V))); |
Rafael Espindola | 19b5238 | 2015-11-27 20:28:19 +0000 | [diff] [blame] | 47 | return NewV; |
| 48 | } |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Dan Gohman | ca26f79 | 2010-08-26 15:41:53 +0000 | [diff] [blame] | 51 | // Global values do not need to be seeded into the VM if they |
| 52 | // are using the identity mapping. |
Teresa Johnson | 83d03dd | 2015-11-15 14:50:14 +0000 | [diff] [blame] | 53 | if (isa<GlobalValue>(V)) { |
| 54 | if (Flags & RF_NullMapMissingGlobalValues) { |
| 55 | assert(!(Flags & RF_IgnoreMissingEntries) && |
| 56 | "Illegal to specify both RF_NullMapMissingGlobalValues and " |
| 57 | "RF_IgnoreMissingEntries"); |
| 58 | return nullptr; |
| 59 | } |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 60 | return VM[V] = const_cast<Value*>(V); |
Teresa Johnson | 83d03dd | 2015-11-15 14:50:14 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Chris Lattner | 8b4cf5e | 2011-07-15 23:18:40 +0000 | [diff] [blame] | 63 | if (const InlineAsm *IA = dyn_cast<InlineAsm>(V)) { |
| 64 | // Inline asm may need *type* remapping. |
| 65 | FunctionType *NewTy = IA->getFunctionType(); |
| 66 | if (TypeMapper) { |
| 67 | NewTy = cast<FunctionType>(TypeMapper->remapType(NewTy)); |
| 68 | |
| 69 | if (NewTy != IA->getFunctionType()) |
| 70 | V = InlineAsm::get(NewTy, IA->getAsmString(), IA->getConstraintString(), |
| 71 | IA->hasSideEffects(), IA->isAlignStack()); |
| 72 | } |
| 73 | |
| 74 | return VM[V] = const_cast<Value*>(V); |
| 75 | } |
Chris Lattner | 6aa34b0 | 2003-10-06 15:23:43 +0000 | [diff] [blame] | 76 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 77 | if (const auto *MDV = dyn_cast<MetadataAsValue>(V)) { |
| 78 | const Metadata *MD = MDV->getMetadata(); |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 79 | // If this is a module-level metadata and we know that nothing at the module |
| 80 | // level is changing, then use an identity mapping. |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 81 | if (!isa<LocalAsMetadata>(MD) && (Flags & RF_NoModuleLevelChanges)) |
| 82 | return VM[V] = const_cast<Value *>(V); |
Dan Gohman | ca26f79 | 2010-08-26 15:41:53 +0000 | [diff] [blame] | 83 | |
Duncan P. N. Exon Smith | 46d7af5 | 2014-12-19 06:06:18 +0000 | [diff] [blame] | 84 | auto *MappedMD = MapMetadata(MD, VM, Flags, TypeMapper, Materializer); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 85 | if (MD == MappedMD || (!MappedMD && (Flags & RF_IgnoreMissingEntries))) |
| 86 | return VM[V] = const_cast<Value *>(V); |
Dan Gohman | ca26f79 | 2010-08-26 15:41:53 +0000 | [diff] [blame] | 87 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 88 | // FIXME: This assert crashes during bootstrap, but I think it should be |
| 89 | // correct. For now, just match behaviour from before the metadata/value |
| 90 | // split. |
| 91 | // |
Teresa Johnson | 83d03dd | 2015-11-15 14:50:14 +0000 | [diff] [blame] | 92 | // assert((MappedMD || (Flags & RF_NullMapMissingGlobalValues)) && |
| 93 | // "Referenced metadata value not in value map"); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 94 | return VM[V] = MetadataAsValue::get(V->getContext(), MappedMD); |
Victor Hernandez | 5fa88d4 | 2010-01-20 05:49:59 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 97 | // Okay, this either must be a constant (which may or may not be mappable) or |
| 98 | // is something that is not in the mapping table. |
Chris Lattner | cf5a47d | 2009-10-29 00:28:30 +0000 | [diff] [blame] | 99 | Constant *C = const_cast<Constant*>(dyn_cast<Constant>(V)); |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 100 | if (!C) |
| 101 | return nullptr; |
Chris Lattner | cf5a47d | 2009-10-29 00:28:30 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 103 | if (BlockAddress *BA = dyn_cast<BlockAddress>(C)) { |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 104 | Function *F = |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 105 | cast<Function>(MapValue(BA->getFunction(), VM, Flags, TypeMapper, Materializer)); |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 106 | BasicBlock *BB = cast_or_null<BasicBlock>(MapValue(BA->getBasicBlock(), VM, |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 107 | Flags, TypeMapper, Materializer)); |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 108 | return VM[V] = BlockAddress::get(F, BB ? BB : BA->getBasicBlock()); |
Chris Lattner | e4dbb1a | 2002-11-20 20:47:41 +0000 | [diff] [blame] | 109 | } |
Chris Lattner | cf5a47d | 2009-10-29 00:28:30 +0000 | [diff] [blame] | 110 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 111 | // Otherwise, we have some other constant to remap. Start by checking to see |
| 112 | // if all operands have an identity remapping. |
| 113 | unsigned OpNo = 0, NumOperands = C->getNumOperands(); |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 114 | Value *Mapped = nullptr; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 115 | for (; OpNo != NumOperands; ++OpNo) { |
| 116 | Value *Op = C->getOperand(OpNo); |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 117 | Mapped = MapValue(Op, VM, Flags, TypeMapper, Materializer); |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 118 | if (Mapped != C) break; |
Chris Lattner | cf5a47d | 2009-10-29 00:28:30 +0000 | [diff] [blame] | 119 | } |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 120 | |
| 121 | // See if the type mapper wants to remap the type as well. |
| 122 | Type *NewTy = C->getType(); |
| 123 | if (TypeMapper) |
| 124 | NewTy = TypeMapper->remapType(NewTy); |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 125 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 126 | // If the result type and all operands match up, then just insert an identity |
| 127 | // mapping. |
| 128 | if (OpNo == NumOperands && NewTy == C->getType()) |
| 129 | return VM[V] = C; |
| 130 | |
| 131 | // Okay, we need to create a new constant. We've already processed some or |
| 132 | // all of the operands, set them all up now. |
| 133 | SmallVector<Constant*, 8> Ops; |
| 134 | Ops.reserve(NumOperands); |
| 135 | for (unsigned j = 0; j != OpNo; ++j) |
| 136 | Ops.push_back(cast<Constant>(C->getOperand(j))); |
| 137 | |
| 138 | // If one of the operands mismatch, push it and the other mapped operands. |
| 139 | if (OpNo != NumOperands) { |
| 140 | Ops.push_back(cast<Constant>(Mapped)); |
| 141 | |
| 142 | // Map the rest of the operands that aren't processed yet. |
| 143 | for (++OpNo; OpNo != NumOperands; ++OpNo) |
| 144 | Ops.push_back(MapValue(cast<Constant>(C->getOperand(OpNo)), VM, |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 145 | Flags, TypeMapper, Materializer)); |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 146 | } |
David Blaikie | 8820884 | 2015-08-21 20:16:51 +0000 | [diff] [blame] | 147 | Type *NewSrcTy = nullptr; |
| 148 | if (TypeMapper) |
| 149 | if (auto *GEPO = dyn_cast<GEPOperator>(C)) |
| 150 | NewSrcTy = TypeMapper->remapType(GEPO->getSourceElementType()); |
| 151 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 152 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) |
David Blaikie | 8820884 | 2015-08-21 20:16:51 +0000 | [diff] [blame] | 153 | return VM[V] = CE->getWithOperands(Ops, NewTy, false, NewSrcTy); |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 154 | if (isa<ConstantArray>(C)) |
| 155 | return VM[V] = ConstantArray::get(cast<ArrayType>(NewTy), Ops); |
| 156 | if (isa<ConstantStruct>(C)) |
| 157 | return VM[V] = ConstantStruct::get(cast<StructType>(NewTy), Ops); |
| 158 | if (isa<ConstantVector>(C)) |
| 159 | return VM[V] = ConstantVector::get(Ops); |
| 160 | // If this is a no-operand constant, it must be because the type was remapped. |
| 161 | if (isa<UndefValue>(C)) |
| 162 | return VM[V] = UndefValue::get(NewTy); |
| 163 | if (isa<ConstantAggregateZero>(C)) |
| 164 | return VM[V] = ConstantAggregateZero::get(NewTy); |
| 165 | assert(isa<ConstantPointerNull>(C)); |
| 166 | return VM[V] = ConstantPointerNull::get(cast<PointerType>(NewTy)); |
Chris Lattner | e4dbb1a | 2002-11-20 20:47:41 +0000 | [diff] [blame] | 167 | } |
Brian Gaeke | 6182acf | 2004-05-19 09:08:12 +0000 | [diff] [blame] | 168 | |
Kaelyn Takata | 22324f3 | 2014-12-09 23:32:46 +0000 | [diff] [blame] | 169 | static Metadata *mapToMetadata(ValueToValueMapTy &VM, const Metadata *Key, |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 170 | Metadata *Val, ValueMaterializer *Materializer, |
| 171 | RemapFlags Flags) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 172 | VM.MD()[Key].reset(Val); |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 173 | if (Materializer && !(Flags & RF_HaveUnmaterializedMetadata)) { |
| 174 | auto *N = dyn_cast_or_null<MDNode>(Val); |
| 175 | // Need to invoke this once we have non-temporary MD. |
| 176 | if (!N || !N->isTemporary()) |
| 177 | Materializer->replaceTemporaryMetadata(Key, Val); |
| 178 | } |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 179 | return Val; |
| 180 | } |
| 181 | |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 182 | static Metadata *mapToSelf(ValueToValueMapTy &VM, const Metadata *MD, |
| 183 | ValueMaterializer *Materializer, RemapFlags Flags) { |
| 184 | return mapToMetadata(VM, MD, const_cast<Metadata *>(MD), Materializer, Flags); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 187 | static Metadata *MapMetadataImpl(const Metadata *MD, |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 188 | SmallVectorImpl<MDNode *> &DistinctWorklist, |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 189 | ValueToValueMapTy &VM, RemapFlags Flags, |
Duncan P. N. Exon Smith | 46d7af5 | 2014-12-19 06:06:18 +0000 | [diff] [blame] | 190 | ValueMapTypeRemapper *TypeMapper, |
Duncan P. N. Exon Smith | 077affd | 2015-01-14 01:01:19 +0000 | [diff] [blame] | 191 | ValueMaterializer *Materializer); |
| 192 | |
Duncan P. N. Exon Smith | 5ed90c0 | 2015-08-04 13:23:30 +0000 | [diff] [blame] | 193 | static Metadata *mapMetadataOp(Metadata *Op, |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 194 | SmallVectorImpl<MDNode *> &DistinctWorklist, |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 195 | ValueToValueMapTy &VM, RemapFlags Flags, |
Duncan P. N. Exon Smith | 422e5c7 | 2015-01-19 22:16:01 +0000 | [diff] [blame] | 196 | ValueMapTypeRemapper *TypeMapper, |
| 197 | ValueMaterializer *Materializer) { |
Duncan P. N. Exon Smith | 077affd | 2015-01-14 01:01:19 +0000 | [diff] [blame] | 198 | if (!Op) |
| 199 | return nullptr; |
Teresa Johnson | 0e7c82c | 2015-12-18 17:51:37 +0000 | [diff] [blame^] | 200 | |
| 201 | if (Materializer && !Materializer->isMetadataNeeded(Op)) |
| 202 | return nullptr; |
| 203 | |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 204 | if (Metadata *MappedOp = MapMetadataImpl(Op, DistinctWorklist, VM, Flags, |
| 205 | TypeMapper, Materializer)) |
Duncan P. N. Exon Smith | 077affd | 2015-01-14 01:01:19 +0000 | [diff] [blame] | 206 | return MappedOp; |
| 207 | // Use identity map if MappedOp is null and we can ignore missing entries. |
| 208 | if (Flags & RF_IgnoreMissingEntries) |
| 209 | return Op; |
| 210 | |
| 211 | // FIXME: This assert crashes during bootstrap, but I think it should be |
| 212 | // correct. For now, just match behaviour from before the metadata/value |
| 213 | // split. |
| 214 | // |
Teresa Johnson | 83d03dd | 2015-11-15 14:50:14 +0000 | [diff] [blame] | 215 | // assert((Flags & RF_NullMapMissingGlobalValues) && |
| 216 | // "Referenced metadata not in value map!"); |
Duncan P. N. Exon Smith | 077affd | 2015-01-14 01:01:19 +0000 | [diff] [blame] | 217 | return nullptr; |
| 218 | } |
| 219 | |
Duncan P. N. Exon Smith | c9fdbdb | 2015-08-07 00:39:26 +0000 | [diff] [blame] | 220 | /// Resolve uniquing cycles involving the given metadata. |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 221 | static void resolveCycles(Metadata *MD, bool MDMaterialized) { |
| 222 | if (auto *N = dyn_cast_or_null<MDNode>(MD)) { |
| 223 | if (!MDMaterialized && N->isTemporary()) |
| 224 | return; |
Duncan P. N. Exon Smith | c9fdbdb | 2015-08-07 00:39:26 +0000 | [diff] [blame] | 225 | if (!N->isResolved()) |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 226 | N->resolveCycles(MDMaterialized); |
| 227 | } |
Duncan P. N. Exon Smith | c9fdbdb | 2015-08-07 00:39:26 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Duncan P. N. Exon Smith | 2705097 | 2015-08-05 23:22:34 +0000 | [diff] [blame] | 230 | /// Remap the operands of an MDNode. |
Duncan P. N. Exon Smith | 8c9dcac | 2015-08-07 00:44:55 +0000 | [diff] [blame] | 231 | /// |
| 232 | /// If \c Node is temporary, uniquing cycles are ignored. If \c Node is |
| 233 | /// distinct, uniquing cycles are resolved as they're found. |
| 234 | /// |
| 235 | /// \pre \c Node.isDistinct() or \c Node.isTemporary(). |
Duncan P. N. Exon Smith | 2705097 | 2015-08-05 23:22:34 +0000 | [diff] [blame] | 236 | static bool remapOperands(MDNode &Node, |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 237 | SmallVectorImpl<MDNode *> &DistinctWorklist, |
Duncan P. N. Exon Smith | 2705097 | 2015-08-05 23:22:34 +0000 | [diff] [blame] | 238 | ValueToValueMapTy &VM, RemapFlags Flags, |
| 239 | ValueMapTypeRemapper *TypeMapper, |
| 240 | ValueMaterializer *Materializer) { |
| 241 | assert(!Node.isUniqued() && "Expected temporary or distinct node"); |
Duncan P. N. Exon Smith | 8c9dcac | 2015-08-07 00:44:55 +0000 | [diff] [blame] | 242 | const bool IsDistinct = Node.isDistinct(); |
Duncan P. N. Exon Smith | 6dc22bf | 2015-01-19 22:44:32 +0000 | [diff] [blame] | 243 | |
Duncan P. N. Exon Smith | 6dc22bf | 2015-01-19 22:44:32 +0000 | [diff] [blame] | 244 | bool AnyChanged = false; |
Duncan P. N. Exon Smith | 2705097 | 2015-08-05 23:22:34 +0000 | [diff] [blame] | 245 | for (unsigned I = 0, E = Node.getNumOperands(); I != E; ++I) { |
| 246 | Metadata *Old = Node.getOperand(I); |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 247 | Metadata *New = mapMetadataOp(Old, DistinctWorklist, VM, Flags, TypeMapper, |
| 248 | Materializer); |
Duncan P. N. Exon Smith | 6dc22bf | 2015-01-19 22:44:32 +0000 | [diff] [blame] | 249 | if (Old != New) { |
| 250 | AnyChanged = true; |
Duncan P. N. Exon Smith | 2705097 | 2015-08-05 23:22:34 +0000 | [diff] [blame] | 251 | Node.replaceOperandWith(I, New); |
Duncan P. N. Exon Smith | 8c9dcac | 2015-08-07 00:44:55 +0000 | [diff] [blame] | 252 | |
| 253 | // Resolve uniquing cycles underneath distinct nodes on the fly so they |
| 254 | // don't infect later operands. |
| 255 | if (IsDistinct) |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 256 | resolveCycles(New, !(Flags & RF_HaveUnmaterializedMetadata)); |
Duncan P. N. Exon Smith | 6dc22bf | 2015-01-19 22:44:32 +0000 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
| 260 | return AnyChanged; |
| 261 | } |
| 262 | |
Duncan P. N. Exon Smith | 4fb46cb | 2015-08-03 17:09:38 +0000 | [diff] [blame] | 263 | /// Map a distinct MDNode. |
Duncan P. N. Exon Smith | 14cc94c | 2015-01-14 01:03:05 +0000 | [diff] [blame] | 264 | /// |
Duncan P. N. Exon Smith | 4fb46cb | 2015-08-03 17:09:38 +0000 | [diff] [blame] | 265 | /// Whether distinct nodes change is independent of their operands. If \a |
| 266 | /// RF_MoveDistinctMDs, then they are reused, and their operands remapped in |
| 267 | /// place; effectively, they're moved from one graph to another. Otherwise, |
| 268 | /// they're cloned/duplicated, and the new copy's operands are remapped. |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 269 | static Metadata *mapDistinctNode(const MDNode *Node, |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 270 | SmallVectorImpl<MDNode *> &DistinctWorklist, |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 271 | ValueToValueMapTy &VM, RemapFlags Flags, |
Duncan P. N. Exon Smith | 14cc94c | 2015-01-14 01:03:05 +0000 | [diff] [blame] | 272 | ValueMapTypeRemapper *TypeMapper, |
| 273 | ValueMaterializer *Materializer) { |
| 274 | assert(Node->isDistinct() && "Expected distinct node"); |
| 275 | |
Duncan P. N. Exon Smith | 4fb46cb | 2015-08-03 17:09:38 +0000 | [diff] [blame] | 276 | MDNode *NewMD; |
| 277 | if (Flags & RF_MoveDistinctMDs) |
| 278 | NewMD = const_cast<MDNode *>(Node); |
| 279 | else |
| 280 | NewMD = MDNode::replaceWithDistinct(Node->clone()); |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 281 | |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 282 | // Remap operands later. |
| 283 | DistinctWorklist.push_back(NewMD); |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 284 | return mapToMetadata(VM, Node, NewMD, Materializer, Flags); |
Duncan P. N. Exon Smith | fb9d128 | 2015-01-14 01:08:47 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Duncan P. N. Exon Smith | b557989 | 2015-01-14 01:06:21 +0000 | [diff] [blame] | 287 | /// \brief Map a uniqued MDNode. |
| 288 | /// |
| 289 | /// Uniqued nodes may not need to be recreated (they may map to themselves). |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 290 | static Metadata *mapUniquedNode(const MDNode *Node, |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 291 | SmallVectorImpl<MDNode *> &DistinctWorklist, |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 292 | ValueToValueMapTy &VM, RemapFlags Flags, |
Duncan P. N. Exon Smith | c862be8 | 2015-01-19 22:40:25 +0000 | [diff] [blame] | 293 | ValueMapTypeRemapper *TypeMapper, |
| 294 | ValueMaterializer *Materializer) { |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 295 | assert(((Flags & RF_HaveUnmaterializedMetadata) || Node->isUniqued()) && |
| 296 | "Expected uniqued node"); |
Duncan P. N. Exon Smith | b557989 | 2015-01-14 01:06:21 +0000 | [diff] [blame] | 297 | |
Duncan P. N. Exon Smith | 2705097 | 2015-08-05 23:22:34 +0000 | [diff] [blame] | 298 | // Create a temporary node and map it upfront in case we have a uniquing |
| 299 | // cycle. If necessary, this mapping will get updated by RAUW logic before |
| 300 | // returning. |
Duncan P. N. Exon Smith | 03e0583 | 2015-01-20 02:56:57 +0000 | [diff] [blame] | 301 | auto ClonedMD = Node->clone(); |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 302 | mapToMetadata(VM, Node, ClonedMD.get(), Materializer, Flags); |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 303 | if (!remapOperands(*ClonedMD, DistinctWorklist, VM, Flags, TypeMapper, |
| 304 | Materializer)) { |
Duncan P. N. Exon Smith | 2705097 | 2015-08-05 23:22:34 +0000 | [diff] [blame] | 305 | // No operands changed, so use the original. |
Duncan P. N. Exon Smith | 706f37e | 2015-08-04 06:42:31 +0000 | [diff] [blame] | 306 | ClonedMD->replaceAllUsesWith(const_cast<MDNode *>(Node)); |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 307 | // Even though replaceAllUsesWith would have replaced the value map |
| 308 | // entry, we need to explictly map with the final non-temporary node |
| 309 | // to replace any temporary metadata via the callback. |
| 310 | return mapToSelf(VM, Node, Materializer, Flags); |
Duncan P. N. Exon Smith | 706f37e | 2015-08-04 06:42:31 +0000 | [diff] [blame] | 311 | } |
Duncan P. N. Exon Smith | 0dcffe2 | 2015-01-19 22:39:07 +0000 | [diff] [blame] | 312 | |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 313 | // Uniquify the cloned node. Explicitly map it with the final non-temporary |
| 314 | // node so that replacement of temporary metadata via the callback occurs. |
| 315 | return mapToMetadata(VM, Node, |
| 316 | MDNode::replaceWithUniqued(std::move(ClonedMD)), |
| 317 | Materializer, Flags); |
Duncan P. N. Exon Smith | b557989 | 2015-01-14 01:06:21 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 320 | static Metadata *MapMetadataImpl(const Metadata *MD, |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 321 | SmallVectorImpl<MDNode *> &DistinctWorklist, |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 322 | ValueToValueMapTy &VM, RemapFlags Flags, |
Duncan P. N. Exon Smith | 077affd | 2015-01-14 01:01:19 +0000 | [diff] [blame] | 323 | ValueMapTypeRemapper *TypeMapper, |
Duncan P. N. Exon Smith | 46d7af5 | 2014-12-19 06:06:18 +0000 | [diff] [blame] | 324 | ValueMaterializer *Materializer) { |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 325 | // If the value already exists in the map, use it. |
| 326 | if (Metadata *NewMD = VM.MD().lookup(MD).get()) |
| 327 | return NewMD; |
| 328 | |
| 329 | if (isa<MDString>(MD)) |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 330 | return mapToSelf(VM, MD, Materializer, Flags); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 331 | |
| 332 | if (isa<ConstantAsMetadata>(MD)) |
| 333 | if ((Flags & RF_NoModuleLevelChanges)) |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 334 | return mapToSelf(VM, MD, Materializer, Flags); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 335 | |
| 336 | if (const auto *VMD = dyn_cast<ValueAsMetadata>(MD)) { |
| 337 | Value *MappedV = |
| 338 | MapValue(VMD->getValue(), VM, Flags, TypeMapper, Materializer); |
| 339 | if (VMD->getValue() == MappedV || |
| 340 | (!MappedV && (Flags & RF_IgnoreMissingEntries))) |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 341 | return mapToSelf(VM, MD, Materializer, Flags); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 342 | |
| 343 | // FIXME: This assert crashes during bootstrap, but I think it should be |
| 344 | // correct. For now, just match behaviour from before the metadata/value |
| 345 | // split. |
| 346 | // |
Teresa Johnson | 83d03dd | 2015-11-15 14:50:14 +0000 | [diff] [blame] | 347 | // assert((MappedV || (Flags & RF_NullMapMissingGlobalValues)) && |
| 348 | // "Referenced metadata not in value map!"); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 349 | if (MappedV) |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 350 | return mapToMetadata(VM, MD, ValueAsMetadata::get(MappedV), Materializer, |
| 351 | Flags); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 352 | return nullptr; |
| 353 | } |
| 354 | |
Duncan P. N. Exon Smith | 170c26d | 2015-03-17 01:14:40 +0000 | [diff] [blame] | 355 | // Note: this cast precedes the Flags check so we always get its associated |
| 356 | // assertion. |
Duncan P. N. Exon Smith | 2bc00f4 | 2015-01-19 23:13:14 +0000 | [diff] [blame] | 357 | const MDNode *Node = cast<MDNode>(MD); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 358 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 359 | // If this is a module-level metadata and we know that nothing at the |
| 360 | // module level is changing, then use an identity mapping. |
| 361 | if (Flags & RF_NoModuleLevelChanges) |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 362 | return mapToSelf(VM, MD, Materializer, Flags); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 363 | |
Duncan P. N. Exon Smith | 170c26d | 2015-03-17 01:14:40 +0000 | [diff] [blame] | 364 | // Require resolved nodes whenever metadata might be remapped. |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 365 | assert(((Flags & RF_HaveUnmaterializedMetadata) || Node->isResolved()) && |
| 366 | "Unexpected unresolved node"); |
| 367 | |
| 368 | if (Materializer && Node->isTemporary()) { |
| 369 | assert(Flags & RF_HaveUnmaterializedMetadata); |
| 370 | Metadata *TempMD = |
| 371 | Materializer->mapTemporaryMetadata(const_cast<Metadata *>(MD)); |
| 372 | // If the above callback returned an existing temporary node, use it |
| 373 | // instead of the current temporary node. This happens when earlier |
| 374 | // function importing passes already created and saved a temporary |
| 375 | // metadata node for the same value id. |
| 376 | if (TempMD) { |
| 377 | mapToMetadata(VM, MD, TempMD, Materializer, Flags); |
| 378 | return TempMD; |
| 379 | } |
| 380 | } |
Duncan P. N. Exon Smith | 170c26d | 2015-03-17 01:14:40 +0000 | [diff] [blame] | 381 | |
Duncan P. N. Exon Smith | 14cc94c | 2015-01-14 01:03:05 +0000 | [diff] [blame] | 382 | if (Node->isDistinct()) |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 383 | return mapDistinctNode(Node, DistinctWorklist, VM, Flags, TypeMapper, |
| 384 | Materializer); |
Duncan P. N. Exon Smith | 953e1a4 | 2015-01-08 22:42:30 +0000 | [diff] [blame] | 385 | |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 386 | return mapUniquedNode(Node, DistinctWorklist, VM, Flags, TypeMapper, |
| 387 | Materializer); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Duncan P. N. Exon Smith | 46d7af5 | 2014-12-19 06:06:18 +0000 | [diff] [blame] | 390 | Metadata *llvm::MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, |
| 391 | RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, |
| 392 | ValueMaterializer *Materializer) { |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 393 | SmallVector<MDNode *, 8> DistinctWorklist; |
| 394 | Metadata *NewMD = MapMetadataImpl(MD, DistinctWorklist, VM, Flags, TypeMapper, |
| 395 | Materializer); |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 396 | |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 397 | // When there are no module-level changes, it's possible that the metadata |
| 398 | // graph has temporaries. Skip the logic to resolve cycles, since it's |
| 399 | // unnecessary (and invalid) in that case. |
| 400 | if (Flags & RF_NoModuleLevelChanges) |
Duncan P. N. Exon Smith | 4fb46cb | 2015-08-03 17:09:38 +0000 | [diff] [blame] | 401 | return NewMD; |
Duncan P. N. Exon Smith | 920df5c | 2015-02-04 19:44:34 +0000 | [diff] [blame] | 402 | |
Duncan P. N. Exon Smith | c9fdbdb | 2015-08-07 00:39:26 +0000 | [diff] [blame] | 403 | // Resolve cycles involving the entry metadata. |
Teresa Johnson | e5a6191 | 2015-12-17 17:14:09 +0000 | [diff] [blame] | 404 | resolveCycles(NewMD, !(Flags & RF_HaveUnmaterializedMetadata)); |
Duncan P. N. Exon Smith | 4fb46cb | 2015-08-03 17:09:38 +0000 | [diff] [blame] | 405 | |
Duncan P. N. Exon Smith | 3115f75 | 2015-08-05 23:52:42 +0000 | [diff] [blame] | 406 | // Remap the operands of distinct MDNodes. |
Duncan P. N. Exon Smith | 8c9dcac | 2015-08-07 00:44:55 +0000 | [diff] [blame] | 407 | while (!DistinctWorklist.empty()) |
| 408 | remapOperands(*DistinctWorklist.pop_back_val(), DistinctWorklist, VM, Flags, |
| 409 | TypeMapper, Materializer); |
Duncan P. N. Exon Smith | 4fb46cb | 2015-08-03 17:09:38 +0000 | [diff] [blame] | 410 | |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 411 | return NewMD; |
| 412 | } |
| 413 | |
Duncan P. N. Exon Smith | 46d7af5 | 2014-12-19 06:06:18 +0000 | [diff] [blame] | 414 | MDNode *llvm::MapMetadata(const MDNode *MD, ValueToValueMapTy &VM, |
| 415 | RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, |
| 416 | ValueMaterializer *Materializer) { |
| 417 | return cast<MDNode>(MapMetadata(static_cast<const Metadata *>(MD), VM, Flags, |
| 418 | TypeMapper, Materializer)); |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Brian Gaeke | 6182acf | 2004-05-19 09:08:12 +0000 | [diff] [blame] | 421 | /// RemapInstruction - Convert the instruction operands from referencing the |
Devang Patel | b8f11de | 2010-06-23 23:55:51 +0000 | [diff] [blame] | 422 | /// current values into those specified by VMap. |
Brian Gaeke | 6182acf | 2004-05-19 09:08:12 +0000 | [diff] [blame] | 423 | /// |
Dan Gohman | ca26f79 | 2010-08-26 15:41:53 +0000 | [diff] [blame] | 424 | void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap, |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 425 | RemapFlags Flags, ValueMapTypeRemapper *TypeMapper, |
| 426 | ValueMaterializer *Materializer){ |
Dan Gohman | ca26f79 | 2010-08-26 15:41:53 +0000 | [diff] [blame] | 427 | // Remap operands. |
Gabor Greif | 5df4326 | 2008-05-30 21:24:22 +0000 | [diff] [blame] | 428 | for (User::op_iterator op = I->op_begin(), E = I->op_end(); op != E; ++op) { |
James Molloy | f6f121e | 2013-05-28 15:17:05 +0000 | [diff] [blame] | 429 | Value *V = MapValue(*op, VMap, Flags, TypeMapper, Materializer); |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 430 | // If we aren't ignoring missing entries, assert that something happened. |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 431 | if (V) |
Chris Lattner | 43f8d16 | 2011-01-08 08:15:20 +0000 | [diff] [blame] | 432 | *op = V; |
| 433 | else |
| 434 | assert((Flags & RF_IgnoreMissingEntries) && |
| 435 | "Referenced value not in value map!"); |
Brian Gaeke | 6182acf | 2004-05-19 09:08:12 +0000 | [diff] [blame] | 436 | } |
Daniel Dunbar | 95fe13c | 2010-08-26 03:48:08 +0000 | [diff] [blame] | 437 | |
Jay Foad | 61ea0e4 | 2011-06-23 09:09:15 +0000 | [diff] [blame] | 438 | // Remap phi nodes' incoming blocks. |
| 439 | if (PHINode *PN = dyn_cast<PHINode>(I)) { |
| 440 | for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { |
| 441 | Value *V = MapValue(PN->getIncomingBlock(i), VMap, Flags); |
| 442 | // If we aren't ignoring missing entries, assert that something happened. |
Craig Topper | f40110f | 2014-04-25 05:29:35 +0000 | [diff] [blame] | 443 | if (V) |
Jay Foad | 61ea0e4 | 2011-06-23 09:09:15 +0000 | [diff] [blame] | 444 | PN->setIncomingBlock(i, cast<BasicBlock>(V)); |
| 445 | else |
| 446 | assert((Flags & RF_IgnoreMissingEntries) && |
| 447 | "Referenced block not in value map!"); |
| 448 | } |
| 449 | } |
| 450 | |
Devang Patel | c017404 | 2011-08-04 20:02:18 +0000 | [diff] [blame] | 451 | // Remap attached metadata. |
Duncan P. N. Exon Smith | de36e80 | 2014-11-11 21:30:22 +0000 | [diff] [blame] | 452 | SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; |
Devang Patel | c017404 | 2011-08-04 20:02:18 +0000 | [diff] [blame] | 453 | I->getAllMetadata(MDs); |
Duncan P. N. Exon Smith | e08bcbf | 2015-08-03 03:27:12 +0000 | [diff] [blame] | 454 | for (const auto &MI : MDs) { |
| 455 | MDNode *Old = MI.second; |
Duncan P. N. Exon Smith | 46d7af5 | 2014-12-19 06:06:18 +0000 | [diff] [blame] | 456 | MDNode *New = MapMetadata(Old, VMap, Flags, TypeMapper, Materializer); |
Dan Gohman | ca26f79 | 2010-08-26 15:41:53 +0000 | [diff] [blame] | 457 | if (New != Old) |
Duncan P. N. Exon Smith | e08bcbf | 2015-08-03 03:27:12 +0000 | [diff] [blame] | 458 | I->setMetadata(MI.first, New); |
Dan Gohman | ca26f79 | 2010-08-26 15:41:53 +0000 | [diff] [blame] | 459 | } |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 460 | |
David Blaikie | 348de69 | 2015-04-23 21:36:23 +0000 | [diff] [blame] | 461 | if (!TypeMapper) |
| 462 | return; |
| 463 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 464 | // If the instruction's type is being remapped, do so now. |
David Blaikie | 348de69 | 2015-04-23 21:36:23 +0000 | [diff] [blame] | 465 | if (auto CS = CallSite(I)) { |
| 466 | SmallVector<Type *, 3> Tys; |
| 467 | FunctionType *FTy = CS.getFunctionType(); |
| 468 | Tys.reserve(FTy->getNumParams()); |
| 469 | for (Type *Ty : FTy->params()) |
| 470 | Tys.push_back(TypeMapper->remapType(Ty)); |
| 471 | CS.mutateFunctionType(FunctionType::get( |
| 472 | TypeMapper->remapType(I->getType()), Tys, FTy->isVarArg())); |
David Blaikie | bf0a42a | 2015-04-29 23:00:35 +0000 | [diff] [blame] | 473 | return; |
| 474 | } |
| 475 | if (auto *AI = dyn_cast<AllocaInst>(I)) |
| 476 | AI->setAllocatedType(TypeMapper->remapType(AI->getAllocatedType())); |
David Blaikie | f5147ef | 2015-06-01 03:09:34 +0000 | [diff] [blame] | 477 | if (auto *GEP = dyn_cast<GetElementPtrInst>(I)) { |
David Blaikie | 73cf872 | 2015-05-05 18:03:48 +0000 | [diff] [blame] | 478 | GEP->setSourceElementType( |
| 479 | TypeMapper->remapType(GEP->getSourceElementType())); |
David Blaikie | f5147ef | 2015-06-01 03:09:34 +0000 | [diff] [blame] | 480 | GEP->setResultElementType( |
| 481 | TypeMapper->remapType(GEP->getResultElementType())); |
| 482 | } |
David Blaikie | bf0a42a | 2015-04-29 23:00:35 +0000 | [diff] [blame] | 483 | I->mutateType(TypeMapper->remapType(I->getType())); |
Dan Gohman | ca26f79 | 2010-08-26 15:41:53 +0000 | [diff] [blame] | 484 | } |