[llvm] r257745 - [OperandBundles] Copy DebugLoc with calls/invokes

Joseph Tremoulet via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 13 22:21:42 PST 2016


Author: josepht
Date: Thu Jan 14 00:21:42 2016
New Revision: 257745

URL: http://llvm.org/viewvc/llvm-project?rev=257745&view=rev
Log:
[OperandBundles] Copy DebugLoc with calls/invokes

Summary:
The overloads of CallInst::Create and InvokeInst::Create that are used to
adjust operand bundles purport to create a new instruction "identical in
every way except [for] the operand bundles", so copy the DebugLoc along
with everything else.


Reviewers: sanjoy, majnemer

Subscribers: majnemer, dblaikie, llvm-commits

Differential Revision: http://reviews.llvm.org/D16157

Modified:
    llvm/trunk/lib/IR/Instructions.cpp
    llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
    llvm/trunk/unittests/IR/InstructionsTest.cpp

Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=257745&r1=257744&r2=257745&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Thu Jan 14 00:21:42 2016
@@ -309,6 +309,7 @@ CallInst *CallInst::Create(CallInst *CI,
   NewCI->setCallingConv(CI->getCallingConv());
   NewCI->SubclassOptionalData = CI->SubclassOptionalData;
   NewCI->setAttributes(CI->getAttributes());
+  NewCI->setDebugLoc(CI->getDebugLoc());
   return NewCI;
 }
 
@@ -596,6 +597,7 @@ InvokeInst *InvokeInst::Create(InvokeIns
   NewII->setCallingConv(II->getCallingConv());
   NewII->SubclassOptionalData = II->SubclassOptionalData;
   NewII->setAttributes(II->getAttributes());
+  NewII->setDebugLoc(II->getDebugLoc());
   return NewII;
 }
 

Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=257745&r1=257744&r2=257745&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Thu Jan 14 00:21:42 2016
@@ -1447,7 +1447,6 @@ bool llvm::InlineFunction(CallSite CS, I
           NewInst = CallInst::Create(cast<CallInst>(I), OpBundles, I);
         else
           NewInst = InvokeInst::Create(cast<InvokeInst>(I), OpBundles, I);
-        NewInst->setDebugLoc(I->getDebugLoc());
         NewInst->takeName(I);
         I->replaceAllUsesWith(NewInst);
         I->eraseFromParent();

Modified: llvm/trunk/unittests/IR/InstructionsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/InstructionsTest.cpp?rev=257745&r1=257744&r2=257745&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/InstructionsTest.cpp (original)
+++ llvm/trunk/unittests/IR/InstructionsTest.cpp Thu Jan 14 00:21:42 2016
@@ -518,7 +518,66 @@ TEST(InstructionsTest, CloneCall) {
   }
 }
 
-}  // end anonymous namespace
-}  // end namespace llvm
+TEST(InstructionsTest, AlterCallBundles) {
+  LLVMContext &C(getGlobalContext());
+  Type *Int32Ty = Type::getInt32Ty(C);
+  Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false);
+  Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
+  Value *Args[] = {ConstantInt::get(Int32Ty, 42)};
+  OperandBundleDef OldBundle("before", UndefValue::get(Int32Ty));
+  std::unique_ptr<CallInst> Call(
+      CallInst::Create(Callee, Args, OldBundle, "result"));
+  Call->setTailCallKind(CallInst::TailCallKind::TCK_NoTail);
+  AttrBuilder AB;
+  AB.addAttribute(Attribute::Cold);
+  Call->setAttributes(AttributeSet::get(C, AttributeSet::FunctionIndex, AB));
+  Call->setDebugLoc(DebugLoc(MDNode::get(C, None)));
 
+  OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7));
+  std::unique_ptr<CallInst> Clone(CallInst::Create(Call.get(), NewBundle));
+  EXPECT_EQ(Call->getNumArgOperands(), Clone->getNumArgOperands());
+  EXPECT_EQ(Call->getArgOperand(0), Clone->getArgOperand(0));
+  EXPECT_EQ(Call->getCallingConv(), Clone->getCallingConv());
+  EXPECT_EQ(Call->getTailCallKind(), Clone->getTailCallKind());
+  EXPECT_TRUE(Clone->hasFnAttr(Attribute::AttrKind::Cold));
+  EXPECT_EQ(Call->getDebugLoc(), Clone->getDebugLoc());
+  EXPECT_EQ(Clone->getNumOperandBundles(), 1);
+  EXPECT_TRUE(Clone->getOperandBundle("after").hasValue());
+}
+
+TEST(InstructionsTest, AlterInvokeBundles) {
+  LLVMContext &C(getGlobalContext());
+  Type *Int32Ty = Type::getInt32Ty(C);
+  Type *FnTy = FunctionType::get(Int32Ty, Int32Ty, /*isVarArg=*/false);
+  Value *Callee = Constant::getNullValue(FnTy->getPointerTo());
+  Value *Args[] = {ConstantInt::get(Int32Ty, 42)};
+  BasicBlock *NormalDest = BasicBlock::Create(C);
+  BasicBlock *UnwindDest = BasicBlock::Create(C);
+  OperandBundleDef OldBundle("before", UndefValue::get(Int32Ty));
+  InvokeInst *Invoke(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args,
+                                        OldBundle, "result"));
+  AttrBuilder AB;
+  AB.addAttribute(Attribute::Cold);
+  Invoke->setAttributes(AttributeSet::get(C, AttributeSet::FunctionIndex, AB));
+  Invoke->setDebugLoc(DebugLoc(MDNode::get(C, None)));
+
+  OperandBundleDef NewBundle("after", ConstantInt::get(Int32Ty, 7));
+  InvokeInst *Clone(InvokeInst::Create(Invoke, NewBundle));
+  EXPECT_EQ(Invoke->getNormalDest(), Clone->getNormalDest());
+  EXPECT_EQ(Invoke->getUnwindDest(), Clone->getUnwindDest());
+  EXPECT_EQ(Invoke->getNumArgOperands(), Clone->getNumArgOperands());
+  EXPECT_EQ(Invoke->getArgOperand(0), Clone->getArgOperand(0));
+  EXPECT_EQ(Invoke->getCallingConv(), Clone->getCallingConv());
+  EXPECT_TRUE(Clone->hasFnAttr(Attribute::AttrKind::Cold));
+  EXPECT_EQ(Invoke->getDebugLoc(), Clone->getDebugLoc());
+  EXPECT_EQ(Clone->getNumOperandBundles(), 1);
+  EXPECT_TRUE(Clone->getOperandBundle("after").hasValue());
+
+  delete Invoke;
+  delete Clone;
+  delete NormalDest;
+  delete UnwindDest;
+}
 
+} // end anonymous namespace
+} // end namespace llvm




More information about the llvm-commits mailing list