Commit Graph

320 Commits

Author SHA1 Message Date
Micah Villmow dd31ca10ef Move TargetData to DataLayout.
llvm-svn: 165395
2012-10-08 16:25:52 +00:00
Richard Smith c030bcdf62 Remove some redundancy from constant aggregate emission. No functionality change.
llvm-svn: 163595
2012-09-11 05:51:06 +00:00
Jin-Gu Kang 1a5e423602 Changing of type checking order on InitListExpr
- UnionType is checked eariler than RecordType.

llvm-svn: 163202
2012-09-05 08:37:43 +00:00
Eli Friedman 34866c7719 Change the representation of builtin functions in the AST
(__builtin_* etc.) so that it isn't possible to take their address.
Specifically, introduce a new type to represent a reference to a builtin
function, and a new cast kind to convert it to a function pointer in the
operand of a call.  Fixes PR13195.

llvm-svn: 162962
2012-08-31 00:14:07 +00:00
Benjamin Kramer 2ef3031496 Remove get(V)BaseClassOffsetInBits, the CharUnit functions should be used instead.
No functionality change.

llvm-svn: 159719
2012-07-04 18:45:14 +00:00
Hans Wennborg d3b01bc7c6 Support the tls_model attribute (PR9788)
This adds support for the tls_model attribute. This allows the user to
choose a TLS model that is better than what LLVM would select by
default. For example, a variable might be declared as:

  __thread int x __attribute__((tls_model("initial-exec")));

if it will not be used in a shared library that is dlopen'ed.

This depends on LLVM r159077.

llvm-svn: 159078
2012-06-23 11:51:46 +00:00
David Blaikie 40ed29730b Revert Decl's iterators back to pointer value_type rather than reference value_type
In addition, I've made the pointer and reference typedef 'void' rather than T*
just so they can't get misused. I would've omitted them entirely but
std::distance likes them to be there even if it doesn't use them.

This rolls back r155808 and r155869.

Review by Doug Gregor incorporating feedback from Chandler Carruth.

llvm-svn: 158104
2012-06-06 20:45:41 +00:00
David Blaikie 2d7c57ec1d Remove the ref/value inconsistency in filter_decl_iterator.
filter_decl_iterator had a weird mismatch where both op* and op-> returned T*
making it difficult to generalize this filtering behavior into a reusable
library of any kind.

This change errs on the side of value, making op-> return T* and op* return
T&.

(reviewed by Richard Smith)

llvm-svn: 155808
2012-04-30 02:36:29 +00:00
Richard Smith 9ec1e48b59 PR12226: don't generate wrong code if a braced string literal is used to
initialize an array of unsigned char. Outside C++11 mode, this bug was benign,
and just resulted in us emitting a constant which was double the required
length, padded with 0s. In C++11, it resulted in us generating an array whose
first element was something like  i8 ptrtoint ([n x i8]* @str to i8).

llvm-svn: 154756
2012-04-15 02:50:59 +00:00
Eli Friedman 5a125b4040 Missing piece of r153720: make sure the vtable pointer is handled correctly.
llvm-svn: 153721
2012-03-30 04:16:06 +00:00
Eli Friedman a154dd5b33 ConstStructBuilder: fix offset math for base classes so it works correctly in general. Found by inspection.
llvm-svn: 153720
2012-03-30 03:55:31 +00:00
Eli Friedman effcd47eef Make sure constant emission handles initializer lists with strings correctly. Part of <rdar://problem/10957867>.
llvm-svn: 152370
2012-03-09 03:06:56 +00:00
Richard Smith bc638767f8 Reinstate r151879, r151880, reverted in r151922, along with a bugfix for
scalar emission of DeclRefExprs to const bools: emit scalar bools as i1,
not as i8.

In addition to the extra unit testing, this has successfully bootstrapped.

llvm-svn: 151955
2012-03-02 23:27:11 +00:00
Sebastian Redl 4a7eab2545 CodeGen support for global variables of type std::initializer_list<X>.
This emits a backing array with internal linkage and fills it with data,
then has the initializer_list point at the array. Dynamic initialization
and global destructors are correctly supported.

