[llvm-commits] [llvm] r62286 - in /llvm/trunk: include/llvm/CodeGen/DwarfWriter.h lib/CodeGen/AsmPrinter/DwarfWriter.cpp lib/CodeGen/SelectionDAG/FastISel.cpp lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp test/DebugInfo/2009-01-15-dbg_declare.ll

Evan Cheng evan.cheng at apple.com
Fri Jan 16 09:55:10 PST 2009


Hi Devang,

Is this the right fix or just a work around? Should llvm-gcc be  
generating these invalid declare intrinsics in the first place? It  
seems like this will increase compile time. It could be noticeable  
when it's in fastisel mode, no?

+    DIDescriptor DI(GV);
+    // Check current version. Allow Version6 for now.
+    unsigned Version = DI.getVersion();
+    if (Version != DIDescriptor::Version7 && Version !=  
DIDescriptor::Version6)
+      return false;

I know DIDescriptor is light weight. But is it necessary to create the  
descriptor just to check the version number? Can you add a helper  
function to DebugInfo that examines GV and returns its corresponding  
version?

Also
+    if (DW && SPI->getContext() && DW->ValidDebugInfo(SPI- 
 >getContext())) {

You might as well fold the "SPI->getContext()" check into  
ValidDebugInfo.

Evan


On Jan 15, 2009, at 3:41 PM, Devang Patel wrote:

> Author: dpatel
> Date: Thu Jan 15 17:41:32 2009
> New Revision: 62286
>
> URL: http://llvm.org/viewvc/llvm-project?rev=62286&view=rev
> Log:
>
> Validate dbg_* intrinsics before lowering them.
>
>
> Added:
>    llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll
> Modified:
>    llvm/trunk/include/llvm/CodeGen/DwarfWriter.h
>    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
>    llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp
>    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
>
> Modified: llvm/trunk/include/llvm/CodeGen/DwarfWriter.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/DwarfWriter.h?rev=62286&r1=62285&r2=62286&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/include/llvm/CodeGen/DwarfWriter.h (original)
> +++ llvm/trunk/include/llvm/CodeGen/DwarfWriter.h Thu Jan 15  
> 17:41:32 2009
> @@ -29,6 +29,7 @@
> class DwarfException;
> class MachineModuleInfo;
> class MachineFunction;
> +class Value;
> class Module;
> class GlobalVariable;
> class TargetAsmInfo;
> @@ -75,6 +76,8 @@
>   ///
>   void EndFunction(MachineFunction *MF);
>
> +  /// ValidDebugInfo - Return true if V represents valid debug info  
> value.
> +  bool ValidDebugInfo(Value *V);
>
>   /// label. Returns a unique label ID used to generate a label and  
> provide
>   /// correspondence to the source line list.
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp?rev=62286&r1=62285&r2=62286&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfWriter.cpp Thu Jan 15  
> 17:41:32 2009
> @@ -19,6 +19,7 @@
> #include "llvm/ADT/UniqueVector.h"
> #include "llvm/Module.h"
> #include "llvm/DerivedTypes.h"
> +#include "llvm/Constants.h"
> #include "llvm/CodeGen/AsmPrinter.h"
> #include "llvm/CodeGen/MachineModuleInfo.h"
> #include "llvm/CodeGen/MachineFrameInfo.h"
> @@ -100,6 +101,25 @@
>     getGlobalVariablesUsing(UseRoot, Result);
> }
>
> +/// getGlobalVariable - Return either a direct or cast Global value.
> +///
> +static GlobalVariable *getGlobalVariable(Value *V) {
> +  if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
> +    return GV;
> +  } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) {
> +    if (CE->getOpcode() == Instruction::BitCast) {
> +      return dyn_cast<GlobalVariable>(CE->getOperand(0));
> +    } else if (CE->getOpcode() == Instruction::GetElementPtr) {
> +      for (unsigned int i=1; i<CE->getNumOperands(); i++) {
> +        if (!CE->getOperand(i)->isNullValue())
> +          return NULL;
> +      }
> +      return dyn_cast<GlobalVariable>(CE->getOperand(0));
> +    }
> +  }
> +  return NULL;
> +}
> +
> // 
> = 
> = 
> = 
> ----------------------------------------------------------------------= 
> ==//
> /// DWLabel - Labels are used to track locations in the assembler  
> file.
> /// Labels appear in the form @verbatim <prefix><Tag><Number>  
> @endverbatim,
> @@ -3056,6 +3076,26 @@
>
> public:
>
> +  /// ValidDebugInfo - Return true if V represents valid debug info  
> value.
> +  bool ValidDebugInfo(Value *V) {
> +    GlobalVariable *GV = getGlobalVariable(V);
> +    if (!GV)
> +      return false;
> +
> +    if (GV->getLinkage() != GlobalValue::InternalLinkage
> +        && GV->getLinkage() != GlobalValue::LinkOnceLinkage)
> +      return false;
> +
> +    DIDescriptor DI(GV);
> +    // Check current version. Allow Version6 for now.
> +    unsigned Version = DI.getVersion();
> +    if (Version != DIDescriptor::Version7 && Version !=  
> DIDescriptor::Version6)
> +      return false;
> +
> +    //FIXME - Check individual descriptors.
> +    return true;
> +  }
> +
>   /// RecordSourceLine - Records location information and associates  
> it with a
>   /// label. Returns a unique label ID used to generate a label and  
> provide
>   /// correspondence to the source line list.
> @@ -4221,6 +4261,11 @@
>     MMI->EndFunction();
> }
>
> +/// ValidDebugInfo - Return true if V represents valid debug info  
> value.
> +bool DwarfWriter::ValidDebugInfo(Value *V) {
> +  return DD->ValidDebugInfo(V);
> +}
> +
> /// RecordSourceLine - Records location information and associates  
> it with a
> /// label. Returns a unique label ID used to generate a label and  
> provide
> /// correspondence to the source line list.
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp?rev=62286&r1=62285&r2=62286&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp Thu Jan 15  
> 17:41:32 2009
> @@ -317,7 +317,7 @@
>   default: break;
>   case Intrinsic::dbg_stoppoint: {
>     DbgStopPointInst *SPI = cast<DbgStopPointInst>(I);
> -    if (DW && SPI->getContext()) {
> +    if (DW && SPI->getContext() && DW->ValidDebugInfo(SPI- 
> >getContext())) {
>       DICompileUnit CU(cast<GlobalVariable>(SPI->getContext()));
>       unsigned SrcFile = DW->RecordSource(CU.getDirectory(),
>                                           CU.getFilename());
> @@ -331,7 +331,7 @@
>   }
>   case Intrinsic::dbg_region_start: {
>     DbgRegionStartInst *RSI = cast<DbgRegionStartInst>(I);
> -    if (DW && RSI->getContext()) {
> +    if (DW && RSI->getContext() && DW->ValidDebugInfo(RSI- 
> >getContext())) {
>       unsigned ID =
>         DW->RecordRegionStart(cast<GlobalVariable>(RSI- 
> >getContext()));
>       const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL);
> @@ -341,7 +341,7 @@
>   }
>   case Intrinsic::dbg_region_end: {
>     DbgRegionEndInst *REI = cast<DbgRegionEndInst>(I);
> -    if (DW && REI->getContext()) {
> +    if (DW && REI->getContext() && DW->ValidDebugInfo(REI- 
> >getContext())) {
>       unsigned ID =
>         DW->RecordRegionEnd(cast<GlobalVariable>(REI->getContext()));
>       const TargetInstrDesc &II = TII.get(TargetInstrInfo::DBG_LABEL);
> @@ -353,7 +353,7 @@
>     if (!DW) return true;
>     DbgFuncStartInst *FSI = cast<DbgFuncStartInst>(I);
>     Value *SP = FSI->getSubprogram();
> -    if (SP) {
> +    if (SP && DW->ValidDebugInfo(SP)) {
>       // llvm.dbg.func.start implicitly defines a dbg_stoppoint  
> which is
>       // what (most?) gdb expects.
>       DISubprogram Subprogram(cast<GlobalVariable>(SP));
> @@ -375,7 +375,7 @@
>   case Intrinsic::dbg_declare: {
>     DbgDeclareInst *DI = cast<DbgDeclareInst>(I);
>     Value *Variable = DI->getVariable();
> -    if (DW && Variable) {
> +    if (DW && Variable && DW->ValidDebugInfo(Variable)) {
>       // Determine the address of the declared object.
>       Value *Address = DI->getAddress();
>       if (BitCastInst *BCI = dyn_cast<BitCastInst>(Address))
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=62286&r1=62285&r2=62286&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp  
> (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Thu  
> Jan 15 17:41:32 2009
> @@ -3746,7 +3746,7 @@
>   case Intrinsic::dbg_stoppoint: {
>     DwarfWriter *DW = DAG.getDwarfWriter();
>     DbgStopPointInst &SPI = cast<DbgStopPointInst>(I);
> -    if (DW && SPI.getContext())
> +    if (DW && SPI.getContext() && DW- 
> >ValidDebugInfo(SPI.getContext()))
>       DAG.setRoot(DAG.getDbgStopPoint(getRoot(),
>                                       SPI.getLine(),
>                                       SPI.getColumn(),
> @@ -3756,7 +3756,7 @@
>   case Intrinsic::dbg_region_start: {
>     DwarfWriter *DW = DAG.getDwarfWriter();
>     DbgRegionStartInst &RSI = cast<DbgRegionStartInst>(I);
> -    if (DW && RSI.getContext()) {
> +    if (DW && RSI.getContext() && DW- 
> >ValidDebugInfo(RSI.getContext())) {
>       unsigned LabelID =
>         DW->RecordRegionStart(cast<GlobalVariable>(RSI.getContext()));
>       DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID));
> @@ -3767,7 +3767,7 @@
>   case Intrinsic::dbg_region_end: {
>     DwarfWriter *DW = DAG.getDwarfWriter();
>     DbgRegionEndInst &REI = cast<DbgRegionEndInst>(I);
> -    if (DW && REI.getContext()) {
> +    if (DW && REI.getContext() && DW- 
> >ValidDebugInfo(REI.getContext())) {
>       unsigned LabelID =
>         DW->RecordRegionEnd(cast<GlobalVariable>(REI.getContext()));
>       DAG.setRoot(DAG.getLabel(ISD::DBG_LABEL, getRoot(), LabelID));
> @@ -3780,7 +3780,7 @@
>     if (!DW) return 0;
>     DbgFuncStartInst &FSI = cast<DbgFuncStartInst>(I);
>     Value *SP = FSI.getSubprogram();
> -    if (SP) {
> +    if (SP && DW->ValidDebugInfo(SP)) {
>       // llvm.dbg.func.start implicitly defines a dbg_stoppoint  
> which is
>       // what (most?) gdb expects.
>       DISubprogram Subprogram(cast<GlobalVariable>(SP));
> @@ -3802,7 +3802,7 @@
>     DwarfWriter *DW = DAG.getDwarfWriter();
>     DbgDeclareInst &DI = cast<DbgDeclareInst>(I);
>     Value *Variable = DI.getVariable();
> -    if (DW && Variable)
> +    if (DW && Variable && DW->ValidDebugInfo(Variable))
>       DAG.setRoot(DAG.getNode(ISD::DECLARE, MVT::Other, getRoot(),
>                               getValue(DI.getAddress()),  
> getValue(Variable)));
>     return 0;
>
> Added: llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll?rev=62286&view=auto
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll (added)
> +++ llvm/trunk/test/DebugInfo/2009-01-15-dbg_declare.ll Thu Jan 15  
> 17:41:32 2009
> @@ -0,0 +1,15 @@
> +
> +; RUN: llvm-as < %s | llc -f -o /dev/null
> +target triple = "powerpc-apple-darwin9.5"
> +        %llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32,  
> { }*, i8*, i8* }
> + at llvm.dbg.variable24 = external constant  
> %llvm.dbg.variable.type                ; <%llvm.dbg.variable.type*>  
> [#uses=1]
> +
> +declare void @llvm.dbg.declare({ }*, { }*) nounwind
> +
> +define i32 @isascii(i32 %_c) nounwind {
> +entry:
> +        call void @llvm.dbg.declare({ }* null, { }* bitcast  
> (%llvm.dbg.variable.type* @llvm.dbg.variable24 to { }*))
> +        unreachable
> +}
> +
> +
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090116/8461e1d8/attachment.html>


More information about the llvm-commits mailing list