llvm-project/llvm/lib/Transforms/Scalar
Duncan Sands 44b8721de8 Executive summary: getTypeSize -> getTypeStoreSize / getABITypeSize.
The meaning of getTypeSize was not clear - clarifying it is important
now that we have x86 long double and arbitrary precision integers.
The issue with long double is that it requires 80 bits, and this is
not a multiple of its alignment.  This gives a primitive type for
which getTypeSize differed from getABITypeSize.  For arbitrary precision
integers it is even worse: there is the minimum number of bits needed to
hold the type (eg: 36 for an i36), the maximum number of bits that will
be overwriten when storing the type (40 bits for i36) and the ABI size
(i.e. the storage size rounded up to a multiple of the alignment; 64 bits
for i36).

This patch removes getTypeSize (not really - it is still there but
deprecated to allow for a gradual transition).  Instead there is:

(1) getTypeSizeInBits - a number of bits that suffices to hold all
values of the type.  For a primitive type, this is the minimum number
of bits.  For an i36 this is 36 bits.  For x86 long double it is 80.
This corresponds to gcc's TYPE_PRECISION.

(2) getTypeStoreSizeInBits - the maximum number of bits that is
written when storing the type (or read when reading it).  For an
i36 this is 40 bits, for an x86 long double it is 80 bits.  This
is the size alias analysis is interested in (getTypeStoreSize
returns the number of bytes).  There doesn't seem to be anything
corresponding to this in gcc.

(3) getABITypeSizeInBits - this is getTypeStoreSizeInBits rounded
up to a multiple of the alignment.  For an i36 this is 64, for an
x86 long double this is 96 or 128 depending on the OS.  This is the
spacing between consecutive elements when you form an array out of
this type (getABITypeSize returns the number of bytes).  This is
TYPE_SIZE in gcc.

Since successive elements in a SequentialType (arrays, pointers
and vectors) need to be aligned, the spacing between them will be
given by getABITypeSize.  This means that the size of an array
is the length times the getABITypeSize.  It also means that GEP
computations need to use getABITypeSize when computing offsets.
Furthermore, if an alloca allocates several elements at once then
these too need to be aligned, so the size of the alloca has to be
the number of elements multiplied by getABITypeSize.  Logically
speaking this doesn't have to be the case when allocating just
one element, but it is simpler to also use getABITypeSize in this
case.  So alloca's and mallocs should use getABITypeSize.  Finally,
since gcc's only notion of size is that given by getABITypeSize, if
you want to output assembler etc the same as gcc then getABITypeSize
is the size you want.

Since a store will overwrite no more than getTypeStoreSize bytes,
and a read will read no more than that many bytes, this is the
notion of size appropriate for alias analysis calculations.

In this patch I have corrected all type size uses except some of
those in ScalarReplAggregates, lib/Codegen, lib/Target (the hard
cases).  I will get around to auditing these too at some point,
but I could do with some help.

Finally, I made one change which I think wise but others might
consider pointless and suboptimal: in an unpacked struct the
amount of space allocated for a field is now given by the ABI
size rather than getTypeStoreSize.  I did this because every
other place that reserves memory for a type (eg: alloca) now
uses getABITypeSize, and I didn't want to make an exception
for unpacked structs, i.e. I did it to make things more uniform.
This only effects structs containing long doubles and arbitrary
precision integers.  If someone wants to pack these types more
tightly they can always use a packed struct.

llvm-svn: 43620
2007-11-01 20:53:16 +00:00
..
ADCE.cpp New CallInst interface to address GLIBCXX_DEBUG errors caused by 2007-08-01 03:43:44 +00:00
BasicBlockPlacement.cpp Fix typo in comment. 2007-05-06 13:37:16 +00:00
CodeGenPrepare.cpp Executive summary: getTypeSize -> getTypeStoreSize / getABITypeSize. 2007-11-01 20:53:16 +00:00
CondPropagate.cpp Fix PR1575 and test/Transforms/CondProp/2007-08-01-InvalidRead.ll 2007-08-02 04:47:05 +00:00
ConstantProp.cpp Fix typo in comment. 2007-05-06 13:37:16 +00:00
CorrelatedExprs.cpp Remove a bogus return statement, what appears to have been a pasto 2007-07-26 15:29:35 +00:00
DCE.cpp Fix typo in comment. 2007-05-06 13:37:16 +00:00
DeadStoreElimination.cpp Executive summary: getTypeSize -> getTypeStoreSize / getABITypeSize. 2007-11-01 20:53:16 +00:00
GCSE.cpp Use DominatorTree instead of ETForest. 2007-06-07 18:45:06 +00:00
GVN.cpp Allow GVN to eliminate redundant calls to functions without side effects. 2007-10-18 19:39:33 +00:00
GVNPRE.cpp explicit keywords. 2007-09-24 15:48:49 +00:00
IndVarSimplify.cpp Move the SCEV object factors from being static members of the individual 2007-10-22 18:31:58 +00:00
InstructionCombining.cpp Executive summary: getTypeSize -> getTypeStoreSize / getABITypeSize. 2007-11-01 20:53:16 +00:00
LICM.cpp Executive summary: getTypeSize -> getTypeStoreSize / getABITypeSize. 2007-11-01 20:53:16 +00:00
LoopIndexSplit.cpp Handle multiple induction variables. 2007-09-25 18:24:48 +00:00
LoopRotation.cpp Use SmallVector instead of std::vector. 2007-08-21 00:31:24 +00:00
LoopStrengthReduce.cpp At end of LSR, replace uses of now constant (as result of SplitCriticalEdge) PHI node with the constant value. 2007-10-30 23:45:15 +00:00
LoopUnroll.cpp wrap some long lines. Major offenders that are left include 2007-08-02 16:53:43 +00:00
LoopUnswitch.cpp Do not walk invalid iterator. 2007-10-09 21:31:36 +00:00
LowerGC.cpp Change llvm.gcroot to not init the root to null at runtime, this prevents 2007-09-12 17:53:10 +00:00
LowerPacked.cpp Don't bitcast from pointer-to-vector to pointer-to-array when 2007-10-29 20:34:35 +00:00
Makefile DONT_BUILD_RELINKED is gone and implied by BUILD_ARCHIVE now 2005-10-24 02:26:13 +00:00
PredicateSimplifier.cpp Executive summary: getTypeSize -> getTypeStoreSize / getABITypeSize. 2007-11-01 20:53:16 +00:00
Reassociate.cpp Fix typo in comment. 2007-05-06 13:37:16 +00:00
Reg2Mem.cpp Reg2Mem cleanup and optimizations: 2007-10-21 23:05:16 +00:00
SCCP.cpp Use empty() member functions when that's what's being tested for instead 2007-10-03 19:26:29 +00:00
ScalarReplAggregates.cpp Don't do SRA for unions with long double fields. 2007-09-28 00:21:38 +00:00
SimplifyCFG.cpp Fix typo in comment. 2007-05-06 13:37:16 +00:00
TailDuplication.cpp Fix typo in comment. 2007-05-06 13:37:16 +00:00
TailRecursionElimination.cpp Prevent tailcallelim from breaking "recursive" calls to builtins. 2007-09-10 20:58:55 +00:00