[llvm-commits] [llvm] r140151 - /llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp

Nick Lewycky nicholas at mxc.ca
Tue Sep 20 11:10:04 PDT 2011


Devang Patel wrote:
> Author: dpatel
> Date: Tue Sep 20 12:43:14 2011
> New Revision: 140151
>
> URL: http://llvm.org/viewvc/llvm-project?rev=140151&view=rev
> Log:
> Eliminate unnecessary copy of FileName from GCOVLines.
> GCOVLines is always accessed through a StringMap where the key is FileName.
>
> Modified:
>      llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
>
> Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=140151&r1=140150&r2=140151&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)
> +++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Tue Sep 20 12:43:14 2011
> @@ -167,18 +167,17 @@
>       }
>
>       uint32_t length() {
> -      return lengthOfGCOVString(Filename) + 2 + Lines.size();
> +      // FIXME: ??? What is the significance of 2 here ?
> +      return 2 + Lines.size();

This no longer computes the length() though. How about changing 
std::string Filename into a StringRef if you're concerned about copies? 
Alternatively, you could name it something like "getNumLines()" and 
hoist out the +2 as well.

Fundamentally, GCOVLines isn't just a list of lines, it's a list of 
lines attached to a particular filename, so I wanted it to contain all 
its own data. The +2 is 1 for string length plus 1 for the '0' line id# 
which means "the filename is" in GCOV format.

Nick

>       }
>
>      private:
>       friend class GCOVBlock;
>
> -    GCOVLines(std::string Filename, raw_ostream *os)
> -        : Filename(Filename) {
> +    GCOVLines(raw_ostream *os) {
>         this->os = os;
>       }
>
> -    std::string Filename;
>       SmallVector<uint32_t, 32>  Lines;
>     };
>
> @@ -190,7 +189,7 @@
>       GCOVLines&getFile(std::string Filename) {
>         GCOVLines *&Lines = LinesByFile[Filename];
>         if (!Lines) {
> -        Lines = new GCOVLines(Filename, os);
> +        Lines = new GCOVLines(os);
>         }
>         return *Lines;
>       }
> @@ -203,7 +202,7 @@
>         uint32_t Len = 3;
>         for (StringMap<GCOVLines *>::iterator I = LinesByFile.begin(),
>                  E = LinesByFile.end(); I != E; ++I) {
> -        Len += I->second->length();
> +        Len = Len + lengthOfGCOVString(I->first()) + I->second->length();
>         }
>
>         writeBytes(LinesTag, 4);
> @@ -212,7 +211,7 @@
>         for (StringMap<GCOVLines *>::iterator I = LinesByFile.begin(),
>                  E = LinesByFile.end(); I != E; ++I) {
>           write(0);
> -        writeGCOVString(I->second->Filename);
> +        writeGCOVString(I->first());
>           for (int i = 0, e = I->second->Lines.size(); i != e; ++i) {
>             write(I->second->Lines[i]);
>           }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list