[llvm-commits] [PATCH] Debug info utilities and printer pass
Devang Patel
dpatel at apple.com
Wed Dec 10 13:13:44 PST 2008
Hi Torok,
On Dec 10, 2008, at 11:02 AM, Török Edwin wrote:
> Hi,
>
> [@John Criswell: this is a much improved version of SourceLocator I
> sent
> you ages ago ;)]
>
> 01-bb.patch:
> BasicBlock::getUniquePredecessor -> similar to getSinglePredecessor()
> but works if there is a unique predecessor listed multiple times
This is OK.
> 02-intrin.patch:
> Introduce DbgFuncStart::getDisplayName() (which refers to unmangled C
> ++
> name!), and DbgDeclareInst::getVariableName()
> Introduce include/llvm/Support/DebugInfo.h:
We already have include/llvm/Analysis/DebugInfo.h, so I suggest that
you use another name for this new header.
+namespace llvm {
+ class DbgStopPointInst;
+ /// Finds the stoppoint coressponding to this instruction, that is
the
+ /// stoppoint that dominates this instruction
+ static const DbgStopPointInst *findStopPoint(const Instruction *Inst)
+ {
+ if (isa<DbgStopPointInst>(Inst))
+ return cast<DbgStopPointInst>(Inst);
pl. use dyn_cast instead of isa + cast.
+
+ const BasicBlock *BB = Inst->getParent();
+ BasicBlock::const_iterator I = Inst, B;
+ do {
+ B = BB->begin();
+ // a BB consisting only of a terminator, can't have a stoppoint
+ if (I != B) {
+ do {
+ --I;
+ if (isa<DbgStopPointInst>(*I))
+ return cast<DbgStopPointInst>(&*I);
+ } while (I != B);
+ }
+ // this BB didn't have a stoppoint, if there is only one
+ // predecessor, look for a stoppoint there
+ // we could use getIDom(), but that would require dominator info
+ BB = I->getParent()->getUniquePredecessor();
+ if (BB)
+ I = BB->getTerminator();
+ } while (BB != 0);
+ return 0;
+ }
+
+ /// Finds the stoppoint corresponding to first real (non-debug
intrinsic)
+ /// instruction in this Basic Block, and returns the stoppoint for
it.
+ static const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB)
+ {
+ for(BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I !
= E; ++I) {
+ if (isa<DbgStopPointInst>(*I))
+ return cast<DbgStopPointInst>(&*I);
+ }
+ // fallback to looking for stoppoint of terminator inst
+ // useful if this BB contains no stoppoints, but unique
predecessor does
+ return findStopPoint(BB->getTerminator());
This will iterate BB again again.
>
> findStopPoint: Instruction* -> associated StopPoint*
> findBBStopPoint: BasicBlock* -> associated StopPoint*
> findDbgDeclare: Value* -> associated DbgDeclareInst*
> This header may not be the best place, but if I place these in
> Support/<something>.cpp I get circular dependencies with VMCore
>
> 03-pass.patch:
> -print-dbg-info: An example pass that shows how to use the functions
> in
> 02-intrin.patch, and how to handle debug info in general for the
> purpose
> of mapping LLVM IR back to original source code.
> This pass can be very useful when developing other passes, because you
> can see which line a certain LLVM instruction corresponds to,
> and can see the unmangled name of functions.
>
> Do you see any problems with these patches, or can I go ahead and
> commit
> them?
>
> Best regards,
> --Edwin
> <01-bb.patch><02-intrin.patch><03-
> pass.patch>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-
Devang
More information about the llvm-commits
mailing list