Commit graph

206 commits

Author SHA1 Message Date
Martin Kinkelin
f241166efb
Fix #4790: Make sure TypeInfo_Class.base is always a TypeInfo_Class ref (#4796)
I.e., ignore all modifiers of the base class.
2024-12-07 08:48:20 +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
2463fe9949 Merge remote-tracking branch 'origin/master' into merge-2.110 2024-08-02 19:15:45 +02:00
Martin Kinkelin
0c1623c1a0 Replace getVoidPtrType() 2024-07-18 23:21:10 +02:00
Martin Kinkelin
d5af843ba9 Remove getNullPtr() parameter 2024-07-18 22:33:20 +02:00
Martin Kinkelin
a5a7b6b74f Adapt to free-standing leastAsSpecialized() function 2024-07-16 16:24:48 +02:00
Martin Kinkelin
a37c2ab5f0 Get rid of now unused variables 2024-05-20 17:48:59 +02:00
Martin Kinkelin
d140f2a283 Skip superfluous IR pointer bitcasts, now that they are always opaque 2024-05-20 16:45:09 +02:00
Martin Kinkelin
f0530e8845 Add support for new TypeInfo_Class.nameSig 2024-03-11 17:39:37 +01:00
Martin Kinkelin
8dd1957c34 Adapt to object.TypeInfo_Class layout change
Without populating the new `nameSig` field yet.
2024-03-04 00:14:28 +01:00
Martin Kinkelin
9041c0bf67 Adapt to free functions in dmd C++ namespace now 2024-03-03 19:14:00 +01:00
Martin Kinkelin
d435c8a451 Merge fix: Adapt to changed mangleToBuffer() signature 2023-11-06 01:10:16 +01:00
Martin Kinkelin
d6d79187e6 Merge fix: Adapt to removed error/warning members 2023-11-06 01:10:16 +01:00
Martin Kinkelin
c8857e8cb8 Fix some LLVM 16 deprecations wrt. DataLayout::getABITypeAlignment() and llvm::makeArrayRef() 2023-08-13 19:10:57 +02:00
Martin Kinkelin
c2b947edef Adapt to newly-non-optional parameter in C++ frontend header 2023-03-26 01:43:54 +01:00
Johan Engelen
51422dca53
Replace sprintf with safer snprintf, fixes compilation warning on newer clang versions. (#4304) 2023-01-25 00:55:10 +01:00
Nicholas Wilson
906037988f
Move abi*.* to abi/ (#4192) 2022-09-21 13:16:04 +00:00
Nicholas Wilson
d15a803d99
Remove getContainedType from getInterfaceVtblInit (#4167) 2022-09-14 15:40:59 +08:00
Nicholas Wilson
6badf8ee68
Remove getContainedType from getClassInfoInit (#4146) 2022-09-13 17:39:08 +08:00
Nicholas Wilson
764e39d35f
Use typed gep in irclass.cpp (#4084) 2022-09-01 10:26:27 +08:00
Nicholas Wilson
e063b8f9d2
Remove getPointeeType from irclass.cpp (#4028) 2022-08-21 10:24:42 +08:00
Nicholas Wilson
da88da192a
[rm-getPointerElementType] Remove usage of getPointerElementType in getClassInfoSymbol (#4019) 2022-08-13 12:47:40 +08:00
Nicholas Wilson
4f7eba7fb2
[rm-getPointeeType] global variable for interface initZ (#4018) 2022-08-13 07:12:33 +08:00
Martin Kinkelin
be9d5817a1 Adapt glue layer to renamed/changed Declaration::linkage 2022-05-06 19:42:18 +02:00
Martin Kinkelin
b7b8e59043 Upgrade frontend & libs to v2.100.0-beta.1+ (dlang/dmd@c0cff59c79) 2022-04-26 23:01:13 +02:00
Martin Kinkelin
8527b3f9c8 Work around llvm::PointerType::getElementType() being deprecated in LLVM 14 2022-03-30 19:53:47 +02:00
Martin Kinkelin
e8997308f9 Always specify a pointee type for llvm::ConstantExpr::getGetElementPtr()
As required by LLVM 13.
2021-10-11 19:21:37 +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
988824d20f Adapt to new TypeInfo names for aggregates 2021-09-08 00:20:24 +02:00
Martin Kinkelin
98838cdf2d Misc. minor adaptations to frontend changes 2021-09-07 16:51:19 +02:00
Martin Kinkelin
e9f40d8a1a Adapt to removed custom (de)allocators 2021-09-07 16:51:19 +02:00
Martin Kinkelin
369cfd13ce Adapt to TY enum class 2021-09-07 16:51:19 +02:00
Martin Kinkelin
49caa9e8a0 Windows: Dllimport aggregate globals too
Init symbols, TypeInfos (classes only) & vtables - unless defined in a
root module. For explicitly exported aggregates, or, with
`-fvisibility=public`, all aggregates.
2021-04-29 17:22:12 +02: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
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
da7f8787c3 Handle IR collisions wrt. built-in TypeInfos and make them mutable
Compiling the rt.util.typeinfo unittests leads to base-typed forward
declarations of built-in TypeInfos colliding with the init symbols for
their TypeInfo_* classes in rt.util.typeinfo.

We've already had a workaround for this in one place (typinf.cpp);
extend it to the other side as well (iraggr.cpp).

Also make sure to emit the TypeInfo metadata even if the IR symbol
already exists as init symbol.

And finally, keep init symbols of built-in TypeInfo classes mutable just
like any other TypeInfo, so that e.g. synchronized() can be used on the
implicit monitor.
2020-10-25 17:06:16 +01:00
Martin Kinkelin
3f452646f5 Refactor generation of interface vtbls for classes 2020-10-24 20:07:29 +02:00
Martin Kinkelin
e9021fd6c8 Refactoring: Improve Ir{Aggr,Class,Struct} encapsulation 2020-10-24 20:07:29 +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
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
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
c09f7ed617 Revise struct/class/interface TypeInfo generation, incl. getting rid of GENERATE_OFFTI
I've also compared against the current DMD implementations, to make sure
we are in sync.

DMD doesn't populate `TypeInfo_Class.m_offTi` either. This seems like a
leftover of some unimplemented idea (the LDC commit introducing the
CMake option is from 2008); the normal `TypeInfo_Class.interfaces` array
contains the offsets nowadays.
2020-07-04 16:42:52 +02:00
Martin Kinkelin
dda1988282 Get rid of superfluous buildClassDtor() helper 2020-07-04 15:51:55 +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