diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp --- a/clang/lib/CodeGen/CGLoopInfo.cpp +++ b/clang/lib/CodeGen/CGLoopInfo.cpp @@ -24,8 +24,7 @@ LoopInfo::createLoopPropertiesMetadata(ArrayRef LoopProperties) { LLVMContext &Ctx = Header->getContext(); SmallVector NewLoopProperties; - TempMDTuple TempNode = MDNode::getTemporary(Ctx, None); - NewLoopProperties.push_back(TempNode.get()); + NewLoopProperties.push_back(nullptr); NewLoopProperties.append(LoopProperties.begin(), LoopProperties.end()); MDNode *LoopID = MDNode::getDistinct(Ctx, NewLoopProperties); @@ -58,8 +57,7 @@ } SmallVector Args; - TempMDTuple TempNode = MDNode::getTemporary(Ctx, None); - Args.push_back(TempNode.get()); + Args.push_back(nullptr); Args.append(LoopProperties.begin(), LoopProperties.end()); if (Attrs.PipelineInitiationInterval > 0) { @@ -113,8 +111,7 @@ FollowupHasTransforms); SmallVector Args; - TempMDTuple TempNode = MDNode::getTemporary(Ctx, None); - Args.push_back(TempNode.get()); + Args.push_back(nullptr); Args.append(LoopProperties.begin(), LoopProperties.end()); // Setting unroll.count @@ -176,8 +173,7 @@ FollowupHasTransforms); SmallVector Args; - TempMDTuple TempNode = MDNode::getTemporary(Ctx, None); - Args.push_back(TempNode.get()); + Args.push_back(nullptr); Args.append(LoopProperties.begin(), LoopProperties.end()); // Setting unroll_and_jam.count @@ -250,8 +246,7 @@ FollowupHasTransforms); SmallVector Args; - TempMDTuple TempNode = MDNode::getTemporary(Ctx, None); - Args.push_back(TempNode.get()); + Args.push_back(nullptr); Args.append(LoopProperties.begin(), LoopProperties.end()); // Setting vectorize.predicate @@ -307,7 +302,7 @@ Ctx, {MDString::get(Ctx, "llvm.loop.vectorize.followup_all"), Followup})); - MDNode *LoopID = MDNode::get(Ctx, Args); + MDNode *LoopID = MDNode::getDistinct(Ctx, Args); LoopID->replaceOperandWith(0, LoopID); HasUserTransforms = true; return LoopID; @@ -344,8 +339,7 @@ createLoopVectorizeMetadata(Attrs, LoopProperties, FollowupHasTransforms); SmallVector Args; - TempMDTuple TempNode = MDNode::getTemporary(Ctx, None); - Args.push_back(TempNode.get()); + Args.push_back(nullptr); Args.append(LoopProperties.begin(), LoopProperties.end()); Metadata *Vals[] = {MDString::get(Ctx, "llvm.loop.distribute.enable"), @@ -359,7 +353,7 @@ Ctx, {MDString::get(Ctx, "llvm.loop.distribute.followup_all"), Followup})); - MDNode *LoopID = MDNode::get(Ctx, Args); + MDNode *LoopID = MDNode::getDistinct(Ctx, Args); LoopID->replaceOperandWith(0, LoopID); HasUserTransforms = true; return LoopID; @@ -389,8 +383,7 @@ } SmallVector Args; - TempMDTuple TempNode = MDNode::getTemporary(Ctx, None); - Args.push_back(TempNode.get()); + Args.push_back(nullptr); Args.append(LoopProperties.begin(), LoopProperties.end()); Args.push_back(MDNode::get(Ctx, MDString::get(Ctx, "llvm.loop.unroll.full"))); diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -1017,8 +1017,7 @@ SmallVector MDs; // Reserve first location for self reference to the LoopID metadata node. - TempMDTuple TempNode = MDNode::getTemporary(Context, None); - MDs.push_back(TempNode.get()); + MDs.push_back(nullptr); // Remove metadata for the transformation that has been applied or that became // outdated. diff --git a/llvm/lib/IR/MDBuilder.cpp b/llvm/lib/IR/MDBuilder.cpp --- a/llvm/lib/IR/MDBuilder.cpp +++ b/llvm/lib/IR/MDBuilder.cpp @@ -151,24 +151,20 @@ } MDNode *MDBuilder::createAnonymousAARoot(StringRef Name, MDNode *Extra) { - // To ensure uniqueness the root node is self-referential. - auto Dummy = MDNode::getTemporary(Context, None); - - SmallVector Args(1, Dummy.get()); + SmallVector Args(1, nullptr); if (Extra) Args.push_back(Extra); if (!Name.empty()) Args.push_back(createString(Name)); - MDNode *Root = MDNode::get(Context, Args); + MDNode *Root = MDNode::getDistinct(Context, Args); // At this point we have - // !0 = metadata !{} <- dummy - // !1 = metadata !{metadata !0} <- root - // Replace the dummy operand with the root node itself and delete the dummy. + // !0 = distinct !{null} <- root + // Replace the reserved operand with the root node itself. Root->replaceOperandWith(0, Root); // We now have - // !1 = metadata !{metadata !1} <- self-referential root + // !0 = distinct !{!0} <- root return Root; } diff --git a/polly/lib/CodeGen/IRBuilder.cpp b/polly/lib/CodeGen/IRBuilder.cpp --- a/polly/lib/CodeGen/IRBuilder.cpp +++ b/polly/lib/CodeGen/IRBuilder.cpp @@ -26,24 +26,22 @@ /// /// The MDNode looks like this (if arg0/arg1 are not null): /// -/// '!n = metadata !{metadata !n, arg0, arg1}' +/// '!n = distinct !{!n, arg0, arg1}' /// /// @return The self referencing id metadata node. static MDNode *getID(LLVMContext &Ctx, Metadata *arg0 = nullptr, Metadata *arg1 = nullptr) { MDNode *ID; SmallVector Args; - // Use a temporary node to safely create a unique pointer for the first arg. - auto TempNode = MDNode::getTemporary(Ctx, None); // Reserve operand 0 for loop id self reference. - Args.push_back(TempNode.get()); + Args.push_back(nullptr); if (arg0) Args.push_back(arg0); if (arg1) Args.push_back(arg1); - ID = MDNode::get(Ctx, Args); + ID = MDNode::getDistinct(Ctx, Args); ID->replaceOperandWith(0, ID); return ID; }