What doesn't work is nested initializer_lists. I have no idea how to
get them to work, either. However, these should be very rare, and so
I'll just call it a known bug and declare generalized initializers
DONE!

llvm-svn: 151457
2012-02-25 20:51:20 +00:00
Richard Smith c899892485 PR12067: When emitting an evaluated constant structure in C++11 mode, don't
forget the vptrs.

llvm-svn: 151245
2012-02-23 08:33:23 +00:00
Douglas Gregor ed90df3800 Generate an AST for the conversion from a lambda closure type to a
block pointer that returns a block literal which captures (by copy)
the lambda closure itself. Some aspects of the block literal are left
unspecified, namely the capture variable (which doesn't actually
exist) and the body (which will be filled in by IRgen because it can't
be written as an AST).

Because we're switching to this model, this patch also eliminates
tracking the copy-initialization expression for the block capture of
the conversion function, since that information is now embedded in the
synthesized block literal. -1 side tables FTW.

llvm-svn: 151131
2012-02-22 05:02:47 +00:00
Sebastian Redl e6c32e6293 Refuse to compile global std::initializer_lists instead of doing completely the wrong thing.
llvm-svn: 150928
2012-02-19 14:53:49 +00:00
John McCall c62bb39142 Split reinterpret_casts of member pointers out from CK_BitCast; this
is general goodness because representations of member pointers are
not always equivalent across member pointer types on all ABIs
(even though this isn't really standard-endorsed).

Take advantage of the new information to teach IR-generation how
to do these reinterprets in constant initializers.  Make sure this
works when intermingled with hierarchy conversions (although
this is not part of our motivating use case).  Doing this in the
constant-evaluator would probably have been better, but that would
require a *lot* of extra structure in the representation of
constant member pointers:  you'd really have to track an arbitrary
chain of hierarchy conversions and reinterpretations in order to
get this right.  Ultimately, this seems less complex.  I also
wasn't quite sure how to extend the constant evaluator to handle
foldings that we don't actually want to treat as extended
constant expressions.

llvm-svn: 150551
2012-02-15 01:22:51 +00:00
Benjamin Kramer 8001f7467a Use a simpler (and more efficient) pattern to pad vectors.
llvm-svn: 150475
2012-02-14 12:06:21 +00:00
Richard Smith 6331c408b5 Deal with a horrible C++11 special case. If a non-literal type has a constexpr
constructor, and that constructor is used to initialize an object of static
storage duration such that all members and bases are initialized by constant
expressions, constant initialization is performed. In this case, the object
can still have a non-trivial destructor, and if it does, we must emit a dynamic
initializer which performs no initialization and instead simply registers that
destructor.

llvm-svn: 150419
2012-02-13 22:16:19 +00:00
Bill Wendling 7ac747245f Bump up the initial vector size to avoid having to grow the vector more often.
llvm-svn: 149945
2012-02-07 00:54:58 +00:00
Chris Lattner ece0409a1a simplify a bunch of code to use the well-known LLVM IR types computed by CodeGenModule.
llvm-svn: 149943
2012-02-07 00:39:47 +00:00
Bill Wendling 9972958a89 Use a more efficient container for these values. Also reserve space when using a
std::vector.

llvm-svn: 149936
2012-02-07 00:13:27 +00:00
Bill Wendling 1e375fa219 Use a SmallVector instead of std::vector. This improves compilation time in
445.gobmk by ~1.7%.

llvm-svn: 149935
2012-02-07 00:04:27 +00:00
Bill Wendling bf21cacef1 Don't recalculate the size of the array each time through the for-loop.
llvm-svn: 149933
2012-02-06 23:46:08 +00:00
Chris Lattner 72977a18db simplify code and smallvectorize.
llvm-svn: 149915
2012-02-06 22:00:56 +00:00
Chris Lattner 9c81833c8d reapply the patches reverted in r149477, which enable ConstantDataArray.
llvm-svn: 149801
2012-02-05 02:30:40 +00:00
Argyrios Kyrtzidis a11b35a9b0 Revert r149363 which was part a series of commits that were reverted in llvm
commit 149470. This fixes test/CodeGen/PR3589-freestanding-libcalls.c.

Original log:

    ConstantArray::get() (for strings) is going away, use
    ConstantDataArray::getString instead.

    Many instances of ConstantArray::get() could be moved to
    use more efficient ConstantDataArray methods that avoid a ton
    of intermediate Constant*'s for each element (e.g.
    GetConstantArrayFromStringLiteral).  I don't plan on doing this
    in the short-term though.

