[cfe-commits] r110660 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h lib/CodeGen/CGExprScalar.cpp lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h test/CodeGen/2010-08-10-DbgConstant.c
Chris Lattner
clattner at apple.com
Tue Aug 10 08:25:48 PDT 2010
On Aug 10, 2010, at 12:24 AM, Devang Patel wrote:
> Author: dpatel
> Date: Tue Aug 10 02:24:25 2010
> New Revision: 110660
>
> URL: http://llvm.org/viewvc/llvm-project?rev=110660&view=rev
> Log:
> Even if a constant's evaluated value is used, emit debug info for the constant variable.
Ok, a couple of comments.
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Aug 10 02:24:25 2010
> @@ -1801,6 +1801,17 @@
> true/*definition*/, Var);
> }
>
> +void CGDebugInfo::EmitGlobalVariable(llvm::Constant *C, const ValueDecl *VD,
> + CGBuilderTy &Builder) {
VD should come first, because it is the global variable you're emitting the debug info for, the constant is secondary. Also, C should be named "Initializer" and/or you should add a doxygen comment explaining what this does.
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Aug 10 02:24:25 2010
> @@ -181,6 +181,10 @@
> /// EmitGlobalVariable - Emit information about an objective-c interface.
> void EmitGlobalVariable(llvm::GlobalVariable *GV, ObjCInterfaceDecl *Decl);
>
> + /// EmitGlobalVariable - Emit information about a constant.
> + void EmitGlobalVariable(llvm::Constant *C, const ValueDecl *VD,
> + CGBuilderTy &Builder);
This comment seems contradictory. Are you emitting debug info for a global variable or a constant?
> +++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Aug 10 02:24:25 2010
> @@ -149,6 +149,7 @@
> Expr::EvalResult Result;
> if (E->Evaluate(Result, CGF.getContext()) && Result.Val.isInt()) {
> assert(!Result.HasSideEffects && "Constant declref with side-effect?!");
> + CGF.EmitDeclRefExprDbgValue(E, Result.Val);
> return llvm::ConstantInt::get(VMContext, Result.Val.getInt());
This is the only caller of CGF.EmitDeclRefExprDbgValue. Please pass the created ConstantInt to it instead of passing the APValue.
> +void CodeGenFunction::EmitDeclRefExprDbgValue(const DeclRefExpr *E,
> + const APValue &AV) {
> + CGDebugInfo *Dbg = getDebugInfo();
> + if (!Dbg) return;
> +
> + llvm::Constant *C = NULL;
> + if (AV.isInt())
> + C = llvm::ConstantInt::get(getLLVMContext(), AV.getInt());
> + else if (AV.isFloat())
> + C = llvm::ConstantFP::get(getLLVMContext(), AV.getFloat());
Passing the constantint will eliminate this code.
> + if (C)
> + Dbg->EmitGlobalVariable(C, E->getDecl(), Builder);
This is calling EmitGlobalVariable *every* time a constant is codegen'd in the code. In your example, ro+ro+ro+ro will cause the global to get emitted 4 times. I realize that MDNodes do autouniquing, but doesn't this sound inefficient?
-Chris
> +}
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=110660&r1=110659&r2=110660&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Tue Aug 10 02:24:25 2010
> @@ -41,6 +41,7 @@
> }
>
> namespace clang {
> + class APValue;
> class ASTContext;
> class CXXDestructorDecl;
> class CXXTryStmt;
> @@ -1372,7 +1373,7 @@
> LValue EmitStmtExprLValue(const StmtExpr *E);
> LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E);
> LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E);
> -
> + void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &AV);
> //===--------------------------------------------------------------------===//
> // Scalar Expression Emission
> //===--------------------------------------------------------------------===//
>
> Added: cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c?rev=110660&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c (added)
> +++ cfe/trunk/test/CodeGen/2010-08-10-DbgConstant.c Tue Aug 10 02:24:25 2010
> @@ -0,0 +1,5 @@
> +// RUN: %clang_cc1 -S -emit-llvm -g %s -o - | grep DW_TAG_constant
> +
> +static const unsigned int ro = 201;
> +void bar(int);
> +void foo() { bar(ro); }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list