Commit graph

262 commits

Author SHA1 Message Date
Martin
1fb269f940 Drop support for LLVM < 3.7 2017-07-16 02:18:00 +02:00
Johan Engelen
a4055962fe Implement optimization: compare slices using memcmp if valid (#2047)
This also fixes a pessimization where the `memcmp` call would become an `invoke` if the user provides his own `memcmp` prototype in the code (the prototype would not carry the `nounwind` function attribute).
2017-03-29 20:00:21 +02:00
Johan Engelen
bd09cdc659 Optimize static array comparisons to a memcmp call for types for which this is valid.
Resolves #1632
2017-03-01 00:37:48 +01:00
David Nadlinger
bf05e91879 Merge pull request #1882 from JohanEngelen/ptrarray
Consider pointer literals as constant in isConstLiteral.
2017-02-19 22:43:25 +01:00
Martin
f95d5fdf1d Optimize initializations of byte arrays with non-const byte to memset()
It was previously restricted to a compile-time-constant right-hand-side byte.
2017-01-22 23:42:17 +01:00
Martin
de26dd6747 Skip some obsolete muls and divs for arrays with element size = 1 2017-01-22 23:42:17 +01:00
Johan Engelen
0f2d594ae5 Back off on what we consider as "constant literals": (some) dynamic array literals are not-const because they are expected to be newly allocated. (#1927)
Resolves #1924
2016-12-20 11:26:25 +01:00
Johan Engelen
3eab44ae85 Consider pointer literals as constant in isConstLiteral. 2016-11-16 17:57:53 +01:00
LemonBoy
557a8bd756 Consider string literals as constant in isConstLiteral. 2016-11-10 21:26:11 +01:00
Martin
ab1432ed06 Use the regular LL type for all init symbols and most globals
There's no <Type>_init type for aggregates (structs and classes) anymore,
effectively eliminating a *lot* of named LLVM types, some bitcasts as well
as replacements of globals etc.

To get there, it was even required to use the regular type for compatible
literals too, otherwise structs embedded as fields in other aggregates had
an anonymous type (well, the LLVM constant for the field initializer had)
and so the container initializer wasn't compatible with the regular type
anymore.

What was also necessary was a fix wrt. static arrays of bools (LLVM
constant of type `[N x i1]` vs. `[N x i8]` for regular type).
I also had to change the initializer for `char[2][3] x = 0xff` from
`[6 x i8]` to `[3 x [2 x i8]]`, i.e., NOT flattening multi-dimensional
inits from a scalar.

So only literals with overlapping (union) fields and an explicit
initializer initializing dominated non-alias union fields should still
have a mismatching anonymous type - i.e., very, very few cases.
2016-10-23 02:52:51 +02:00
LemonBoy
517f9095a4 Check StructLiteralExp elements in isConstLiteral. 2016-10-17 23:37:04 +02:00
David Nadlinger
776357c40d gen/arrays: Get rid of return/else chain [nfc] 2016-09-03 14:38:10 +01:00
Martin
7d15ab9ffc Reduce ScopeStack to JumpTargets
Add some comments after this more or less clean separation, and move
callOrInvoke() to FuncGenState.
2016-08-07 21:29:47 +02:00
Martin
e711deac1b Refactor basic block construction and revise BB order 2016-08-06 22:04:41 +02:00
David Nadlinger
6cc93bc8ba gen/ir: Move function body codegen state into separate class
Previously, the transitory state only needed and valid during
generation of the LLVM IR for the function body was conflated
with the general codegen metadata for the function declaration
in IrFunction.

There is further potential for cleanup regarding the use of
gIR->func() and so on all over the code base, but this is out
of scope of this commit, which is only concerned with those
IrFunction members moved to FuncGenState.

GitHub: Fixes #1661.
2016-08-03 21:07:18 +01:00
Martin
54cab47890 Revise DtoAssign() 2016-07-28 01:03:53 +02:00
Martin
a14e31bd94 Attempt to fix issue #1608 2016-07-28 01:03:42 +02:00
Martin
ca8c932d75 Safe some allocas+loads when creating LL slices
Create the LL pair directly instead.
2016-07-21 19:49:33 +02:00
Martin
126184a8b6 More in-place construction
Also for struct literal fields, array literal elements and associative array
literal elements as well as basic types allocated on the heap.
2016-07-21 19:49:28 +02:00
Martin
d6dcc7a4db Enforce type consistency for most DValues
At the cost of some more bitcasts.
2016-07-17 06:22:22 +02:00
Johan Engelen
df10fca7fa Clarify code (NFC) 2016-07-07 21:25:42 +02:00
Rainer Schuetze
f9995b1883 fix build against LLVM trunk svn rev 273030 2016-06-18 10:54:23 +02:00
Martin
de9149f1b6 Remove getLVal() from DValue and add DtoL/RVal() overloads 2016-06-13 22:30:16 +02:00
Martin
0c0c1ecaf5 Rename DVarValue to DLValue 2016-06-13 22:30:15 +02:00
Martin
963a10b225 Let DValue types handle memory-only types consistently
I.e., disallow memory-only values from being represented as DImValues
and disallow getRVal() for such types instead of returning the address.
2016-06-13 22:30:14 +02:00
Martin
c1c285782d Streamline DSliceValue
All DValues are now required to have a (main) LL value, which allows
to conveniently refactor the DValue hierarchy.

DSliceValue now represents a LL struct instead of separate values for
length and pointer.
2016-06-13 22:30:14 +02:00
Martin
e3e2f4b2e9 DValue: Remove method getType()
Use the existing public field directly instead.

It's shorter and different than LLValue's getType() (making it easier
to discriminate DValues and LLValues for experienced LDC devs imho).
2016-06-13 22:30:13 +02:00
Martin
039560bd83 Introduce DtoRVal/DtoLVal convenience functions
No functional changes intended.
2016-06-13 22:30:13 +02:00
Martin
0440bd20db Optimize array comparisons against null
This fixes issue #894 and includes some refactorings.
2016-03-28 15:30:55 +02:00
David Nadlinger
03429eb60f gen: Fix another array literal crash with vectors 2016-02-06 20:57:07 +01:00
David Nadlinger
b756b2de8a arrays: Fix accessing array literal elements with 2.069 frontend
This is unrelated to the move to DDMD. It would have probably been
a good idea to merge the last C++ frontend first.
2016-01-29 22:34:04 +01:00
David Nadlinger
77c29bc8c1 Re-clang-formatify gen/arrays.cpp 2016-01-29 22:32:47 +01:00
Johan Engelen
29ce4012af dmd2 --> ddmd. Merge (almost all of) our changes to dmd source into the new D source of dmd 2.069.2.
Also adds the CMake infrastructure to compile and link the D source files.

The build is partially broken:
- A few files in Phobos and druntime do not build
- MSVC build is broken because of unresolved symbols involving reals
2016-01-28 19:03:58 +01:00
Martin
956061c3c7 Revise DtoGEP() helpers and mark most GEPs inbounds 2015-12-14 00:18:15 +01:00
Martin
0671e91d6b Remove getTypePaddedSize() and use getTypeAllocSize() instead
The functions were equivalent, only leading to confusion.
2015-12-04 22:23:09 +01:00
Johan Engelen
70a6e73188 Cleanup runtime fwd decls and use ABI functiontype rewriting 2015-11-22 01:27:26 +01:00
Martin
2dfa5e8569 Some more cosmetic fixes
Found by searching for lines > 80 chars.
2015-11-05 19:12:32 +01:00
David Nadlinger
05d45350aa clang-tidy: Add readability-else-after-return 2015-11-02 11:30:40 +02:00
David Nadlinger
9df487edff gen/ir: clang-tidy the world 2015-11-02 11:30:40 +02:00
David Nadlinger
44b0f7b615 driver/gen/ir: clang-format the world
This uses the LLVM style, which makes sense for sharing code
with other LLVM projects. The DMD code we use will soon all
be in D anyway.
2015-11-02 00:28:01 +02:00
Martin
d30310c1f9 Support implicit casts in DtoArrayPtr()
On branch merge-2.068, `runnable/testassign.d` checks that a dynamic
array of objects of type B can be assigned to a dynamic array of objects
of a base class A.
The front-end seems to modify the rhs expression type from B[] to A[],
so we need to perform an implicit cast in DtoArrayPtr() to prevent
further type mismatches, notably in DtoArrayAssign().
2015-10-04 00:13:52 +02:00
Martin
b13565c17e Refactor common i1ToI8(voidToI8(DtoType(...))) code occurrences 2015-10-03 22:58:00 +02:00
David Nadlinger
c897015f62 Fix misaligned vector variable initializers
GitHub: Closes #1092.
2015-09-26 19:48:54 +02:00
Martin
9e194bfe2c Refactor store-to-new-alloca code occurrences. 2015-09-25 17:12:42 +02:00
David Nadlinger
4bcd29d0d0 Fix infinite recursion with empty member array default initializers
GitHub: Closes #1101
2015-09-20 19:05:55 +02:00
David Nadlinger
ac792497f2 Properly ignore statically known SliceExp bounds
GitHub: Fixes #1008.
2015-08-29 01:34:25 +02:00
David Nadlinger
ef431836b0 Remove _ad{Eq, Cmp} defines from back when we supported both D1/D2 (NFC) 2015-08-22 19:01:02 +02:00
David Nadlinger
4bcae9731a The big catch/finally rework, part 2
Now with *almost* working EH codegen. Does not compile Phobos yet
because we run into the "instruction does not dominate all uses"
issue when an r-value result of toElemDtor is used and we need to
run cleanups in between. Should easily be fixed by promoting those
values to allocas.

Most of the changes outside of ir/irfunction.{h, cpp} are just
because CreateCallOrInvoke moved locations. I took the
opportunity to also make use of the different arg count
overloads where possible.
2015-08-19 19:56:39 +02:00
David Nadlinger
bfc20df4c8 Remove IRScope::end
Specifying the basic block before which to insert the new one
is not mandatory when calling llvm::BasicBlock::Create. This
was the only use of the tracked "end" block. The concept was
phony anyway because there is no single "end" to a scope with
unwinding and so on.

For prettying up the IR, it is possible to change the order
of basic blocks using move{Before, After}().
2015-08-19 19:56:39 +02:00
David Nadlinger
8e92db150c arrays: Fix crash with void arrays 2015-07-30 00:40:43 +02:00