Commit graph

513 commits

Author SHA1 Message Date
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
c155e3c141
Merge pull request #3600 from kinke/linkonce2
Extend -linkonce-templates by matching template emission scheme
2020-11-27 02:45:14 +01:00
Martin Kinkelin
3f716ff75e Refactoring: Introduce getIrType()
As *the* way to access the IrType associated with a Type via its `ctype`
field. Most importantly, it makes sure all access is redirected to the
*unqualified* type's `ctype`, which allows to get rid of the 'multiple
types' workaround for aggregates in DtoType(). Those were e.g. hit for
`shared struct SpinLock`, where the struct's type includes the `shared`
modifier...
2020-11-13 15:43:18 +01:00
Martin Kinkelin
ec9caae7fc Replace DtoIsTemplateInstance() by Dsymbol::isInstantiated()
The semantics were almost identical, except for DtoIsTemplateInstance()
checking the specified Dsymbol and its parents, while isInstantiated()
starts from its parent and ignores the symbol itself.

After a quick glance, we seem to have fed it with {Aggregate,Func,Var}
Declarations only, so should be fine with the default front-end variant.
2020-11-13 02:41:11 +01:00
Martin Kinkelin
145ce40b11 Extend -linkonce-templates by matching template emission scheme
I.e., *define* templated symbols in each referencing compilation unit
when using discardable linkonce_odr linkage, analogous to C++.

This makes each compilation unit self-sufficient wrt. templated symbols,
which also means increased opportunity for inlining and less need for
LTO. There should be no more undefined symbol issues caused by buggy
template culling.

The biggest advantage is that the optimizer can discard unused
linkonce_odr symbols early instead of optimizing and forwarding to the
assembler. So this is especially useful with -O to decrease compilation
times and can at least in some scenarios greatly outweigh the
(potentially very much) higher number of symbols defined by the glue
layer.

