[PATCH] D27763: Debug Info: Modified DIBuilder::createCompileUnit() to take DIFile instead of FileName and Directory. (Clang part)

2016-12-14 Thread Amjad Aboud via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289701: [DebugInfo] Changed DIBuilder::createCompileUnit() 
to take DIFile instead of… (authored by aaboud).

Changed prior to commit:
  https://reviews.llvm.org/D27763?vs=81397&id=81438#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27763

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp


Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -466,7 +466,8 @@
   // Create new compile unit.
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
-  LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
+  LangTag, DBuilder.createFile(remapDIPath(MainFileName),
+remapDIPath(getCurrentDirname())),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
   CGM.getCodeGenOpts().SplitDwarfInlining);
@@ -1977,10 +1978,11 @@
 // but LLVM detects skeleton CUs by looking for a non-zero DWO id.
 uint64_t Signature = Mod.getSignature() ? Mod.getSignature() : ~1ULL;
 llvm::DIBuilder DIB(CGM.getModule());
-DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.getModuleName(),
-  Mod.getPath(), TheCU->getProducer(), true,
-  StringRef(), 0, Mod.getASTFile(),
-  llvm::DICompileUnit::FullDebug, Signature);
+DIB.createCompileUnit(TheCU->getSourceLanguage(),
+  DIB.createFile(Mod.getModuleName(), Mod.getPath()),
+  TheCU->getProducer(), true, StringRef(), 0,
+  Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
+  Signature);
 DIB.finalize();
   }
   llvm::DIModule *Parent =


Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -466,7 +466,8 @@
   // Create new compile unit.
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
-  LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
+  LangTag, DBuilder.createFile(remapDIPath(MainFileName),
+remapDIPath(getCurrentDirname())),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
   CGM.getCodeGenOpts().SplitDwarfInlining);
@@ -1977,10 +1978,11 @@
 // but LLVM detects skeleton CUs by looking for a non-zero DWO id.
 uint64_t Signature = Mod.getSignature() ? Mod.getSignature() : ~1ULL;
 llvm::DIBuilder DIB(CGM.getModule());
-DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.getModuleName(),
-  Mod.getPath(), TheCU->getProducer(), true,
-  StringRef(), 0, Mod.getASTFile(),
-  llvm::DICompileUnit::FullDebug, Signature);
+DIB.createCompileUnit(TheCU->getSourceLanguage(),
+  DIB.createFile(Mod.getModuleName(), Mod.getPath()),
+  TheCU->getProducer(), true, StringRef(), 0,
+  Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
+  Signature);
 DIB.finalize();
   }
   llvm::DIModule *Parent =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27641: DebugInfo: Added support for Checksum debug info feature (Clang part)

2016-12-15 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a subscriber: bwyma.
aaboud updated this revision to Diff 81640.
aaboud added a comment.

Moved getChecksum from SourceManager to CGDebugInfo.
Also, now checksum is emitted only for CodeView.


https://reviews.llvm.org/D27641

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGen/debug-info-file-checksum.c
  test/CodeGen/debug-info-file-checksum.c.source

Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -442,6 +442,10 @@
   /// Remap a given path with the current debug prefix map
   std::string remapDIPath(StringRef) const;
 
+  /// Get the file checksum debug info for input file ID.
+  llvm::DIFile::ChecksumKind getChecksum(FileID FID,
+ SmallString<32> &Checksum) const;
+
   /// Get the file debug info descriptor for the input location.
   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -41,6 +41,7 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
 using namespace clang;
 using namespace clang::CodeGen;
@@ -320,19 +321,46 @@
   return StringRef();
 }
 
+llvm::DIFile::ChecksumKind
+CGDebugInfo::getChecksum(FileID FID, SmallString<32> &Checksum) const {
+  Checksum.clear();
+
+  if (!CGM.getCodeGenOpts().EmitCodeView)
+return llvm::DIFile::CSK_None;
+
+  SourceManager &SM = CGM.getContext().getSourceManager();
+  bool Invalid;
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
+  if (Invalid)
+return llvm::DIFile::CSK_None;
+
+  llvm::MD5 Hash;
+  llvm::MD5::MD5Result Result;
+
+  Hash.update(MemBuffer->getBuffer());
+  Hash.final(Result);
+
+  Hash.stringifyResult(Result, Checksum);
+  return llvm::DIFile::CSK_MD5;
+}
+
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()));
+   remapDIPath(TheCU->getDirectory()),
+   TheCU->getFile()->getChecksumKind(),
+   TheCU->getFile()->getChecksum());
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(Loc);
 
   if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
 // If the location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()));
+   remapDIPath(TheCU->getDirectory()),
+   TheCU->getFile()->getChecksumKind(),
+   TheCU->getFile()->getChecksum());
 
   // Cache the results.
   const char *fname = PLoc.getFilename();
@@ -344,16 +372,22 @@
   return cast(V);
   }
 
+  SmallString<32> Checksum;
+  llvm::DIFile::ChecksumKind CSKind = getChecksum(SM.getFileID(Loc), Checksum);
+
   llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
-remapDIPath(getCurrentDirname()));
+remapDIPath(getCurrentDirname()),
+CSKind, Checksum);
 
   DIFileCache[fname].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
   return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
- remapDIPath(TheCU->getDirectory()));
+ remapDIPath(TheCU->getDirectory()),
+ TheCU->getFile()->getChecksumKind(),
+ TheCU->getFile()->getChecksum());
 }
 
 std::string CGDebugInfo::remapDIPath(StringRef Path) const {
@@ -396,6 +430,8 @@
 }
 
 void CGDebugInfo::CreateCompileUnit() {
+   SmallString<32> Checksum;
+  llvm::DIFile::ChecksumKind CSKind = llvm::DIFile::CSK_None;
 
   // Should we be asking the SourceManager for the main file name, instead of
   // accepting it as an argument? This just causes the main file name to
@@ -422,6 +458,7 @@
   llvm::sys::path::append(MainFileDirSS, MainFileName);
   MainFileName = MainFileDirSS.str();
 }
+CSKind = getChecksum(SM.getMainFileID(), Checksum);
   }
 
   llvm::dwarf::SourceLanguage LangTag;
@@ -467,7 +504,8 @@
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
   LangTag, DBuilder.createFile(remapDIPath(MainFileName),
-remapDIPath(getCurrentDirname())),
+   remapDIPath(getCurrentDirname()), CSKind,
+ 

[PATCH] D27641: DebugInfo: Added support for Checksum debug info feature (Clang part)

2016-12-19 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud updated this revision to Diff 81953.
aaboud marked 3 inline comments as done.
aaboud added a comment.

Addressed comments by Reid and David.


https://reviews.llvm.org/D27641

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGen/Inputs/debug-info-file-checksum.c
  test/CodeGen/debug-info-file-checksum.c

Index: lib/CodeGen/CGDebugInfo.h
===
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -442,6 +442,10 @@
   /// Remap a given path with the current debug prefix map
   std::string remapDIPath(StringRef) const;
 
+  /// Get the file checksum debug info for input file ID.
+  llvm::DIFile::ChecksumKind getChecksum(FileID FID,
+ SmallString<32> &Checksum) const;
+
   /// Get the file debug info descriptor for the input location.
   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
 
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -41,6 +41,7 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
 using namespace clang;
 using namespace clang::CodeGen;
@@ -320,19 +321,46 @@
   return StringRef();
 }
 
