Commit graph

470 commits

Author SHA1 Message Date
Ivan Butygin
a26bfc1223 Refactor code to hide direct IrFunction->func usage and add convenient functions (#1911) 2017-01-17 22:40:32 +01:00
Ivan
def709c59b Renamed helpers.h to scope_exit.h 2017-01-06 12:17:50 +03:00
Ivan
6c4f421ead Use SCOPE_EXIT in DtoDefineFunction 2016-12-19 00:51:07 +03:00
Martin
0de021fe32 Fix check if nested function can access outer function frame
The previous check wouldn't check intermediate aggregates for static-ness,
that was one problem. The other was the assertion that the outer function
can be reached as long as there are no static functions inbetween, which
isn't always the case, as issue #1864 clearly shows, which is resolved by
this.
2016-11-18 18:05:56 +01:00
Martin
b7c2a30950 Win64: Don't enforce uwtable function attribute 2016-11-15 21:15:56 +01:00
Martin
67d5fe5624 Map export visibility to LLVM DLL storage classes
Compatible with DMD, but restricted to Windows and functions only.

`export` functions with bodies get the dllexport attribute and will be
exported if the containing object is pulled in when linking.

Body-less `export` functions get the dllimport attribute and will be
accessed via an import table indirection, set up at runtime by the OS.

This is a temporary solution, the proper fix is a pending DMD PR, after
which LDC will need to be adapted.
2016-11-15 21:15:56 +01:00
LemonBoy
596fc82254 Implement -finstrument-functions.
Closes #1839.
2016-11-06 23:17:04 +01:00
Johan Engelen
ed3afed77a UseSoftFloat was removed from the TargetOptions in LLVM3.7. It's replacement (I believe) is the "+soft-float" target feature (in the target feature string). Inside LLVM, the "use-soft-float" attribute is upgraded to the "+soft-float" feature, so we can do that ourselves when creating the target machine.
(at the point where we add the attributes to the function, we have no access to whether our TargetMachine was created with FloatABI:SoftFP or not)
2016-10-28 17:19:26 +09:00
Johan Engelen
cf1a48870e Merge pull request #1811 from JohanEngelen/funcattributes
Apply TargetMachine options as function attributes in IR.
2016-10-14 00:07:46 +02:00
Martin
8be1e3e719 Adapt emission of debuginfos for parameters
Emit all parameters (except for captured ones) as DI parameters.
2016-10-09 20:17:39 +02:00
Johan Engelen
63fba4efdb Add a matching call to llvm.va_end when llvm.va_start was called.
Resolves #1744
2016-10-07 14:48:46 +02:00
Johan Engelen
00dfb4d138 Apply TargetMachine options as function attributes in IR. Needed for LTO. 2016-10-06 19:06:30 +02:00
Rainer Schuetze
2dec29b825 CodeView: fix display of dynamic array arguments (#1761) 2016-09-24 21:06:58 +02:00
David Nadlinger
6cc93bc8ba gen/ir: Move function body codegen state into separate class
Previously, the transitory state only needed and valid during
generation of the LLVM IR for the function body was conflated
with the general codegen metadata for the function declaration
in IrFunction.

There is further potential for cleanup regarding the use of
gIR->func() and so on all over the code base, but this is out
of scope of this commit, which is only concerned with those
IrFunction members moved to FuncGenState.

GitHub: Fixes #1661.
2016-08-03 21:07:18 +01:00
Johan Engelen
c6ba2dc29b Fix a few clang warnings. [NFC] 2016-07-27 20:21:02 +02:00
Johan Engelen
463e53b9ac Apply DDMD PR #5885 (f5f9150ea57cce5fabb43c79ff1b187d34d37044).
This fixes incorrect overriding of class methods and gets rid of many C++ warnings.
2016-07-25 15:25:01 +02:00
Martin
126184a8b6 More in-place construction
Also for struct literal fields, array literal elements and associative array
literal elements as well as basic types allocated on the heap.
2016-07-21 19:49:28 +02:00
David Nadlinger
75e1573cb2 Merge pull request #1577 from JohanEngelen/inlining
Implement cross-module inlining
2016-07-04 21:32:28 +01:00
Johan Engelen
f2c3ed4cce Separate inlining-heuristic code into its own file. Implement a simple statement-counting inlining heuristic. 2016-07-02 17:08:48 +02:00
Johan Engelen
7919805eb4 Disable cross-module inlining for LLVM < 3.7. 2016-07-02 17:08:48 +02:00
Johan Engelen
7ed5a09dc3 Fixes and improvements to cross-module inlining code. 2016-07-02 17:08:48 +02:00
Johan Engelen
a3f0678283 Fix inlining problem: reverse order in which module array is codegenned. 2016-07-02 17:08:48 +02:00
Johan Engelen
0eb8689006 Implement cross-module inlining (with and without pragma). 2016-07-02 17:08:47 +02:00
Johan Engelen
b8048be6e4 Implement same-module pragma(inline, {true|false}). 2016-07-02 17:08:47 +02:00
Martin
cdb817633e Rename IrFunction::retArg to sretArg 2016-07-02 12:52:28 +02:00
Martin
82005009e7 Refactor and fix intrinsics for variadic functions
I.e., va_start(), va_copy() and va_arg().
2016-06-28 22:40:14 +02:00
Johan Engelen
bab4f96246 clang-format (NFC) 2016-06-23 20:26:37 +02:00
Johan Engelen
e0d9c58443 [PGO] Add PGO to LDC. Supported for LLVM >= 3.7
Add the commandline options -fprofile-instr-generate[=filename] and -profile-instr-use=filename
-fprofile-instr-generate
-- Add instrumentation on branches, switches, and function entry; uses LLVM's InstrProf pass.
-- Link to profile runtime that writes instrumentation counters to a file.
-fprofile-instr-use
-- Read profile data from a file and apply branch weights to branches and switches, and annotate functions with entrycount in LLVM IR.
-- Functions with low or high entrycount are marked with 'cold' or 'inlinehint'.

The only statement type without PGO yet is "try-finally".

A new pragma, `pragma(LDC_profile_instr, [ true | false ])`, is added to selectively disable/enable instrumentation of functions (granularity = whole functions).

The runtime library ldc-profile-rt is a copy of LLVM compiler-rt lib/profile. It has to be exactly in-sync with the LLVM version, and thus we need a copy for each PGO-supported LLVM (>=3.7).
import ldc.profile for a D interface to ldc-profile-rt (for example to reset execution counts after a program startup phase).

The instrumentation data is mainly passed on to LLVM: function-entry counts and branch counts/probabilities. LDC marks functions as hot when "execution count is 30% of the maximum function execution count", and marks functions as cold if their count is 1% of maximum function execution count.

The source of LLVM's llvm-profdata tool is hereby included in LDCs repository (different source for each LLVM version), and the binary is included in the install bin folder.
The executable is named "ldc-profdata" to avoid clashing with llvm-profdata on the same machine. This is needed because profdata executable has to be in-sync with the LLVM version used to build LDC.

Maintenance burden: for trunk LLVM, we have to keep ldc-profile-rt and llvm-profdata in sync. There is no diff with upstream; but because of active development there are the occasional API changes.
2016-06-20 17:28:22 +02:00
Martin
de9149f1b6 Remove getLVal() from DValue and add DtoL/RVal() overloads 2016-06-13 22:30:16 +02:00
Martin
0c0c1ecaf5 Rename DVarValue to DLValue 2016-06-13 22:30:15 +02:00
Martin
963a10b225 Let DValue types handle memory-only types consistently
I.e., disallow memory-only values from being represented as DImValues
and disallow getRVal() for such types instead of returning the address.
2016-06-13 22:30:14 +02:00
Martin
0f41c0c681 Refactor defining a function's explicit parameters 2016-05-29 11:54:30 +02:00
Martin
fc6c340661 Optimize ABIRewrite system for lvalues
Allow ABIRewrites to return the D parameter's LL value directly.
Most rewrites store to memory anyway, so let the D parameter point
directly to that memory instead of a dedicated alloca bitcopy.
2016-05-28 21:03:56 +02:00
Martin
a6a6786d8d Try to boil down special cases in nested.cpp 2016-05-28 03:03:56 +02:00
Johan Engelen
776e32d801 Add experimental -hash-threshold option to hash very long symbol names. 2016-05-24 11:39:08 +02:00
Johan Engelen
91d308fa00 Apply "unsafe-fp-math"="false" per default on all functions.
This is needed because of: see comment in applyDefaultMathAttributes.
2016-05-22 19:56:57 +02:00
Johan Engelen
53a14b325b Add per-function FastMathFlags and apply them upon function codegen. 2016-05-22 19:56:56 +02:00
Johan Engelen
b25b7966cc Pass IrFunction* to applyFuncDeclUDAs instead of irfunc->func (llvm::Function*) such that LDC's UDAs can set function properties that are not part of llvm::Function. 2016-05-22 19:56:56 +02:00
David Nadlinger
219758756c Merge branch 'merge-2.071' 2016-05-06 19:24:48 +01:00
Rainer Schuetze
bc1a1b1f9e fix runnable/cppa.d for Windows: C++ interface functions are implemented without thunks, the this pointer is adjusted in the function itself 2016-04-28 23:43:50 +02:00
Rainer Schuetze
8672cf409f implement check for scoped destruction in closure, fixes fail_compilation/fail10666.d 2016-04-21 23:30:26 +02:00
Johan Engelen
9955d8e4e4 For LDC_inline_ir functions: instantiate a new "alwaysinline" function for each call, which is the current behavior for inline ASM too.
When certain attributes are applied to the calling function, like "unsafe-fp-math", the inlined inlineIR function has to have the same attributes otherwise the calling function attribute will be reset to the safe merge of the two: "false". Because the same inlineIR function can be called in different functions using an alias definition, a new function (with possibly different attributes) has to be instantiated upon every call.

Related GH issue #1438
2016-04-21 10:16:33 +02:00
Dan Olson
cd216538f9 Merge branch 'master' into objc-wip 2016-04-08 22:38:39 -07:00
Kai Nacke
88f3de8bea Merge branch 'ltsmaster' 2016-03-22 19:05:07 +01:00
Martin
88dcb4349a Refactor setting linkage type and COMDAT 2016-03-20 16:37:44 +01:00
David Nadlinger
123727ee99 DtoDefineFunction: Avoid assertion after unanalyzed function ICE
The first check is what DMD also does; the second one is to replace
the assertion by an ICE, since the bug can apparently be triggered
rather reliably.

See GitHub #1360.
2016-03-20 01:14:22 +00:00
Martin
4ecfadbc1c MSVC: Re-enable alignment attribute for sret params
Seems to be working with recent LLVM - at least for x64.
2016-03-16 19:45:37 +01:00
Dan Olson
87bbd57ffa Emit error if Objective-C method missing selector
Otherwise method is called as a virtual function and program crashes.
2016-03-08 00:17:42 -08:00
Kai Nacke
d4dc52d4aa Fix compile errors caused by D frontend
- scope is now _scope
- targetTriple requires -> instead of .
- factory method createTypeIdentifier() instead of new TypeIdentifier()
2016-03-03 21:41:46 +01:00
Kai Nacke
24adf155ff Revert "Revert "Merge branch 'ltsmaster'""
This reverts commit 1653911600.
2016-03-03 21:12:53 +01:00