[llvm] r203831 - MCDwarf: Simplify MCDwarfFile to just use std::string instead of cunning use of MCContext's allocator.

David Blaikie dblaikie at gmail.com
Thu Mar 13 11:55:04 PDT 2014


Author: dblaikie
Date: Thu Mar 13 13:55:04 2014
New Revision: 203831

URL: http://llvm.org/viewvc/llvm-project?rev=203831&view=rev
Log:
MCDwarf: Simplify MCDwarfFile to just use std::string instead of cunning use of MCContext's allocator.

There aren't /that/ many files, and we are already using various maps
and other standard containers that don't use MCContext's allocator to
store these values, so this doesn't seem to be critical and simplifies
the design (I'll be moving construction out of MCContext shortly so it'd
be annoying to have to pass the allocator around to allocate these
things... and we'll have non-MCContext users (debug_line.dwo) shortly)

Modified:
    llvm/trunk/include/llvm/MC/MCContext.h
    llvm/trunk/include/llvm/MC/MCDwarf.h
    llvm/trunk/lib/MC/MCContext.cpp
    llvm/trunk/lib/MC/MCDwarf.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=203831&r1=203830&r2=203831&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Thu Mar 13 13:55:04 2014
@@ -322,7 +322,7 @@ namespace llvm {
       return I->second;
     }
 
-    const SmallVectorImpl<MCDwarfFile *> &getMCDwarfFiles(unsigned CUID = 0) {
+    const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles(unsigned CUID = 0) {
       return getMCDwarfFileTable(CUID).getMCDwarfFiles();
     }
     const SmallVectorImpl<StringRef> &getMCDwarfDirs(unsigned CUID = 0) {

Modified: llvm/trunk/include/llvm/MC/MCDwarf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf.h?rev=203831&r1=203830&r2=203831&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Thu Mar 13 13:55:04 2014
@@ -40,7 +40,7 @@ class SMLoc;
 struct MCDwarfFile {
   // Name - the base name of the file without its directory path.
   // The StringRef references memory allocated in the MCContext.
-  StringRef Name;
+  std::string Name;
 
   // DirIndex - the index into the list of directory names for this file name.
   unsigned DirIndex;
@@ -176,7 +176,7 @@ public:
 class MCDwarfFileTable {
   MCSymbol *Label;
   SmallVector<StringRef, 3> MCDwarfDirs;
-  SmallVector<MCDwarfFile *, 3> MCDwarfFiles;
+  SmallVector<MCDwarfFile, 3> MCDwarfFiles;
   MCLineSection MCLineSections;
 
 public:
@@ -197,11 +197,11 @@ public:
     return MCDwarfDirs;
   }
 
-  const SmallVectorImpl<MCDwarfFile *> &getMCDwarfFiles() const {
+  const SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles() const {
     return MCDwarfFiles;
   }
 
-  SmallVectorImpl<MCDwarfFile *> &getMCDwarfFiles() {
+  SmallVectorImpl<MCDwarfFile> &getMCDwarfFiles() {
     return MCDwarfFiles;
   }
 

Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=203831&r1=203830&r2=203831&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu Mar 13 13:55:04 2014
@@ -338,20 +338,19 @@ const MCSectionCOFF *MCContext::getCOFFS
 unsigned MCContext::GetDwarfFile(StringRef Directory, StringRef FileName,
                                  unsigned FileNumber, unsigned CUID) {
   MCDwarfFileTable &Table = MCDwarfFileTablesCUMap[CUID];
-  SmallVectorImpl<MCDwarfFile *>& MCDwarfFiles = Table.getMCDwarfFiles();
+  SmallVectorImpl<MCDwarfFile>& MCDwarfFiles = Table.getMCDwarfFiles();
   SmallVectorImpl<StringRef>& MCDwarfDirs = Table.getMCDwarfDirs();
   // Make space for this FileNumber in the MCDwarfFiles vector if needed.
   if (FileNumber >= MCDwarfFiles.size()) {
     MCDwarfFiles.resize(FileNumber + 1);
-  } else {
-    MCDwarfFile *&ExistingFile = MCDwarfFiles[FileNumber];
-    if (ExistingFile)
-      // It is an error to use see the same number more than once.
-      return 0;
   }
 
   // Get the new MCDwarfFile slot for this FileNumber.
-  MCDwarfFile *&File = MCDwarfFiles[FileNumber];
+  MCDwarfFile &File = MCDwarfFiles[FileNumber];
+
+  // It is an error to use see the same number more than once.
+  if (!File.Name.empty())
+    return 0;
 
   if (Directory.empty()) {
     // Separate the directory part from the basename of the FileName.
@@ -387,13 +386,8 @@ unsigned MCContext::GetDwarfFile(StringR
     DirIndex++;
   }
 
-  // Now make the MCDwarfFile entry and place it in the slot in the MCDwarfFiles
-  // vector.
-  char *Buf = static_cast<char *>(Allocate(FileName.size()));
-  memcpy(Buf, FileName.data(), FileName.size());
-  File = new (*this) MCDwarfFile;
-  File->Name = StringRef(Buf, FileName.size());
-  File->DirIndex = DirIndex;
+  File.Name = FileName;
+  File.DirIndex = DirIndex;
 
   // return the allocated FileNumber.
   return FileNumber;
@@ -402,11 +396,11 @@ unsigned MCContext::GetDwarfFile(StringR
 /// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
 /// currently is assigned and false otherwise.
 bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
-  const SmallVectorImpl<MCDwarfFile *>& MCDwarfFiles = getMCDwarfFiles(CUID);
+  const SmallVectorImpl<MCDwarfFile>& MCDwarfFiles = getMCDwarfFiles(CUID);
   if(FileNumber == 0 || FileNumber >= MCDwarfFiles.size())
     return false;
 
-  return MCDwarfFiles[FileNumber] != 0;
+  return !MCDwarfFiles[FileNumber].Name.empty();
 }
 
 void MCContext::FatalError(SMLoc Loc, const Twine &Msg) {

Modified: llvm/trunk/lib/MC/MCDwarf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev=203831&r1=203830&r2=203831&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)
+++ llvm/trunk/lib/MC/MCDwarf.cpp Thu Mar 13 13:55:04 2014
@@ -289,10 +289,10 @@ const MCSymbol *MCDwarfFileTable::EmitCU
 
   // Second the file table.
   for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
-    MCOS->EmitBytes(MCDwarfFiles[i]->Name); // FileName
+    MCOS->EmitBytes(MCDwarfFiles[i].Name); // FileName
     MCOS->EmitBytes(StringRef("\0", 1)); // the null term. of the string
     // the Directory num
-    MCOS->EmitULEB128IntValue(MCDwarfFiles[i]->DirIndex);
+    MCOS->EmitULEB128IntValue(MCDwarfFiles[i].DirIndex);
     MCOS->EmitIntValue(0, 1); // last modification timestamp (always 0)
     MCOS->EmitIntValue(0, 1); // filesize (always 0)
   }
@@ -602,9 +602,9 @@ static void EmitGenDwarfInfo(MCStreamer
     MCOS->EmitBytes(MCDwarfDirs[0]);
     MCOS->EmitBytes("/");
   }
-  const SmallVectorImpl<MCDwarfFile *> &MCDwarfFiles =
+  const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =
     MCOS->getContext().getMCDwarfFiles();
-  MCOS->EmitBytes(MCDwarfFiles[1]->Name);
+  MCOS->EmitBytes(MCDwarfFiles[1].Name);
   MCOS->EmitIntValue(0, 1); // NULL byte to terminate the string.
 
   // AT_comp_dir, the working directory the assembly was done in.

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=203831&r1=203830&r2=203831&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Thu Mar 13 13:55:04 2014
@@ -662,10 +662,10 @@ bool AsmParser::Run(bool NoInitialTextSe
     return TokError("unmatched .ifs or .elses");
 
   // Check to see there are no empty DwarfFile slots.
-  const SmallVectorImpl<MCDwarfFile *> &MCDwarfFiles =
+  const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =
       getContext().getMCDwarfFiles();
   for (unsigned i = 1; i < MCDwarfFiles.size(); i++) {
-    if (!MCDwarfFiles[i])
+    if (MCDwarfFiles[i].Name.empty())
       TokError("unassigned file number: " + Twine(i) + " for .file directives");
   }
 
@@ -1589,10 +1589,10 @@ bool AsmParser::parseStatement(ParseStat
     // If we previously parsed a cpp hash file line comment then make sure the
     // current Dwarf File is for the CppHashFilename if not then emit the
     // Dwarf File table for it and adjust the line number for the .loc.
-    const SmallVectorImpl<MCDwarfFile *> &MCDwarfFiles =
+    const SmallVectorImpl<MCDwarfFile> &MCDwarfFiles =
         getContext().getMCDwarfFiles();
     if (CppHashFilename.size() != 0) {
-      if (MCDwarfFiles[getContext().getGenDwarfFileNumber()]->Name !=
+      if (MCDwarfFiles[getContext().getGenDwarfFileNumber()].Name !=
           CppHashFilename)
         getStreamer().EmitDwarfFileDirective(
             getContext().nextGenDwarfFileNumber(), StringRef(),





More information about the llvm-commits mailing list