Commit graph

550 commits

Author SHA1 Message Date
Martin Kinkelin
9858cfb01c Simplify dmd/ldcbindings.{d,h} 2021-09-17 03:49:28 +02:00
Martin Kinkelin
5e8490d69e
Merge pull request #3821 from kinke/merge-2.098
Upgrade frontend & libs to early v2.098.0
2021-09-11 20:12:55 +02:00
Martin Kinkelin
86f430c039 Slightly revise frontend diff
E.g., preferring local imports for less merge conflict potential.
2021-09-11 17:34:51 +02:00
Martin Kinkelin
16b9eab374
-dllimport=defaultLibsOnly: Avoid -linkonce-templates requirement (#3816)
Via a sorts-of '-linkonce-templates light', only defining all *data*
symbols instantiated from druntime/Phobos templates in each
referencing CU.
2021-09-11 04:53:21 +02:00
Martin Kinkelin
369cfd13ce Adapt to TY enum class 2021-09-07 16:51:19 +02:00
Johan Engelen
c517ce9d12
Improve ftime-trace implementation. (#3797)
* Improve ftime-trace implementation.
- Rewrite ftime-trace to our own implementatation instead of using LLVM's time trace code. The disadvantage is that this removes LLVM's work from the trace (optimization), but has the large benefit of being able to tailor the tracing output to our needs.
- Add memory tracing to ftime-trace (not possible with LLVM's implementation)
- Do not output the sum for each "category"/named string. This causes the LLVM output to be _very_ long, because we put more information in each time segment name. Tooling that processes the time trace output can do this summing itself (i.e. Tracy), and makes the time trace much more pleasant to view in trace viewers.
- Use MonoTime, move timescale calculation to output stage, 'measurement' stage uses ticks as unit
- Fix crash on `ldc2 -ftime-trace` without files passed.
2021-08-14 14:11:22 +02:00
Martin Kinkelin
6e15e1ab04
Make sure special struct TypeInfo members are semantically analyzed before emitting the TypeInfo (#3783)
As there are apparently cases where the struct hasn't had semantic3
yet, at least with -linkonce-templates. This prevents erroneous xopCmp
etc. (failing to compile) from being referenced in the TypeInfo (=>
linker errors) / being analyzed for -linkonce-templates codegen.
`semanticTypeInfoMembers()` replaces them by `object._xopCmp()` etc.
if compilation fails.
2021-07-14 15:41:06 +02:00
Martin Kinkelin
92617aba94 Refactoring: Push/pop FuncGenState for naked asm functions in DtoDefineFunction() too 2021-06-18 16:35:15 +02:00
Martin Kinkelin
1e00f63045 Adapt to upstream global.params.* -> target.* shuffling 2021-05-29 00:19:22 +02:00
Martin Kinkelin
64a5b53566 Windows: Disable @weak emulation for dllexported functions
Otherwise the functions aren't exported. We have some @weak functions in
druntime.
2021-04-29 17:20:32 +02:00
Martin Kinkelin
fb709e9b5f Windows: Only export all external and weak_odr symbols with -fvisibility=public
Mainly, don't export any linkonce_odr symbols.
2021-04-29 17:20:32 +02:00
Martin Kinkelin
eaeb65a9d8 Windows: Make -fvisibility=public export all defined symbols
To pave the way for simple DLL generation (end goal:
druntime-ldc-shared.dll).

The dllexport storage class for functions definitions is enough; the
automatically generated import .lib seems to resolve the regular symbol
name to the actual symbol (__imp_*), so dllimport for declarations seems
superfluous.

For global variables, things are apparently different unfortunately.
2021-04-29 17:20:32 +02:00
Martin Kinkelin
3cdd5b58cb LLVM 12: Add type information to sret and byval parameter attributes
This fixes the failing bitcode writer assertions.
2021-04-27 23:48:26 +02:00
Martin Kinkelin
f39371a32d Merge remote-tracking branch 'origin/master' into merge-2.096
Conflicts:
	gen/dibuilder.cpp
2021-04-10 15:57:21 +02:00
Martin Kinkelin
a268b23469
Don't enforce the frame pointer for functions with GCC-style inline asm (#3685)
As GDC doesn't either.
2021-04-04 19:25:55 +02:00
Martin Kinkelin
52bcbcc566 Fix ICE for ref/out params of opaque structs
Fixes dmd-testsuite's new compilable/test21668.d.
2021-03-01 13:10:16 +01:00
Martin Kinkelin
44daef934a Add support for 'noreturn' type
It's apparently already in the AST, e.g., for core.internal.abort.
2021-02-28 18:57:45 +01:00
Martin Kinkelin
0c079fbdf9 Silence 2 C++ compiler warnings for builds with disabled assertions 2021-02-10 03:27:43 +01:00
Martin Kinkelin
fe5a1776ac Merge remote-tracking branch 'origin/master' into merge-2.095 2021-01-06 23:58:20 +01:00
Martin Kinkelin
0ae530f966 Merge upstream stable (dlang/dmd@ebd5e81dc9) 2021-01-06 23:34:36 +01:00
Johan Engelen
29245c8255
Add --ftime-trace functionality. (#3624)
This uses LLVM's TimeProfiler functionality, such that LLVM's work is traced in the same profile (optimization and machine code gen).
Functionality is meant to be identical to Clang and LLD's --ftime-trace.
2020-12-28 17:05:04 +01:00
Martin Kinkelin
3eab44153a Merge branch 'master' into merge-2.095
Conflicts:
	runtime/phobos
2020-12-03 21:34:29 +01:00
Johan Engelen
b7b676e8da
Remove unused function.cpp:binary (#3626) 2020-12-01 09:52:36 +01:00
Martin Kinkelin
079858f3b2 Upgrade frontend & libs to early v2.095.0 (dlang/dmd@a4274b3c39) 2020-11-27 17:45:13 +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
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
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
cacdc46154 Use LLVM 10+ setFunctionAttributes()
Which supports more cmdline options in the meantime than what we have
been supporting manually, and should be future-proof, similar to
InitTargetOptionsFromCodeGenFlags().
Attributes are only set if explicitly specified in the cmdline (and not
already present in the function's existing attributes).

This started out as a workaround for not being able to determine whether
the user has explicitly set -frame-pointer in the cmdline with LLVM 11,
and ended with having to touch more than I wanted. An *enabled*
-ffast-math flag (from us, not LLVM) overriding LLVM's
-enable-unsafe-fp-math, but e.g. -ffast-math=false NOT overriding was/is
one of the quirks.
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
834f666ce5
Raise min LLVM version to 6.0 (#3493) 2020-07-13 20:42:50 +02:00
Martin Kinkelin
bc8dfe3f9f Fix: Prevent regular definitions from being weakened to available_externally
This is exactly what happened for the 4 problematic delegate literals
for the Phobos unittests - DtoDefineFunction(fd) could result in that
definition ending up as available_externally - all done as part of
DtoResolveFunction(), which declared it, and DtoDeclareFunction()
defined it as available_externally, and the outer DtoDefineFunction()
returned early in that case without fixing up the linkage.
2020-06-01 02:28:58 +02:00
Martin Kinkelin
7dddf506a7 Cross-module inlining: Enable emission into multiple object files
Previously, the logic gave up early if semantic3 was run for the
function to be inlined, either because the function is going to be
codegen'd in some root module, or because sema3 was already run for an
available_externally 'copy' in a previous compilation unit.
This restricted a function to being defined in at most one compilation
unit per ldc2 invocation.

So e.g. a little `pragma(inline, true)` wrapper in druntime wasn't
inlined into other druntime modules, because the whole lib is built in a
single cmdline by default, and sema3 was obviously run for the actual
emission in the corresponding object file.

When later compiling Phobos in a single cmdline, only the first object
file referencing the wrapper got lucky, running sema3 manually and
getting an available_externally 'copy'.
2020-06-01 02:28:58 +02:00
Martin Kinkelin
75f18b49ba
Merge pull request #3441 from kinke/fix_captured_nonpassed
Fix ICE for *captured* parameters *not* passed on the LLVM level
2020-05-29 18:28:45 +02:00
Hiroki Noda
b8b7615696
Add --fno-plt option to avoid PLT external calls (#3443)
This patch gives new option which avoids the PLT and lazy binding while
making external calls.
Implementation inspired by `-fno-plt` support to Clang.

Clang's patch: https://reviews.llvm.org/D39079
2020-05-24 22:31:07 +02:00
Martin Kinkelin
0c0102a9e4 Fix ICE for *captured* parameters *not* passed on the LLVM level
Their IrParameter isn't created as part of DtoDeclareFunction(). Before
being able to handle that later in defineParameters() (as part of
defining the function), DtoCreateNestedContextType() steps in and
creates an IrLocal if not already created.

1) Create an IrParameter in that case in DtoCreateNestedContextType().
2) Handle these new value-less (no LL param) IrParameters in
   defineParameters().
3) Fix the iOS AArch64 ABI, as apparently not all empty structs are
   ignored for parameter passing, but only POD ones.
   Also don't ignore anything passed by reference.
2020-05-22 14:58:29 +02:00
Martin Kinkelin
967947eb84 Emulate @weak functions on Windows and don't emit COMDATs for ELF anymore
Emulation for @weak global variables is still left out but should be
analogous.

The test adaptations are mostly a revert of 3893840f. The testcase has
shown that @weak hasn't worked properly for ELF (linker apparently
prefers the version in the 1st object file, independent of whether it's
weak or not), because the functions are emitted in COMDATs.
clang emits COMDATs for templates and inline functions only, not for
regular functions.
2020-05-16 20:42:57 +02:00
Martin Kinkelin
f4f80d32d7 Make IR type determination for captured lazy params TargetABI-agnostic
This fixes codegen/nested_lazy_gh2302.d for AArch64, which failed due to
the TargetABI rewriting the delegate (IR struct) to `[2 x i64]`.
2020-05-03 16:31:46 +02:00
Martin Kinkelin
d603010159 Refactoring: Introduce TargetABI::isExternD() 2020-05-03 16:31:46 +02:00
Martin Kinkelin
3786614967 Merge upstream stable (dlang/dmd@2dc6c9d619) 2020-05-03 13:36:07 +02:00
Martin Kinkelin
d8f22699a8 Prevent redundant type semantic for va_list 2020-05-02 01:06:58 +02:00
Martin Kinkelin
684acd6a3f Improve check for multiple entry point definitions
* Extend the error message, closely following DMD. Tested by
  fail_compilation/fail5634.d.
* Check across all compiled modules, not on a per-object-file basis.
  That's what DMD does too.
* Apply the implicit `return 0` / void -> int return type promotion to
  all D/C main functions, not just the first one. This prevents some
  potential follow-up crashes.
2020-04-28 01:37:49 +02:00
Martin Kinkelin
5e7e0d55bc Merge remote-tracking branch 'origin/master' into merge-2090
Conflicts:
	tests/d2/dmd-testsuite
2020-01-06 17:01:57 +01:00
Martin Kinkelin
1f5c442519 Revise recent adaptations to frontend refactorings 2020-01-06 17:01:31 +01:00
Fangrui Song
77775a40de Use function attribute "frame-pointer" instead of "no-frame-pointer-elim"/"no-frame-pointer-elim-non-leaf"
LLVM 8 (D56351) introduced "frame-pointer" which was intended to replace
"no-frame-pointer-elim"/"no-frame-pointer-elim-non-leaf".
2019-12-28 09:26:26 -08: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
d4fa4710e0 Don't emit DMD-style tracing with pragma(LDC_profile_instr, false)
E.g., this disables it for __entrypoint.d (the C main function(s) in
there), which is required.

A wmain on Windows is not detected as FuncDeclaration.isCMain() yet,
that should be fixed too.
2019-08-08 22:38:38 +02:00