llvm.org GIT mirror llvm / 9f961da
[ArgPromotion] Set debug location at updated callsites Set the correct debug location on instructions which load arguments in preparation for a call to an arg-promoted function. This prevents location cascade from misattributing the line/scope of one of these loads to the location of the instruction preceding the call. Differential Revision: https://reviews.llvm.org/D60113 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357500 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 5 months ago
2 changed file(s) with 32 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
5757 #include "llvm/IR/DataLayout.h"
5858 #include "llvm/IR/DerivedTypes.h"
5959 #include "llvm/IR/Function.h"
60 #include "llvm/IR/IRBuilder.h"
6061 #include "llvm/IR/InstrTypes.h"
6162 #include "llvm/IR/Instruction.h"
6263 #include "llvm/IR/Instructions.h"
6364 #include "llvm/IR/Metadata.h"
6465 #include "llvm/IR/Module.h"
66 #include "llvm/IR/NoFolder.h"
6567 #include "llvm/IR/PassManager.h"
6668 #include "llvm/IR/Type.h"
6769 #include "llvm/IR/Use.h"
241243 assert(CS.getCalledFunction() == F);
242244 Instruction *Call = CS.getInstruction();
243245 const AttributeList &CallPAL = CS.getAttributes();
246 IRBuilder IRB(Call);
244247
245248 // Loop over the operands, inserting GEP and loads in the caller as
246249 // appropriate.
259262 ConstantInt::get(Type::getInt32Ty(F->getContext()), 0), nullptr};
260263 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
261264 Idxs[1] = ConstantInt::get(Type::getInt32Ty(F->getContext()), i);
262 Value *Idx = GetElementPtrInst::Create(
263 STy, *AI, Idxs, (*AI)->getName() + "." + Twine(i), Call);
265 auto *Idx =
266 IRB.CreateGEP(STy, *AI, Idxs, (*AI)->getName() + "." + Twine(i));
264267 // TODO: Tell AA about the new values?
265 Args.push_back(new LoadInst(STy->getElementType(i), Idx,
266 Idx->getName() + ".val", Call));
268 Args.push_back(IRB.CreateLoad(STy->getElementType(i), Idx,
269 Idx->getName() + ".val"));
267270 ArgAttrVec.push_back(AttributeSet());
268271 }
269272 } else if (!I->use_empty()) {
293296 ElTy = cast(ElTy)->getTypeAtIndex(II);
294297 }
295298 // And create a GEP to extract those indices.
296 V = GetElementPtrInst::Create(ArgIndex.first, V, Ops,
297 V->getName() + ".idx", Call);
299 V = IRB.CreateGEP(ArgIndex.first, V, Ops, V->getName() + ".idx");
298300 Ops.clear();
299301 }
300302 // Since we're replacing a load make sure we take the alignment
301303 // of the previous load.
302304 LoadInst *newLoad =
303 new LoadInst(OrigLoad->getType(), V, V->getName() + ".val", Call);
305 IRB.CreateLoad(OrigLoad->getType(), V, V->getName() + ".val");
304306 newLoad->setAlignment(OrigLoad->getAlignment());
305307 // Transfer the AA info too.
306308 AAMDNodes AAInfo;
1010 ret void
1111 }
1212
13 define void @caller(i32** %Y) {
14 ; CHECK: call void @test(i32 %
15 call void @test(i32** %Y)
13 %struct.pair = type { i32, i32 }
14
15 ; CHECK: define internal void @test_byval(i32 %{{.*}}, i32 %{{.*}})
16 define internal void @test_byval(%struct.pair* byval %P) {
17 ret void
18 }
19
20 ; CHECK-LABEL: define {{.*}} @caller(
21 define void @caller(i32** %Y, %struct.pair* %P) {
22 ; CHECK: load i32*, {{.*}} !dbg [[LOC_1:![0-9]+]]
23 ; CHECK-NEXT: load i32, {{.*}} !dbg [[LOC_1]]
24 ; CHECK-NEXT: call void @test(i32 %{{.*}}), !dbg [[LOC_1]]
25 call void @test(i32** %Y), !dbg !1
26
27 ; CHECK: getelementptr %struct.pair, {{.*}} !dbg [[LOC_2:![0-9]+]]
28 ; CHECK-NEXT: load i32, i32* {{.*}} !dbg [[LOC_2]]
29 ; CHECK-NEXT: getelementptr %struct.pair, {{.*}} !dbg [[LOC_2]]
30 ; CHECK-NEXT: load i32, i32* {{.*}} !dbg [[LOC_2]]
31 ; CHECK-NEXT: call void @test_byval(i32 %{{.*}}, i32 %{{.*}}), !dbg [[LOC_2]]
32 call void @test_byval(%struct.pair* %P), !dbg !6
1633 ret void
1734 }
1835
1936 ; CHECK: [[SP]] = distinct !DISubprogram(name: "test",
37 ; CHECK: [[LOC_1]] = !DILocation(line: 8
38 ; CHECK: [[LOC_2]] = !DILocation(line: 9
2039
2140 !llvm.module.flags = !{!0}
2241 !llvm.dbg.cu = !{!3}
2645 !2 = distinct !DISubprogram(name: "test", file: !5, line: 3, isLocal: true, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !3, scopeLine: 3, scope: null)
2746 !3 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: false, emissionKind: LineTablesOnly, file: !5)
2847 !5 = !DIFile(filename: "test.c", directory: "")
48 !6 = !DILocation(line: 9, scope: !2)