+llvm::DIFile::ChecksumKind
+CGDebugInfo::getChecksum(FileID FID, SmallString<32> &Checksum) const {
+  Checksum.clear();
+
+  if (!CGM.getCodeGenOpts().EmitCodeView)
+return llvm::DIFile::CSK_None;
+
+  SourceManager &SM = CGM.getContext().getSourceManager();
+  bool Invalid;
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
+  if (Invalid)
+return llvm::DIFile::CSK_None;
+
+  llvm::MD5 Hash;
+  llvm::MD5::MD5Result Result;
+
+  Hash.update(MemBuffer->getBuffer());
+  Hash.final(Result);
+
+  Hash.stringifyResult(Result, Checksum);
+  return llvm::DIFile::CSK_MD5;
+}
+
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()));
+   remapDIPath(TheCU->getDirectory()),
+   TheCU->getFile()->getChecksumKind(),
+   TheCU->getFile()->getChecksum());
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(Loc);
 
   if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
 // If the location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()));
+   remapDIPath(TheCU->getDirectory()),
+   TheCU->getFile()->getChecksumKind(),
+   TheCU->getFile()->getChecksum());
 
   // Cache the results.
   const char *fname = PLoc.getFilename();
@@ -344,16 +372,22 @@
   return cast(V);
   }
 
+  SmallString<32> Checksum;
+  llvm::DIFile::ChecksumKind CSKind = getChecksum(SM.getFileID(Loc), Checksum);
+
   llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
-remapDIPath(getCurrentDirname()));
+remapDIPath(getCurrentDirname()),
+CSKind, Checksum);
 
   DIFileCache[fname].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
   return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
- remapDIPath(TheCU->getDirectory()));
+ remapDIPath(TheCU->getDirectory()),
+ TheCU->getFile()->getChecksumKind(),
+ TheCU->getFile()->getChecksum());
 }
 
 std::string CGDebugInfo::remapDIPath(StringRef Path) const {
@@ -396,6 +430,8 @@
 }
 
 void CGDebugInfo::CreateCompileUnit() {
+  SmallString<32> Checksum;
+  llvm::DIFile::ChecksumKind CSKind = llvm::DIFile::CSK_None;
 
   // Should we be asking the SourceManager for the main file name, instead of
   // accepting it as an argument? This just causes the main file name to
@@ -422,6 +458,7 @@
   llvm::sys::path::append(MainFileDirSS, MainFileName);
   MainFileName = MainFileDirSS.str();
 }
+CSKind = getChecksum(SM.getMainFileID(), Checksum);
   }
 
   llvm::dwarf::SourceLanguage LangTag;
@@ -467,7 +504,8 @@
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
   LangTag, DBuilder.createFile(remapDIPath(MainFileName),
-remapDIPath(getCurrentDirname())),
+   remapDIPath(getCurrentDirname()), CSKind,
+   Checksum),
   Producer, LO.O

[PATCH] D27641: DebugInfo: Added support for Checksum debug info feature (Clang part)

2016-12-25 Thread Amjad Aboud via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
aaboud marked an inline comment as done.
Closed by commit rL290515: [DebugInfo] Added support for Checksum debug info 
feature. (authored by aaboud).

Changed prior to commit:
  https://reviews.llvm.org/D27641?vs=81953&id=82463#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27641

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum.c
  cfe/trunk/test/CodeGen/debug-info-file-checksum.c

Index: cfe/trunk/test/CodeGen/debug-info-file-checksum.c
===
--- cfe/trunk/test/CodeGen/debug-info-file-checksum.c
+++ cfe/trunk/test/CodeGen/debug-info-file-checksum.c
@@ -0,0 +1,5 @@
+// RUN: %clang -emit-llvm -S -g -gcodeview -x c %S/Inputs/debug-info-file-checksum.c -o - | FileCheck %s
+
+// Check that "checksum" is created correctly for the compiled file.
+
+// CHECK: !DIFile(filename:{{.*}}, directory:{{.*}}, checksumkind: CSK_MD5, checksum: "a3b7d27af071accdeccaa933fc603608")
Index: cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum.c
===
--- cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum.c
+++ cfe/trunk/test/CodeGen/Inputs/debug-info-file-checksum.c
@@ -0,0 +1,3 @@
+int foo(int x) {
+  return x+1;
+}
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -41,6 +41,7 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MD5.h"
 #include "llvm/Support/Path.h"
 using namespace clang;
 using namespace clang::CodeGen;
@@ -320,19 +321,46 @@
   return StringRef();
 }
 
+llvm::DIFile::ChecksumKind
+CGDebugInfo::computeChecksum(FileID FID, SmallString<32> &Checksum) const {
+  Checksum.clear();
+
+  if (!CGM.getCodeGenOpts().EmitCodeView)
+return llvm::DIFile::CSK_None;
+
+  SourceManager &SM = CGM.getContext().getSourceManager();
+  bool Invalid;
+  llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid);
+  if (Invalid)
+return llvm::DIFile::CSK_None;
+
+  llvm::MD5 Hash;
+  llvm::MD5::MD5Result Result;
+
+  Hash.update(MemBuffer->getBuffer());
+  Hash.final(Result);
+
+  Hash.stringifyResult(Result, Checksum);
+  return llvm::DIFile::CSK_MD5;
+}
+
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()));
+   remapDIPath(TheCU->getDirectory()),
+   TheCU->getFile()->getChecksumKind(),
+   TheCU->getFile()->getChecksum());
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(Loc);
 
   if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
 // If the location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()));
+   remapDIPath(TheCU->getDirectory()),
+   TheCU->getFile()->getChecksumKind(),
+   TheCU->getFile()->getChecksum());
 
   // Cache the results.
   const char *fname = PLoc.getFilename();
@@ -344,16 +372,23 @@
   return cast(V);
   }
 
+  SmallString<32> Checksum;
+  llvm::DIFile::ChecksumKind CSKind =
+  computeChecksum(SM.getFileID(Loc), Checksum);
+
   llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
-remapDIPath(getCurrentDirname()));
+remapDIPath(getCurrentDirname()),
+CSKind, Checksum);
 
   DIFileCache[fname].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
   return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
- remapDIPath(TheCU->getDirectory()));
+ remapDIPath(TheCU->getDirectory()),
+ TheCU->getFile()->getChecksumKind(),
+ TheCU->getFile()->getChecksum());
 }
 
 std::string CGDebugInfo::remapDIPath(StringRef Path) const {
@@ -396,6 +431,8 @@
 }
 
 void CGDebugInfo::CreateCompileUnit() {
+  SmallString<32> Checksum;
+  llvm::DIFile::ChecksumKind CSKind = llvm::DIFile::CSK_None;
 
   // Should we be asking the SourceManager for the main file name, instead of
   // accepting it as an argument? This just causes the main file name to
@@ -422,6 +459,7 @@
   llvm::sys::path::append(MainFileDirSS, MainFileName);

[PATCH] D16135: Macro Debug Info support in Clang

2016-12-29 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud updated this revision to Diff 82696.
aaboud added a comment.
Herald added subscribers: mgorny, nemanjai.

Improved code based on Richard's comments.
Removed the change to ASTConsumer, now it does not need to know anything about 
PP consumer.
However, I still needed to change the CodeGenerator ASTConsumer to return the 
CGDebugInfo class.

Richard, please review the new patch.
This time I made sure to add the "MacroPPCallbacks.*" new files.


https://reviews.llvm.org/D16135

Files:
  include/clang/CodeGen/ModuleBuilder.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/CodeGen/ModuleBuilder.cpp
  test/CodeGen/debug-info-global-constant.c

Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -65,6 +65,7 @@
 
   private:
 SmallVector DeferredInlineMethodDefinitions;
+CGDebugInfo *DebugInfoRef;
 
   public:
 CodeGeneratorImpl(DiagnosticsEngine &diags, llvm::StringRef ModuleName,
@@ -74,7 +75,8 @@
   CoverageSourceInfo *CoverageInfo = nullptr)
 : Diags(diags), Ctx(nullptr), HeaderSearchOpts(HSO),
   PreprocessorOpts(PPO), CodeGenOpts(CGO), HandlingTopLevelDecls(0),
-  CoverageInfo(CoverageInfo), M(new llvm::Module(ModuleName, C)) {
+  CoverageInfo(CoverageInfo), M(new llvm::Module(ModuleName, C)),
+  DebugInfoRef(nullptr) {
   C.setDiscardValueNames(CGO.DiscardValueNames);
 }
 
@@ -92,6 +94,10 @@
   return M.get();
 }
 
+CGDebugInfo *&getModuleDebugInfoRef() {
+  return DebugInfoRef;
+}
+
 llvm::Module *ReleaseModule() {
   return M.release();
 }
@@ -124,6 +130,9 @@
PreprocessorOpts, CodeGenOpts,
*M, Diags, CoverageInfo));
 
