Commit graph

760 commits

Author SHA1 Message Date
Martin Kinkelin
64aa4fe1e3 Emit struct TypeInfos & special member functions in owning module only
Analogous to ClassInfos, incl. normal linkage (external for non-
templates, weak_odr for templates).

This enables to get rid of frontend logic wrt. whether to add
TypeInfoStructDeclarations to a module's members tree - previously,
it was defined as linkonce_odr in the owning module and each referencing
module (unless speculative) - and related extra semantic and codegen for
the special member functions.
I've gone a bit further and moved the entire TypeInfo emission for LDC
to the codegen layer; no TypeInfoDeclarations are added to the module
members anymore. Whenever we need a TypeInfo symbol during codegen, it
is declared or defined, and we don't need to rely on brittle frontend
logic with speculative-ness complications.

This might slightly increase compilation speed due to less emitted
TypeInfos and functions (possibly less work for the linker too).

A slight drawback is that the job of stripping unused struct TypeInfos
is fully delegated to the linker, as the TypeInfo is guaranteed to end
up in the owning object file due to no linkonce_odr.

Another theoretical drawback is that the optimizer can definitely not
inline xtoHash/xopEquals/xopCmp/xtoString/xdtor[ti]/xpostblit function
pointer indirections in non-owning CUs without LTO (neither the pointers
nor the special member functions are defined anymore).
These (public) members are probably hardly used directly though, and
instead used by the virtual TypeInfo_Struct methods equals/compare/
getHash/destroy/postblit, which are exclusively defined in druntime's
object.o (incl. the TypeInfo_Struct vtable) and aren't cross-module-
inlined anyway (without LTO).

Re-emitting the struct TypeInfos (and optionally the special member
functions too) into each referencing CU could be handled in our codegen
layer, which should be much simpler and more robust than the upstream
scheme.
2020-10-11 12:58:48 +02:00
Martin Kinkelin
6f5730049b Merge remote-tracking branch 'origin/master' into merge-2.094
Conflicts:
	gen/tocall.cpp
	runtime/phobos
2020-09-30 19:46:43 +02:00
Martin Kinkelin
39cd6caed7 Align with upstream by employing VectorArrayExp for <vector>.array
Fixing a regression in dmd-testsuite's compilable/test8543.d, where CTFE
changes seem not to consider such previous LDC-specific CastExp as lvalue
anymore.
2020-09-27 17:53:04 +02:00
Martin Kinkelin
1d969cfcca Revise IRScope refactoring
LLVM already provides suited RAII helper types to restore the IRBuilder
state. [They sadly aren't movable, so I've had to wrap them in a
unique_ptr.]

