1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00
Commit Graph

88 Commits

Author SHA1 Message Date
Reid Kleckner
3691294c25 [WinEH] Start EH preparation for 32-bit x86, it uses no arguments
32-bit x86 MSVC-style exceptions are functionaly similar to 64-bit, but
they take no arguments. Instead, they implicitly use the value of EBP
passed in by the caller as a pointer to the parent's frame. In LLVM, we
can represent this as llvm.frameaddress(1), and feed that into all of
our calls to llvm.framerecover.

The next steps are:
- Add an alloca to the fs:00 linked list of handlers
- Add something like llvm.sjlj.lsda or generalize it to store in the
  alloca
- Move state number calculation to WinEHPrepare, arrange for
  FunctionLoweringInfo to call it
- Use the state numbers to insert explicit loads and stores in the IR

llvm-svn: 236172
2015-04-29 22:49:54 +00:00
Andrew Kaylor
532d9d8414 [WinEH] Fix minor bug in begincatch block splitting
llvm-svn: 236129
2015-04-29 17:21:26 +00:00
Andrew Kaylor
0b76fb5239 Style updates
llvm-svn: 236048
2015-04-28 22:01:51 +00:00
Andrew Kaylor
9f3b999556 [WinEH] Split blocks at calls to llvm.eh.begincatch
Differential Revision: http://reviews.llvm.org/D9311

llvm-svn: 236046
2015-04-28 21:54:14 +00:00
Andrew Kaylor
35234dfd91 Fix build error from accidental change
llvm-svn: 235792
2015-04-24 23:34:46 +00:00
Andrew Kaylor
24fdb26f91 [WinEH] Find correct cloned entry block for outlined handler functions.
llvm-svn: 235791
2015-04-24 23:27:32 +00:00
Andrew Kaylor
19baec58e1 [WinEH] Find correct cloned entry block for outlined handler functions.
llvm-svn: 235789
2015-04-24 23:10:38 +00:00
Kaelyn Takata
07731d12a1 Remove an unused variable to prevent -Werror build failures.
llvm-svn: 235773
2015-04-24 21:02:18 +00:00
Reid Kleckner
3a59b4e3a9 [SEH] Implement GetExceptionCode in __except blocks
This introduces an intrinsic called llvm.eh.exceptioncode. It is lowered
by copying the EAX value live into whatever basic block it is called
from. Obviously, this only works if you insert it late during codegen,
because otherwise mid-level passes might reschedule it.

llvm-svn: 235768
2015-04-24 20:25:05 +00:00
Reid Kleckner
a6adb4cb4e [WinEH] Split the landingpad BB instead of cloning it
This means we don't have to RAUW the landingpad instruction and
landingpad BB, which is a nice win.

llvm-svn: 235725
2015-04-24 16:22:19 +00:00
Reid Kleckner
40c6671601 Re-commit "[SEH] Remove the old __C_specific_handler code now that WinEHPrepare works"
This reverts commit r235617.

r235649 should have addressed the problems.

llvm-svn: 235667
2015-04-23 23:22:33 +00:00
Andrew Kaylor
ea1f0f8058 [WinEH] Ignore filter clauses while mapping landing pad blocks.
llvm-svn: 235656
2015-04-23 22:38:36 +00:00
Reid Kleckner
d598235d1f Remove trivial assert to fix NDEBUG Werror builds
llvm-svn: 235652
2015-04-23 21:36:32 +00:00
Reid Kleckner
ffabe51b14 [WinEH] Replace more lpad value uses with undef
We were asserting on code like this:
  extern "C" unsigned long _exception_code();
  void might_crash(unsigned long);
  void foo() {
    __try {
      might_crash(0);
    } __except(1) {
      might_crash(_exception_code());
    }
  }

Gtest and many other libraries get the exception code from the __except
block. What's supposed to happen here is that EAX is live into the
__except block, and it contains the exception code. Eventually we'll
represent that as a use of the landingpad ehptr value, but for now we
can replace it with undef.

llvm-svn: 235649
2015-04-23 21:22:30 +00:00
Andrew Kaylor
efbd8f06a4 [WinEH] Handle stubs for outlined functions that have only unreached terminators.
llvm-svn: 235618
2015-04-23 18:37:39 +00:00
Reid Kleckner
7a1a1e4e4e Revert "[SEH] Remove the old __C_specific_handler code now that WinEHPrepare works"
We still have some "uses remain after removal" issues in -O0 builds.

This reverts commit r235557.

llvm-svn: 235617
2015-04-23 18:34:01 +00:00
Andrew Kaylor
1ed92e06d5 [WinEH] Don't skip landing pads that end with an unreachable instruction.
llvm-svn: 235563
2015-04-23 00:20:44 +00:00
Reid Kleckner
dbbb7b8ac8 [SEH] Remove the old __C_specific_handler code now that WinEHPrepare works
This removes the -sehprepare flag and makes __C_specific_handler
functions always to use WinEHPrepare.

