diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include using namespace llvm; @@ -497,7 +498,10 @@ NewCI->setCallingConv(CI->getCallingConv()); NewCI->SubclassOptionalData = CI->SubclassOptionalData; NewCI->setAttributes(CI->getAttributes()); - NewCI->setDebugLoc(CI->getDebugLoc()); + SmallVector, 2> MDs; + CI->getAllMetadata(MDs); + for (auto &MD : MDs) + NewCI->setMetadata(MD.first, MD.second); return NewCI; } @@ -808,7 +812,10 @@ NewII->setCallingConv(II->getCallingConv()); NewII->SubclassOptionalData = II->SubclassOptionalData; NewII->setAttributes(II->getAttributes()); - NewII->setDebugLoc(II->getDebugLoc()); + SmallVector, 2> MDs; + II->getAllMetadata(MDs); + for (auto &MD : MDs) + NewII->setMetadata(MD.first, MD.second); return NewII; } @@ -891,8 +898,11 @@ NewCBI->setCallingConv(CBI->getCallingConv()); NewCBI->SubclassOptionalData = CBI->SubclassOptionalData; NewCBI->setAttributes(CBI->getAttributes()); - NewCBI->setDebugLoc(CBI->getDebugLoc()); NewCBI->NumIndirectDests = CBI->NumIndirectDests; + SmallVector, 2> MDs; + CBI->getAllMetadata(MDs); + for (auto &MD : MDs) + NewCBI->setMetadata(MD.first, MD.second); return NewCBI; } diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -6,10 +6,10 @@ // //===----------------------------------------------------------------------===// -#include "llvm/AsmParser/Parser.h" #include "llvm/IR/Instructions.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/ValueTracking.h" +#include "llvm/AsmParser/Parser.h" #include "llvm/IR/BasicBlock.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DataLayout.h" @@ -25,6 +25,7 @@ #include "gmock/gmock-matchers.h" #include "gtest/gtest.h" #include +#include namespace llvm { namespace { @@ -628,6 +629,7 @@ AB.addAttribute(Attribute::Cold); Call->setAttributes(AttributeList::get(C, AttributeList::FunctionIndex, AB)); Call->setDebugLoc(DebugLoc(MDNode::get(C, None))); + Call->setProfWeight(7); OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7)); std::unique_ptr Clone(CallInst::Create(Call.get(), NewBundle)); @@ -637,6 +639,9 @@ EXPECT_EQ(Call->getTailCallKind(), Clone->getTailCallKind()); EXPECT_TRUE(Clone->hasFnAttr(Attribute::AttrKind::Cold)); EXPECT_EQ(Call->getDebugLoc(), Clone->getDebugLoc()); + uint64_t W; + EXPECT_TRUE(Clone->extractProfTotalWeight(W)); + EXPECT_EQ(W, 7U); EXPECT_EQ(Clone->getNumOperandBundles(), 1U); EXPECT_TRUE(Clone->getOperandBundle("after").hasValue()); } @@ -658,6 +663,7 @@ Invoke->setAttributes( AttributeList::get(C, AttributeList::FunctionIndex, AB)); Invoke->setDebugLoc(DebugLoc(MDNode::get(C, None))); + Invoke->setProfWeight(7); OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7)); std::unique_ptr Clone( @@ -669,6 +675,9 @@ EXPECT_EQ(Invoke->getCallingConv(), Clone->getCallingConv()); EXPECT_TRUE(Clone->hasFnAttr(Attribute::AttrKind::Cold)); EXPECT_EQ(Invoke->getDebugLoc(), Clone->getDebugLoc()); + uint64_t W; + EXPECT_TRUE(Clone->extractProfTotalWeight(W)); + EXPECT_EQ(W, 7U); EXPECT_EQ(Clone->getNumOperandBundles(), 1U); EXPECT_TRUE(Clone->getOperandBundle("after").hasValue()); }