+  // Initialize the place holder for the CGDebugInfo.
+  DebugInfoRef = Builder->getModuleDebugInfo();
+
   for (auto &&Lib : CodeGenOpts.DependentLibraries)
 Builder->AddDependentLib(Lib);
   for (auto &&Opt : CodeGenOpts.LinkerOptions)
@@ -299,6 +308,10 @@
   return static_cast(this)->ReleaseModule();
 }
 
+CGDebugInfo *&CodeGenerator::getModuleDebugInfoRef() {
+  return static_cast(this)->getModuleDebugInfoRef();
+}
+
 const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
Index: lib/CodeGen/MacroPPCallbacks.h
===
--- lib/CodeGen/MacroPPCallbacks.h
+++ lib/CodeGen/MacroPPCallbacks.h
@@ -0,0 +1,110 @@
+//===--- MacroPPCallbacks.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines implementation for the macro preprocessors callbacks.
+//
+//===--===//
+
+#include "clang/Lex/PPCallbacks.h"
+
+namespace llvm {
+class DIMacroFile;
+class DIMacroNode;
+}
+namespace clang {
+class Preprocessor;
+class MacroInfo;
+
+namespace CodeGen {
+class CGDebugInfo;
+}
+
+class MacroPPCallbacks : public PPCallbacks {
+  /// A reference pointer to debug info code generator.
+  CodeGen::CGDebugInfo *&DebugInfo;
+
+  /// Preprocessor.
+  Preprocessor &PP;
+
+  /// Location of recent included file, used for line number.
+  SourceLocation LastHashLoc;
+
+  /// Location of main file, used for file info.
+  SourceLocation MainFileLoc;
+
+  /// Counts current number of command line included files, which was entered
+  /// and was not exited yet.
+  int CommandIncludeFiles;
+
+  enum FileScopeStatus {
+NoScope,  // Scope is not initialized yet.
+InitializedScope, // Main file scope is initialized but not set yet.
+BuiltinScope, //  file scope.
+CommandLineScope, //  file scope.
+CommandLineScopeIncludes, // Included file, from  file, scope.
+MainFileScope // Main file scope.
+  };
+  FileScopeStatus Status;
+
+  /// Parent contains all entered files that were not exited yet according to
+  /// the inclusion order.
+  llvm::SmallVector Scopes;
+
+  /// Get current DIMacroFile scope.
+  /// \return current DIMacroFile scope or nullptr if there is no such scope.
+  llvm::DIMacroFile *getCurrentScope();
+
+  /// Get current line location or invalid location.
+  /// \param Loc current line location.
+  /// \return current line location \p `Loc`, or invalid location if it's in a
+  /// skipped file scope.
+  SourceLocation getCorrectLocatio

[PATCH] D22045: [X86] Support of no_caller_saved_registers attribute (Clang part)

2017-04-12 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud abandoned this revision.
aaboud marked an inline comment as not done.
aaboud added a comment.

Changes in this patch are being reviewed in a new patch 
https://reviews.llvm.org/D31871.


https://reviews.llvm.org/D22045



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-01-17 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a comment.

Richard, can you please review the new patch?


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-01-29 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a comment.

Kindly reminder, I am still waiting for a review on this new patch.

Thanks


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-01 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud marked 7 inline comments as done.
aaboud added a comment.

Thanks Adrian and Richard for the comments, I appreciate that.
I am uploading a new patch that address most of the comments.

Adrian, I answered some of your comments below.

Thanks,
Amjad




Comment at: lib/CodeGen/MacroPPCallbacks.cpp:31
+  MacroInfo::arg_iterator AI = MI.arg_begin(), E = MI.arg_end();
+  for (; AI + 1 != E; ++AI) {
+Name << (*AI)->getName();

aprantl wrote:
> std::next() ?
I am not that satisfied with this function, and I hope we can do it in a better 
way.
This function is based on a code I took from this a static function in file 
"lib\Frontend\PrintPreprocessedOutput.cpp":

```
/// PrintMacroDefinition - Print a macro definition in a form that will be
/// properly accepted back as a definition.
static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
 Preprocessor &PP, raw_ostream &OS) {
```



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:44
+if (MI.isGNUVarargs())
+  Name << "..."; // #define foo(x...)
+

aprantl wrote:
> LLVM style prefers comments to be full sentences and above the code.
As I said above, this code is taken from 
"lib\Frontend\PrintPreprocessedOutput.cpp"
Also, I ran clang-format on it, and it did not suggest to change this line.

But, I do not mind fixing this, if it is the preferred comment style.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:154
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  // Only care about "include" directives.
+  if (!IncludeTok.is(tok::identifier))

aprantl wrote:
> #include as opposed to #import? If so, why?
I am not familiar with "#import" keyword.
1. Is it handled differently by clang that #include?
2. Do we need to generate macro debug info for it?

The reason I have this switch below, is that I am not sure if we call this 
"InclusionDirective" callback for identifiers that are not "#include".

However, I see no harm of updating the LastHashLoc every time we enter this 
function. The value will not be used unless it is set just before calling 
"FileChanged"callback.



Comment at: lib/CodeGen/ModuleBuilder.cpp:68
 SmallVector DeferredInlineMethodDefinitions;
+CGDebugInfo *DebugInfoRef;
 

aprantl wrote:
> What does Ref stand for?
Ref - stands for reference, I think I do not need the "Ref" prefix for this 
member, only for the get function.
But, I will follow Richards suggestion that will eliminate the need for this 
member.


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-01 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud updated this revision to Diff 86669.
aaboud marked an inline comment as done.
aaboud added a comment.

Address Adrian and Richard comments.

Please, review the new patch and let me know if I need to change anything else.

Thanks,
Amjad


https://reviews.llvm.org/D16135

Files:
  include/clang/CodeGen/ModuleBuilder.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/CodeGen/ModuleBuilder.cpp
  test/CodeGen/debug-info-global-constant.c

Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -92,6 +92,10 @@
   return M.get();
 }
 
+CGDebugInfo *getCGDebugInfo() {
+  return Builder->getModuleDebugInfo();
+}
+
 llvm::Module *ReleaseModule() {
   return M.release();
 }
@@ -299,6 +303,10 @@
   return static_cast(this)->ReleaseModule();
 }
 
+CGDebugInfo *CodeGenerator::getCGDebugInfo() {
+  return static_cast(this)->getCGDebugInfo();
+}
+
 const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
Index: lib/CodeGen/MacroPPCallbacks.h
===
--- lib/CodeGen/MacroPPCallbacks.h
+++ lib/CodeGen/MacroPPCallbacks.h
@@ -0,0 +1,107 @@
+//===--- MacroPPCallbacks.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines implementation for the macro preprocessors callbacks.
+//
+//===--===//
+
+#include "clang/Lex/PPCallbacks.h"
+
+namespace llvm {
+class DIMacroFile;
+class DIMacroNode;
+}
+namespace clang {
+class Preprocessor;
+class MacroInfo;
+class CodeGenerator;
+
+class MacroPPCallbacks : public PPCallbacks {
+  /// A pointer to code generator, where debug info generator can be found.
+  CodeGenerator *Gen;
+
+  /// Preprocessor.
+  Preprocessor &PP;
+
+  /// Location of recent included file, used for line number.
+  SourceLocation LastHashLoc;
+
+  /// Location of main file, used for file info.
+  SourceLocation MainFileLoc;
+
+  /// Counts current number of command line included files, which was entered
+  /// and was not exited yet.
+  int CommandIncludeFiles = 0;
+
+  enum FileScopeStatus {
+NoScope,  // Scope is not initialized yet.
+InitializedScope, // Main file scope is initialized but not set yet.
+BuiltinScope, //  file scope.
+CommandLineScope, //  file scope.
+CommandLineScopeIncludes, // Included file, from  file, scope.
+MainFileScope // Main file scope.
+  };
+  FileScopeStatus Status;
+
+  /// Parent contains all entered files that were not exited yet according to
+  /// the inclusion order.
+  llvm::SmallVector Scopes;
+
+  /// Get current DIMacroFile scope.
+  /// \return current DIMacroFile scope or nullptr if there is no such scope.
+  llvm::DIMacroFile *getCurrentScope();
+
+  /// Get current line location or invalid location.
+  /// \param Loc current line location.
+  /// \return current line location \p `Loc`, or invalid location if it's in a
+  /// skipped file scope.
+  SourceLocation getCorrectLocation(SourceLocation Loc);
+
+  /// Use the passed preprocessor to calculate the macro name and value from
+  /// the given macro info and identifier info.
+  ///
+  /// \param II Identifier info, used to get the Macro name.
+  /// \param MI Macro info, used to get the Macro argumets and values.
+  /// \param PP Preprocessor.
+  /// \param [out] Name Place holder for returned macro name and arguments.
+  /// \param [out] Value Place holder for returned macro value.
+  static void calculatMacroDefinition(const IdentifierInfo &II,
+  const MacroInfo &MI, Preprocessor &PP,
+  raw_ostream &Name, raw_ostream &Value);
+
+public:
+  MacroPPCallbacks(CodeGenerator *Gen, Preprocessor &PP);
+
+  /// Callback invoked whenever a source file is entered or exited.
+  ///
+  /// \param Loc Indicates the new location.
+  /// \param PrevFID the file that was exited if \p Reason is ExitFile.
+  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+   SrcMgr::CharacteristicKind FileType,
+   FileID PrevFID = FileID()) override;
+
+  /// Callback invoked whenever a directive (#xxx) is processed.
+  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
+  StringRef FileName, bool IsAngled,
+

[PATCH] D16135: Macro Debug Info support in Clang

2017-02-01 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a comment.

Thanks Adrian for the fast response.
See some answers below.

I will update the code and upload a new patch soon.




Comment at: lib/CodeGen/MacroPPCallbacks.cpp:154
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  // Only care about "include" directives.
+  if (!IncludeTok.is(tok::identifier))

aprantl wrote:
> aaboud wrote:
> > aprantl wrote:
> > > #include as opposed to #import? If so, why?
> > I am not familiar with "#import" keyword.
> > 1. Is it handled differently by clang that #include?
> > 2. Do we need to generate macro debug info for it?
> > 
> > The reason I have this switch below, is that I am not sure if we call this 
> > "InclusionDirective" callback for identifiers that are not "#include".
> > 
> > However, I see no harm of updating the LastHashLoc every time we enter this 
> > function. The value will not be used unless it is set just before calling 
> > "FileChanged"callback.
> #import comes from Objective-C. It is equivalent to #include + #pragma once.
> I'm curious whether this comment means that it isn't handled?
I will remove the switch and update the LastHashLoc unconditionally.
I did not check Objective-C debug info, but I assume it will work fine once I 
change these lines.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:88
+  // Invalid location represents line zero.
+  return SourceLocation();
+}

aprantl wrote:
> I think the entire function can be replaced with
> ```
> if ((Status == MainFileScope) ||
> (Status == CommandLineScopeIncludes && CommandIncludeFiles))
>   return Loc;
> return SourceLocation();
> ```
Sure, will do.
The reason I have a switch, because I had more cases during the implementation 
that I get rid of.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:100
+  bool CreateMacroFile = false;
+  bool PopScope = false;
+  SourceLocation LineLoc = getCorrectLocation(LastHashLoc);

aprantl wrote:
> Could you try splitting this function up into two functions?
> 
> MacroPPCallbacks::FileEntered()
> MacroPPCallbacks::FileExited()
> 
> and the common code factored out into a helper? The control flow here seems 
> unnecessarily complex with all the flags.
Will try restructure.
The way I implemented this is by having stages (parsing levels).
The control flow is to identify the current stage and decide how to continue 
from there.

I will see what I can do to make the code much clear.



Comment at: lib/CodeGen/MacroPPCallbacks.cpp:177
+  llvm::raw_string_ostream Value(ValueBuffer);
+  calculatMacroDefinition(*Id, *MD->getMacroInfo(), PP, Name, Value);
+  Gen->getCGDebugInfo()->CreateMacro(getCurrentScope(),

aprantl wrote:
> calculat*e*MacroDefinition
> (is there a better word than calculate?)
How about:
GenerateMacroDefinition
PrintMacroDefinition
ParseMacroDefinition

Do you think any of the above would be better choice?


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-03 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud updated this revision to Diff 87020.
aaboud marked 4 inline comments as done.
aaboud added a comment.

Addressed Adrian's comments.
Please, let me know if I missed any.

Also, I improved the code and added explanation about the file inclusion 
structure that is being handled in the macro callbacks.


https://reviews.llvm.org/D16135

Files:
  include/clang/CodeGen/ModuleBuilder.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/CodeGen/ModuleBuilder.cpp
  test/CodeGen/debug-info-global-constant.c

Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -92,6 +92,10 @@
   return M.get();
 }
 
+CGDebugInfo *getCGDebugInfo() {
+  return Builder->getModuleDebugInfo();
+}
+
 llvm::Module *ReleaseModule() {
   return M.release();
 }
@@ -299,6 +303,10 @@
   return static_cast(this)->ReleaseModule();
 }
 
