Commit graph

263 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
David Nadlinger
9f4cdb5168 Remove unnecessary semicolon [nfc] 2016-11-27 04:10:03 +00:00
LemonBoy
596fc82254 Implement -finstrument-functions.
Closes #1839.
2016-11-06 23:17:04 +01:00
Johan Engelen
8d84cc7f8c PGO: remove unnecessary instrumentationn BBs for switch statements in instrumentation-disabled functions. 2016-09-27 12:19:24 +02:00
Johan Engelen
5448b5f0ff Fix unused private field warning (SwitchCaseTargets::llFunc) and remove use of global gIR. 2016-08-15 18:24:58 +02:00
Martin
7d15ab9ffc Reduce ScopeStack to JumpTargets
Add some comments after this more or less clean separation, and move
callOrInvoke() to FuncGenState.
2016-08-07 21:29:47 +02:00
Martin
caf5397f6f Extend TryCatchScopes to TryCatchFinallyScopes 2016-08-07 18:45:59 +02:00
Martin
e711deac1b Refactor basic block construction and revise BB order 2016-08-06 22:04:41 +02:00
Martin
fffe86cd2e Introduce try-catch scopes abstraction
Single intended functional change/fix: check ALL active catch blocks in
`isCatchingNonExceptions()`, not just the ones from the innermost
try-catch scope.

The catch bodies of a try-catch scope are now emitted in lexical order
(used to be reversed, last catch block first).
2016-08-06 04:05:08 +02:00
Martin
a4eb01e4e4 Remove obsolete method ScopeStack::currentCatchScope()
It was only used by MSVC EH code which doesn't make use of the catchScopes
stack at all.
2016-08-06 00:10:23 +02:00
Martin
163ba88db9 Restrict nothrow invokes to try blocks catching non-Exceptions
A further optimization for try blocks only catching Exceptions.
2016-08-06 00:10:22 +02:00
David Nadlinger
9d5bf5a707 gen: Keep case/default body IR blocks in lexical order [nfc]
This makes the IR slightly easier to read, in particular the
PGO lit tests.
2016-08-03 21:07:18 +01:00
David Nadlinger
8fbb0ddbfa gen: Do not store body bb for {Case, Default}Statements in AST
Instead, put the mapping into the function-local codegen state,
where it belongs. As a side-effect of the refactoring, avoids
generating trivial "forwarding" BBs (see `nbb` in old code).

Avoids the issue from GitHub #1638 and similar altogether.
2016-08-03 21:07:18 +01: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
David Nadlinger
5cf48c2135 gen: Do not store CaseStatement index values in AST nodes
They were only ever used in ToIRVisitor[SwitchStatement] anyway,
so just use a local vector.

The code for emitting the string switch tables was moved and slightly
refactored, but should functionally still be the same.

Really looking forward to easily being able to zip together
two containers for iteration in C++.
2016-08-02 17:32:21 +01:00
kinke
54511869d7 Merge pull request #1647 from JohanEngelen/switchstatebug
Fix ICE upon second codegen pass of the same SwitchStatement.
2016-07-30 21:19:44 +02:00
Martin
54cab47890 Revise DtoAssign() 2016-07-28 01:03:53 +02:00
Johan Engelen
51af7bf596 Fix ICE upon second codegen pass of the same SwitchStatement.
We should not store codegen state into the AST and the variables touched in this commit should be moved out of the AST. Added a TODO item for it.

Resolves #1638
2016-07-27 17:50:28 +02:00
Johan Engelen
a8761617ac Merge pull request #1598 from Syniurge/llvm38-debuginfofix-master
Debug info generation fixes for LLVM >= 3.8
2016-07-18 15:12:30 +02:00
Martin
343147bf5e Use direct sret construction for return statements too 2016-07-06 12:12:02 +02:00
Martin
1760e261db Move special __result variable into return value (no postblit)
This fixes issue #1335.
2016-07-03 21:58:10 +02:00
Elie Morisse
302d71a9de MSVC: Attach !dbg info to _d_eh_enter_catch, _d_enter_cleanup and _d_leave_cleanup calls. 2016-07-03 16:46:51 -03:00
Martin
cdb817633e Rename IrFunction::retArg to sretArg 2016-07-02 12:52:28 +02:00
Martin
879fb97d56 Rename retvar to sretPointer 2016-07-02 12:52:21 +02:00
David Nadlinger
24048025c7 gen/statements: Always create new "after return" block for unreachable code
This makes sure we do not emit IR into the return bb after the terminator
instruction, which is invalid.

