From da19475328ece3da19437a2e9eef035dcafa2814 Mon Sep 17 00:00:00 2001
From: Devang Patel
Date: Tue, 5 Apr 2011 22:52:06 +0000
Subject: [PATCH] Add support to encode function's template parameters.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128947 91177308-0d34-0410-b5e6-96231b3b80d8
---
docs/SourceLevelDebugging.html | 10 +++++++++-
include/llvm/Analysis/DIBuilder.h | 8 ++++++--
include/llvm/Analysis/DebugInfo.h | 1 +
lib/Analysis/DIBuilder.cpp | 12 ++++++++----
lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 3 +++
5 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/docs/SourceLevelDebugging.html b/docs/SourceLevelDebugging.html
index c786a7d0a81..79ea71ac302 100644
--- a/docs/SourceLevelDebugging.html
+++ b/docs/SourceLevelDebugging.html
@@ -441,6 +441,7 @@ global variables are collected by named metadata !llvm.dbg.gv.
i1 ;; isArtificial
i1 ;; isOptimized
Function *;; Pointer to LLVM function
+ metadata ;; Lists function template parameters
}
@@ -1200,7 +1201,14 @@ int main(int argc, char *argv[]) {
i32 1, ;; Line number
metadata !4, ;; Type
i1 false, ;; Is local
- i1 true ;; Is definition
+ i1 true, ;; Is definition
+ i32 0, ;; Virtuality attribute, e.g. pure virtual function
+ i32 0, ;; Index into virtual table for C++ methods
+ i32 0, ;; Type that holds virtual table.
+ i32 0, ;; Flags
+ i1 false, ;; True if this function is optimized
+ Function *, ;; Pointer to llvm::Function
+ null ;; Function template parameters
}
;;
;; Define the subprogram itself.
diff --git a/include/llvm/Analysis/DIBuilder.h b/include/llvm/Analysis/DIBuilder.h
index 5c0c0378a6d..329db64e301 100644
--- a/include/llvm/Analysis/DIBuilder.h
+++ b/include/llvm/Analysis/DIBuilder.h
@@ -368,6 +368,7 @@ namespace llvm {
/// This flags are used to emit dwarf attributes.
/// @param isOptimized True if optimization is ON.
/// @param Fn llvm::Function pointer.
+ /// @param TParam Function template parameters.
DISubprogram createFunction(DIDescriptor Scope, StringRef Name,
StringRef LinkageName,
DIFile File, unsigned LineNo,
@@ -375,7 +376,8 @@ namespace llvm {
bool isDefinition,
unsigned Flags = 0,
bool isOptimized = false,
- Function *Fn = 0);
+ Function *Fn = 0,
+ MDNode *TParam = 0);
/// createMethod - Create a new descriptor for the specified C++ method.
/// See comments in DISubprogram for descriptions of these fields.
@@ -395,6 +397,7 @@ namespace llvm {
/// This flags are used to emit dwarf attributes.
/// @param isOptimized True if optimization is ON.
/// @param Fn llvm::Function pointer.
+ /// @param TParam Function template parameters.
DISubprogram createMethod(DIDescriptor Scope, StringRef Name,
StringRef LinkageName,
DIFile File, unsigned LineNo,
@@ -404,7 +407,8 @@ namespace llvm {
MDNode *VTableHolder = 0,
unsigned Flags = 0,
bool isOptimized = false,
- Function *Fn = 0);
+ Function *Fn = 0,
+ MDNode *TParam = 0);
/// createNameSpace - This creates new descriptor for a namespace
/// with the specified parent scope.
diff --git a/include/llvm/Analysis/DebugInfo.h b/include/llvm/Analysis/DebugInfo.h
index 951fd3cf1f6..276ac451c1f 100644
--- a/include/llvm/Analysis/DebugInfo.h
+++ b/include/llvm/Analysis/DebugInfo.h
@@ -511,6 +511,7 @@ namespace llvm {
bool describes(const Function *F);
Function *getFunction() const { return getFunctionField(16); }
+ DIArray getTemplateParams() const { return getFieldAs(17); }
};
/// DIGlobalVariable - This is a wrapper for a global variable.
diff --git a/lib/Analysis/DIBuilder.cpp b/lib/Analysis/DIBuilder.cpp
index 766624f87ce..108d2d2ec2b 100644
--- a/lib/Analysis/DIBuilder.cpp
+++ b/lib/Analysis/DIBuilder.cpp
@@ -642,7 +642,8 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context,
DIType Ty,
bool isLocalToUnit, bool isDefinition,
unsigned Flags, bool isOptimized,
- Function *Fn) {
+ Function *Fn,
+ MDNode *TParams) {
Value *Elts[] = {
GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
@@ -660,7 +661,8 @@ DISubprogram DIBuilder::createFunction(DIDescriptor Context,
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
- Fn
+ Fn,
+ TParams
};
MDNode *Node = MDNode::get(VMContext, &Elts[0], array_lengthof(Elts));
@@ -682,7 +684,8 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context,
MDNode *VTableHolder,
unsigned Flags,
bool isOptimized,
- Function *Fn) {
+ Function *Fn,
+ MDNode *TParam) {
Value *Elts[] = {
GetTagConstant(VMContext, dwarf::DW_TAG_subprogram),
llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
@@ -700,7 +703,8 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context,
VTableHolder,
ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
- Fn
+ Fn,
+ TParam,
};
MDNode *Node = MDNode::get(VMContext, &Elts[0], array_lengthof(Elts));
diff --git a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index be5c206eeda..bad87c1b558 100644
--- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1455,6 +1455,9 @@ DIE *DwarfDebug::createSubprogramDIE(DISubprogram SP) {
addUInt(SPDie, dwarf::DW_AT_APPLE_isa, dwarf::DW_FORM_flag, isa);
}
+ // Add function template parameters.
+ addTemplateParams(*SPDie, SP.getTemplateParams());
+
// DW_TAG_inlined_subroutine may refer to this DIE.
SPCU->insertDIE(SP, SPDie);