This was tested by building all of chromium_builder_tests and running a
few tests that use SEH, but if something breaks, we can revert this.

llvm-svn: 235557
2015-04-22 22:13:09 +00:00
Reid Kleckner
37da701417 [WinEH] Demote values and phis live across exception handlers up front
In particular, this handles SSA values that are live *out* of a handler.
The existing code only handles values that are live *in* to a handler.

It also handles phi nodes in the block where normal control should
resume after the end of a catch handler.  When EH return points have phi
nodes, we need to split the return edge. It is impossible for phi
elimination to emit copies in the previous block if that block gets
outlined. The indirectbr that we leave in the function is only notional,
and is eliminated from the MachineFunction CFG early on.

Reviewers: majnemer, andrew.w.kaylor

Differential Revision: http://reviews.llvm.org/D9158

llvm-svn: 235545
2015-04-22 21:05:21 +00:00
Reid Kleckner
2e3b8976cc [WinEH] Correctly handle inlined __finally blocks with captures
We should also teach the inliner to collapse framerecover of
frameaddress of the current frame down to an alloca, but that can happen
later.

llvm-svn: 235459
2015-04-22 00:07:52 +00:00
Andrew Kaylor
6e7a901083 [WinEH] Fix problem with landing pad return values used in PHI nodes during outlining.
llvm-svn: 235358
2015-04-20 22:53:42 +00:00
Andrew Kaylor
721c6b75e7 [WinEH] Fix problem with mapping shared empty handler blocks.
Differential Revision: http://reviews.llvm.org/D9125

llvm-svn: 235354
2015-04-20 22:04:09 +00:00
Andrew Kaylor
342b958186 [WinEH] Fix memory leak with catch-all mapping.
llvm-svn: 235328
2015-04-20 18:48:45 +00:00
Andrew Kaylor
a28ade4115 Fix build wanrings and line endings
llvm-svn: 235241
2015-04-17 23:20:24 +00:00
Andrew Kaylor
dcac5320d4 [WinEH] Fixes for a few cppeh failures.
Differential Review: http://reviews.llvm.org/D9065