Also improved variable names and comments for clarity.

GitHub: Fixes #1582.
2016-06-25 00:27:18 +01:00
David Nadlinger
92d6eb57a5 gen/statements: clang-format again [nfc] 2016-06-25 00:27:07 +01: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
David Nadlinger
c9c4b7cc42 Fix string switch table sorting
GitHub: Fixes #1406.
2016-04-03 02:48:43 +01:00
Rainer Schuetze
03e7834a49 cleanup obsolete changes 2016-03-13 17:27:56 +01:00
Rainer Schuetze
1f41496326 fix compilation after merge 2016-03-13 17:27:56 +01:00
Rainer Schuetze
3adf19c50d _d_enter_catch can throw, so it might have to be invoked 2016-03-13 17:27:55 +01:00
Rainer Schuetze
18b1492733 avoid outlining catch handler 2016-03-13 17:27:55 +01:00
Rainer Schuetze
83368904d1 - add classinfo argument to _d_eh_enter_catch 2016-03-13 17:27:54 +01:00
Rainer Schuetze
858128a540 - add a global condition to cleanup pads to avoid them being inferred as "noreturn" by the optimizer
- do not inline functions into the cleanup funclets, it can break exception handling
- even if no var given, retrieve the caught exception to pass it to _d_eh_enter_catch
2016-03-13 17:27:53 +01:00
Rainer Schuetze
5dabf78c7b fix MSVC-EH again, disable inlining and tail call optimization for functions with EH 2016-03-13 17:27:51 +01:00
Rainer Schuetze
aad27069ca MSVC/x86 EH support using __CxxFrameHandler3 personality 2016-03-13 17:27:51 +01:00
Johan Engelen
29ce4012af dmd2 --> ddmd. Merge (almost all of) our changes to dmd source into the new D source of dmd 2.069.2.
Also adds the CMake infrastructure to compile and link the D source files.

The build is partially broken:
- A few files in Phobos and druntime do not build
- MSVC build is broken because of unresolved symbols involving reals
2016-01-28 19:03:58 +01:00
Martin
956061c3c7 Revise DtoGEP() helpers and mark most GEPs inbounds 2015-12-14 00:18:15 +01:00
Martin
b9f7d2b499 Normalize signatures of EH runtime functions 2015-12-04 15:07:47 +01:00
Johan Engelen
70a6e73188 Cleanup runtime fwd decls and use ABI functiontype rewriting 2015-11-22 01:27:26 +01:00
David Nadlinger
c9c854f664 eh: Do not use GC for _d_exception records 2015-11-03 00:53:34 +02:00
David Nadlinger
9df487edff gen/ir: clang-tidy the world 2015-11-02 11:30:40 +02:00
David Nadlinger
44b0f7b615 driver/gen/ir: clang-format the world
This uses the LLVM style, which makes sense for sharing code
with other LLVM projects. The DMD code we use will soon all
be in D anyway.
2015-11-02 00:28:01 +02:00
Martin
2d959ea540 Make use of C++11 range-based for
Should be available now that support for LLVM < 3.5 has been dropped.
2015-11-01 14:49:04 +01:00
Martin
60d676e2a1 Drop support for LLVM < 3.5
This allows to clean up the code a little.
2015-10-30 22:24:05 +01:00
David Nadlinger
431c14615e Remove llvm::Value address in log 2015-09-26 15:24:36 +02:00
Martin
80c677be46 Slightly refactor ABIRewrite interface for clarification
* put(): pass DValue alone, without explicit D type
* get(): pass LLValue instead of a faked DValue
2015-09-26 00:30:24 +02:00