llvm.org GIT mirror llvm / cc1ea9c
Utils: Extract shouldRemapUniquedNode(), NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225911 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 5 years ago
1 changed file(s) with 33 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
201201 return NewMD;
202202 }
203203
204 /// \brief Check whether a uniqued node needs to be remapped.
205 ///
206 /// Check whether a uniqued node needs to be remapped (due to any operands
207 /// changing).
208 static bool shouldRemapUniquedNode(const UniquableMDNode *Node,
209 ValueToValueMapTy &VM, RemapFlags Flags,
210 ValueMapTypeRemapper *TypeMapper,
211 ValueMaterializer *Materializer) {
212 // Check all operands to see if any need to be remapped.
213 for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I) {
214 Metadata *Op = Node->getOperand(I);
215 if (Op != mapMetadataOp(Op, VM, Flags, TypeMapper, Materializer))
216 return true;
217 }
218 return false;
219 }
220
204221 /// \brief Map a uniqued MDNode.
205222 ///
206223 /// Uniqued nodes may not need to be recreated (they may map to themselves).
215232 mapToMetadata(VM, Node, Dummy);
216233
217234 // Check all operands to see if any need to be remapped.
218 for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I) {
219 Metadata *Op = Node->getOperand(I);
220 if (Op == mapMetadataOp(Op, VM, Flags, TypeMapper, Materializer))
221 continue;
222
223 // Ok, at least one operand needs remapping.
224 SmallVector Elts;
225 Elts.reserve(Node->getNumOperands());
226 for (I = 0; I != E; ++I)
227 Elts.push_back(mapMetadataOp(Node->getOperand(I), VM, Flags, TypeMapper,
228 Materializer));
229
230 MDNode *NewMD = MDTuple::get(Node->getContext(), Elts);
231 Dummy->replaceAllUsesWith(NewMD);
235 if (!shouldRemapUniquedNode(Node, VM, Flags, TypeMapper, Materializer)) {
236 // Use an identity mapping.
237 mapToSelf(VM, Node);
232238 MDNode::deleteTemporary(Dummy);
233 return mapToMetadata(VM, Node, NewMD);
234 }
235
236 // No operands needed remapping. Use an identity mapping.
237 mapToSelf(VM, Node);
239 return const_cast(static_cast(Node));
240 }
241
242 // At least one operand needs remapping.
243 SmallVector Elts;
244 Elts.reserve(Node->getNumOperands());
245 for (unsigned I = 0, E = Node->getNumOperands(); I != E; ++I)
246 Elts.push_back(mapMetadataOp(Node->getOperand(I), VM, Flags, TypeMapper,
247 Materializer));
248
249 MDNode *NewMD = MDTuple::get(Node->getContext(), Elts);
250 Dummy->replaceAllUsesWith(NewMD);
238251 MDNode::deleteTemporary(Dummy);
239 return const_cast(static_cast(Node));
252 return mapToMetadata(VM, Node, NewMD);
240253 }
241254
242255 static Metadata *MapMetadataImpl(const Metadata *MD, ValueToValueMapTy &VM,