+CGDebugInfo *CodeGenerator::getCGDebugInfo() {
+  return static_cast(this)->getCGDebugInfo();
+}
+
 const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
Index: lib/CodeGen/MacroPPCallbacks.h
===
--- lib/CodeGen/MacroPPCallbacks.h
+++ lib/CodeGen/MacroPPCallbacks.h
@@ -0,0 +1,118 @@
+//===--- MacroPPCallbacks.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines implementation for the macro preprocessors callbacks.
+//
+//===--===//
+
+#include "clang/Lex/PPCallbacks.h"
+
+namespace llvm {
+class DIMacroFile;
+class DIMacroNode;
+}
+namespace clang {
+class Preprocessor;
+class MacroInfo;
+class CodeGenerator;
+
+class MacroPPCallbacks : public PPCallbacks {
+  /// A pointer to code generator, where debug info generator can be found.
+  CodeGenerator *Gen;
+
+  /// Preprocessor.
+  Preprocessor &PP;
+
+  /// Location of recent included file, used for line number.
+  SourceLocation LastHashLoc;
+
+  /// Counts current number of command line included files, which was entered
+  /// and was not exited yet.
+  int CommandIncludeFiles = 0;
+
+  enum FileScopeStatus {
+NoScope = 0,  // Scope is not initialized yet.
+InitializedScope, // Main file scope is initialized but not set yet.
+BuiltinScope, //  and  file scopes.
+CommandLineScopeIncludes, // Included file, from  file, scope.
+MainFileScope // Main file scope.
+  };
+  FileScopeStatus Status;
+
+  /// Parent contains all entered files that were not exited yet according to
+  /// the inclusion order.
+  llvm::SmallVector Scopes;
+
+  /// Get current DIMacroFile scope.
+  /// \return current DIMacroFile scope or nullptr if there is no such scope.
+  llvm::DIMacroFile *getCurrentScope();
+
+  /// Get current line location or invalid location.
+  /// \param Loc current line location.
+  /// \return current line location \p `Loc`, or invalid location if it's in a
+  /// skipped file scope.
+  SourceLocation getCorrectLocation(SourceLocation Loc);
+
+  /// Use the passed preprocessor to write the macro name and value from the
+  /// given macro info and identifier info into the given \p `Name` and \p
+  /// `Value` output streams.
+  ///
+  /// \param II Identifier info, used to get the Macro name.
+  /// \param MI Macro info, used to get the Macro argumets and values.
+  /// \param PP Preprocessor.
+  /// \param [out] Name Place holder for returned macro name and arguments.
+  /// \param [out] Value Place holder for returned macro value.
+  static void writeMacroDefinition(const IdentifierInfo &II,
+   const MacroInfo &MI, Preprocessor &PP,
+   raw_ostream &Name, raw_ostream &Value);
+
+  /// Update current file scope status to next file scope.
+  void updateStatusToNextScope();
+
+  /// Handle the case when entering a file.
+  ///
+  /// \param Loc Indicates the new location.
+  /// \Return true if file scope status should be updated.
+  void FileEntered(SourceLocation Loc);
+
+  /// Handle the case when exiting a file.
+  ///
+  /// \Return true if file scope status should be updated.
+  void FileExited(SourceLocation Loc);
+
+public:
+  MacroPPCallbacks(CodeGenerator *Gen, Preprocessor &PP);
+
+  /// Callback invoked whenever a source file is entered or exited.
+  ///
+  /// \param Loc Indicates the new location.
+  /// \param PrevFID t

[PATCH] D16135: Macro Debug Info support in Clang

2017-02-07 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud updated this revision to Diff 87408.
aaboud marked 2 inline comments as done.
aaboud added a comment.

Addressed Adrian last comments.
Added a LIT tests that covers all the macro kinds:

1. built-in (define)
2. command-line (define, include, undef)
3. main source (define, include, undef)

Checked the above with and without PCH include.

Notice, that current implementation does not support debug info for macro 
definition and inclusion generated during the PCH file creation.
To support that, we need to extend the PCH format to preserve this information.
If you believe this feature is important, I will open a bugzilla ticket and we 
can handle it separately.


https://reviews.llvm.org/D16135

Files:
  include/clang/CodeGen/ModuleBuilder.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/CodeGen/ModuleBuilder.cpp
  test/CodeGen/debug-info-global-constant.c
  test/CodeGen/debug-info-macro.c
  test/CodeGen/include/debug-info-macro.h

Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -92,6 +92,10 @@
   return M.get();
 }
 
+CGDebugInfo *getCGDebugInfo() {
+  return Builder->getModuleDebugInfo();
+}
+
 llvm::Module *ReleaseModule() {
   return M.release();
 }
@@ -299,6 +303,10 @@
   return static_cast(this)->ReleaseModule();
 }
 