llvm-svn: 149477
2012-02-01 06:36:49 +00:00
Chris Lattner f4a4bec3a0 ConstantArray::get() (for strings) is going away, use
ConstantDataArray::getString instead.

Many instances of ConstantArray::get() could be moved to 
use more efficient ConstantDataArray methods that avoid a ton
of intermediate Constant*'s for each element (e.g. 
GetConstantArrayFromStringLiteral).  I don't plan on doing this
in the short-term though.

llvm-svn: 149363
2012-01-31 06:13:55 +00:00
Richard Smith dd5bdd8de7 Remove constant member pointer support from Expr-based constant emission now
that APValue-based constant emission knows how to emit member pointers.

llvm-svn: 148336
2012-01-17 21:42:19 +00:00
David Chisnall fa35df628a Some improvements to the handling of C11 atomic types:
- Add atomic-to/from-nonatomic cast types
- Emit atomic operations for arithmetic on atomic types
- Emit non-atomic stores for initialisation of atomic types, but atomic stores and loads for every other store / load
- Add a __atomic_init() intrinsic which does a non-atomic store to an _Atomic() type.  This is needed for the corresponding C11 stdatomic.h function.
- Enables the relevant __has_feature() checks.  The feature isn't 100% complete yet, but it's done enough that we want people testing it.

Still to do:

- Make the arithmetic operations on atomic types (e.g. Atomic(int) foo = 1; foo++;) use the correct LLVM intrinsic if one exists, not a loop with a cmpxchg.
- Add a signal fence builtin
- Properly set the fenv state in atomic operations on floating point values
- Correctly handle things like _Atomic(_Complex double) which are too large for an atomic cmpxchg on some platforms (this requires working out what 'correctly' means in this context)
- Fix the many remaining corner cases

llvm-svn: 148242
2012-01-16 17:27:18 +00:00
Richard Smith dafff94759 constexpr irgen: Add irgen support for APValue::Struct, APValue::Union,
APValue::Array and APValue::MemberPointer. All APValue values can now be emitted
as constants.

Add new CGCXXABI entry point for emitting an APValue MemberPointer. The other
entrypoints dealing with constant member pointers are no longer necessary and
will be removed in a later change.

Switch codegen from using EvaluateAsRValue/EvaluateAsLValue to
VarDecl::evaluateValue. This performs caching and deals with the nasty cases in
C++11 where a non-const object's initializer can refer indirectly to
previously-initialized fields within the same object.

Building the intermediate APValue object incurs a measurable performance hit on
pathological testcases with huge initializer lists, so we continue to build IR
directly from the Expr nodes for array and record types outside of C++11.

llvm-svn: 148178
2012-01-14 04:30:29 +00:00
Eli Friedman c4b251dc2b Implement the missing pieces of Evaluate for _Complex types. With that complete, remove some code from CGExprConstant which is no longer necessary. While I'm here, a couple minor tweaks to _Complex-in-C++. (Specifically, make _Complex types literal types, and don't warn for _Complex int.)
llvm-svn: 147840
2012-01-10 04:58:17 +00:00
Eli Friedman b1bc368ca7 Address Richard's review comments on r147561 (Evaluate support for address-of-label differences).
llvm-svn: 147631
2012-01-05 23:59:40 +00:00
Eli Friedman fd5e54da2d Add an APValue representation for the difference between two address-of-label expressions. Add support to Evaluate and CGExprConstant for generating/handling them. Remove the special-case for such differences in Expr::isConstantInitializer.
With that done, remove a bunch of buggy code from CGExprConstant for handling scalar expressions which is no longer necessary.