llvm-svn: 235239
2015-04-17 23:05:43 +00:00
Nico Weber
ffd0269e17 Revert r235154-r235156, they cause asserts when building win64 code (http://crbug.com/477988)
llvm-svn: 235170
2015-04-17 09:10:43 +00:00
Reid Kleckner
52ead7bcab [SEH] Reimplement x64 SEH using WinEHPrepare
This now emits simple, unoptimized xdata tables for __C_specific_handler
based on the handlers listed in @llvm.eh.actions calls produced by
WinEHPrepare.

This adds support for running __finally blocks when exceptions are
thrown, and removes the old landingpad fan-in codepath.

I ran some manual execution tests on small basic test cases with and
without optimization, as well as on Chrome base_unittests, which uses a
small amount of SEH.  I'm sure there are bugs, and we may need to
revert.

llvm-svn: 235154
2015-04-17 01:01:27 +00:00
Reid Kleckner
01ceef5d17 [WinEH] Handle a landingpad, resume, and cleanup all rolled into a BB
This happens a lot with simple cleanups after SimplifyCFG.

llvm-svn: 235117
2015-04-16 17:02:23 +00:00
Reid Kleckner
3183c50ddf [SEH] Deal with users of the old lpad for SEH catch-all blocks
The way we split SEH catch-all blocks can leave some dead EH values
behind at -O0. Try to remove them, and if we fail, replace them all with
undef.

Fixes a crash when removing the old unreachable landingpad which is
still used by extractvalue instructions in the catch-all block.

llvm-svn: 235061
2015-04-16 00:02:04 +00:00
Richard Trieu
5eedf6b231 Change range-based for-loops to be -Wrange-loop-analysis clean.
No functionality change.

llvm-svn: 234963
2015-04-15 01:21:15 +00:00
Alexander Kornienko
71412ece39 Use 'override/final' instead of 'virtual' for overridden methods
The patch is generated using clang-tidy misc-use-override check.

This command was used:

  tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \
    -checks='-*,misc-use-override' -header-filter='llvm|clang' \
    -j=32 -fix -format

http://reviews.llvm.org/D8925

llvm-svn: 234679
2015-04-11 02:11:45 +00:00
Reid Kleckner
ea3a855088 [WinEH] Recognize SEH finally block inserted by the frontend
This allows winehprepare to build sensible llvm.eh.actions calls for SEH
finally blocks.  The pattern matching in this change is brittle and
should be replaced with something more robust soon.  In the meantime,
this will let us write the code that produces __C_specific_handler xdata
tables, which we need regardless of how we decide to get finally blocks
through EH preparation.

llvm-svn: 234663
2015-04-10 23:12:29 +00:00
Reid Kleckner
4e07d71509 [WinEH] Try to make outlining invokes work a little better
WinEH currently turns invokes into calls. Long term, we will reconsider
this, but for now, make sure we remap the operands and clone the
successors of the new terminator.

llvm-svn: 234608
2015-04-10 16:26:42 +00:00
Andrew Kaylor
28081cec7b Formmatting correction
llvm-svn: 234438
2015-04-08 21:22:46 +00:00
Andrew Kaylor
c8c7b73c5c [WinEH] Minor bug fixes.
Fixed insert point for allocas created for demoted values.
Clear the nested landing pad list after it has been processed.

llvm-svn: 234433
2015-04-08 20:57:22 +00:00
Andrew Kaylor
37739bc02d [WinEH] Add invoke of llvm.donothing to outlined catch and cleanup handlers to identify their personality.
Differential Review: http://reviews.llvm.org/D8835

llvm-svn: 234360
2015-04-07 21:30:23 +00:00
Reid Kleckner
b881568c8b [WinEH] Don't sink allocas into child handlers
The uselist isn't enough to infer anything about the lifetime of such
allocas. If we want to re-add this optimization, we will need to
leverage lifetime markers to do it.

Fixes PR23122.

llvm-svn: 234196
2015-04-06 18:50:38 +00:00
David Majnemer
4a823b111e [WinEH] Fill out .xdata for catch objects
This add support for catching an exception such that an exception object
available to the catch handler will be initialized by the runtime.

llvm-svn: 234062
2015-04-03 22:49:05 +00:00
David Majnemer
694a466675 [WinEH] Sink UnwindHelp completely out of IR
We don't need to represent UnwindHelp in IR.  Instead, we can use the
knowledge that we are emitting the parent function to decide if we
should create the UnwindHelp stack object.

llvm-svn: 234061
2015-04-03 22:32:26 +00:00
Andrew Kaylor
cecffb7afd Fixing a memory leak in WinEHPrepare
llvm-svn: 234059
2015-04-03 21:44:17 +00:00
Andrew Kaylor
4fdb9c2a2e Fixing a build error
llvm-svn: 234045
2015-04-03 19:55:30 +00:00
Andrew Kaylor
8bd817aff0 Fixing build warnings.
llvm-svn: 234043
2015-04-03 19:45:32 +00:00
Andrew Kaylor
cd70932cf9 [WinEH] Handle nested landing pads in outlined catch handlers
Differential Revision: http://reviews.llvm.org/D8596

llvm-svn: 234041
2015-04-03 19:37:50 +00:00
Reid Kleckner
629f070af4 [WinEH] Fold cast into assertion based on review feedback
llvm-svn: 234034
2015-04-03 18:18:06 +00:00
Reid Kleckner
9ca8805526 Fix unused variable in NDEBUG builds
llvm-svn: 233978
2015-04-02 21:43:22 +00:00
Reid Kleckner
b08b580e85 [WinEH] Make llvm.eh.actions use frameescape indices for catch params
This makes it possible to use the same representation of llvm.eh.actions
in outlined handlers as we use in the parent function because i32's are
just constants that can be copied freely between functions.

I had to add a sentinel alloca to the list of child allocas so that we
don't try to sink the catch object into the handler. Normally, one would
use nullptr for this kind of thing, but TinyPtrVector doesn't support
null elements. More than that, it's elements have to have a suitable
alignment. Therefore, I settled on this for my sentinel:

  AllocaInst *getCatchObjectSentinel() {
    return static_cast<AllocaInst *>(nullptr) + 1;
  }

llvm-svn: 233947
2015-04-02 21:13:31 +00:00
Andrew Kaylor
60fe895e88 Fix WinEHPrepare bug with multiple catch handlers
Differential Revision: http://reviews.llvm.org/D8682

llvm-svn: 233824
2015-04-01 17:21:25 +00:00
David Majnemer
e7ba02b466 [WinEH] Generate .xdata for catch handlers
This lets us catch exceptions in simple cases.

N.B. Things that do not work include (but are not limited to):
- Throwing from within a catch handler.
- Catching an object with a named catch parameter.
- 'CatchHigh' is fictitious, we aren't sure of its purpose.
- We aren't entirely efficient with regards to the number of EH states
  that we generate.
- IP-to-State tables are sensitive to the order of emission.

llvm-svn: 233767
2015-03-31 22:35:44 +00:00
David Majnemer
6b3129357f [WinEH] Run cleanup handlers when an exception is thrown
Generate tables in the .xdata section representing what actions to take
when an exception is thrown.  This currently fills in state for
cleanups, catch handlers are still unfinished.

llvm-svn: 233636
2015-03-30 22:58:10 +00:00
Andrew Kaylor
1c24d1b7fa Fixing a bug with optimized catch-all handlers in WinEHPrepare
llvm-svn: 233439
2015-03-27 22:31:12 +00:00