+CGDebugInfo *CodeGenerator::getCGDebugInfo() {
+  return static_cast(this)->getCGDebugInfo();
+}
+
 const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
Index: lib/CodeGen/MacroPPCallbacks.h
===
--- lib/CodeGen/MacroPPCallbacks.h
+++ lib/CodeGen/MacroPPCallbacks.h
@@ -0,0 +1,118 @@
+//===--- MacroPPCallbacks.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines implementation for the macro preprocessors callbacks.
+//
+//===--===//
+
+#include "clang/Lex/PPCallbacks.h"
+
+namespace llvm {
+class DIMacroFile;
+class DIMacroNode;
+}
+namespace clang {
+class Preprocessor;
+class MacroInfo;
+class CodeGenerator;
+
+class MacroPPCallbacks : public PPCallbacks {
+  /// A pointer to code generator, where debug info generator can be found.
+  CodeGenerator *Gen;
+
+  /// Preprocessor.
+  Preprocessor &PP;
+
+  /// Location of recent included file, used for line number.
+  SourceLocation LastHashLoc;
+
+  /// Counts current number of command line included files, which were entered
+  /// and were not exited yet.
+  int EnteredCommandLineIncludeFiles = 0;
+
+  enum FileScopeStatus {
+NoScope = 0,  // Scope is not initialized yet.
+InitializedScope, // Main file scope is initialized but not set yet.
+BuiltinScope, //  and  file scopes.
+CommandLineIncludeScope,  // Included file, from  file, scope.
+MainFileScope // Main file scope.
+  };
+  FileScopeStatus Status;
+
+  /// Parent contains all entered files that were not exited yet according to
+  /// the inclusion order.
+  llvm::SmallVector Scopes;
+
+  /// Get current DIMacroFile scope.
+  /// \return current DIMacroFile scope or nullptr if there is no such scope.
+  llvm::DIMacroFile *getCurrentScope();
+
+  /// Get current line location or invalid location.
+  /// \param Loc current line location.
+  /// \return current line location \p `Loc`, or invalid location if it's in a
+  /// skipped file scope.
+  SourceLocation getCorrectLocation(SourceLocation Loc);
+
+  /// Use the passed preprocessor to write the macro name and value from the
+  /// given macro info and identifier info into the given \p `Name` and \p
+  /// `Value` output streams.
+  ///
+  /// \param II Identifier info, used to get the Macro name.
+  /// \param MI Macro info, used to get the Macro argumets and values.
+  /// \param PP Preprocessor.
+  /// \param [out] Name Place holder for returned macro name and arguments.
+  /// \param [out] Value Place holder for returned macro value.
+  static void writeMacroDefinition(const IdentifierInfo &II,
+   const MacroInfo &MI, Preprocessor &PP,
+   raw_ostream &Name, raw_ostream &Value);
+
+  /// Update current file scope status to next file scope.
+  void updateStatusToNextScope();
+
+  /// Handle the case when entering a file.
+  ///
+  /// \param Loc Indicates the new location.
+  /// \Return tr

[PATCH] D16135: Macro Debug Info support in Clang

2017-02-07 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a comment.

In https://reviews.llvm.org/D16135#669416, @aprantl wrote:

> In https://reviews.llvm.org/D16135#669045, @aaboud wrote:
>
> > Addressed Adrian last comments.
> >  Added a LIT tests that covers all the macro kinds:
> >
> > 1. built-in (define)
> > 2. command-line (define, include, undef)
> > 3. main source (define, include, undef) Checked the above with and without 
> > PCH include.
> >
> >   Notice, that current implementation does not support debug info for macro 
> > definition and inclusion generated during the PCH file creation. To support 
> > that, we need to extend the PCH format to preserve this information. If you 
> > believe this feature is important, I will open a bugzilla ticket and we can 
> > handle it separately.
>
>
> That would be a good idea and important to fix. I don't think we want the the 
> generated code (or the debug info for that matter) to change just because the 
> user decides to switch to PCH. Ideally turning on PCH should be transparent.
>
> I have one final question: What's the impact of this change on, e.g., 
> building clang?
>
> - How much does the build directory grow?
> - Is there any noticeable compile time regression?


I will run self-build and come back with answers for these questions.
I am just wondering, if I build in debug mode, will it use the flag 
"-fstandalone-debug"?
This flag is set by default only for DarwinClang and FreeBSD, is there a way to 
assure it will be used with self-build?
Notice that without this flag, there will be no debug info macro generated.


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-08 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a comment.

> How much does the build directory grow?
>  Is there any noticeable compile time regression?

I build clang in release mode using GCC, then used that build to build clang in 
debug mode with "-fstandalone-debug" flag, one time with my changes and another 
time without my changes.

Without my changes
--

Clang executable Size: 1,565MB
Build time: 17m57.504s

Withmy changes
--

Clang executable Size: 2,043MB
Build time:  17m58.008s

Do, build time is the same, but binary size was increased about 30%.
However, remember that we are emitting macro debug info in dwarf4 format, once 
we support emitting it in dwarf5 format the size should be reduced 
significantly.

> I'm not sure it makes sense to motivate this feature with 
> "-fstandalone-debug" flag.

Is "-fmacro-debug" flag sounds good?
Should we extend DebugInfoKind enumeration to support the debug info macro? Or 
we should add a new option to CodeGenOptions?


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-09 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud updated this revision to Diff 87796.
aaboud added a comment.

Added flag to control macro debug info generation:

1. -fdebug-macro (-fno-debug-macro) for Clang driver
2. -debug-info-macro for Clang compiler (-cc1)

Also, made sure FE will discard this flag when debug info is not required, i.e. 
with -g0.
Should we discard the macro debug info when "-gline-tables-only" is used? or it 
is up to the user not to use "-fdebug-macro" in this case?

I also extended the test to check all combinations of using -debug-info-macro 
flag with -debug-info-kind flag.


https://reviews.llvm.org/D16135

Files:
  docs/UsersManual.rst
  include/clang/CodeGen/ModuleBuilder.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/CodeGen/ModuleBuilder.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/debug-info-macro.c
  test/CodeGen/include/debug-info-macro.h

Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -92,6 +92,10 @@
   return M.get();
 }
 
+CGDebugInfo *getCGDebugInfo() {
+  return Builder->getModuleDebugInfo();
+}
+
 llvm::Module *ReleaseModule() {
   return M.release();
 }
@@ -299,6 +303,10 @@
   return static_cast(this)->ReleaseModule();
 }
 