Libraries compiled with -linkonce-templates can generally not be linked
against dependent code compiled without -linkonce-templates; the other
way around works.
2020-11-13 02:41:11 +01:00
Martin Kinkelin
209ba2553d Get rid of superfluous IrDsymbol state Initialized 2020-10-24 20:07:29 +02:00
Martin Kinkelin
a765bf8901 Refactoring: Move IR global declaration & definition to IrGlobal 2020-10-24 19:55:38 +02:00
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
c8889a9219 Fix alignment issue when casting vector rvalue to static array
Previously, the static-array alloca wasn't suitably aligned for the
store instruction, which uses the greater vector alignment.
This has surfaced now with LLVM 11 on Win32 - this fixes dmd-testsuite's
runnable/ldc_llvm_inline_ir.d.
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
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
Martin Kinkelin
834f666ce5
Raise min LLVM version to 6.0 (#3493) 2020-07-13 20:42:50 +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
Ernesto Castellotti
c40bbbc320
AVR: Add predefined version AVR and emit TLS globals as regular ones (#3420)
The AVR target on LLVM and AVR-GCC does not have support for TLS, so
it is necessary to emit global variables as NotThreadLocal.
2020-05-08 22:47:10 +02:00
Martin Kinkelin
0563aedad3 WebAssembly: Emit all TLS globals as regular __gshared globals 2020-02-08 15:43:04 +01:00
Martin Kinkelin
4ac7f0554b Adapt to frontend refactorings 2019-12-22 16:29:45 +01:00
Martin Kinkelin
649d19e2ab
Fix regression #3234 (#3235) 2019-11-20 20:45:03 +01:00
Johan Engelen
9c47b12895 LLVM 10 fix: add llvm::make_unique and LLMaybeAlign "aliases". (an explicit cast from integer to llvm::MaybeAlign is needed now to setAlignment) 2019-10-16 22:53:46 +02:00
Martin Kinkelin
ad400ff2d0
Keep lvalue-ness when casting AA to another AA (#3179)
Fixes issue #3162.
2019-10-07 21:20:43 +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
Martin Kinkelin
c1725809c2
-fvisibility=hidden: Hide init symbols, TypeInfos and vtables too if the associated aggregate isn't exported (#3129) 2019-08-20 01:41:26 +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
ebcffc4361
Merge pull request #3082 from kinke/gh3078
Fix C assert calls for uClibc
2019-06-01 00:03:02 +02:00
Martin Kinkelin
6b80dd985f
Improve error msg on global var collision (#3081)
Resolves #3080.
2019-06-01 00:02:41 +02:00
Martin Kinkelin
3e0e98607f Fix C assert calls for uClibc
Resolves #3078.
2019-05-31 11:14:13 +02:00
Martin Kinkelin
1c3cb2bade Refactoring: Replace isMusl() by triple.isMusl()
As LLVM 3.9 is the min required version now.
2019-05-31 10:49:45 +02:00
Martin Kinkelin
6264d45199 Get rid of superfluous LDC-specific TypeBasic.alignment() override
16 is LLVM's default alignment for x87 floats and x86_64 targets
(verified for Linux and macOS).
2019-04-13 20:41:02 +02:00
Martin Kinkelin
c62b760263
Support templated LLVM intrinsics with vector arguments (#2971)
Fixes #2962.
2019-01-21 22:22:36 +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
04e9910ad2 Support ptr -> AA casts 2018-12-18 20:39:44 +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
bc24e53565
Declare extern const/immutable globals as IR constants (issue #2849) (#2852) 2018-09-27 00:02:49 +02:00
Martin Kinkelin
9fe95daeea Improve diagnostics for multiple function decls with IR type mismatch 2018-08-18 20:41:41 +02:00
Martin Kinkelin
5557278ba2 Adapt to refactored defaultInit() (method => free-standing) 2018-08-17 21:34:46 +02:00
Martin Kinkelin
d534d370a8
No context ptr for nested non-extern(D) functions (#2809) 2018-08-13 22:45:53 +02:00
Martin Kinkelin
64f4ee92a6 Emit debuginfo for NRVO/result variables
It may likely show up as garbage, as it's not a real local variable
(allocated by caller, address mostly passed in a register); e.g., this
happens on Win64 with the VS debugger ('expression is not an address' or
something along these lines), but at least output *some* DI.

We may be able to fix this and similar issues with LLVM 7 and new
intrinsic llvm.dbg.addr().
2018-06-24 02:14:38 +02:00
Martin Kinkelin
ef1e655767 Handle new special vtbl symbol
There's a new need to access a class' vtable symbol, see dlang/dmd#8362.

Use it as alias to the actual vtable symbol with different type (dummy:
`i8*`, actual: `[N x i8*]`) and mangled name.

I tried matching the special symbol's mangled name and using an
appropriate static array front-end type for it, but then casting the
symbol address for the assignment leads to issues if the ctor is @safe.
So I decided to handle it in DtoSymbolAddress().

Unfortunately, this seems not to solve the extern(C++) issues exposed by
LDC self-compilation yet.
2018-06-23 15:47:01 +02:00
Martin Kinkelin
6dfaebb33e Adapt to new special-ref result variables in out contracts
The AST now features special-ref result variables (storage classes:
ref, temp, result) after rewriting out contracts; from dmd/func.d:

/*   out(id1) { statements1... }
 *   out(id2) { statements2... }
 *   ...
 * becomes:
 *   out(__result) { { ref id1 = __result; { statements1... } }
 *                   { ref id2 = __result; { statements2... } } ... }
 */

We are talking about the `id1` and `id2` variables here.
There's an existing assertion that we don't set a special-ref variable's
lvalue (T**) to the sret pointer (T*) which was already triggered when
compiling Phobos without unittests.
2018-06-20 21:31:52 +02:00
Martin
05839a784f Adapt LDC to dropped floating-point comparison operators 2018-04-25 01:00:46 +02:00
Martin
2dea0e96ee Account for special case of builtin TypeInfos (rt.typeinfo.*)
And aid in debugging by outputting the IR type names if there are type
mismatches when declaring global variables.
2018-04-10 22:13:00 +02:00
Martin
8d5a94c7b8 Only emit interface vtables in the module declaring the class type 2018-04-10 22:13:00 +02:00
Martin
f38a7972a5 Split up getOrCreateGlobal() in {declare,define}Global()
Making it obvious which of the two operations is performed, reducing
call args and making sure a global isn't defined multiple times via
`defineGlobal()`.

The only [intended] functional change is in gen/trycatchfinally.cpp,
where I inserted a check for an existing __cpp_type_info_ptr global when
emitting a catch for C++ exceptions.
2018-04-10 22:13:00 +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
b144fe1123 Merge branch 'master' into merge-2.079
Conflicts:
	runtime/druntime
	runtime/phobos
2018-03-30 00:06:01 +02:00
joakim-noah
04cd029bb9 Pull in Musl's assert function for betterC mode. (#2604) 2018-03-04 20:48:07 +01:00