Commit graph

287 commits

Author SHA1 Message Date
Martin Kinkelin
369cfd13ce Adapt to TY enum class 2021-09-07 16:51:19 +02:00
Martin Kinkelin
d3574b9835 DtoTypeInfoOf(): Make Loc param mandatory and move to 1st position 2020-12-13 15:15:37 +01:00
Martin Kinkelin
a9aafac862 Glue layer: Make all mutable Loc & params const 2020-12-13 15:01:19 +01:00
DaveP1776
3f9d05ac16 Fix missing location information for error reporting of TypeInfo in betterC
This fixes an issue where any instantiation of TypeInfo in the final
output would lead to a cryptic error with no file or line information.
This change brings ldc in line with dmd's reporting of the same error,
which at least gives file and line information to discover the problem.
2020-12-12 22:41:21 -05:00
Martin Kinkelin
96b9cde428 Add support for LLVM 11
One major change is the removal of llvm::CallSite, which I've replaced
by llvm::CallBase*.
2020-09-26 01:04:50 +02:00
Martin Kinkelin
69269f3bd9 Refactor IRScope handling
Replace the stack of IRScopes, each with its own IRBuilder, by directly
tampering with the state of a single IRBuilder.

This seems like the most feasible way to account for a breaking change
in LLVM 11, disallowing IRBuilder from being copied.
2020-09-26 01:04:50 +02:00
Martin Kinkelin
7be38fd220
Try to use memcmp for (in)equality of non-mutable static arrays and mutable slices (#3401)
Fixes #3400. The frontend pre-casts the static array operand to the
slice type for cases like `bool[4] == bool[]`, but that's not possible
in case the static array is non-mutable but the slice type is mutable.

So check the element types for equivalence, not the array types, as
static arrays and slices are NOT equivalent.
2020-04-17 22:09:55 +02:00
Martin Kinkelin
26673c174f
Refactoring: Replace Expression::op check followed by static cast to Expression::is<ExpressionType> (#3141)
This may negatively impact performance, as the (final, i.e.,
non-virtual) Expression::is... family is implemented in D and not
available inline in the C++ headers.
2020-01-15 12:54:05 +01:00
Martin Kinkelin
4ac7f0554b Adapt to frontend refactorings 2019-12-22 16:29:45 +01:00
Martin Kinkelin
8fd69da8fb Make all DtoGEP helpers use implicit inbounds
Single functional change: always emit inbounds when computing the base
pointer of a SliceExp.
2019-09-10 22:36:25 +02:00
Martin Kinkelin
e52199469f Upgrade front-end & libs to v2.087.0-beta.1 2019-06-21 15:39:45 +02:00
Martin Kinkelin
9469c6b5b8 Fix array casts with constant source lengths
The `__ArrayCast` lowering isn't (always?) done when casting a static
array to a slice with different element size.
So exploit constant source lengths and compute the target length at
compile-time.

This fixes compilable/ldc_github_421.d - a float[16] can be cast to a
float4[] with constant length 4.
2019-04-25 00:57:46 +02:00
Martin Kinkelin
3817ab0595 Upgrade front-end & libs to v2.086.0-beta.1 2019-04-23 22:13:13 +02:00
Martin Kinkelin
ec72854739
Propagate well-known length of newly allocated arrays (#3042)
For better optimizability, as the length information is lost when using
the slice returned by the druntime hooks directly. Resolves #3041.
2019-04-06 00:41:59 +02:00
Martin Kinkelin
2fb5098f48 Optimize some slice copies
Cache length & ptr in DSliceValue, so that e.g. a pair constructed from
a constant length and some ptr keeps returning a constant length instead
of an extractvalue instruction every time the length is needed.

This enables checking for matching constant lengths when copying slices
and makes `test1()` in runnable/betterc.d work (memcpy instead of
_d_array_slice_copy call):

```
int[10] a1 = void;
int[10] a2 = void;
a1[] = a2[];
```

(more or less equivalent to `a1 = a2`, which is already optimized)
2019-01-09 23:50:44 +01:00
Martin Kinkelin
33cadfaca6 Remove ldc.arrayinit & streamline _d_array_slice_copy/_d_arraycast_len with upstream 2019-01-07 15:54:26 +01:00
Martin Kinkelin
4a23399236 Aim for consistent #includes (order + dir prefix)
I surely missed a few.
2018-10-20 16:19:46 +02:00
Martin Kinkelin
5c24f60cf9
Raise min LLVM version to 3.9 (#2872) 2018-10-15 22:31:59 +02:00
Martin Kinkelin
5557278ba2 Adapt to refactored defaultInit() (method => free-standing) 2018-08-17 21:34:46 +02:00
Martin
9ff736bf0f Lookup runtime function before constructing the call args
To retain the LoC information in case TypeInfo declarations are missing.
2018-04-04 19:59:10 +02:00
Martin Kinkelin
f0aba4559f
Fix cat-assign-element issue if rhs affects the lhs length (#2589)
I.e., this fixes #2588.

To fix the index of the new array element to be assigned to, I went for
decrementing the new length instead of saving the old length directly
before the druntime call (i.e., after evaluating the rhs expression due
to its potential side effects). The IR seems more intuitive to me this
way - load both new length+ptr directly after the druntime call and then
decrement the length by 1.
2018-02-23 18:51:36 +01:00
Martin
f9575686e1 Get rid of obsolete runtime functions
For array comparisons (new) and the _adReverse family.
2018-01-07 05:03:37 +01:00
Martin
cfad799f48 Merge 2.078.0 front-end and stdlibs 2018-01-06 01:39:18 +01:00
Martin
30b858781b -betterC: Use C assert function
Instead of druntime's _d_assert[_msg], _d_arraybounds and
_d_switch_error.

Tested by dmd-testsuite's runnable/cassert and compilable/betterCarray.
2017-10-25 00:38:05 +02:00
Martin
2616261fd2 Revise all LDC-specific errors/warnings/deprecs and insert backticks
For DMD's new syntax highlighting. I grepped in all .{h,cpp} files only.
2017-08-03 22:53:49 +02:00
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