+CGDebugInfo *CodeGenerator::getCGDebugInfo() {
+  return static_cast(this)->getCGDebugInfo();
+}
+
 const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
Index: lib/CodeGen/MacroPPCallbacks.h
===
--- lib/CodeGen/MacroPPCallbacks.h
+++ lib/CodeGen/MacroPPCallbacks.h
@@ -0,0 +1,118 @@
+//===--- MacroPPCallbacks.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines implementation for the macro preprocessors callbacks.
+//
+//===--===//
+
+#include "clang/Lex/PPCallbacks.h"
+
+namespace llvm {
+class DIMacroFile;
+class DIMacroNode;
+}
+namespace clang {
+class Preprocessor;
+class MacroInfo;
+class CodeGenerator;
+
+class MacroPPCallbacks : public PPCallbacks {
+  /// A pointer to code generator, where debug info generator can be found.
+  CodeGenerator *Gen;
+
+  /// Preprocessor.
+  Preprocessor &PP;
+
+  /// Location of recent included file, used for line number.
+  SourceLocation LastHashLoc;
+
+  /// Counts current number of command line included files, which were entered
+  /// and were not exited yet.
+  int EnteredCommandLineIncludeFiles = 0;
+
+  enum FileScopeStatus {
+NoScope = 0,  // Scope is not initialized yet.
+InitializedScope, // Main file scope is initialized but not set yet.
+BuiltinScope, //  and  file scopes.
+CommandLineIncludeScope,  // Included file, from  file, scope.
+MainFileScope // Main file scope.
+  };
+  FileScopeStatus Status;
+
+  /// Parent contains all entered files that were not exited yet according to
+  /// the inclusion order.
+  llvm::SmallVector Scopes;
+
+  /// Get current DIMacroFile scope.
+  /// \return current DIMacroFile scope or nullptr if there is no such scope.
+  llvm::DIMacroFile *getCurrentScope();
+
+  /// Get current line location or invalid location.
+  /// \param Loc current line location.
+  /// \return current line location \p `Loc`, or invalid location if it's in a
+  /// skipped file scope.
+  SourceLocation getCorrectLocation(SourceLocation Loc);
+
+  /// Use the passed preprocessor to write the macro name and value from the
+  /// given macro info and identifier info into the given \p `Name` and \p
+  /// `Value` output streams.
+  ///
+  /// \param II Identifier info, used to get the Macro name.
+  /// \param MI Macro info, used to get the Macro argumets and values.
+  /// \param PP Preprocessor.
+  /// \param [out] Name Place holder for returned macro name and arguments.
+  /// \param [out] Value Place holder for returned macro value.
+  static void writeMacroDefinition(const IdentifierInfo &II,
+   const MacroInfo &MI, Preprocessor &PP,
+   raw_ostream &Name, raw_ostream &Value);
+
+  /// Update current file scope status to next file scope.
+  void updateStatusToNextScope();
+
+  /// Handle the case when entering a file.
+  ///
+  /// \param 

[PATCH] D16135: Macro Debug Info support in Clang

2017-02-09 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud added a comment.

> How are you measuring the build time? Total time for, say "ninja clang" with 
> full parallelism? That'd be hard to measure the actual impact (since it could 
> be the link time or other things are dominating, etc). If you have a reliable 
> way to time (I'm assuming Intel has lots of tools for measuring compiler 
> performance) the compilation, get a sense of the variance, etc (& link time, 
> to get a sense of how much the larger inputs affect linker performance) would 
> be useful.

I did a manual measurement, but I believe it is representative.
I used "time" tool to measure the whole time of the build (compile + link).

- time make -j8

Also, notice that I limited the targets to X86 only, so it was not a full build 
of LLVM.

- -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_TARGETS_TO_BUILD="X86" 
-DCMAKE_CXX_FLAGS="-fstandalone-debug" -DCMAKE_C_FLAGS="-fstandalone-debug"

However, as I already said, it should answer the time change and size question 
fairly enough.

> Does GCC have a command line option for this that we could mirror?

GCC emits macro debug info when when build with -g3.


https://reviews.llvm.org/D16135



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D16135: Macro Debug Info support in Clang

2017-02-09 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud updated this revision to Diff 87819.
aaboud marked 2 inline comments as done.
aaboud added a comment.

Added test cases for driver debug info macro flags in 
test/Driver/debug-options.c
Applied some changes to the documentation suggested by Ardian.


https://reviews.llvm.org/D16135

Files:
  docs/UsersManual.rst
  include/clang/CodeGen/ModuleBuilder.h
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenAction.cpp
  lib/CodeGen/MacroPPCallbacks.cpp
  lib/CodeGen/MacroPPCallbacks.h
  lib/CodeGen/ModuleBuilder.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/debug-info-macro.c
  test/CodeGen/include/debug-info-macro.h
  test/Driver/debug-options.c

Index: lib/CodeGen/ModuleBuilder.cpp
===
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -92,6 +92,10 @@
   return M.get();
 }
 