While at it, also minimally revise debuginfo generation for functions.
2020-09-26 01:04:50 +02: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
f202c851ae Upgrade frontend & libs to v2.094.0-beta.1 2020-09-22 00:06:19 +02:00
Martin Kinkelin
4ec8fc0089
Fix potentially wrong context pointers when calling delegate literals (#3554)
Don't simply forward the caller's context without checking whether the
lambda actually needs a parent context. Fixes #3553.
2020-09-09 12:56:02 +02:00
Martin Kinkelin
9e8111738b
Simplify IR names of virtual function pointers (#3534)
This works around #3526 (but makes sense in general IMO).
For that testcase, the v1.22 IR was:

  %"(bar() , foo)().length@vtbl" = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i32 0, i32 5 ; [#uses = 1, type = i8**]
  %5 = load i8*, i8** %"(bar() , foo)().length@vtbl", align 8 ; [#uses = 1]
  %"(bar() , foo)().length" = bitcast i8* %5 to i64 (%current.Foo*)* ; [#uses = 1]
  %6 = call x86_vectorcallcc i64 %"(bar() , foo)().length"(%current.Foo* nonnull %2) ; [#uses = 1]

Now it's:

  %"length@vtbl" = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i32 0, i32 5 ; [#uses = 1, type = i8**]
  %5 = load i8*, i8** %"length@vtbl", align 8     ; [#uses = 1]
  %length = bitcast i8* %5 to i64 (%current.Foo*)* ; [#uses = 1]
  %6 = call x86_vectorcallcc i64 %length(%current.Foo* nonnull %2) ; [#uses = 1]
2020-08-08 17:04:04 +02:00
Martin Kinkelin
49affcffb2
Fix issue #3496 - missing IR declarations for some fwd-declared functions (#3503)
Whenever we need an IR function, we'd better make sure it exists. Handle
that in DtoCallee(), by invoking DtoDeclareFunction() by default,
instead of the previous DtoResolveFunction() + DtoCallee() combo.
DtoResolveFunction() usually declares the function, but somehow doesn't
for abstract and body-less functions.
2020-07-13 21:49:41 +02:00
looked-at-me
1b5b40556a
Refactor and improve string literal emission (#3492)
Fixes #3490 by avoiding unnecessary extra key allocations for the literals cache etc.
Also gets rid of code duplication and improves IRState encapsulation.
2020-07-11 01:06:10 +02:00
Martin Kinkelin
48e8c2ecee Frontend: Get rid of unused backend-reserved Symbol
Somewhat reducing memory requirements by stripping the unused fields too.
2020-07-01 22:36:51 +02:00
Martin Kinkelin
8813f0eec0
Add proper support for -checkaction=halt (#3431)
Fixes #3430.
2020-05-16 01:17:21 +02:00
Martin Kinkelin
338a43344f
Fix casting (static and dynamic) arrays to vectors (#3419)
Fixes #3418.
2020-05-09 21:23:27 +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
9a87d45f61
Fix DMD issue 20401 (#3233)
See https://issues.dlang.org/show_bug.cgi?id=20401; a testcase will be
added with https://github.com/dlang/dmd/pull/10577.

It's a pretty serious issue (the previously returned reference in the
testcase was a dangling reference to a local memcopy of the original
value in memory), hence this early fix.
2019-11-23 02:53:11 +01:00
Martin Kinkelin
ce3de8be0b Make sure a replaced temporary's lvalue is an alloca
As the replacement most likely wouldn't work if the temporary lvalue was
a bitcast alloca, for example. We want to replace all usages of the
alloca to make sure all writes are redirected to the final lvalue.
2019-10-27 00:53:52 +02:00
Martin Kinkelin
a984145dde Try to in-place-construct temporary structs and static arrays
Inspired by https://issues.dlang.org/show_bug.cgi?id=20321.
2019-10-26 16:43:20 +02:00
Martin Kinkelin
3840a03af4
Don't emit init symbol for zero-initialized structs (#3131)
And optimize previous usages of it to direct memset-zero.
2019-09-12 00:30:09 +02: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
Stefanos Baziotis
122ecd127e Add inbounds to static arrays and dynamic arrays 2019-09-10 22:27:36 +02:00
Stefanos Baziotis
eedde0ab16 Add inbounds where possible 2019-09-10 22:27:36 +02:00
Martin Kinkelin
a9b9097918
Improve emission of vector literals (#3139) 2019-08-27 00:08:39 +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
45460a1e5c Fix this in functions nested in in/out contracts
Contracts are special nested functions, previously receiving the
aggregate `this` pointer as context ptr, as nothing except for `this`
can actually be captured from the original function (parameters are
passed explicitly).

If a contract features a nested function and that function accesses
`this`, it is captured from the original function, and the nested
function expects a regular context of depth 2.

By passing a pointer to the `this` pointer as context for contracts, it
can naturally be used directly as parent context in the contract.

This fixes newly extended runnable/testcontracts.d.
2019-05-27 21:14:45 +02:00
Martin Kinkelin
a44c78fb88 Disallow some vector ops and fix integral vector identity comparisons
Bail out on unsupported vector ops (not checking the rhs type for binops
though) in the frontend instead of causing LLVM errors.

Also precompute the target's critical section size once at startup, like
DMD.
2019-05-26 05:11:16 +02:00
Martin Kinkelin
b3b06d0cc7 Replace LDC-specific VarDeclaration.scopeClassType by .onstackWithDtor
This doesn't increase the VarDeclaration size.
2019-04-13 20:34:16 +02:00
Martin Kinkelin
68fa7b0167 Enforce slice IR rvalues to be represented by DSliceValue, disallow DImValue 2019-01-10 00:53:24 +01:00
Martin Kinkelin
32ecbdd266 Upgrade front-end & libs to v2.084.0-beta.1 2018-12-18 02:31:57 +01:00
Johan Engelen
7966987178 Assigning T.init should only create a temporary when needed. (#2927) 2018-12-03 20:57:40 +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
7776c4081b Upgrade frontend & libs to v2.083.0-beta.1 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
dbf263aa1f Fix issue #2865 (#2867)
Functions, labels etc. aren't sized; respect that when coming across a SymOffExp (and checking whether we can elide a pointer cast to i8* for the GEP).
2018-10-08 21:04:53 +02:00
Martin Kinkelin
5557278ba2 Adapt to refactored defaultInit() (method => free-standing) 2018-08-17 21:34:46 +02:00
Martin Kinkelin
14c74efb7a Support new explicitly direct calls of struct methods
dlang/dmd#8359 introduces direct call expressions for struct methods
(which cannot be virtual anyway and are so always called directly).

Our previous code relied on the instance being a class. There are
multiple ways to fix this; I went with this one.
2018-06-23 17:19:28 +02:00
Martin Kinkelin
c01dfc3db8 Fix: Don't emit struct literals aliasing T.init
This fixes the std.conv unittests on Win64 with the more efficient
IndirectByvalRewrite. This code would segfault:

```
import std.typecons;

alias T = Tuple!(string, string, int);

void main()
{
    T local;
    local = T.init;
}
```

`T.init` represents a struct literal here (a D rvalue in memory) and is
newly forwarded directly by ref to the Tuple's `opAssign(auto ref
Tuple)` for high-level-by-value semantics.

The problem was that `emitStructLiteral()` would actually return a
DLValue to the global init symbol directly in some cases, i.e., a D
lvalue, instead of allocating a dedicated temporary and filling it with
a bitcopy.
2018-05-30 21:46:39 +02:00
Martin
05839a784f Adapt LDC to dropped floating-point comparison operators 2018-04-25 01:00:46 +02:00
Martin
bd623f028a Redirect access to remaining TypeInfo subtypes through gen/runtime 2018-04-04 19:59:10 +02:00
Martin
d8f60d2f5c Redirect access to object.d type declarations through gen/runtime
Not all type declarations yet (e.g., some TypeInfo subtypes are still
accessed directly), but those already wrapped as LazyType in the
gen/runtime.cpp module (with check and proper error msg in case object.d
doesn't contain a required declaration).
2018-04-04 19:59:10 +02:00
Martin
2ffd6ba3c4 Error out when trying to concatenate arrays in -betterC mode
This fixes the error message for fail_compilation/test18312.d, which
used to be:

Error: `TypeInfo` cannot be used with -betterC
2018-03-31 01:22:03 +02:00
Martin
6eceb9141e Merge branch 'master' into merge-2.079
Conflicts:
	.circleci/config.yml
	runtime/druntime
	runtime/phobos
	tests/d2/dmd-testsuite
2018-02-25 15:32:50 +01: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
df4f854dd5 Upgrade to D v2.079.0-beta.1 2018-02-20 02:04:41 +01:00
Martin
c6132508b1 Don't waste an alloca for the nested context argument
And so get rid of all loads too; just use the untouched pointer argument
directly.
2018-02-11 18:43:02 +00:00
Martin
1b860e70d7 Merge branch 'master' into merge-2.078 2018-01-26 18:52:49 +01:00
Martin Kinkelin
6367d98d3a
Don't finalize scope objects without dtors and monitor (#2516)
The dtors can be checked at compile-time; insert a runtime check for the
monitor before finalizing the stack-allocated class object via druntime
call.

See issue #2515.
2018-01-26 18:38:16 +01:00
Martin
1941ea0b7b Refactoring: Make DtoAllocaDump(DValue*) overloads handle DLValues 2018-01-14 22:42:27 +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