Commit graph

129 commits

Author SHA1 Message Date
Martin
079e60fee8 SysV ABI: filter out irrelevant ABI mismatches wrt. to previous implementation. 2015-02-23 22:52:12 +01:00
Martin
af18df953f SysV ABI: fix X86_64_C_struct_rewrite.
Don't attempt to store past the end of alloca()ted memory.
This is important for structs passed in registers whose size
is not a power of 2.
Fix: alloca()te another sufficiently sized chunk, store into
it and then memcpy() the relevant bytes to the target chunk.
2015-02-23 22:52:12 +01:00
Martin
7376a0ca8e SysV ABI: fix ExplicitByValRewrite for D structs and static D arrays. 2015-02-23 22:52:12 +01:00
Martin
bc63b4e1f2 SysV ABI: get rid of some more superfluous rewrites.
Ignore pointer type mismatches as long as both types are pointers;
the element type has no effect on the memory layout.

The RegCount constructor had to be improved to handle more complex
types correctly (e.g., nested structs such as { { i64, i32* } }) as
these are not rewritten anymore.
2015-02-23 22:52:12 +01:00
Martin
2663ae325f SysV ABI: make sure all potential padding bytes of a struct are copied.
For structs > 8 bytes passed in registers.
2015-02-23 22:52:11 +01:00
Martin
76d65d45b5 Never rewrite varargs passed by value. 2015-02-23 22:52:11 +01:00
Martin
90223622c7 SysV ABI: only rewrite function arguments if really necessary.
E.g., don't rewrite named struct types to equivalent unnamed ones.
2015-02-23 22:52:11 +01:00
Martin
3cac22de36 Some more SysV ABI fixes.
Debug unittests: only std.range-debug failing.

Not allowing dynamic arrays to be split seems to have fixed
std.stream-debug and also works for dynamic-array varargs crossing the
registers/stack boundary and extracted using core.vararg.va_arg!T().

Not sure about associative arrays and delegates yet. Delegates cannot
be rewritten using ExplicitByvalRewrite; that triggers type mismatches
somewhere.
2015-02-23 22:52:11 +01:00
Martin
a67c6a3f30 SysV ABI: exclude validation against old LDC implementation by default.
It's quite a bit of optional code.
2015-02-23 22:52:11 +01:00
Martin
97dfd89127 SysV ABI: prevent varargs from being only partially passed in registers. 2015-02-23 22:52:11 +01:00
Martin
6bb2c30c05 SysV ABI: prevent structs from being only partially passed in registers.
Only for formal parameters for now, optional args still need to be fixed.
2015-02-23 22:52:11 +01:00
Martin
9cb1e9465d Refactor and revise SysV AMD64 ABI.
I had another look at the official ABI specs and fixed some issues of
our classify()-based version, e.g.:

* upper half X87Up, but lower half not X87
  => pass whole argument in memory
* choose a fitting (integer/struct) type for structs/static arrays of
  sizes 3,5,6,7,11,13,14,15 bytes
