Alexander Potapenko via llvm-dev
2018-Sep-17 13:59 UTC
[llvm-dev] Obtaining the origin function for a local var after inlining
(I think I've asked a similar question off-list a couple of times, but never got an answer) Hi folks, For [K]MSAN we need to figure out which inlined function a local var originally belonged to in the source file. E.g. when a local buffer %buf is declared in @bar(), but @bar() is inlined into @foo(), then there's a local %buf.i in @foo(), but we need to determine that the local came from @bar(). In the case of nested inline functions we need the deepest one. Is there any existing code for that? If not, which debug info constructs do we need to look up to get this information? https://llvm.org/docs/SourceLevelDebugging.html mentions @llvm.dbg.addr as the source of information about a local var, but the ToT Clang doesn't emit it. There're calls to @llvm.debug.declare in the IR, but it's said to be deprecated, so I'm not sure if it's ok to use it. Thanks in advance, -- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Straße, 33 80636 München Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg
Reid Kleckner via llvm-dev
2018-Sep-17 20:57 UTC
[llvm-dev] Obtaining the origin function for a local var after inlining
I wanted to start a migration from dbg.declare to dbg.addr, but never finished it. For your purposes, they are probably equivalent. The slight semantic difference is that dbg.declare cannot be mixed with dbg.value to create a variable that is sometimes in memory and sometimes a pure value. To distinguish between two inlined copies of the same variable, look at the inlinedAt location of the location of the dbg intrinsic. The inlinedAt location will be distinct for every inlined call site. You can see how it is used in CodeGen/AsmPrinter/Dwarf* by looking for uses of InlinedEntity: using InlinedEntity = std::pair<const DINode *, const DILocation *>; ... for (const auto &VI : Asm->MF->getVariableDbgInfo()) { if (!VI.Var) continue; assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) && "Expected inlined-at fields to agree"); InlinedEntity Var(VI.Var, VI.Loc->getInlinedAt()); ... On Mon, Sep 17, 2018 at 7:00 AM Alexander Potapenko <glider at google.com> wrote:> (I think I've asked a similar question off-list a couple of times, but > never got an answer) > > Hi folks, > > For [K]MSAN we need to figure out which inlined function a local var > originally belonged to in the source file. > E.g. when a local buffer %buf is declared in @bar(), but @bar() is > inlined into @foo(), then there's a local %buf.i in @foo(), but we > need to determine that the local came from @bar(). In the case of > nested inline functions we need the deepest one. > > Is there any existing code for that? If not, which debug info > constructs do we need to look up to get this information? > > https://llvm.org/docs/SourceLevelDebugging.html mentions > @llvm.dbg.addr as the source of information about a local var, but the > ToT Clang doesn't emit it. There're calls to @llvm.debug.declare in > the IR, but it's said to be deprecated, so I'm not sure if it's ok to > use it. > > Thanks in advance, > -- > Alexander Potapenko > Software Engineer > > Google Germany GmbH > Erika-Mann-Straße, 33 > 80636 München > > Geschäftsführer: Paul Manicle, Halimah DeLaine Prado > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180917/a300566d/attachment.html>
Adrian Prantl via llvm-dev
2018-Sep-17 23:56 UTC
[llvm-dev] Obtaining the origin function for a local var after inlining
> On Sep 17, 2018, at 6:59 AM, Alexander Potapenko via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > (I think I've asked a similar question off-list a couple of times, but > never got an answer) > > Hi folks, > > For [K]MSAN we need to figure out which inlined function a local var > originally belonged to in the source file.If you are looking at a llvm.dbg.declar/value/addr intrinsic, then the DILocation attached to the intrinsic indirectly points there: DIScope *Scope = DILocation(dbg_intrinsic.getDebugLoc()).getScope(); while (!isa<DISubprogram>(Scope)) Scope = Scope->getScope(); auto *origFunction = cast<DIFunction>(Scope); if you want to find the function that it was inlined *into* then you need to follow the inlinedAt link in the DILoation. -- adrian> E.g. when a local buffer %buf is declared in @bar(), but @bar() is > inlined into @foo(), then there's a local %buf.i in @foo(), but we > need to determine that the local came from @bar(). In the case of > nested inline functions we need the deepest one. > > Is there any existing code for that? If not, which debug info > constructs do we need to look up to get this information? > > https://llvm.org/docs/SourceLevelDebugging.html mentions > @llvm.dbg.addr as the source of information about a local var, but the > ToT Clang doesn't emit it. There're calls to @llvm.debug.declare in > the IR, but it's said to be deprecated, so I'm not sure if it's ok to > use it. > > Thanks in advance, > -- > Alexander Potapenko > Software Engineer > > Google Germany GmbH > Erika-Mann-Straße, 33 > 80636 München > > Geschäftsführer: Paul Manicle, Halimah DeLaine Prado > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Alexander Potapenko via llvm-dev
2018-Sep-19 11:08 UTC
[llvm-dev] Obtaining the origin function for a local var after inlining
On Tue, Sep 18, 2018 at 1:56 AM Adrian Prantl <aprantl at apple.com> wrote:> > > > > On Sep 17, 2018, at 6:59 AM, Alexander Potapenko via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > > > (I think I've asked a similar question off-list a couple of times, but > > never got an answer) > > > > Hi folks, > > > > For [K]MSAN we need to figure out which inlined function a local var > > originally belonged to in the source file. > > If you are looking at a llvm.dbg.declar/value/addr intrinsic, then the DILocation attached to the intrinsic indirectly points there: > > DIScope *Scope = DILocation(dbg_intrinsic.getDebugLoc()).getScope(); > while (!isa<DISubprogram>(Scope)) > Scope = Scope->getScope(); > auto *origFunction = cast<DIFunction>(Scope);This works, thank you! (I had to slightly modify the code FWIW: DILocation *DIL = dbg_intrinsic.getDebugLoc(); if (DIL) { DIScope *Scope = DIL->getScope(); while (Scope && !isa<DISubprogram>(Scope)) Scope = Scope->getScope().resolve(); auto *origFunction = cast<DISubprogram>(Scope) ) I also thought that it would be natural if the AllocaInst corresponding to the llvm.dbg.declare() call will share the same DILocation as the debug intrinsic. Does anyone have an idea why this isn't so? Right now one needs to build a mapping between AllocaInst and llvm.dbg.declare() in order to get the debug info for the allocation.> if you want to find the function that it was inlined *into* then you need to follow the inlinedAt link in the DILoation. > > -- adrian > > > E.g. when a local buffer %buf is declared in @bar(), but @bar() is > > inlined into @foo(), then there's a local %buf.i in @foo(), but we > > need to determine that the local came from @bar(). In the case of > > nested inline functions we need the deepest one. > > > > Is there any existing code for that? If not, which debug info > > constructs do we need to look up to get this information? > > > > https://llvm.org/docs/SourceLevelDebugging.html mentions > > @llvm.dbg.addr as the source of information about a local var, but the > > ToT Clang doesn't emit it. There're calls to @llvm.debug.declare in > > the IR, but it's said to be deprecated, so I'm not sure if it's ok to > > use it. > > > > Thanks in advance, > > -- > > Alexander Potapenko > > Software Engineer > > > > Google Germany GmbH > > Erika-Mann-Straße, 33 > > 80636 München > > > > Geschäftsführer: Paul Manicle, Halimah DeLaine Prado > > Registergericht und -nummer: Hamburg, HRB 86891 > > Sitz der Gesellschaft: Hamburg > > _______________________________________________ > > LLVM Developers mailing list > > llvm-dev at lists.llvm.org > > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Straße, 33 80636 München Geschäftsführer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg
Apparently Analagous Threads
- Obtaining the origin function for a local var after inlining
- Obtaining the origin function for a local var after inlining
- Dead store elimination in the backend for -ftrivial-auto-var-init
- Dead store elimination in the backend for -ftrivial-auto-var-init
- Dead store elimination in the backend for -ftrivial-auto-var-init