[llvm-commits] new .file directive

Nick Lewycky nlewycky at google.com
Mon Oct 17 14:33:33 PDT 2011


On 17 October 2011 14:00, Devang Patel <dpatel at apple.com> wrote:

>
> On Oct 14, 2011, at 7:10 PM, Nick Lewycky wrote:
>
>
>> Please review!
>>
>
>
> Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
> ===================================================================
> --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp (revision 142035)
> +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp (working copy)
> @@ -442,23 +442,21 @@
>    if (FileName.empty())
>      return GetOrCreateSourceID("<stdin>", StringRef());
>
> -  // MCStream expects full path name as filename.
> -  if (!DirName.empty() && !sys::path::is_absolute(FileName)) {
> -    SmallString<128> FullPathName = DirName;
> -    sys::path::append(FullPathName, FileName);
> -    // Here FullPathName will be copied into StringMap by
> GetOrCreateSourceID.
> -    return GetOrCreateSourceID(StringRef(FullPathName), StringRef());
> -  }
> +  unsigned SrcId = SourceIdMap.size()+1;
> +  std::pair<std::string, std::string> SourceName =
> +      std::make_pair(FileName, DirName);
> +  std::pair<std::pair<std::string, std::string>, unsigned> Entry =
> +      make_pair(SourceName, SrcId);
>
> -  StringMapEntry<unsigned> &Entry =
> SourceIdMap.GetOrCreateValue(FileName);
> -  if (Entry.getValue())
> -    return Entry.getValue();
> +  std::map<std::pair<std::string, std::string>, unsigned>::iterator I;
> +  bool NewlyInserted;
> +  tie(I, NewlyInserted) = SourceIdMap.insert(Entry);
> +  if (!NewlyInserted)
> +    return I->second;
>
> -  unsigned SrcId = SourceIdMap.size();
> -  Entry.setValue(SrcId);
> -
>    // Print out a .file directive to specify files for .loc directives.
> -  Asm->OutStreamer.EmitDwarfFileDirective(SrcId, Entry.getKey());
> +  Asm->OutStreamer.EmitDwarfFileDirective(SrcId, Entry.first.second,
> +                                          Entry.first.first);
>
>    return SrcId;
>  }
> Index: lib/CodeGen/AsmPrinter/DwarfDebug.h
> ===================================================================
> --- lib/CodeGen/AsmPrinter/DwarfDebug.h (revision 142035)
> +++ lib/CodeGen/AsmPrinter/DwarfDebug.h (working copy)
> @@ -26,6 +26,7 @@
>  #include "llvm/ADT/UniqueVector.h"
>  #include "llvm/Support/Allocator.h"
>  #include "llvm/Support/DebugLoc.h"
> +#include <map>
>
>  namespace llvm {
>
> @@ -207,9 +208,9 @@
>    ///
>    std::vector<DIEAbbrev *> Abbreviations;
>
> -  /// SourceIdMap - Source id map, i.e. pair of directory id and source
> file
> -  /// id mapped to a unique id.
> -  StringMap<unsigned> SourceIdMap;
> +  /// SourceIdMap - Source id map, i.e. pair of source filename and
> directory
> +  /// mapped to a unique id.
> +  std::map<std::pair<std::string, std::string>, unsigned> SourceIdMap;
>
>    /// StringPool - A String->Symbol mapping of strings used by indirect
>    /// references.
>
>
> Why do you need this change in DwarfDebug ? Why can't MCAsmStreamer split
> file and directly ?
>

It can, but that's missing the point :) Clang emits separate file and
directory, the .bc has the separate file and directory, we currently join
them again here so that the asm stream can split them again. I'm removing
that extra join+split pair.

Going forward, the split could produce different results. I want to encode
"clang -isystem foo/bar" + "#include <x/y.h>" into
  directory entry: foo/bar
  file entry: x/y.h
and there's no way that the resplitting could know that as opposed to "foo"
+ "bar/x/y.h" and "foo/bar/x" + "y.h".

Also, this more closely represents what really goes into the debug info,
there's a dir entry with the dirname and a file entry which has the filename
and the dir entry number.

Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20111017/94993a68/attachment.html>


More information about the llvm-commits mailing list