[PATCH] lld] handle the case of errors from createLinkerInput

Chandler Carruth chandlerc at gmail.com
Mon Sep 2 20:19:32 PDT 2013



================
Comment at: include/lld/Driver/GnuLDInputGraph.h:77
@@ -72,2 +76,3 @@
   bool _asNeeded : 1;
+  bool _isDashlPrefix : 1;
   std::vector<StringRef> _libraryPaths;
----------------
Shankar Kalpathi Easwaran wrote:
> Rui Ueyama wrote:
> > Shankar Kalpathi Easwaran wrote:
> > > Rui Ueyama wrote:
> > > > Why did you make them bitfields? I think we don't usually make boolean fields bitfields only because they need only 1 bit.
> > > bool is an alias for a char, which takes a byte instead of a bit.
> > > 
> > > Below is an example :-
> > > 
> > > #include <stdio.h>
> > > 
> > > struct x {
> > > bool a:1;
> > > bool b:1;
> > > bool c:1;
> > > };
> > > 
> > > struct y {
> > >   bool a;
> > >   bool b;
> > >   bool c;
> > > };
> > > 
> > > int main() {
> > >   printf("%ld\n",sizeof(struct x));
> > >   printf("%ld\n",sizeof(struct y));
> > > }
> > > 
> > > Prints :
> > > 1
> > > 3
> > > 
> > As far as I know in LLVM and in general we don't use bitfield unless
> > 
> >  - it's mapped to some concrete data structure that already exists in memory or file, nor
> >  - the number of instance is really large and need to save memory.
> > 
> > Otherwise bitfield is not necessary. It will actually slows down the execution of code because the compiler need to emit load, mask, and shift operations to get a boolean bitfield value, instead of one load instruction.
> I feel all the options that are either true/false should just use a bitfield. and bit fields are usually faster as the compiler needs to just do one store instead of three stores(stores are usually more costlier).
I generally agree wi/ Rui.

While it's important to avoid growing the memory footprint when we can avoid it by using bitfields, they are definitely slower.

To address your specific point, stores to L1 are exceptionally fast. Also, nothing prevents the compiler (in theory) from merging these stores into a single store. This is all premature optimization. The fact is that the complexity required to manipulate bitfields is strictly greater (and harder to optimize) than the complexity of a bool variable. So unless you're saving memory footprint, I would use normal bools.

(Note that here, I don't think your saving any memory at all. Three bools or three bitfields, all of this is going to be subsumed in padding to align the next member.)


http://llvm-reviews.chandlerc.com/D1571



More information about the llvm-commits mailing list