1 /*========================== begin_copyright_notice ============================ 2 3 Copyright (C) 2021 Intel Corporation 4 5 SPDX-License-Identifier: MIT 6 7 ============================= end_copyright_notice ===========================*/ 8 9 #ifndef VC_UTILS_GENERAL_DEBUG_INFO_H 10 #define VC_UTILS_GENERAL_DEBUG_INFO_H 11 12 #include <llvm/IR/DebugInfoMetadata.h> 13 14 #include <llvm/ADT/StringRef.h> 15 16 namespace llvm { 17 class GlobalVariable; 18 class DbgDeclareInst; 19 class Instruction; 20 class Function; 21 class Module; 22 class Type; 23 } // namespace llvm 24 25 namespace vc { 26 27 // Utility class to construct new debug information nodes 28 // The interface is vaguely similar to llvm::DIBuilder, however it can 29 // be used on a Module that already contains DICompilation units, allowing 30 // for an addition or modification of an existing debug information. 31 class DIBuilder { 32 llvm::Module &M; 33 34 llvm::DIType *translateScalarTypeToDIType(llvm::Type &Ty) const; 35 36 void registerNewGlobalVariable(llvm::DIGlobalVariableExpression *NewGV) const; 37 38 public: 39 static bool checkIfModuleHasDebugInfo(const llvm::Module &M); 40 static bool checkIfFunctionHasDebugInfo(const llvm::Function &F); 41 42 static llvm::DbgDeclareInst * 43 createDbgDeclareForLocalizedGlobal(llvm::Instruction &Address, 44 const llvm::GlobalVariable &GV, 45 llvm::Instruction &InsertPt); 46 DIBuilder(llvm::Module & MIn)47 DIBuilder(llvm::Module &MIn) : M(MIn) {} 48 llvm::DIType *translateTypeToDIType(llvm::Type &Ty) const; 49 50 llvm::DICompileUnit *getDICompileUnit() const; 51 52 llvm::DILocation *createLocationForFunctionScope(llvm::Function &Fn) const; 53 54 llvm::DIGlobalVariableExpression * 55 createGlobalVariableExpression(llvm::StringRef Name, 56 llvm::StringRef LinkageName, 57 llvm::DIType *Type) const; 58 59 llvm::DbgDeclareInst *createDbgDeclare(llvm::Value &Address, 60 llvm::DILocalVariable &LocalVar, 61 llvm::DIExpression &Expr, 62 llvm::DILocation &Loc, 63 llvm::Instruction &InsertPt) const; 64 65 llvm::DILocalVariable * 66 createLocalVariable(llvm::DILocalScope *Scope, llvm::StringRef Name, 67 llvm::DIFile *File, unsigned LineNo, llvm::DIType *Type, 68 unsigned ArgNo, llvm::DINode::DIFlags Flags, 69 unsigned AlignInBits) const; 70 }; 71 72 } // namespace vc 73 74 #endif // VC_UTILS_GENERAL_DEBUG_INFO_H 75