2015-02-23 22:52:11 +01:00
Martin
3f02467d31 Improve some ABI rewrites.
Support structs/static arrays and basic types in X86_64_C_struct_rewrite.
2015-02-23 22:52:11 +01:00
Martin
c19550ad39 Fix va_arg intrinsic. 2015-02-23 22:52:11 +01:00
Martin
995ab00295 SysV AMD64 ABI: fix classify() for void and empty structs.
Their size is 1, so classify as byte.
2015-02-23 22:52:11 +01:00
Martin
7dcadc299a SysV AMD64 ABI: don't rewrite to a single bit.
Otherwise std.uni cannot be compiled:
getAbiType(BitPacked!(bool, 1LU)) mismatch: i1 vs. i8
gen/tollvm.cpp:527: void DtoStore(llvm::Value*, llvm::Value*): Assertion `src->getType() != llvm::Type::getInt1Ty(gIR->context()) && "Should store bools as i8 instead of i1."' failed.
2015-02-23 22:52:11 +01:00
Martin
12aa7864d4 System V AMD64 ABI: don't use CompositeToInt rewrite.
Hope for toArgTypes() to get it right and otherwise be compatible with DMD.
2015-02-23 22:52:11 +01:00
Martin
aa38fe06ec Refactoring: move ABI-specific variadic stuff to TargetABI type. 2015-02-23 22:52:11 +01:00
Martin
7388861686 Validate new toArgTypes()-based System V implementation against
previous version.
2015-02-23 22:52:11 +01:00
Martin
e05b5d2691 Fix System V AMD64 ABI and facilitate debugging.
Fix: void type's size isn't 0 and so must be filtered out in returnInArg()
before calling passByVal().
2015-02-23 22:52:11 +01:00
Martin
a00c2b5732 Rewrite suited structs/static arrays as integers for extern(C) too. 2015-02-23 22:52:11 +01:00
Martin
e5deefb1dd Re-implement __va_list struct allocation for System V AMD64 varargs ABI. 2015-02-23 22:52:11 +01:00
Martin
5e3785159f Re-reverse parameter order for extern(D). 2015-02-23 22:52:11 +01:00
Martin
c6c05f1585 Daring, untested attempt to simplify the System V AMD64 ABI.
Rely on LLVM to assign the registers, for D linkage too.
2015-02-23 22:52:11 +01:00
Martin
9c9d0f66c7 Don't swap real and imaginary parts of complex numbers.
Rely on LLVM to select a sane order, don't use DMD as reference anymore.
2015-02-23 22:52:10 +01:00
kai
dbbbe0092b Fix for issue #637.
In case of a ctor `this` is passed to the function and is also the
return value. This is the perfect case for the `Returned` attribute.
But the x86_64 ABI missed the fact that the return value was a pointer
to a struct and did a struct rewrite, resulting in an bitcast
incompatible type.
2014-11-13 02:06:57 +01:00
Alexey Prokhin
a6f358c59b Remove LINKintrisic 2014-07-10 18:10:46 +04:00
kai
2b6dbb03f4 Add IF_LOG to more logging statements.
Evaluating arguments which call toChars() or toPrettyChars() are much more expensive then checking Logger::enabled().
2014-06-26 06:54:38 +02:00
David Nadlinger
cb341586e3 First merge of 2.064 beta.
This corresponds to DMD commit a913ce4bc59a94a022a27e390fc841f4aededffb.

Doesn't build Phobos yet.
2013-10-29 19:21:15 +01:00
Alexey Prokhin
b819975c84 Eliminate the need for TypeFunction::funcdecl 2013-10-05 19:03:03 +04:00
kai
37558273c2 Remove SARRAYVALUE 2013-03-06 10:20:24 +01:00
kai
1e4a8fffc2 Remove DMDV1 and DMDV2. 2013-03-06 10:20:24 +01:00
David Nadlinger
3392f70a4e Move calling convention conversion into TargetABI.
The code is tightly coupled to TargetABI (the transformations
there only make sense knowing that the right CC is selected).
2013-02-26 00:20:45 +01:00
David Nadlinger
0a96aea868 Sort includes according to style guidelines:
1. Main include corresponding to .cpp file, if any.
 2. DMD and LDC includes.
 3. LLVM includes.
 4. System includes.

Also updated a few include guards to match the default format.
2013-02-07 21:20:55 +01:00
David Nadlinger
8ff3a8060a Use llvm_unreachable instead of assert(0).
Also removed some unused functions.
2013-02-07 03:38:15 +01:00
David Nadlinger
88b8ba1053 extern(D): Return static arrays via sret parameters.
On x86_64, a proper solution (see GitHub #120) is still needed,
but this will have to wait until the special case for extern(D)
is gone from the implementation.

We need this right now as std.digest.md in 2.061 triggers a
miscompilation issue in the LLVM x86 backend (not the optimizer!)
when returning them directly as LLVM arrays.
2013-02-04 03:26:18 +01:00
David Nadlinger
2be27279c7 Added x86_64 System V ABI extern(D) TODO note. 2013-02-04 03:26:08 +01:00
kai
f806ec0ed5 Attribute holds no longer multiple values in LLVM 3.3.
The solution is to replace Attribute with AttrBuilder in IrFuncTyArg.
Then the argument attributes can be easily manipulated and transformed
into the final AttributeSet.
2013-02-03 15:09:36 +01:00
kai
5f37ae30cf LLVM 3.3: class Attributes is renamed to Attribute.
Some other renamings took place in "llvm/Attributes.h" but only this causes
compile errors in LDC.
Also uses new location of "llvm/IRBuilder.h".
2012-12-21 17:32:17 +01:00
David Nadlinger
4118cddd1f Cleanup: GCC warning fixes. 2012-12-20 01:21:10 +01:00
David Nadlinger
9458911839 Added LLVM-style license headers to all our files. 2012-12-16 17:19:14 +01:00
kai
fde625b33d More changes to the Attributes class in LLVM 3.2. 2012-10-20 17:22:55 +02:00
kai
657fc42221 And still more changes for LLVM 3.2
There were additional changes to the Attributes class.
2012-10-15 18:31:18 +02:00
kai
a7c7b514c0 Add changes for LLVM 3.2
- The Attributes class was changed again
- TargetData was renamed to DataLayout

Compiles again with LLVm 3.0, 3.1 and trunk(3.2).
2012-10-13 18:54:42 +02:00
kai
2dbee75523 Prefer C++-style casts.
This is based on Item 2 of "More Effective C++". In general, the C++ cast operators are more expressive and easy to find,
e.g. by grep. Using const_cast also shuts up some compiler warnings.
2012-08-02 19:55:29 +02:00
David Nadlinger
62bfda0259 Fix #113 - promotion of small static array arguments to registers. 2012-06-06 22:55:59 +02:00
David Nadlinger
ba9fb721ed Removed trailing whitespace. 2012-06-06 20:41:46 +02:00
Dan Sanduleac
2748cdaa88 Fix #49: Static arrays that don't fit in a register should be passed using byval 2012-06-05 02:52:25 +01:00
Alexey Prokhin
f8bf70ff7a Fixed an assert when compiling derelict.
The assert was triggered by a line similar to this:
   extern(C) void func(float[4] a1, float[4] a2, float[4] a3, float[4] a4, float[4] a5);
2011-12-06 13:14:57 +04:00
Alexey Prokhin
629f13929e WIP: port to llvm 3.0 2011-10-25 15:43:39 +04:00