+CGDebugInfo *getCGDebugInfo() {
+  return Builder->getModuleDebugInfo();
+}
+
 llvm::Module *ReleaseModule() {
   return M.release();
 }
@@ -299,6 +303,10 @@
   return static_cast(this)->ReleaseModule();
 }
 
+CGDebugInfo *CodeGenerator::getCGDebugInfo() {
+  return static_cast(this)->getCGDebugInfo();
+}
+
 const Decl *CodeGenerator::GetDeclForMangledName(llvm::StringRef name) {
   return static_cast(this)->GetDeclForMangledName(name);
 }
Index: lib/CodeGen/MacroPPCallbacks.h
===
--- lib/CodeGen/MacroPPCallbacks.h
+++ lib/CodeGen/MacroPPCallbacks.h
@@ -0,0 +1,118 @@
+//===--- MacroPPCallbacks.h -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines implementation for the macro preprocessors callbacks.
+//
+//===--===//
+
+#include "clang/Lex/PPCallbacks.h"
+
+namespace llvm {
+class DIMacroFile;
+class DIMacroNode;
+}
+namespace clang {
+class Preprocessor;
+class MacroInfo;
+class CodeGenerator;
+
+class MacroPPCallbacks : public PPCallbacks {
+  /// A pointer to code generator, where debug info generator can be found.
+  CodeGenerator *Gen;
+
+  /// Preprocessor.
+  Preprocessor &PP;
+
+  /// Location of recent included file, used for line number.
+  SourceLocation LastHashLoc;
+
+  /// Counts current number of command line included files, which were entered
+  /// and were not exited yet.
+  int EnteredCommandLineIncludeFiles = 0;
+
+  enum FileScopeStatus {
+NoScope = 0,  // Scope is not initialized yet.
+InitializedScope, // Main file scope is initialized but not set yet.
+BuiltinScope, //  and  file scopes.
+CommandLineIncludeScope,  // Included file, from  file, scope.
+MainFileScope // Main file scope.
+  };
+  FileScopeStatus Status;
+
+  /// Parent contains all entered files that were not exited yet according to
+  /// the inclusion order.
+  llvm::SmallVector Scopes;
+
+  /// Get current DIMacroFile scope.
+  /// \return current DIMacroFile scope or nullptr if there is no such scope.
+  llvm::DIMacroFile *getCurrentScope();
+
+  /// Get current line location or invalid location.
+  /// \param Loc current line location.
+  /// \return current line location \p `Loc`, or invalid location if it's in a
+  /// skipped file scope.
+  SourceLocation getCorrectLocation(SourceLocation Loc);
+
+  /// Use the passed preprocessor to write the macro name and value from the
+  /// given macro info and identifier info into the given \p `Name` and \p
+  /// `Value` output streams.
+  ///
+  /// \param II Identifier info, used to get the Macro name.
+  /// \param MI Macro info, used to get the Macro argumets and values.
+  /// \param PP Preprocessor.
+  /// \param [out] Name Place holder for returned macro name and arguments.
+  /// \param [out] Value Place holder for returned macro value.
+  static void writeMacroDefinition(const IdentifierInfo &II,
+   const MacroInfo &MI, Preprocessor &PP,
+   raw_ostream &Name, raw_ostream &Value);
+
+  /// Update current file scope status to next file scope.
+  void updateStatusToNextScope();
+
+  /// Handle the case when entering a file.
+  ///
+  /// \param Loc Indicates the new location.
+  /// \Return true if file scope status should be updated.
+  void FileEntered(SourceLocation Loc);
+
+  /// Handle the case when exiting a file.
+  ///
+  /// \Return true if file scope status should be updated.
+  void FileExited(SourceLocation 

[PATCH] D16135: Macro Debug Info support in Clang

2017-02-09 Thread Amjad Aboud via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL294637: [DebugInfo] Added support to Clang FE for generating 
debug info for… (authored by aaboud).

Changed prior to commit:
  https://reviews.llvm.org/D16135?vs=87819&id=87881#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D16135

Files:
  cfe/trunk/docs/UsersManual.rst
  cfe/trunk/include/clang/CodeGen/ModuleBuilder.h
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/lib/CodeGen/CMakeLists.txt
  cfe/trunk/lib/CodeGen/CodeGenAction.cpp
  cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
  cfe/trunk/lib/CodeGen/MacroPPCallbacks.h
  cfe/trunk/lib/CodeGen/ModuleBuilder.cpp
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/debug-info-macro.c
  cfe/trunk/test/CodeGen/include/debug-info-macro.h
  cfe/trunk/test/Driver/debug-options.c

Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h
@@ -413,6 +413,16 @@
 
   void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
 
+  /// Create debug info for a macro defined by a #define directive or a macro
+  /// undefined by a #undef directive.
+  llvm::DIMacro *CreateMacro(llvm::DIMacroFile *Parent, unsigned MType,
+ SourceLocation LineLoc, StringRef Name,
+ StringRef Value);
+
+  /// Create debug info for a file referenced by an #include directive.
+  llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *Parent,
+ SourceLocation LineLoc,
+ SourceLocation FileLoc);
 private:
   /// Emit call to llvm.dbg.declare for a variable declaration.
   void EmitDeclare(const VarDecl *decl, llvm::Value *AI,
Index: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp
@@ -10,6 +10,7 @@
 #include "clang/CodeGen/CodeGenAction.h"
 #include "CodeGenModule.h"
 #include "CoverageMappingGen.h"
+#include "MacroPPCallbacks.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
@@ -97,6 +98,8 @@
   return std::unique_ptr(Gen->ReleaseModule());
 }
 
+CodeGenerator *getCodeGenerator() { return Gen.get(); }
+
 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override {
   Gen->HandleCXXStaticMemberVarInstantiation(VD);
 }
@@ -830,6 +833,17 @@
   CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
   std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
   BEConsumer = Result.get();
+
+  // Enable generating macro debug info only when debug info is not disabled and
+  // also macro debug info is enabled.
+  if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo &&
+  CI.getCodeGenOpts().MacroDebugInfo) {
+std::unique_ptr Callbacks =
+llvm::make_unique(BEConsumer->getCodeGenerator(),
+CI.getPreprocessor());
+CI.getPreprocessor().addPPCallbacks(std::move(Callbacks));
+  }
+
   return std::move(Result);
 }
 