Fixes PR11705.

llvm-svn: 147561
2012-01-04 23:13:47 +00:00
Richard Smith 6e52514c5d constexpr: support for evaluation and codegen of typeid constants.
llvm-svn: 147290
2011-12-27 12:18:28 +00:00
Eli Friedman 5c9cd7a8a3 Fix a failure (which led to a crash) in constant emission code with vector compound literals.
llvm-svn: 147111
2011-12-22 00:04:00 +00:00
Eli Friedman dae858aca3 Make sure we correctly zero-initialize unions containing a pointer to data member as the first field. PR11487.
llvm-svn: 146009
2011-12-07 01:30:11 +00:00
Richard Smith 2d988f0f05 Use static storage duration for file-scope compound literals, even when they
appear in non-constant initializers in C++.

llvm-svn: 145087
2011-11-22 22:48:32 +00:00
Richard Smith 027bf11eb3 Constant expression evaluation: add support for evaluation of member pointers
and base-to-derived casts, and add proper handling of temporaries.

llvm-svn: 144926
2011-11-17 22:56:20 +00:00
Richard Smith ce40ad677e Represent an APValue based on a Decl as that Decl, rather than a DeclRefExpr
or MemberExpr which refers to it. As a side-effect, MemberExprs which refer to
static member functions and static data members are now emitted as constant
expressions.

llvm-svn: 144468
2011-11-12 22:28:03 +00:00
Richard Smith d62306a481 Constant expression evaluation: support for evaluation of structs and unions of
literal types, as well as derived-to-base casts for lvalues and
derived-to-virtual-base casts.

llvm-svn: 144265
2011-11-10 06:34:14 +00:00
Richard Smith f3e9e43da4 Constant expression evaluation: support for arrays.
llvm-svn: 143922
2011-11-07 09:22:26 +00:00
John McCall ffc8ca2d84 Rip out CK_GetObjCProperty.
llvm-svn: 143910
2011-11-07 05:09:54 +00:00
Eli Friedman fcec630a57 Fix the representation of wide strings in the AST and IR so that it uses the native representation of integers for the elements. This fixes a bunch of nastiness involving
treating wide strings as a series of bytes.

Patch by Seth Cantrell.

llvm-svn: 143417
2011-11-01 02:23:42 +00:00
Richard Smith 7b553f1b19 Rename Expr::Evaluate to Expr::EvaluateAsRValue to make it clear that it will
implicitly perform an lvalue-to-rvalue conversion if used on an lvalue
expression. Also improve the documentation of Expr::Evaluate* to indicate which
of them will accept expressions with side-effects.

llvm-svn: 143263
2011-10-29 00:50:52 +00:00
Eli Friedman 9190e19b66 Don't try to emit CK_LValueBitCast casts as constants. PR9558.
llvm-svn: 142863
2011-10-24 22:25:55 +00:00
Anton Korobeynikov f0c267e6e0 Provide half floating point support as a storage only type.
Lack of half FP was a regression compared to llvm-gcc.

llvm-svn: 142016
2011-10-14 23:23:15 +00:00
Eli Friedman fde961dbf3 PR11124: Don't overwrite memory outside of a base class when performing zero-initialization before running its constructor.
llvm-svn: 141933
2011-10-14 02:27:24 +00:00
Richard Smith caf3390d44 Constant expression evaluation refactoring:
- Remodel Expr::EvaluateAsInt to behave like the other EvaluateAs* functions,
   and add Expr::EvaluateKnownConstInt to capture the current fold-or-assert
   behaviour.
 - Factor out evaluation of bitfield bit widths.
 - Fix a few places which would evaluate an expression twice: once to determine
   whether it is a constant expression, then again to get the value.

llvm-svn: 141561
2011-10-10 18:28:20 +00:00