Commit graph

162 commits

Author SHA1 Message Date
Martin Kinkelin
a57715ae5c [adapt to new free-standing functions] 2025-03-13 16:37:37 +01:00
Luna
82878ef32c
Improve Objective-C support (#4777)
* WIP: Objective-C support

* Further work on implementation

* ObjC dynamic cast

* Add swift stub class attribute

* Classes, protocols and ivars

* Fix compilation issues

* Fix objc ir codegen

* Add objc linker option

* Add swift stub classref get ir gen

* Minor cleanup

* Fix objc link flag being added on non-darwin platforms

* Refactor objc gen

* remove use of std::nullopt

* Emit protocol tables

* Remove unused variable

* Formatting

* Fix build in release mode. Thanks for nothing, c++.

* Fix consistency

* Fix dynamic casts

* Fix tocall parentfd ref and arm msgsend call

* Make instance variables work

* Implicitly add isa pointer to objc classes.

* Fix protocol referencing & allow pragma mangle

* Fix protocol linkage

* Fix direct call support

* always generate var type for methods

* Fix test 16096a

* Fix extern ivar symbol gen, retain method decls

* Remove arm32 and x86 support

* Check method and ivar info before pushing to member list

* Make ObjcMethod info untyped.

* Make ivar and method gen more robust

* Generate optional protocol symbols

* Use bitcasting instead of creating multiple type defs

* Fix invalid protocol list struct gen

* More codegen robustness

* emit protocol table as const

* Make protocol table anon struct

* Fix callable type, generate protocol_list_t properly.

* Cast vthis to argtype

* Handle protorefs and classrefs properly

* seperate label ref and deref

* Fix method lookup

* Enable objective-c tests

* Enable objc_call_static test

* Scan both classes and protocols for method ref

* Enable objective-c tests on arm as well.

* supress objc linker warning in tests

* Fix class and protocol gen structure

* Fix objc_protocol_sections test

* ObjcMethod only get callee for functions with bodies

* Fix protocol class method gen

* Make ObjcMethod anon again

* Fix missing emit calls

* Fix classref gen

* Implement some of the requested changes

* Enable compilable tests

* Fix property selector gen, ugly hack for final funcs.

* Fix segfault in referencing fd->type

* Refactor implementation

* Fix null references in class and method lookup

* include unordered_map

* Get functionality on-par with prev impl.

* Fix super context calls

* Move -L-w flag to d_do_test and use IN_LLVM in objc.d/h

* add LDC version tag to -L-w flag

* Update CHANGELOG.md
2024-12-03 04:26:27 +01:00
Martin Kinkelin
3beb68904f Avoid deprecations with LLVM 18 wrt. renamed llvm::StringRef::{starts,ends}with() 2024-03-28 16:42:51 +01:00
Martin Kinkelin
561b9ba04c Add support for new CAsmDeclarations 2024-03-11 17:39:37 +01:00
Martin Kinkelin
9041c0bf67 Adapt to free functions in dmd C++ namespace now 2024-03-03 19:14:00 +01:00
Martin Kinkelin
d6d79187e6 Merge fix: Adapt to removed error/warning members 2023-11-06 01:10:16 +01:00
Martin Kinkelin
4d5553f545 [slight cleanup] 2023-08-05 12:21:50 +02:00
ryuukk
cf32bac668
Do not prefix static libs from pragma(lib) with -l (#4460) 2023-08-01 22:20:32 +02:00
Martin Kinkelin
94216ca7e2
Lazily IR-declare all function fwd declarations (#4420)
Instead of eagerly IR-declaring all such functions in root modules
being compiled.

This might reduce compile times in some cases, and is a cheap way
to improve the situation wrt. issue #2782.
2023-06-10 17:41:00 +02:00
Martin Kinkelin
b796588e08 Use new FuncDeclaration::skipCodegen()
Another betterC hack, hooray! - Fixes compilable/test23606.d.
2023-03-25 18:09:57 +01:00
Martin Kinkelin
e0bc077e69 Adapt to renamed VarDeclaration.aliasTuple (from aliassym) 2023-03-12 20:45:40 +01:00
Martin Kinkelin
4fcd0da328 Adapt TupleDeclaration codegen
Using its `foreachVar()` method to visit the nested vars, as done
in the DMD glue layer.
2022-09-15 14:38:38 +02:00
Martin Kinkelin
b7624aa625 Upgrade frontend & libs to pre-DMD-monorepo state (dlang/dmd@20bd0cacbd) 2022-09-12 16:14:16 +02:00
Martin Kinkelin
4cbaebd965
Make -linkonce-templates less aggressive by default & add -linkonce-templates-aggressive (#3924)
Make -linkonce-templates *not* tamper with the general template
emission algorithm anymore (so on top of default non-allinst or
-allinst modes), and keep those tweaks as experimental
-linkonce-templates-aggressive.

Compiling the druntime/Phobos unittests is only marginally slowed
down compared to the more aggressive variant (~1.5% for debug,
~2.5% for release). It does show some rough 10% increase in required
memory, but that's in line with non-linkonce-templates.

The more aggressive variant has the advantage of skipping
needsCodegen() and potentially codegen'ing less symbols. The problem
is that if an instantiated symbol isn't explicitly referenced, for
instance a CRT ctor, it might not be codegen'd at all.
2022-03-01 00:10:34 +01:00
Martin Kinkelin
599f563fe4 Implement new Target::supportsLinkerDirective() properly 2022-02-24 03:59:43 +01:00
Martin Kinkelin
4bd8dcd91b Adapt to new TOK and EXP enum classes 2022-02-16 20:52:07 +01:00
Martin Kinkelin
423a1d8270
-linkonce-templates: Cull 'discardable' template instances (#3899)
Such instances are guaranteed not to need codegen (e.g., CTFE only).
2022-01-29 14:07:43 +01: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
369cfd13ce Adapt to TY enum class 2021-09-07 16:51:19 +02:00
Martin Kinkelin
fb0401d80a Fix missed definition of globals defined in imported lambdas 2021-02-07 03:02:42 +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
e9021fd6c8 Refactoring: Improve Ir{Aggr,Class,Struct} encapsulation 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
a6ed0e500f Emit struct TypeInfos in referencing CUs only
I.e., not in their owning CU if unused therein, but in all referencing
CUs instead, as linkonce_odr. The special member functions are still
only and unconditionally emitted in the owning CU.
2020-10-11 14:34:49 +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
b1bd6fb2ac
Don't enforce (normal) emission for pragma(inline, true) function templates, and don't cull lambdas (#3570)
With the new available_externally emission into each referencing CU, the
enforced regular emission from the module members tree shouldn't be
required anymore.

After adapting the codegen/inlining_templates.d lit-test accordingly (no
IR definitions anymore in .ll file, because available_externally doesn't
make it there), I've noticed that a lambda in imported and inlined
call_enforce_with_default_template_params() wasn't emitted - it got
culled by alreadyOrWillBeDefined().
Function/delegate literals aren't culled anymore.
2020-09-30 21:26:26 +02:00
Martin Kinkelin
40dedab1e8 Move TypeInfo_Struct emission to new ir/irstruct.cpp
Incl. getting rid of the dependence on an associated
TypeInfoStructDeclaration, which was only really needed for the mangled
name of the global.

Also slightly revise metadata generation.
2020-07-03 21:52:55 +02:00
Martin Kinkelin
ab619744f2 Refactoring: Specialize IrAggr into IrStruct and IrClass
And move ClassInfo generation from gen/classes.cpp to ir/irclass.cpp.
2020-07-01 21:28:45 +02:00
Martin Kinkelin
82f6d4fb85
Embed linker directives in ELF and Mach-O object files (#3259)
Resolves #3245 by adding `pragma(lib, <name>)` library names to
`llvm.dependent-libraries` for ELF object files.

For Mach-O, embed appropriate linker options for `pragma(lib)` and
support generic `pragma(linkerDirective, <flag>, ...)` as well.
2020-01-14 23:12:55 +01:00
Martin Kinkelin
1f5c442519 Revise recent adaptations to frontend refactorings 2020-01-06 17:01:31 +01:00
Martin Kinkelin
4ac7f0554b Adapt to frontend refactorings 2019-12-22 16:29:45 +01: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
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
c17cee71f3 Extend pragma(LDC_no_typeinfo) to classes and interfaces 2019-05-04 20:56:03 +02:00
Martin Kinkelin
45646d1f21 Add declaration context to semantic errors 2019-04-06 15:27:08 +02:00
Martin Kinkelin
47de443652 Don't emit object.RTInfo(Impl) instantiations in dcompute modules
As RTInfoImpl contains unsupported global variables.

`object.RTInfo` is automatically instantiated by the front-end for each
aggregate starting with v2.085, incl. the special structs in the
`ldc.dcompute` module (representing pointers), so that dcompute was
basically totally broken.

Resolves #3009.
2019-03-22 21:31:41 +01:00
Andrey Penechko
7bcd6d34dd Add option '-fvisibility=<hidden|default>' able to hide symbols not marked as 'export' on non-Windows targets. Resolves #2431 (#2894) 2018-11-09 20:55:57 +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
ee8f1ffa00 MSVC: Add support for pragma(linkerDirective) 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
Elie Morisse
841146644b Debug info: emit llvm::DIModule and llvm::DIImportedEntity for modules and imports
Matches GDC's DWARF output and enables access to global and imported symbols from GDB.
2018-10-15 22:48:03 +02:00
Martin Kinkelin
494bc8b1e4
Add some support for classes without TypeInfos (#2765)
For -betterC and/or a minimal object.d without TypeInfo:

* Skip TypeInfo emission for classes and interfaces.
* Emit null as first vtable member.

Makes dmd-testsuite's {compilable,runnable}/minimal2.d work.
2018-07-10 17:56:05 +02:00
Martin
f1b3d8e95f Add backticks in -transition=tls compiler message 2018-04-25 03:01:55 +02:00
Martin
8d5a94c7b8 Only emit interface vtables in the module declaring the class type 2018-04-10 22:13:00 +02:00
Martin
24c2d3e867 Skip TypeInfo emission if there's no TypeInfo declaration
This is compatible with DMD.
2018-04-04 19:59:10 +02:00
Martin
97514dd52f Fix betterC regression for struct TypeInfos
Don't attempt to emit the TypeInfo for each struct declaration. We skip
the IR emission later on for betterC anyway, but starting with 2.079,
the frontend emits an error when invoking genTypeInfo() in betterC mode.
2018-02-25 01:19:09 +01:00
Martin
df4f854dd5 Upgrade to D v2.079.0-beta.1 2018-02-20 02:04:41 +01:00
Martin
197e65efde Merge branch 'master' into merge-2.078
Conflicts:
	driver/main.cpp
	gen/cl_helpers.h
	gen/declarations.cpp
	runtime/druntime
	tests/d2/dmd-testsuite
2018-01-20 11:20:17 +01:00
Martin
27deb2ff8c Get rid of obsolete gen/llvmcompat.h
Not needed anymore since C++11.
2018-01-12 20:20:47 +01:00