Index: cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
===
--- cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
+++ cfe/trunk/lib/CodeGen/MacroPPCallbacks.cpp
@@ -0,0 +1,211 @@
+//===--- MacroPPCallbacks.cpp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file contains implementation for the macro preprocessors callbacks.
+//
+//===--===//
+
+#include "MacroPPCallbacks.h"
+#include "CGDebugInfo.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Parse/Parser.h"
+
+using namespace clang;
+
+void MacroPPCallbacks::writeMacroDefinition(const IdentifierInfo &II,
+const MacroInfo &MI,
+Preprocessor &PP, raw_ostream &Name,
+raw_ostream &Value) {
+  Name << II.getName();
+
+  if (MI.isFunctionLike()) {
+Name << '(';
+if (!MI.arg_empty()) {
+  MacroInfo::arg_iterator AI = MI.arg_begin(), E = MI.arg_end();
+  for (; AI + 1 != E; ++AI) {
+Name << (*AI)->getName();
+Name << ',';
+  }
+
+  

[PATCH] D27641: DebugInfo: Added support for Checksum debug info feature (Clang part)

2016-12-09 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud created this revision.
aaboud added reviewers: rnk, probinson, rsmith.
aaboud added a subscriber: cfe-commits.

Resolve Bug 30978 .

This patch contains changes in Clang to support Checksum debug info feature.


https://reviews.llvm.org/D27641

Files:
  include/clang/Basic/SourceManager.h
  lib/Basic/SourceManager.cpp
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGen/debug-info-atomic.c
  test/CodeGen/debug-info-file-checksum.c
  test/CodeGen/debug-info-file-checksum.c.source
  test/CodeGen/debug-prefix-map.c
  test/PCH/debug-info-pch-path.c

Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -324,15 +324,17 @@
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()));
+   remapDIPath(TheCU->getDirectory()),
+   TheCU->getChecksum());
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(Loc);
 
   if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
 // If the location is not valid then use main input file.
 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()));
+   remapDIPath(TheCU->getDirectory()),
+   TheCU->getChecksum());
 
   // Cache the results.
   const char *fname = PLoc.getFilename();
@@ -344,16 +346,23 @@
   return cast(V);
   }
 
+  std::string Checksum;
+  SM.getChecksumMD5(SM.getFileID(Loc), Checksum);
+
+  llvm::DIChecksum *C =
+  DBuilder.createChecksum(llvm::DIChecksum::MD5, Checksum);
+
   llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
-remapDIPath(getCurrentDirname()));
+remapDIPath(getCurrentDirname()), C);
 
   DIFileCache[fname].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
   return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
- remapDIPath(TheCU->getDirectory()));
+ remapDIPath(TheCU->getDirectory()),
+ TheCU->getChecksum());
 }
 
 std::string CGDebugInfo::remapDIPath(StringRef Path) const {
@@ -396,6 +405,7 @@
 }
 
 void CGDebugInfo::CreateCompileUnit() {
+  std::string Checksum;
 
   // Should we be asking the SourceManager for the main file name, instead of
   // accepting it as an argument? This just causes the main file name to
@@ -422,6 +432,7 @@
   llvm::sys::path::append(MainFileDirSS, MainFileName);
   MainFileName = MainFileDirSS.str();
 }
+SM.getChecksumMD5(SM.getMainFileID(), Checksum);
   }
 
   llvm::dwarf::SourceLanguage LangTag;
@@ -467,7 +478,8 @@
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
   LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
-  Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
+  llvm::DIChecksum::MD5, Checksum, Producer, LO.Optimize,
+  CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
   CGM.getCodeGenOpts().SplitDwarfInlining);
 }
@@ -1978,9 +1990,10 @@
 uint64_t Signature = Mod.getSignature() ? Mod.getSignature() : ~1ULL;
 llvm::DIBuilder DIB(CGM.getModule());
 DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.getModuleName(),
-  Mod.getPath(), TheCU->getProducer(), true,
-  StringRef(), 0, Mod.getASTFile(),
-  llvm::DICompileUnit::FullDebug, Signature);
+  Mod.getPath(), llvm::DIChecksum::None, "",
+  TheCU->getProducer(), true, StringRef(), 0,
+  Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
+  Signature);
 DIB.finalize();
   }
   llvm::DIModule *Parent =
Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -20,6 +20,8 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/Capacity.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/MD5.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
@@ -1442,6 +1444,24 @@
   return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
 }
 
+void SourceManager::getChecksumMD5(FileID FID, std::string &Checksum) const {
+  bool Invalid;
+
+  llvm::MemoryBuffer *MemBuffer = getBuffer(FID, &Invalid);
+  if

[PATCH] D27763: Debug Info: Modified DIBuilder::createCompileUnit() to take DIFile instead of FileName and Directory. (Clang part)

2016-12-14 Thread Amjad Aboud via Phabricator via cfe-commits
aaboud created this revision.
aaboud added a reviewer: rnk.
aaboud added a subscriber: cfe-commits.

Changed DIBuilder::createCompileUnit() to take DIFile instead of FileName and 
Directory.
This way it will be easier to expand DIFile (e.g., to contain checksum) without 
the need to modify the createCompileUnit() API.


https://reviews.llvm.org/D27763

Files:
  lib/CodeGen/CGDebugInfo.cpp


Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -466,7 +466,8 @@
   // Create new compile unit.
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
-  LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
+  LangTag, DBuilder.createFile(remapDIPath(MainFileName),
+remapDIPath(getCurrentDirname())),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
   CGM.getCodeGenOpts().SplitDwarfInlining);
@@ -1977,10 +1978,11 @@
 // but LLVM detects skeleton CUs by looking for a non-zero DWO id.
 uint64_t Signature = Mod.getSignature() ? Mod.getSignature() : ~1ULL;
 llvm::DIBuilder DIB(CGM.getModule());
-DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.getModuleName(),
-  Mod.getPath(), TheCU->getProducer(), true,
-  StringRef(), 0, Mod.getASTFile(),
-  llvm::DICompileUnit::FullDebug, Signature);
+DIB.createCompileUnit(TheCU->getSourceLanguage(),
+  DIB.createFile(Mod.getModuleName(), Mod.getPath()),
+  TheCU->getProducer(), true, StringRef(), 0,
+  Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
+  Signature);
 DIB.finalize();
   }
   llvm::DIModule *Parent =


Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -466,7 +466,8 @@
   // Create new compile unit.
   // FIXME - Eliminate TheCU.
   TheCU = DBuilder.createCompileUnit(
-  LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
+  LangTag, DBuilder.createFile(remapDIPath(MainFileName),
+remapDIPath(getCurrentDirname())),
   Producer, LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers,
   CGM.getCodeGenOpts().SplitDwarfFile, EmissionKind, 0 /* DWOid */,
   CGM.getCodeGenOpts().SplitDwarfInlining);
@@ -1977,10 +1978,11 @@
 // but LLVM detects skeleton CUs by looking for a non-zero DWO id.
 uint64_t Signature = Mod.getSignature() ? Mod.getSignature() : ~1ULL;
 llvm::DIBuilder DIB(CGM.getModule());
-DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.getModuleName(),
-  Mod.getPath(), TheCU->getProducer(), true,
-  StringRef(), 0, Mod.getASTFile(),
-  llvm::DICompileUnit::FullDebug, Signature);
+DIB.createCompileUnit(TheCU->getSourceLanguage(),
+  DIB.createFile(Mod.getModuleName(), Mod.getPath()),
+  TheCU->getProducer(), true, StringRef(), 0,
+  Mod.getASTFile(), llvm::DICompileUnit::FullDebug,
+  Signature);
 DIB.finalize();
   }
   llvm::DIModule *Parent =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits