From: Devang Patel Date: Tue, 10 Aug 2010 17:53:33 +0000 (+0000) Subject: Simplify code and add comments, in code that generate debug info for constant integer... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=25c2c8fb9309050612009a6571e2660e75531348;p=clang Simplify code and add comments, in code that generate debug info for constant integer globals, based on Chris's feedback. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110694 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 5ec68c0ff0..a75ff10476 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1801,7 +1801,9 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var, true/*definition*/, Var); } -void CGDebugInfo::EmitGlobalVariable(llvm::Constant *C, const ValueDecl *VD, +/// EmitGlobalVariable - Emit global variable's debug info. +void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, + llvm::ConstantInt *Init, CGBuilderTy &Builder) { // Create the descriptor for the variable. llvm::DIFile Unit = getOrCreateFile(VD->getLocation()); @@ -1809,7 +1811,7 @@ void CGDebugInfo::EmitGlobalVariable(llvm::Constant *C, const ValueDecl *VD, DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit, getLineNumber(VD->getLocation()), getOrCreateType(VD->getType(), Unit), - true, true, C); + true, true, Init); } /// getOrCreateNamesSpace - Return namespace descriptor for the given diff --git a/lib/CodeGen/CGDebugInfo.h b/lib/CodeGen/CGDebugInfo.h index 4df2ab62f8..93c9aeea3c 100644 --- a/lib/CodeGen/CGDebugInfo.h +++ b/lib/CodeGen/CGDebugInfo.h @@ -181,8 +181,8 @@ public: /// 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, + /// EmitGlobalVariable - Emit global variable's debug info. + void EmitGlobalVariable(const ValueDecl *VD, llvm::ConstantInt *Init, CGBuilderTy &Builder); private: diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index f6f126a8a6..89947df940 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -149,8 +149,10 @@ public: 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()); + llvm::ConstantInt *CI + = llvm::ConstantInt::get(VMContext, Result.Val.getInt()); + CGF.EmitDeclRefExprDbgValue(E, CI); + return CI; } return EmitLoadOfLValue(E); } diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index f992aa72e2..f883bec4ff 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -1286,15 +1286,8 @@ llvm::Value *CodeGenFunction::getEHCleanupDestSlot() { } 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()); - if (C) - Dbg->EmitGlobalVariable(C, E->getDecl(), Builder); + llvm::ConstantInt *Init) { + assert (Init && "Invalid DeclRefExpr initializer!"); + if (CGDebugInfo *Dbg = getDebugInfo()) + Dbg->EmitGlobalVariable(E->getDecl(), Init, Builder); } diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index e0673d9917..325940d245 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1373,7 +1373,7 @@ public: LValue EmitStmtExprLValue(const StmtExpr *E); LValue EmitPointerToDataMemberBinaryExpr(const BinaryOperator *E); LValue EmitObjCSelectorLValue(const ObjCSelectorExpr *E); - void EmitDeclRefExprDbgValue(const DeclRefExpr *E, const APValue &AV); + void EmitDeclRefExprDbgValue(const DeclRefExpr *E, llvm::ConstantInt *Init); //===--------------------------------------------------------------------===// // Scalar Expression Emission //===--------------------------------------------------------------------===//