llvm.org GIT mirror llvm / 528f964
[DebugInfo] Let IRBuilder::SetInsertPoint(BB::iterator) update current debug location. IRBuilder::SetInsertPoint(BB, BB::iterator) is an older version of IRBuilder::SetInsertPoint(Instruction). However, the latter updates the current debug location of emitted instruction, while the former doesn't, which is confusing. Unify the behavior of these methods: now they both set current debug location to the debug location of instruction at insertion point. The callers of IRBuilder::SetInsertPoint(BB, BB::iterator) doesn't seem to depend on the old behavior (keeping the original debug info location). On the contrary, sometimes they (e.g. SCEV) *should* be updating debug info location, but don't. I'll look at gdb bots after the commit to check that we don't regress on debug info somewhere. This change may make line table more fine-grained, thus increasing debug info size. I haven't observed significant increase, though: it varies from negligible to 0.3% on several binaries and self-hosted Clang. This is yet another change targeted at resolving PR23837. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241101 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 5 years ago
2 changed file(s) with 34 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
100100 void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
101101 BB = TheBB;
102102 InsertPt = IP;
103 if (IP != TheBB->end())
104 SetCurrentDebugLocation(IP->getDebugLoc());
103105 }
104106
105107 /// \brief Find the nearest point that dominates this use, and specify that
549551 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr)
550552 : IRBuilderBase(IP->getContext(), FPMathTag), Folder() {
551553 SetInsertPoint(IP);
552 SetCurrentDebugLocation(IP->getDebugLoc());
553554 }
554555
555556 explicit IRBuilder(Use &U, MDNode *FPMathTag = nullptr)
556557 : IRBuilderBase(U->getContext(), FPMathTag), Folder() {
557558 SetInsertPoint(U);
558 SetCurrentDebugLocation(cast(U.getUser())->getDebugLoc());
559559 }
560560
561561 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F,
332332 EXPECT_TRUE(String2->getType()->getPointerAddressSpace() == 1);
333333 EXPECT_TRUE(String3->getType()->getPointerAddressSpace() == 2);
334334 }
335 }
335
336 TEST_F(IRBuilderTest, DebugLoc) {
337 auto CalleeTy = FunctionType::get(Type::getVoidTy(Ctx),
338 /*isVarArg=*/false);
339 auto Callee =
340 Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get());
341
342 DIBuilder DIB(*M);
343 auto File = DIB.createFile("tmp.cpp", "/");
344 auto SPType = DIB.createSubroutineType(File, DIB.getOrCreateTypeArray(None));
345 auto SP =
346 DIB.createFunction(File, "foo", "foo", File, 1, SPType, false, true, 1);
347 DebugLoc DL1 = DILocation::get(Ctx, 2, 0, SP);
348 DebugLoc DL2 = DILocation::get(Ctx, 3, 0, SP);
349
350 auto BB2 = BasicBlock::Create(Ctx, "bb2", F);
351 auto Br = BranchInst::Create(BB2, BB);
352 Br->setDebugLoc(DL1);
353
354 IRBuilder<> Builder(Ctx);
355 Builder.SetInsertPoint(Br);
356 EXPECT_EQ(DL1, Builder.getCurrentDebugLocation());
357 auto Call1 = Builder.CreateCall(Callee, None);
358 EXPECT_EQ(DL1, Call1->getDebugLoc());
359
360 Call1->setDebugLoc(DL2);
361 Builder.SetInsertPoint(Call1->getParent(), Call1);
362 EXPECT_EQ(DL2, Builder.getCurrentDebugLocation());
363 auto Call2 = Builder.CreateCall(Callee, None);
364 EXPECT_EQ(DL2, Call2->getDebugLoc());
365 }
366 }