llvm.org GIT mirror llvm / 8cec2f2
[IR] Reformulate LLVM's EH funclet IR While we have successfully implemented a funclet-oriented EH scheme on top of LLVM IR, our scheme has some notable deficiencies: - catchendpad and cleanupendpad are necessary in the current design but they are difficult to explain to others, even to seasoned LLVM experts. - catchendpad and cleanupendpad are optimization barriers. They cannot be split and force all potentially throwing call-sites to be invokes. This has a noticable effect on the quality of our code generation. - catchpad, while similar in some aspects to invoke, is fairly awkward. It is unsplittable, starts a funclet, and has control flow to other funclets. - The nesting relationship between funclets is currently a property of control flow edges. Because of this, we are forced to carefully analyze the flow graph to see if there might potentially exist illegal nesting among funclets. While we have logic to clone funclets when they are illegally nested, it would be nicer if we had a representation which forbade them upfront. Let's clean this up a bit by doing the following: - Instead, make catchpad more like cleanuppad and landingpad: no control flow, just a bunch of simple operands; catchpad would be splittable. - Introduce catchswitch, a control flow instruction designed to model the constraints of funclet oriented EH. - Make funclet scoping explicit by having funclet instructions consume the token produced by the funclet which contains them. - Remove catchendpad and cleanupendpad. Their presence can be inferred implicitly using coloring information. N.B. The state numbering code for the CLR has been updated but the veracity of it's output cannot be spoken for. An expert should take a look to make sure the results are reasonable. Reviewers: rnk, JosephTremoulet, andrew.w.kaylor Differential Revision: http://reviews.llvm.org/D15139 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255422 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 3 years ago
109 changed file(s) with 3684 addition(s) and 6692 deletion(s). Raw diff Collapse all Expand all
521521 Exception Handling using the Windows Runtime
522522 =================================================
523523
524 (Note: Windows C++ exception handling support is a work in progress and is not
525 yet fully implemented. The text below describes how it will work when
526 completed.)
527
528524 Background on Windows exceptions
529525 ---------------------------------
530526
531 Interacting with exceptions on Windows is significantly more complicated than on
532 Itanium C++ ABI platforms. The fundamental difference between the two models is
533 that Itanium EH is designed around the idea of "successive unwinding," while
527 Interacting with exceptions on Windows is significantly more complicated than
528 on Itanium C++ ABI platforms. The fundamental difference between the two models
529 is that Itanium EH is designed around the idea of "successive unwinding," while
534530 Windows EH is not.
535531
536532 Under Itanium, throwing an exception typically involes allocating thread local
617613
618614 The following new instructions are considered "exception handling pads", in that
619615 they must be the first non-phi instruction of a basic block that may be the
620 unwind destination of an invoke: ``catchpad``, ``cleanuppad``, and
621 ``terminatepad``. As with landingpads, when entering a try scope, if the
616 unwind destination of an EH flow edge:
617 ``catchswitch``, ``catchpad``, ``cleanuppad``, and ``terminatepad``.
618 As with landingpads, when entering a try scope, if the
622619 frontend encounters a call site that may throw an exception, it should emit an
623 invoke that unwinds to a ``catchpad`` block. Similarly, inside the scope of a
620 invoke that unwinds to a ``catchswitch`` block. Similarly, inside the scope of a
624621 C++ object with a destructor, invokes should unwind to a ``cleanuppad``. The
625622 ``terminatepad`` instruction exists to represent ``noexcept`` and throw
626623 specifications with one combined instruction. All potentially throwing calls in
633630 executes a ``catchret`` instruction, which is a terminator indicating where in
634631 the function control is returned to. A cleanup handler which reaches its end
635632 by normal execution executes a ``cleanupret`` instruction, which is a terminator
636 indicating where the active exception will unwind to next. A catch or cleanup
637 handler which is exited by another exception being raised during its execution will
638 unwind through a ``catchendpad`` or ``cleanuupendpad`` (respectively). The
639 ``catchendpad`` and ``cleanupendpad`` instructions are considered "exception
640 handling pads" in the same sense that ``catchpad``, ``cleanuppad``, and
641 ``terminatepad`` are.
642
643 Each of these new EH pad instructions has a way to identify which
644 action should be considered after this action. The ``catchpad`` and
645 ``terminatepad`` instructions are terminators, and have a label operand considered
646 to be an unwind destination analogous to the unwind destination of an invoke. The
647 ``cleanuppad`` instruction is different from the other two in that it is not a
648 terminator. The code inside a cleanuppad runs before transferring control to the
649 next action, so the ``cleanupret`` and ``cleanupendpad`` instructions are the
650 instructions that hold a label operand and unwind to the next EH pad. All of
651 these "unwind edges" may refer to a basic block that contains an EH pad instruction,
652 or they may simply unwind to the caller. Unwinding to the caller has roughly the
653 same semantics as the ``resume`` instruction in the ``landingpad`` model. When
654 inlining through an invoke, instructions that unwind to the caller are hooked
655 up to unwind to the unwind destination of the call site.
633 indicating where the active exception will unwind to next.
634
635 Each of these new EH pad instructions has a way to identify which action should
636 be considered after this action. The ``catchswitch`` and ``terminatepad``
637 instructions are terminators, and have a unwind destination operand analogous
638 to the unwind destination of an invoke. The ``cleanuppad`` instruction is not
639 a terminator, so the unwind destination is stored on the ``cleanupret``
640 instruction instead. Successfully executing a catch handler should resume
641 normal control flow, so neither ``catchpad`` nor ``catchret`` instructions can
642 unwind. All of these "unwind edges" may refer to a basic block that contains an
643 EH pad instruction, or they may unwind to the caller. Unwinding to the caller
644 has roughly the same semantics as the ``resume`` instruction in the landingpad
645 model. When inlining through an invoke, instructions that unwind to the caller
646 are hooked up to unwind to the unwind destination of the call site.
656647
657648 Putting things together, here is a hypothetical lowering of some C++ that uses
658649 all of the new IR instructions:
693684 call void @"\01??_DCleanup@@QEAA@XZ"(%struct.Cleanup* nonnull %obj) nounwind
694685 br label %return
695686
696 return: ; preds = %invoke.cont.2, %invoke.cont.3
697 %retval.0 = phi i32 [ 0, %invoke.cont.2 ], [ %9, %catch ]
687 return: ; preds = %invoke.cont.3, %invoke.cont.2
688 %retval.0 = phi i32 [ 0, %invoke.cont.2 ], [ %3, %invoke.cont.3 ]
698689 ret i32 %retval.0
699690
700 ; EH scope code, ordered innermost to outermost:
701
702 lpad.cleanup: ; preds = %invoke.cont
703 %cleanup = cleanuppad []
704 call void @"\01??_DCleanup@@QEAA@XZ"(%struct.Cleanup* nonnull %obj) nounwind
705 cleanupret %cleanup unwind label %lpad.catch
706
707 lpad.catch: ; preds = %entry, %lpad.cleanup
708 %catch = catchpad [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %e]
709 to label %catch.body unwind label %catchend
691 lpad.cleanup: ; preds = %invoke.cont.2
692 %0 = cleanuppad within none []
693 call void @"\01??1Cleanup@@QEAA@XZ"(%struct.Cleanup* nonnull %obj) nounwind
694 cleanupret %0 unwind label %lpad.catch
695
696 lpad.catch: ; preds = %lpad.cleanup, %entry
697 %1 = catchswitch within none [label %catch.body] unwind label %lpad.terminate
710698
711699 catch.body: ; preds = %lpad.catch
700 %catch = catchpad within %1 [%rtti.TypeDescriptor2* @"\01??_R0H@8", i32 0, i32* %e]
712701 invoke void @"\01?may_throw@@YAXXZ"()
713 to label %invoke.cont.3 unwind label %catchend
702 to label %invoke.cont.3 unwind label %lpad.terminate
714703
715704 invoke.cont.3: ; preds = %catch.body
716 %9 = load i32, i32* %e, align 4
717 catchret %catch to label %return
718
719 catchend: ; preds = %lpad.catch, %catch.body
720 catchendpad unwind label %lpad.terminate
721
722 lpad.terminate: ; preds = %catchend
723 terminatepad [void ()* @"\01?terminate@@YAXXZ"]
724 unwind to caller
705 %3 = load i32, i32* %e, align 4
706 catchret from %catch to label %return
707
708 lpad.terminate: ; preds = %catch.body, %lpad.catch
709 terminatepad within none [void ()* @"\01?terminate@@YAXXZ"] unwind to caller
725710 }
711
712 Funclet parent tokens
713 -----------------------
714
715 In order to produce tables for EH personalities that use funclets, it is
716 necessary to recover the nesting that was present in the source. This funclet
717 parent relationship is encoded in the IR using tokens produced by the new "pad"
718 instructions. The token operand of a "pad" or "ret" instruction indicates which
719 funclet it is in, or "none" if it is not nested within another funclet.
720
721 The ``catchpad`` and ``cleanuppad`` instructions establish new funclets, and
722 their tokens are consumed by other "pad" instructions to establish membership.
723 The ``catchswitch`` instruction does not create a funclet, but it produces a
724 token that is always consumed by its immediate successor ``catchpad``
725 instructions. This ensures that every catch handler modelled by a ``catchpad``
726 belongs to exactly one ``catchswitch``, which models the dispatch point after a
727 C++ try. The ``terminatepad`` instruction cannot contain lexically nested
728 funclets inside the termination action, so it does not produce a token.
729
730 Here is an example of what this nesting looks like using some hypothetical
731 C++ code:
732
733 .. code-block:: c
734
735 void f() {
736 try {
737 throw;
738 } catch (...) {
739 try {
740 throw;
741 } catch (...) {
742 }
743 }
744 }
745
746 .. code-block:: llvm
747 define void @f() #0 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
748 entry:
749 invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1
750 to label %unreachable unwind label %catch.dispatch
751
752 catch.dispatch: ; preds = %entry
753 %0 = catchswitch within none [label %catch] unwind to caller
754
755 catch: ; preds = %catch.dispatch
756 %1 = catchpad within %0 [i8* null, i32 64, i8* null]
757 invoke void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #1
758 to label %unreachable unwind label %catch.dispatch2
759
760 catch.dispatch2: ; preds = %catch
761 %2 = catchswitch within %1 [label %catch3] unwind to caller
762
763 catch3: ; preds = %catch.dispatch2
764 %3 = catchpad within %2 [i8* null, i32 64, i8* null]
765 catchret from %3 to label %try.cont
766
767 try.cont: ; preds = %catch3
768 catchret from %1 to label %try.cont6
769
770 try.cont6: ; preds = %try.cont
771 ret void
772
773 unreachable: ; preds = %catch, %entry
774 unreachable
775 }
776
777 The "inner" ``catchswitch`` consumes ``%1`` which is produced by the outer
778 catchswitch.
50005000 The terminator instructions are: ':ref:`ret `',
50015001 ':ref:`br `', ':ref:`switch `',
50025002 ':ref:`indirectbr `', ':ref:`invoke `',
5003 ':ref:`resume `', ':ref:`catchpad `',
5004 ':ref:`catchendpad >`',
5003 ':ref:`resume `', ':ref:`catchswitch >`',
50055004 ':ref:`catchret `',
5006 ':ref:`cleanupendpad `',
50075005 ':ref:`cleanupret `',
50085006 ':ref:`terminatepad `',
50095007 and ':ref:`unreachable `'.
53615359
53625360 resume { i8*, i32 } %exn
53635361
5362 .. _i_catchswitch:
5363
5364 '``catchswitch``' Instruction
5365 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5366
5367 Syntax:
5368 """""""
5369
5370 ::
5371
5372 = catchswitch within [ label , label , ... ] unwind to caller
5373 = catchswitch within [ label , label , ... ] unwind label
5374
5375 Overview:
5376 """""""""
5377
5378 The '``catchswitch``' instruction is used by `LLVM's exception handling system
5379 `_ to describe the set of possible catch handlers
5380 that may be executed by the :ref:`EH personality routine `.
5381
5382 Arguments:
5383 """"""""""
5384
5385 The ``parent`` argument is the token of the funclet that contains the
5386 ``catchswitch`` instruction. If the ``catchswitch`` is not inside a funclet,
5387 this operand may be the token ``none``.
5388
5389 The ``default`` argument is the label of another basic block beginning with a
5390 "pad" instruction, one of ``cleanuppad``, ``terminatepad``, or
5391 ``catchswitch``.
5392
5393 The ``handlers`` are a list of successor blocks that each begin with a
5394 :ref:`catchpad ` instruction.
5395
5396 Semantics:
5397 """"""""""
5398
5399 Executing this instruction transfers control to one of the successors in
5400 ``handlers``, if appropriate, or continues to unwind via the unwind label if
5401 present.
5402
5403 The ``catchswitch`` is both a terminator and a "pad" instruction, meaning that
5404 it must be both the first non-phi instruction and last instruction in the basic
5405 block. Therefore, it must be the only non-phi instruction in the block.
5406
5407 Example:
5408 """"""""
5409
5410 .. code-block:: llvm
5411
5412 dispatch1:
5413 %cs1 = catchswitch within none [label %handler0, label %handler1] unwind to caller
5414 dispatch2:
5415 %cs2 = catchswitch within %parenthandler [label %handler0] unwind label %cleanup
5416
53645417 .. _i_catchpad:
53655418
53665419 '``catchpad``' Instruction
53715424
53725425 ::
53735426
5374 = catchpad [*]
5375 to label unwind label
5427 = catchpad within [*]
53765428
53775429 Overview:
53785430 """""""""
53795431
53805432 The '``catchpad``' instruction is used by `LLVM's exception handling
53815433 system `_ to specify that a basic block
5382 is a catch block --- one where a personality routine attempts to transfer
5434 begins a catch handler --- one where a personality routine attempts to transfer
53835435 control to catch an exception.
5384 The ``args`` correspond to whatever information the personality
5385 routine requires to know if this is an appropriate place to catch the
5386 exception. Control is transfered to the ``exception`` label if the
5387 ``catchpad`` is not an appropriate handler for the in-flight exception.
5388 The ``normal`` label should contain the code found in the ``catch``
5389 portion of a ``try``/``catch`` sequence. The ``resultval`` has the type
5390 :ref:`token ` and is used to match the ``catchpad`` to
5391 corresponding :ref:`catchrets `.
5392
5393 Arguments:
5394 """"""""""
5395
5396 The instruction takes a list of arbitrary values which are interpreted
5397 by the :ref:`personality function `.
5398
5399 The ``catchpad`` must be provided a ``normal`` label to transfer control
5400 to if the ``catchpad`` matches the exception and an ``exception``
5401 label to transfer control to if it doesn't.
5402
5403 Semantics:
5404 """"""""""
5405
5406 When the call stack is being unwound due to an exception being thrown,
5407 the exception is compared against the ``args``. If it doesn't match,
5408 then control is transfered to the ``exception`` basic block.
5409 As with calling conventions, how the personality function results are
5410 represented in LLVM IR is target specific.
5411
5412 The ``catchpad`` instruction has several restrictions:
5413
5414 - A catch block is a basic block which is the unwind destination of
5415 an exceptional instruction.
5416 - A catch block must have a '``catchpad``' instruction as its
5417 first non-PHI instruction.
5418 - A catch block's ``exception`` edge must refer to a catch block or a
5419 catch-end block.
5420 - There can be only one '``catchpad``' instruction within the
5421 catch block.
5422 - A basic block that is not a catch block may not include a
5423 '``catchpad``' instruction.
5424 - A catch block which has another catch block as a predecessor may not have
5425 any other predecessors.
5426 - It is undefined behavior for control to transfer from a ``catchpad`` to a
5427 ``ret`` without first executing a ``catchret`` that consumes the
5428 ``catchpad`` or unwinding through its ``catchendpad``.
5429 - It is undefined behavior for control to transfer from a ``catchpad`` to
5430 itself without first executing a ``catchret`` that consumes the
5431 ``catchpad`` or unwinding through its ``catchendpad``.
5436
5437 Arguments:
5438 """"""""""
5439
5440 The ``catchswitch`` operand must always be a token produced by a
5441 :ref:`catchswitch ` instruction in a predecessor block. This
5442 ensures that each ``catchpad`` has exactly one predecessor block, and it always
5443 terminates in a ``catchswitch``.
5444
5445 The ``args`` correspond to whatever information the personality routine
5446 requires to know if this is an appropriate handler for the exception. Control
5447 will transfer to the ``catchpad`` if this is the first appropriate handler for
5448 the exception.
5449
5450 The ``resultval`` has the type :ref:`token ` and is used to match the
5451 ``catchpad`` to corresponding :ref:`catchrets ` and other nested EH
5452 pads.
5453
5454 Semantics:
5455 """"""""""
5456
5457 When the call stack is being unwound due to an exception being thrown, the
5458 exception is compared against the ``args``. If it doesn't match, control will
5459 not reach the ``catchpad`` instruction. The representation of ``args`` is
5460 entirely target and personality function-specific.
5461
5462 Like the :ref:`landingpad ` instruction, the ``catchpad``
5463 instruction must be the first non-phi of its parent basic block.
5464
5465 The meaning of the tokens produced and consumed by ``catchpad`` and other "pad"
5466 instructions is described in the
5467 `Windows exception handling documentation `.
5468
5469 Executing a ``catchpad`` instruction constitutes "entering" that pad.
5470 The pad may then be "exited" in one of three ways:
5471 1) explicitly via a ``catchret`` that consumes it. Executing such a ``catchret``
5472 is undefined behavior if any descendant pads have been entered but not yet
5473 exited.
5474 2) implicitly via a call (which unwinds all the way to the current function's caller),
5475 or via a ``catchswitch``, ``cleanupret``, or ``terminatepad`` that unwinds to caller.
5476 3) implicitly via an unwind edge whose destination EH pad isn't a descendant of
5477 the ``catchpad``. When the ``catchpad`` is exited in this manner, it is
5478 undefined behavior if the destination EH pad has a parent which is not an
5479 ancestor of the ``catchpad`` being exited.
54325480
54335481 Example:
54345482 """"""""
54355483
54365484 .. code-block:: llvm
54375485
5486 dispatch:
5487 %cs = catchswitch within none [label %handler0] unwind to caller
54385488 ;; A catch block which can catch an integer.
5439 %tok = catchpad [i8** @_ZTIi]
5440 to label %int.handler unwind label %terminate
5441
5442 .. _i_catchendpad:
5443
5444 '``catchendpad``' Instruction
5445 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5446
5447 Syntax:
5448 """""""
5449
5450 ::
5451
5452 catchendpad unwind label
5453 catchendpad unwind to caller
5454
5455 Overview:
5456 """""""""
5457
5458 The '``catchendpad``' instruction is used by `LLVM's exception handling
5459 system `_ to communicate to the
5460 :ref:`personality function ` which invokes are associated
5461 with a chain of :ref:`catchpad ` instructions; propagating an
5462 exception out of a catch handler is represented by unwinding through its
5463 ``catchendpad``. Unwinding to the outer scope when a chain of catch handlers
5464 do not handle an exception is also represented by unwinding through their
5465 ``catchendpad``.
5466
5467 The ``nextaction`` label indicates where control should transfer to if
5468 none of the ``catchpad`` instructions are suitable for catching the
5469 in-flight exception.
5470
5471 If a ``nextaction`` label is not present, the instruction unwinds out of
5472 its parent function. The
5473 :ref:`personality function ` will continue processing
5474 exception handling actions in the caller.
5475
5476 Arguments:
5477 """"""""""
5478
5479 The instruction optionally takes a label, ``nextaction``, indicating
5480 where control should transfer to if none of the preceding
5481 ``catchpad`` instructions are suitable for the in-flight exception.
5482
5483 Semantics:
5484 """"""""""
5485
5486 When the call stack is being unwound due to an exception being thrown
5487 and none of the constituent ``catchpad`` instructions match, then
5488 control is transfered to ``nextaction`` if it is present. If it is not
5489 present, control is transfered to the caller.
5490
5491 The ``catchendpad`` instruction has several restrictions:
5492
5493 - A catch-end block is a basic block which is the unwind destination of
5494 an exceptional instruction.
5495 - A catch-end block must have a '``catchendpad``' instruction as its
5496 first non-PHI instruction.
5497 - There can be only one '``catchendpad``' instruction within the
5498 catch-end block.
5499 - A basic block that is not a catch-end block may not include a
5500 '``catchendpad``' instruction.
5501 - Exactly one catch block may unwind to a ``catchendpad``.
5502 - It is undefined behavior to execute a ``catchendpad`` if none of the
5503 '``catchpad``'s chained to it have been executed.
5504 - It is undefined behavior to execute a ``catchendpad`` twice without an
5505 intervening execution of one or more of the '``catchpad``'s chained to it.
5506 - It is undefined behavior to execute a ``catchendpad`` if, after the most
5507 recent execution of the normal successor edge of any ``catchpad`` chained
5508 to it, some ``catchret`` consuming that ``catchpad`` has already been
5509 executed.
5510 - It is undefined behavior to execute a ``catchendpad`` if, after the most
5511 recent execution of the normal successor edge of any ``catchpad`` chained
5512 to it, any other ``catchpad`` or ``cleanuppad`` has been executed but has
5513 not had a corresponding
5514 ``catchret``/``cleanupret``/``catchendpad``/``cleanupendpad`` executed.
5515
5516 Example:
5517 """"""""
5518
5519 .. code-block:: llvm
5520
5521 catchendpad unwind label %terminate
5522 catchendpad unwind to caller
5489 handler0:
5490 %tok = catchpad within %cs [i8** @_ZTIi]
55235491
55245492 .. _i_catchret:
55255493
55315499
55325500 ::
55335501
5534 catchret > to label
5502 catchret from > to label
55355503
55365504 Overview:
55375505 """""""""
55515519 Semantics:
55525520 """"""""""
55535521
5554 The '``catchret``' instruction ends the existing (in-flight) exception
5555 whose unwinding was interrupted with a
5556 :ref:`catchpad ` instruction.
5557 The :ref:`personality function ` gets a chance to execute
5558 arbitrary code to, for example, run a C++ destructor.
5559 Control then transfers to ``normal``.
5560 It may be passed an optional, personality specific, value.
5561
5562 It is undefined behavior to execute a ``catchret`` whose ``catchpad`` has
5563 not been executed.
5564
5565 It is undefined behavior to execute a ``catchret`` if, after the most recent
5566 execution of its ``catchpad``, some ``catchret`` or ``catchendpad`` linked
5567 to the same ``catchpad`` has already been executed.
5568
5569 It is undefined behavior to execute a ``catchret`` if, after the most recent
5570 execution of its ``catchpad``, any other ``catchpad`` or ``cleanuppad`` has
5571 been executed but has not had a corresponding
5572 ``catchret``/``cleanupret``/``catchendpad``/``cleanupendpad`` executed.
5522 The '``catchret``' instruction ends an existing (in-flight) exception whose
5523 unwinding was interrupted with a :ref:`catchpad ` instruction. The
5524 :ref:`personality function ` gets a chance to execute arbitrary
5525 code to, for example, destroy the active exception. Control then transfers to
5526 ``normal``.
5527
5528 The ``token`` argument must be a token produced by a dominating ``catchpad``
5529 instruction. The ``catchret`` destroys the physical frame established by
5530 ``catchpad``, so executing multiple returns on the same token without
5531 re-executing the ``catchpad`` will result in undefined behavior.
5532 See :ref:`catchpad ` for more details.
55735533
55745534 Example:
55755535 """"""""
55765536
55775537 .. code-block:: llvm
55785538
5579 catchret %catch label %continue
5580
5581 .. _i_cleanupendpad:
5582
5583 '``cleanupendpad``' Instruction
5584 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5585
5586 Syntax:
5587 """""""
5588
5589 ::
5590
5591 cleanupendpad unwind label
5592 cleanupendpad unwind to caller
5593
5594 Overview:
5595 """""""""
5596
5597 The '``cleanupendpad``' instruction is used by `LLVM's exception handling
5598 system `_ to communicate to the
5599 :ref:`personality function ` which invokes are associated
5600 with a :ref:`cleanuppad ` instructions; propagating an exception
5601 out of a cleanup is represented by unwinding through its ``cleanupendpad``.
5602
5603 The ``nextaction`` label indicates where control should unwind to next, in the
5604 event that a cleanup is exited by means of an(other) exception being raised.
5605
5606 If a ``nextaction`` label is not present, the instruction unwinds out of
5607 its parent function. The
5608 :ref:`personality function ` will continue processing
5609 exception handling actions in the caller.
5610
5611 Arguments:
5612 """"""""""
5613
5614 The '``cleanupendpad``' instruction requires one argument, which indicates
5615 which ``cleanuppad`` it exits, and must be a :ref:`cleanuppad `.
5616 It also has an optional successor, ``nextaction``, indicating where control
5617 should transfer to.
5618
5619 Semantics:
5620 """"""""""
5621
5622 When and exception propagates to a ``cleanupendpad``, control is transfered to
5623 ``nextaction`` if it is present. If it is not present, control is transfered to
5624 the caller.
5625
5626 The ``cleanupendpad`` instruction has several restrictions:
5627
5628 - A cleanup-end block is a basic block which is the unwind destination of
5629 an exceptional instruction.
5630 - A cleanup-end block must have a '``cleanupendpad``' instruction as its
5631 first non-PHI instruction.
5632 - There can be only one '``cleanupendpad``' instruction within the
5633 cleanup-end block.
5634 - A basic block that is not a cleanup-end block may not include a
5635 '``cleanupendpad``' instruction.
5636 - It is undefined behavior to execute a ``cleanupendpad`` whose ``cleanuppad``
5637 has not been executed.
5638 - It is undefined behavior to execute a ``cleanupendpad`` if, after the most
5639 recent execution of its ``cleanuppad``, some ``cleanupret`` or ``cleanupendpad``
5640 consuming the same ``cleanuppad`` has already been executed.
5641 - It is undefined behavior to execute a ``cleanupendpad`` if, after the most
5642 recent execution of its ``cleanuppad``, any other ``cleanuppad`` or
5643 ``catchpad`` has been executed but has not had a corresponding
5644 ``cleanupret``/``catchret``/``cleanupendpad``/``catchendpad`` executed.
5645
5646 Example:
5647 """"""""
5648
5649 .. code-block:: llvm
5650
5651 cleanupendpad %cleanup unwind label %terminate
5652 cleanupendpad %cleanup unwind to caller
5539 catchret from %catch label %continue
56535540
56545541 .. _i_cleanupret:
56555542
56615548
56625549 ::
56635550
5664 cleanupret unwind label
5665 cleanupret unwind to caller
5551 cleanupret from unwind label
5552 cleanupret from unwind to caller
56665553
56675554 Overview:
56685555 """""""""
56865573 :ref:`cleanuppad ` it transferred control to has ended.
56875574 It transfers control to ``continue`` or unwinds out of the function.
56885575
5689 It is undefined behavior to execute a ``cleanupret`` whose ``cleanuppad`` has
5690 not been executed.
5691
5692 It is undefined behavior to execute a ``cleanupret`` if, after the most recent
5693 execution of its ``cleanuppad``, some ``cleanupret`` or ``cleanupendpad``
5694 consuming the same ``cleanuppad`` has already been executed.
5695
5696 It is undefined behavior to execute a ``cleanupret`` if, after the most recent
5697 execution of its ``cleanuppad``, any other ``cleanuppad`` or ``catchpad`` has
5698 been executed but has not had a corresponding
5699 ``cleanupret``/``catchret``/``cleanupendpad``/``catchendpad`` executed.
5576 The unwind destination ``continue``, if present, must be an EH pad
5577 whose parent is either ``none`` or an ancestor of the ``cleanuppad``
5578 being returned from. This constitutes an exceptional exit from all
5579 ancestors of the completed ``cleanuppad``, up to but not including
5580 the parent of ``continue``.
5581 See :ref:`cleanuppad ` for more details.
57005582
57015583 Example:
57025584 """"""""
57035585
57045586 .. code-block:: llvm
57055587
5706 cleanupret %cleanup unwind to caller
5707 cleanupret %cleanup unwind label %continue
5588 cleanupret from %cleanup unwind to caller
5589 cleanupret from %cleanup unwind label %continue
57085590
57095591 .. _i_terminatepad:
57105592
57165598
57175599 ::
57185600
5719 terminatepad [*] unwind label
5720 terminatepad [*] unwind to caller
5601 terminatepad within [*] unwind label
5602 terminatepad within [*] unwind to caller
57215603
57225604 Overview:
57235605 """""""""
57515633 the first argument to ``terminatepad`` specifies what function the
57525634 personality should defer to in order to terminate the program.
57535635
5754 The ``terminatepad`` instruction has several restrictions:
5755
5756 - A terminate block is a basic block which is the unwind destination of
5757 an exceptional instruction.
5758 - A terminate block must have a '``terminatepad``' instruction as its
5759 first non-PHI instruction.
5760 - There can be only one '``terminatepad``' instruction within the
5761 terminate block.
5762 - A basic block that is not a terminate block may not include a
5763 '``terminatepad``' instruction.
5636 The ``terminatepad`` instruction is both a terminator and a "pad" instruction,
5637 meaning that is always the only non-phi instruction in the basic block.
57645638
57655639 Example:
57665640 """"""""
57685642 .. code-block:: llvm
57695643
57705644 ;; A terminate block which only permits integers.
5771 terminatepad [i8** @_ZTIi] unwind label %continue
5645 terminatepad within none [i8** @_ZTIi] unwind label %continue
57725646
57735647 .. _i_unreachable:
57745648
87618635
87628636 ::
87638637
8764 = cleanuppad [*]
8638 = cleanuppad within [*]
87658639
87668640 Overview:
87678641 """""""""
87748648 information the :ref:`personality function ` requires to
87758649 execute the cleanup.
87768650 The ``resultval`` has the type :ref:`token ` and is used to
8777 match the ``cleanuppad`` to corresponding :ref:`cleanuprets `
8778 and :ref:`cleanupendpads >`.
8651 match the ``cleanuppad`` to corresponding :ref:`cleanuprets >`.
8652 The ``parent`` argument is the token of the funclet that contains the
8653 ``cleanuppad`` instruction. If the ``cleanuppad`` is not inside a funclet,
8654 this operand may be the token ``none``.
87798655
87808656 Arguments:
87818657 """"""""""
88028678 cleanup block.
88038679 - A basic block that is not a cleanup block may not include a
88048680 '``cleanuppad``' instruction.
8805 - All '``cleanupret``'s and '``cleanupendpad``'s which consume a ``cleanuppad``
8806 must have the same exceptional successor.
8807 - It is undefined behavior for control to transfer from a ``cleanuppad`` to a
8808 ``ret`` without first executing a ``cleanupret`` or ``cleanupendpad`` that
8809 consumes the ``cleanuppad``.
8810 - It is undefined behavior for control to transfer from a ``cleanuppad`` to
8811 itself without first executing a ``cleanupret`` or ``cleanupendpad`` that
8812 consumes the ``cleanuppad``.
8681
8682 Executing a ``cleanuppad`` instruction constitutes "entering" that pad.
8683 The pad may then be "exited" in one of three ways:
8684 1) explicitly via a ``cleanupret`` that consumes it. Executing such a ``cleanupret``
8685 is undefined behavior if any descendant pads have been entered but not yet
8686 exited.
8687 2) implicitly via a call (which unwinds all the way to the current function's caller),
8688 or via a ``catchswitch``, ``cleanupret``, or ``terminatepad`` that unwinds to caller.
8689 3) implicitly via an unwind edge whose destination EH pad isn't a descendant of
8690 the ``cleanuppad``. When the ``cleanuppad`` is exited in this manner, it is
8691 undefined behavior if the destination EH pad has a parent which is not an
8692 ancestor of the ``cleanuppad`` being exited.
8693
8694 It is undefined behavior for the ``cleanuppad`` to exit via an unwind edge which
8695 does not transitively unwind to the same destination as a constituent
8696 ``cleanupret``.
88138697
88148698 Example:
88158699 """"""""
88168700
88178701 .. code-block:: llvm
88188702
8819 %tok = cleanuppad []
8703 %tok = cleanuppad within %cs []
88208704
88218705 .. _intrinsics:
88228706
99 #ifndef LLVM_ANALYSIS_EHPERSONALITIES_H
1010 #define LLVM_ANALYSIS_EHPERSONALITIES_H
1111
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/TinyPtrVector.h"
1214 #include "llvm/Support/ErrorHandling.h"
1315
1416 namespace llvm {
17 class BasicBlock;
1518 class Function;
1619 class Value;
1720
7780
7881 bool canSimplifyInvokeNoUnwind(const Function *F);
7982
83 typedef TinyPtrVector ColorVector;
84
85 /// \brief If an EH funclet personality is in use (see isFuncletEHPersonality),
86 /// this will recompute which blocks are in which funclet. It is possible that
87 /// some blocks are in multiple funclets. Consider this analysis to be
88 /// expensive.
89 DenseMap colorEHFunclets(Function &F);
90
8091 } // end namespace llvm
8192
8293 #endif
422422 FUNC_CODE_INST_CATCHPAD = 50, // CATCHPAD: [bb#,bb#,num,args...]
423423 FUNC_CODE_INST_TERMINATEPAD = 51, // TERMINATEPAD: [bb#,num,args...]
424424 FUNC_CODE_INST_CLEANUPPAD = 52, // CLEANUPPAD: [num,args...]
425 FUNC_CODE_INST_CATCHENDPAD = 53, // CATCHENDPAD: [] or [bb#]
426 FUNC_CODE_INST_CLEANUPENDPAD = 54, // CLEANUPENDPAD: [val] or [val,bb#]
427
425 FUNC_CODE_INST_CATCHSWITCH = 53, // CATCHSWITCH: [num,args...] or [num,args...,bb]
426 // 54 is unused.
428427 FUNC_CODE_OPERAND_BUNDLE = 55, // OPERAND_BUNDLE: [tag#, value...]
429428 };
430429
8888
8989 struct WinEHFuncInfo {
9090 DenseMap EHPadStateMap;
91 DenseMap FuncletBaseStateMap;
92 DenseMap InvokeStateMap;
9193 DenseMap
9294 CatchRetSuccessorColorMap;
93 DenseMap> InvokeToStateMap;
95 DenseMap> LabelToStateMap;
9496 SmallVector CxxUnwindMap;
9597 SmallVector TryBlockMap;
9698 SmallVector SEHUnwindMap;
100102
101103 int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }
102104
103 void addIPToStateRange(const BasicBlock *PadBB, MCSymbol *InvokeBegin,
105 void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
104106 MCSymbol *InvokeEnd);
105107
106108 int EHRegNodeFrameIndex = INT_MAX;
707707 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
708708 }
709709
710 CleanupEndPadInst *CreateCleanupEndPad(CleanupPadInst *CleanupPad,
711 BasicBlock *UnwindBB = nullptr) {
712 return Insert(CleanupEndPadInst::Create(CleanupPad, UnwindBB));
713 }
714
715 CatchPadInst *CreateCatchPad(BasicBlock *NormalDest, BasicBlock *UnwindDest,
716 ArrayRef Args, const Twine &Name = "") {
717 return Insert(CatchPadInst::Create(NormalDest, UnwindDest, Args), Name);
718 }
719
720 CatchEndPadInst *CreateCatchEndPad(BasicBlock *UnwindBB = nullptr) {
721 return Insert(CatchEndPadInst::Create(Context, UnwindBB));
722 }
723
724 TerminatePadInst *CreateTerminatePad(BasicBlock *UnwindBB = nullptr,
725 ArrayRef Args = {},
710 CatchSwitchInst *CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB,
711 unsigned NumHandlers,
712 const Twine &Name = "") {
713 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
714 Name);
715 }
716
717 CatchPadInst *CreateCatchPad(Value *ParentPad, ArrayRef Args,
718 const Twine &Name = "") {
719 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
720 }
721
722 TerminatePadInst *CreateTerminatePad(Value *ParentPad,
723 BasicBlock *UnwindBB = nullptr,
724 ArrayRef Args = None,
726725 const Twine &Name = "") {
727 return Insert(TerminatePadInst::Create(Context, UnwindBB, Args), Name);
728 }
729
730 CleanupPadInst *CreateCleanupPad(ArrayRef Args,
726 return Insert(TerminatePadInst::Create(ParentPad, UnwindBB, Args), Name);
727 }
728
729 CleanupPadInst *CreateCleanupPad(Value *ParentPad,
730 ArrayRef Args = None,
731731 const Twine &Name = "") {
732 return Insert(CleanupPadInst::Create(Context, Args), Name);
732 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
733733 }
734734
735735 CatchReturnInst *CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB) {
169169 RetTy visitResumeInst(ResumeInst &I) { DELEGATE(TerminatorInst);}
170170 RetTy visitUnreachableInst(UnreachableInst &I) { DELEGATE(TerminatorInst);}
171171 RetTy visitCleanupReturnInst(CleanupReturnInst &I) { DELEGATE(TerminatorInst);}
172 RetTy visitCleanupEndPadInst(CleanupEndPadInst &I) { DELEGATE(TerminatorInst); }
173172 RetTy visitCatchReturnInst(CatchReturnInst &I) { DELEGATE(TerminatorInst); }
174 RetTy visitCatchPadInst(CatchPadInst &I) { DELEGATE(TerminatorInst);}
175 RetTy visitCatchEndPadInst(CatchEndPadInst &I) { DELEGATE(TerminatorInst); }
173 RetTy visitCatchSwitchInst(CatchSwitchInst &I) { DELEGATE(TerminatorInst);}
176174 RetTy visitTerminatePadInst(TerminatePadInst &I) { DELEGATE(TerminatorInst);}
177175 RetTy visitICmpInst(ICmpInst &I) { DELEGATE(CmpInst);}
178176 RetTy visitFCmpInst(FCmpInst &I) { DELEGATE(CmpInst);}
205203 RetTy visitExtractValueInst(ExtractValueInst &I){ DELEGATE(UnaryInstruction);}
206204 RetTy visitInsertValueInst(InsertValueInst &I) { DELEGATE(Instruction); }
207205 RetTy visitLandingPadInst(LandingPadInst &I) { DELEGATE(Instruction); }
208 RetTy visitCleanupPadInst(CleanupPadInst &I) { DELEGATE(Instruction); }
206 RetTy visitFuncletPadInst(FuncletPadInst &I) { DELEGATE(Instruction); }
207 RetTy visitCleanupPadInst(CleanupPadInst &I) { DELEGATE(FuncletPadInst); }
208 RetTy visitCatchPadInst(CatchPadInst &I) { DELEGATE(FuncletPadInst); }
209209
210210 // Handle the special instrinsic instruction classes.
211211 RetTy visitDbgDeclareInst(DbgDeclareInst &I) { DELEGATE(DbgInfoIntrinsic);}
8181 // \brief Returns true if this terminator relates to exception handling.
8282 bool isExceptional() const {
8383 switch (getOpcode()) {
84 case Instruction::CatchPad:
85 case Instruction::CatchEndPad:
84 case Instruction::CatchSwitch:
8685 case Instruction::CatchRet:
87 case Instruction::CleanupEndPad:
8886 case Instruction::CleanupRet:
8987 case Instruction::Invoke:
9088 case Instruction::Resume:
11101108 };
11111109
11121110 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CmpInst, Value)
1111
1112 //===----------------------------------------------------------------------===//
1113 // FuncletPadInst Class
1114 //===----------------------------------------------------------------------===//
1115 class FuncletPadInst : public Instruction {
1116 private:
1117 void init(Value *ParentPad, ArrayRef Args, const Twine &NameStr);
1118
1119 FuncletPadInst(const FuncletPadInst &CPI);
1120
1121 explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
1122 ArrayRef Args, unsigned Values,
1123 const Twine &NameStr, Instruction *InsertBefore);
1124 explicit FuncletPadInst(Instruction::FuncletPadOps Op, Value *ParentPad,
1125 ArrayRef Args, unsigned Values,
1126 const Twine &NameStr, BasicBlock *InsertAtEnd);
1127
1128 protected:
1129 // Note: Instruction needs to be a friend here to call cloneImpl.
1130 friend class Instruction;
1131 friend class CatchPadInst;
1132 friend class CleanupPadInst;
1133 FuncletPadInst *cloneImpl() const;
1134
1135 public:
1136 /// Provide fast operand accessors
1137 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
1138
1139 /// getNumArgOperands - Return the number of funcletpad arguments.
1140 ///
1141 unsigned getNumArgOperands() const { return getNumOperands() - 1; }
1142
1143 /// Convenience accessors
1144
1145 /// \brief Return the outer EH-pad this funclet is nested within.
1146 ///
1147 /// Note: This returns the associated CatchSwitchInst if this FuncletPadInst
1148 /// is a CatchPadInst.
1149 Value *getParentPad() const { return Op<-1>(); }
1150 void setParentPad(Value *ParentPad) {
1151 assert(ParentPad);
1152 Op<-1>() = ParentPad;
1153 }
1154
1155 /// getArgOperand/setArgOperand - Return/set the i-th funcletpad argument.
1156 ///
1157 Value *getArgOperand(unsigned i) const { return getOperand(i); }
1158 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
1159
1160 /// arg_operands - iteration adapter for range-for loops.
1161 op_range arg_operands() { return op_range(op_begin(), op_end() - 1); }
1162
1163 /// arg_operands - iteration adapter for range-for loops.
1164 const_op_range arg_operands() const {
1165 return const_op_range(op_begin(), op_end() - 1);
1166 }
1167
1168 // Methods for support type inquiry through isa, cast, and dyn_cast:
1169 static inline bool classof(const Instruction *I) { return I->isFuncletPad(); }
1170 static inline bool classof(const Value *V) {
1171 return isa(V) && classof(cast(V));
1172 }
1173 };
1174
1175 template <>
1176 struct OperandTraits
1177 : public VariadicOperandTraits {};
1178
1179 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(FuncletPadInst, Value)
11131180
11141181 /// \brief A lightweight accessor for an operand bundle meant to be passed
11151182 /// around by value.
7171 #endif
7272 #ifndef LAST_CAST_INST
7373 #define LAST_CAST_INST(num)
74 #endif
75
76 #ifndef FIRST_FUNCLETPAD_INST
77 #define FIRST_FUNCLETPAD_INST(num)
78 #endif
79 #ifndef HANDLE_FUNCLETPAD_INST
80 #ifndef HANDLE_INST
81 #define HANDLE_FUNCLETPAD_INST(num, opcode, Class)
82 #else
83 #define HANDLE_FUNCLETPAD_INST(num, opcode, Class) HANDLE_INST(num, opcode, Class)
84 #endif
85 #endif
86 #ifndef LAST_FUNCLETPAD_INST
87 #define LAST_FUNCLETPAD_INST(num)
7488 #endif
7589
7690 #ifndef FIRST_OTHER_INST
101115 HANDLE_TERM_INST ( 7, Unreachable , UnreachableInst)
102116 HANDLE_TERM_INST ( 8, CleanupRet , CleanupReturnInst)
103117 HANDLE_TERM_INST ( 9, CatchRet , CatchReturnInst)
104 HANDLE_TERM_INST (10, CatchPad , CatchPadInst)
118 HANDLE_TERM_INST (10, CatchSwitch , CatchSwitchInst)
105119 HANDLE_TERM_INST (11, TerminatePad , TerminatePadInst)
106 HANDLE_TERM_INST (12, CatchEndPad , CatchEndPadInst)
107 HANDLE_TERM_INST (13, CleanupEndPad , CleanupEndPadInst)
108 LAST_TERM_INST (13)
120 LAST_TERM_INST (11)
109121
110122 // Standard binary operators...
111 FIRST_BINARY_INST(14)
112 HANDLE_BINARY_INST(14, Add , BinaryOperator)
113 HANDLE_BINARY_INST(15, FAdd , BinaryOperator)
114 HANDLE_BINARY_INST(16, Sub , BinaryOperator)
115 HANDLE_BINARY_INST(17, FSub , BinaryOperator)
116 HANDLE_BINARY_INST(18, Mul , BinaryOperator)
117 HANDLE_BINARY_INST(19, FMul , BinaryOperator)
118 HANDLE_BINARY_INST(20, UDiv , BinaryOperator)
119 HANDLE_BINARY_INST(21, SDiv , BinaryOperator)
120 HANDLE_BINARY_INST(22, FDiv , BinaryOperator)
121 HANDLE_BINARY_INST(23, URem , BinaryOperator)
122 HANDLE_BINARY_INST(24, SRem , BinaryOperator)
123 HANDLE_BINARY_INST(25, FRem , BinaryOperator)
123 FIRST_BINARY_INST(12)
124 HANDLE_BINARY_INST(12, Add , BinaryOperator)
125 HANDLE_BINARY_INST(13, FAdd , BinaryOperator)
126 HANDLE_BINARY_INST(14, Sub , BinaryOperator)
127 HANDLE_BINARY_INST(15, FSub , BinaryOperator)
128 HANDLE_BINARY_INST(16, Mul , BinaryOperator)
129 HANDLE_BINARY_INST(17, FMul , BinaryOperator)
130 HANDLE_BINARY_INST(18, UDiv , BinaryOperator)
131 HANDLE_BINARY_INST(19, SDiv , BinaryOperator)
132 HANDLE_BINARY_INST(20, FDiv , BinaryOperator)
133 HANDLE_BINARY_INST(21, URem , BinaryOperator)
134 HANDLE_BINARY_INST(22, SRem , BinaryOperator)
135 HANDLE_BINARY_INST(23, FRem , BinaryOperator)
124136
125137 // Logical operators (integer operands)
126 HANDLE_BINARY_INST(26, Shl , BinaryOperator) // Shift left (logical)
127 HANDLE_BINARY_INST(27, LShr , BinaryOperator) // Shift right (logical)
128 HANDLE_BINARY_INST(28, AShr , BinaryOperator) // Shift right (arithmetic)
129 HANDLE_BINARY_INST(29, And , BinaryOperator)
130 HANDLE_BINARY_INST(30, Or , BinaryOperator)
131 HANDLE_BINARY_INST(31, Xor , BinaryOperator)
132 LAST_BINARY_INST(31)
138 HANDLE_BINARY_INST(24, Shl , BinaryOperator) // Shift left (logical)
139 HANDLE_BINARY_INST(25, LShr , BinaryOperator) // Shift right (logical)
140 HANDLE_BINARY_INST(26, AShr , BinaryOperator) // Shift right (arithmetic)
141 HANDLE_BINARY_INST(27, And , BinaryOperator)
142 HANDLE_BINARY_INST(28, Or , BinaryOperator)
143 HANDLE_BINARY_INST(29, Xor , BinaryOperator)
144 LAST_BINARY_INST(29)
133145
134146 // Memory operators...
135 FIRST_MEMORY_INST(32)
136 HANDLE_MEMORY_INST(32, Alloca, AllocaInst) // Stack management
137 HANDLE_MEMORY_INST(33, Load , LoadInst ) // Memory manipulation instrs
138 HANDLE_MEMORY_INST(34, Store , StoreInst )
139 HANDLE_MEMORY_INST(35, GetElementPtr, GetElementPtrInst)
140 HANDLE_MEMORY_INST(36, Fence , FenceInst )
141 HANDLE_MEMORY_INST(37, AtomicCmpXchg , AtomicCmpXchgInst )
142 HANDLE_MEMORY_INST(38, AtomicRMW , AtomicRMWInst )
143 LAST_MEMORY_INST(38)
147 FIRST_MEMORY_INST(30)
148 HANDLE_MEMORY_INST(30, Alloca, AllocaInst) // Stack management
149 HANDLE_MEMORY_INST(31, Load , LoadInst ) // Memory manipulation instrs
150 HANDLE_MEMORY_INST(32, Store , StoreInst )
151 HANDLE_MEMORY_INST(33, GetElementPtr, GetElementPtrInst)
152 HANDLE_MEMORY_INST(34, Fence , FenceInst )
153 HANDLE_MEMORY_INST(35, AtomicCmpXchg , AtomicCmpXchgInst )
154 HANDLE_MEMORY_INST(36, AtomicRMW , AtomicRMWInst )
155 LAST_MEMORY_INST(36)
144156
145157 // Cast operators ...
146158 // NOTE: The order matters here because CastInst::isEliminableCastPair
147159 // NOTE: (see Instructions.cpp) encodes a table based on this ordering.
148 FIRST_CAST_INST(39)
149 HANDLE_CAST_INST(39, Trunc , TruncInst ) // Truncate integers
150 HANDLE_CAST_INST(40, ZExt , ZExtInst ) // Zero extend integers
151 HANDLE_CAST_INST(41, SExt , SExtInst ) // Sign extend integers
152 HANDLE_CAST_INST(42, FPToUI , FPToUIInst ) // floating point -> UInt
153 HANDLE_CAST_INST(43, FPToSI , FPToSIInst ) // floating point -> SInt
154 HANDLE_CAST_INST(44, UIToFP , UIToFPInst ) // UInt -> floating point
155 HANDLE_CAST_INST(45, SIToFP , SIToFPInst ) // SInt -> floating point
156 HANDLE_CAST_INST(46, FPTrunc , FPTruncInst ) // Truncate floating point
157 HANDLE_CAST_INST(47, FPExt , FPExtInst ) // Extend floating point
158 HANDLE_CAST_INST(48, PtrToInt, PtrToIntInst) // Pointer -> Integer
159 HANDLE_CAST_INST(49, IntToPtr, IntToPtrInst) // Integer -> Pointer
160 HANDLE_CAST_INST(50, BitCast , BitCastInst ) // Type cast
161 HANDLE_CAST_INST(51, AddrSpaceCast, AddrSpaceCastInst) // addrspace cast
162 LAST_CAST_INST(51)
160 FIRST_CAST_INST(37)
161 HANDLE_CAST_INST(37, Trunc , TruncInst ) // Truncate integers
162 HANDLE_CAST_INST(38, ZExt , ZExtInst ) // Zero extend integers
163 HANDLE_CAST_INST(39, SExt , SExtInst ) // Sign extend integers
164 HANDLE_CAST_INST(40, FPToUI , FPToUIInst ) // floating point -> UInt
165 HANDLE_CAST_INST(41, FPToSI , FPToSIInst ) // floating point -> SInt
166 HANDLE_CAST_INST(42, UIToFP , UIToFPInst ) // UInt -> floating point
167 HANDLE_CAST_INST(43, SIToFP , SIToFPInst ) // SInt -> floating point
168 HANDLE_CAST_INST(44, FPTrunc , FPTruncInst ) // Truncate floating point
169 HANDLE_CAST_INST(45, FPExt , FPExtInst ) // Extend floating point
170 HANDLE_CAST_INST(46, PtrToInt, PtrToIntInst) // Pointer -> Integer
171 HANDLE_CAST_INST(47, IntToPtr, IntToPtrInst) // Integer -> Pointer
172 HANDLE_CAST_INST(48, BitCast , BitCastInst ) // Type cast
173 HANDLE_CAST_INST(49, AddrSpaceCast, AddrSpaceCastInst) // addrspace cast
174 LAST_CAST_INST(49)
175
176 FIRST_FUNCLETPAD_INST(50)
177 HANDLE_FUNCLETPAD_INST(50, CleanupPad, CleanupPadInst)
178 HANDLE_FUNCLETPAD_INST(51, CatchPad , CatchPadInst)
179 LAST_FUNCLETPAD_INST(51)
163180
164181 // Other operators...
165182 FIRST_OTHER_INST(52)
177194 HANDLE_OTHER_INST(63, ExtractValue, ExtractValueInst)// extract from aggregate
178195 HANDLE_OTHER_INST(64, InsertValue, InsertValueInst) // insert into aggregate
179196 HANDLE_OTHER_INST(65, LandingPad, LandingPadInst) // Landing pad instruction.
180 HANDLE_OTHER_INST(66, CleanupPad, CleanupPadInst)
181 LAST_OTHER_INST(66)
197 LAST_OTHER_INST(65)
182198
183199 #undef FIRST_TERM_INST
184200 #undef HANDLE_TERM_INST
196212 #undef HANDLE_CAST_INST
197213 #undef LAST_CAST_INST
198214
215 #undef FIRST_FUNCLETPAD_INST
216 #undef HANDLE_FUNCLETPAD_INST
217 #undef LAST_FUNCLETPAD_INST
218
199219 #undef FIRST_OTHER_INST
200220 #undef HANDLE_OTHER_INST
201221 #undef LAST_OTHER_INST
108108 bool isBinaryOp() const { return isBinaryOp(getOpcode()); }
109109 bool isShift() { return isShift(getOpcode()); }
110110 bool isCast() const { return isCast(getOpcode()); }
111 bool isFuncletPad() const { return isFuncletPad(getOpcode()); }
111112
112113 static const char* getOpcodeName(unsigned OpCode);
113114
138139 /// @brief Determine if the OpCode is one of the CastInst instructions.
139140 static inline bool isCast(unsigned OpCode) {
140141 return OpCode >= CastOpsBegin && OpCode < CastOpsEnd;
142 }
143
144 /// @brief Determine if the OpCode is one of the FuncletPadInst instructions.
145 static inline bool isFuncletPad(unsigned OpCode) {
146 return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd;
141147 }
142148
143149 //===--------------------------------------------------------------------===//
385391 /// \brief Return true if the instruction is a variety of EH-block.
386392 bool isEHPad() const {
387393 switch (getOpcode()) {
394 case Instruction::CatchSwitch:
388395 case Instruction::CatchPad:
389 case Instruction::CatchEndPad:
390396 case Instruction::CleanupPad:
391 case Instruction::CleanupEndPad:
392397 case Instruction::LandingPad:
393398 case Instruction::TerminatePad:
394399 return true;
477482 #include "llvm/IR/Instruction.def"
478483 };
479484
485 enum FuncletPadOps {
486 #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N,
487 #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N,
488 #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1
489 #include "llvm/IR/Instruction.def"
490 };
491
480492 enum OtherOps {
481493 #define FIRST_OTHER_INST(N) OtherOpsBegin = N,
482494 #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N,
1717
1818 #include "llvm/ADT/ArrayRef.h"
1919 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/STLExtras.h"
2021 #include "llvm/ADT/iterator_range.h"
2122 #include "llvm/IR/Attributes.h"
2223 #include "llvm/IR/CallingConv.h"
38183819 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)
38193820
38203821 //===----------------------------------------------------------------------===//
3821 // CatchEndPadInst Class
3822 //===----------------------------------------------------------------------===//
3823
3824 class CatchEndPadInst : public TerminatorInst {
3825 private:
3826 CatchEndPadInst(const CatchEndPadInst &RI);
3827
3828 void init(BasicBlock *UnwindBB);
3829 CatchEndPadInst(LLVMContext &C, BasicBlock *UnwindBB, unsigned Values,
3830 Instruction *InsertBefore = nullptr);
3831 CatchEndPadInst(LLVMContext &C, BasicBlock *UnwindBB, unsigned Values,
3822 // CatchSwitchInst Class
3823 //===----------------------------------------------------------------------===//
3824 class CatchSwitchInst : public TerminatorInst {
3825 void *operator new(size_t, unsigned) = delete;
3826 /// ReservedSpace - The number of operands actually allocated. NumOperands is
3827 /// the number actually in use.
3828 unsigned ReservedSpace;
3829 // Operand[0] = Outer scope
3830 // Operand[1] = Unwind block destination
3831 // Operand[n] = BasicBlock to go to on match
3832 CatchSwitchInst(const CatchSwitchInst &CSI);
3833 void init(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumReserved);
3834 void growOperands(unsigned Size);
3835 // allocate space for exactly zero operands
3836 void *operator new(size_t s) { return User::operator new(s); }
3837 /// CatchSwitchInst ctor - Create a new switch instruction, specifying a
3838 /// default destination. The number of additional handlers can be specified
3839 /// here to make memory allocation more efficient.
3840 /// This constructor can also autoinsert before another instruction.
3841 CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
3842 unsigned NumHandlers, const Twine &NameStr,
3843 Instruction *InsertBefore);
3844
3845 /// CatchSwitchInst ctor - Create a new switch instruction, specifying a
3846 /// default destination. The number of additional handlers can be specified
3847 /// here to make memory allocation more efficient.
3848 /// This constructor also autoinserts at the end of the specified BasicBlock.
3849 CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
3850 unsigned NumHandlers, const Twine &NameStr,
38323851 BasicBlock *InsertAtEnd);
38333852
38343853 protected:
38353854 // Note: Instruction needs to be a friend here to call cloneImpl.
38363855 friend class Instruction;
3837 CatchEndPadInst *cloneImpl() const;
3856 CatchSwitchInst *cloneImpl() const;
38383857
38393858 public:
3840 static CatchEndPadInst *Create(LLVMContext &C, BasicBlock *UnwindBB = nullptr,
3859 static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
3860 unsigned NumHandlers,
3861 const Twine &NameStr = "",
38413862 Instruction *InsertBefore = nullptr) {
3842 unsigned Values = UnwindBB ? 1 : 0;
3843 return new (Values) CatchEndPadInst(C, UnwindBB, Values, InsertBefore);
3844 }
3845 static CatchEndPadInst *Create(LLVMContext &C, BasicBlock *UnwindBB,
3863 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
3864 InsertBefore);
3865 }
3866 static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
3867 unsigned NumHandlers, const Twine &NameStr,
38463868 BasicBlock *InsertAtEnd) {
3847 unsigned Values = UnwindBB ? 1 : 0;
3848 return new (Values) CatchEndPadInst(C, UnwindBB, Values, InsertAtEnd);
3869 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
3870 InsertAtEnd);
38493871 }
38503872
38513873 /// Provide fast operand accessors
38523874 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
38533875
3876 // Accessor Methods for CatchSwitch stmt
3877 Value *getParentPad() const { return getOperand(0); }
3878 void setParentPad(Value *ParentPad) { setOperand(0, ParentPad); }
3879
3880 // Accessor Methods for CatchSwitch stmt
38543881 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
38553882 bool unwindsToCaller() const { return !hasUnwindDest(); }
3856
3857 /// Convenience accessor. Returns null if there is no return value.
3858 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
3859
38603883 BasicBlock *getUnwindDest() const {
3861 return hasUnwindDest() ? cast(Op<-1>()) : nullptr;
3862 }
3863 void setUnwindDest(BasicBlock *NewDest) {
3864 assert(NewDest);
3865 Op<-1>() = NewDest;
3884 if (hasUnwindDest())
3885 return cast(getOperand(1));
3886 return nullptr;
3887 }
3888 void setUnwindDest(BasicBlock *UnwindDest) {
3889 assert(UnwindDest);
3890 assert(hasUnwindDest());
3891 setOperand(1, UnwindDest);
3892 }
3893
3894 /// getNumHandlers - return the number of 'handlers' in this catchswitch
3895 /// instruction, except the default handler
3896 unsigned getNumHandlers() const {
3897 if (hasUnwindDest())
3898 return getNumOperands() - 2;
3899 return getNumOperands() - 1;
3900 }
3901
3902 private:
3903 static BasicBlock *handler_helper(Value *V) { return cast(V); }
3904 static const BasicBlock *handler_helper(const Value *V) {
3905 return cast(V);
3906 }
3907
3908 public:
3909 typedef std::pointer_to_unary_function DerefFnTy;
3910 typedef mapped_iterator handler_iterator;
3911 typedef iterator_range handler_range;
3912
3913
3914 typedef std::pointer_to_unary_function
3915 ConstDerefFnTy;
3916 typedef mapped_iterator const_handler_iterator;
3917 typedef iterator_range const_handler_range;
3918
3919 /// Returns an iterator that points to the first handler in CatchSwitchInst.
3920 handler_iterator handler_begin() {
3921 op_iterator It = op_begin() + 1;
3922 if (hasUnwindDest())
3923 ++It;
3924 return handler_iterator(It, DerefFnTy(handler_helper));
3925 }
3926 /// Returns an iterator that points to the first handler in the
3927 /// CatchSwitchInst.
3928 const_handler_iterator handler_begin() const {
3929 const_op_iterator It = op_begin() + 1;
3930 if (hasUnwindDest())
3931 ++It;
3932 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
3933 }
3934
3935 /// Returns a read-only iterator that points one past the last
3936 /// handler in the CatchSwitchInst.
3937 handler_iterator handler_end() {
3938 return handler_iterator(op_end(), DerefFnTy(handler_helper));
3939 }
3940 /// Returns an iterator that points one past the last handler in the
3941 /// CatchSwitchInst.
3942 const_handler_iterator handler_end() const {
3943 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
3944 }
3945
3946 /// handlers - iteration adapter for range-for loops.
3947 handler_range handlers() {
3948 return make_range(handler_begin(), handler_end());
3949 }
3950
3951 /// handlers - iteration adapter for range-for loops.
3952 const_handler_range handlers() const {
3953 return make_range(handler_begin(), handler_end());
3954 }
3955
3956 /// addHandler - Add an entry to the switch instruction...
3957 /// Note:
3958 /// This action invalidates handler_end(). Old handler_end() iterator will
3959 /// point to the added handler.
3960 void addHandler(BasicBlock *Dest);
3961
3962 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
3963 BasicBlock *getSuccessor(unsigned Idx) const {
3964 assert(Idx < getNumSuccessors() &&
3965 "Successor # out of range for catchswitch!");
3966 return cast(getOperand(Idx + 1));
3967 }
3968 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
3969 assert(Idx < getNumSuccessors() &&
3970 "Successor # out of range for catchswitch!");
3971 setOperand(Idx + 1, NewSucc);
38663972 }
38673973
38683974 // Methods for support type inquiry through isa, cast, and dyn_cast:
38693975 static inline bool classof(const Instruction *I) {
3870 return (I->getOpcode() == Instruction::CatchEndPad);
3976 return I->getOpcode() == Instruction::CatchSwitch;
38713977 }
38723978 static inline bool classof(const Value *V) {
38733979 return isa(V) && classof(cast(V));
38773983 BasicBlock *getSuccessorV(unsigned Idx) const override;
38783984 unsigned getNumSuccessorsV() const override;
38793985 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
3986 };
3987
3988 template <>
3989 struct OperandTraits : public HungoffOperandTraits<2> {};
3990
3991 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchSwitchInst, Value)
3992
3993 //===----------------------------------------------------------------------===//
3994 // TerminatePadInst Class
3995 //===----------------------------------------------------------------------===//
3996
3997 class TerminatePadInst : public TerminatorInst {
3998 private:
3999 void init(Value *ParentPad, BasicBlock *BB, ArrayRef Args);
4000
4001 TerminatePadInst(const TerminatePadInst &TPI);
4002
4003 explicit TerminatePadInst(Value *ParentPad, BasicBlock *BB,
4004 ArrayRef Args, unsigned Values,
4005 Instruction *InsertBefore);
4006 explicit TerminatePadInst(Value *ParentPad, BasicBlock *BB,
4007 ArrayRef Args, unsigned Values,
4008 BasicBlock *InsertAtEnd);
4009
4010 protected:
4011 // Note: Instruction needs to be a friend here to call cloneImpl.
4012 friend class Instruction;
4013 TerminatePadInst *cloneImpl() const;
4014
4015 public:
4016 static TerminatePadInst *Create(Value *ParentPad, BasicBlock *BB = nullptr,
4017 ArrayRef Args = None,
4018 Instruction *InsertBefore = nullptr) {
4019 unsigned Values = unsigned(Args.size()) + 1;
4020 if (BB)
4021 ++Values;
4022 return new (Values)
4023 TerminatePadInst(ParentPad, BB, Args, Values, InsertBefore);
4024 }
4025 static TerminatePadInst *Create(Value *ParentPad, BasicBlock *BB,
4026 ArrayRef Args,
4027 BasicBlock *InsertAtEnd) {
4028 unsigned Values = unsigned(Args.size()) + 1;
4029 if (BB)
4030 ++Values;
4031 return new (Values)
4032 TerminatePadInst(ParentPad, BB, Args, Values, InsertAtEnd);
4033 }
4034
4035 /// Provide fast operand accessors
4036 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4037
4038 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4039 bool unwindsToCaller() const { return !hasUnwindDest(); }
4040
4041 /// getNumArgOperands - Return the number of terminatepad arguments.
4042 ///
4043 unsigned getNumArgOperands() const {
4044 unsigned NumOperands = getNumOperands();
4045 if (hasUnwindDest())
4046 return NumOperands - 2;
4047 return NumOperands - 1;
4048 }
4049
4050 /// Convenience accessors
4051 Value *getParentPad() const { return Op<-1>(); }
4052 void setParentPad(Value *ParentPad) {
4053 assert(ParentPad);
4054 Op<-1>() = ParentPad;
4055 }
4056
4057 /// getArgOperand/setArgOperand - Return/set the i-th terminatepad argument.
4058 ///
4059 Value *getArgOperand(unsigned i) const { return getOperand(i); }
4060 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
4061
4062 const_op_iterator arg_begin() const { return op_begin(); }
4063 op_iterator arg_begin() { return op_begin(); }
4064
4065 const_op_iterator arg_end() const {
4066 if (hasUnwindDest())
4067 return op_end() - 2;
4068 return op_end() - 1;
4069 }
4070
4071 op_iterator arg_end() {
4072 if (hasUnwindDest())
4073 return op_end() - 2;
4074 return op_end() - 1;
4075 }
4076
4077 /// arg_operands - iteration adapter for range-for loops.
4078 iterator_range arg_operands() {
4079 return make_range(arg_begin(), arg_end());
4080 }
4081
4082 /// arg_operands - iteration adapter for range-for loops.
4083 iterator_range arg_operands() const {
4084 return make_range(arg_begin(), arg_end());
4085 }
4086
4087 /// \brief Wrappers for getting the \c Use of a terminatepad argument.
4088 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
4089 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
4090
4091 // get*Dest - Return the destination basic blocks...
4092 BasicBlock *getUnwindDest() const {
4093 if (!hasUnwindDest())
4094 return nullptr;
4095 return cast(Op<-2>());
4096 }
4097 void setUnwindDest(BasicBlock *B) {
4098 assert(B && hasUnwindDest());
4099 Op<-2>() = B;
4100 }
4101
4102 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4103
4104 // Methods for support type inquiry through isa, cast, and dyn_cast:
4105 static inline bool classof(const Instruction *I) {
4106 return I->getOpcode() == Instruction::TerminatePad;
4107 }
4108 static inline bool classof(const Value *V) {
4109 return isa(V) && classof(cast(V));
4110 }
4111
4112 private:
4113 BasicBlock *getSuccessorV(unsigned idx) const override;
4114 unsigned getNumSuccessorsV() const override;
4115 void setSuccessorV(unsigned idx, BasicBlock *B) override;
38804116
38814117 // Shadow Instruction::setInstructionSubclassData with a private forwarding
38824118 // method so that subclasses cannot accidentally use it.
38864122 };
38874123
38884124 template <>
3889 struct OperandTraits
3890 : public VariadicOperandTraits {};
3891
3892 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchEndPadInst, Value)
3893
3894 //===----------------------------------------------------------------------===//
3895 // CatchPadInst Class
3896 //===----------------------------------------------------------------------===//
3897
3898 class CatchPadInst : public TerminatorInst {
4125 struct OperandTraits
4126 : public VariadicOperandTraits {};
4127
4128 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(TerminatePadInst, Value)
4129
4130 //===----------------------------------------------------------------------===//
4131 // CleanupPadInst Class
4132 //===----------------------------------------------------------------------===//
4133 class CleanupPadInst : public FuncletPadInst {
38994134 private:
3900 void init(BasicBlock *IfNormal, BasicBlock *IfException,
3901 ArrayRef Args, const Twine &NameStr);
3902
3903 CatchPadInst(const CatchPadInst &CPI);
3904
3905 explicit CatchPadInst(BasicBlock *IfNormal, BasicBlock *IfException,
3906 ArrayRef Args, unsigned Values,
3907 const Twine &NameStr, Instruction *InsertBefore);
3908 explicit CatchPadInst(BasicBlock *IfNormal, BasicBlock *IfException,
3909 ArrayRef Args, unsigned Values,
3910 const Twine &NameStr, BasicBlock *InsertAtEnd);
3911
3912 protected:
3913 // Note: Instruction needs to be a friend here to call cloneImpl.
3914 friend class Instruction;
3915 CatchPadInst *cloneImpl() const;
4135 explicit CleanupPadInst(Value *ParentPad, ArrayRef Args,
4136 unsigned Values, const Twine &NameStr,
4137 Instruction *InsertBefore)
4138 : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
4139 NameStr, InsertBefore) {}
4140 explicit CleanupPadInst(Value *ParentPad, ArrayRef Args,
4141 unsigned Values, const Twine &NameStr,
4142 BasicBlock *InsertAtEnd)
4143 : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
4144 NameStr, InsertAtEnd) {}
39164145
39174146 public:
3918 static CatchPadInst *Create(BasicBlock *IfNormal, BasicBlock *IfException,
3919 ArrayRef Args, const Twine &NameStr = "",
4147 static CleanupPadInst *Create(Value *ParentPad, ArrayRef Args = None,
4148 const Twine &NameStr = "",
4149 Instruction *InsertBefore = nullptr) {
4150 unsigned Values = 1 + Args.size();
4151 return new (Values)
4152 CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore);
4153 }
4154 static CleanupPadInst *Create(Value *ParentPad, ArrayRef Args,
4155 const Twine &NameStr, BasicBlock *InsertAtEnd) {
4156 unsigned Values = 1 + Args.size();
4157 return new (Values)
4158 CleanupPadInst(ParentPad, Args, Values, NameStr, InsertAtEnd);
4159 }
4160
4161 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
4162 static inline bool classof(const Instruction *I) {
4163 return I->getOpcode() == Instruction::CleanupPad;
4164 }
4165 static inline bool classof(const Value *V) {
4166 return isa(V) && classof(cast(V));
4167 }
4168 };
4169
4170 //===----------------------------------------------------------------------===//
4171 // CatchPadInst Class
4172 //===----------------------------------------------------------------------===//
4173 class CatchPadInst : public FuncletPadInst {
4174 private:
4175 explicit CatchPadInst(Value *CatchSwitch, ArrayRef Args,
4176 unsigned Values, const Twine &NameStr,
4177 Instruction *InsertBefore)
4178 : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
4179 NameStr, InsertBefore) {}
4180 explicit CatchPadInst(Value *CatchSwitch, ArrayRef Args,
4181 unsigned Values, const Twine &NameStr,
4182 BasicBlock *InsertAtEnd)
4183 : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
4184 NameStr, InsertAtEnd) {}
4185
4186 public:
4187 static CatchPadInst *Create(Value *CatchSwitch, ArrayRef Args,
4188 const Twine &NameStr = "",
39204189 Instruction *InsertBefore = nullptr) {
3921 unsigned Values = unsigned(Args.size()) + 2;
3922 return new (Values) CatchPadInst(IfNormal, IfException, Args, Values,
3923 NameStr, InsertBefore);
3924 }
3925 static CatchPadInst *Create(BasicBlock *IfNormal, BasicBlock *IfException,
3926 ArrayRef Args, const Twine &NameStr,
3927 BasicBlock *InsertAtEnd) {
3928 unsigned Values = unsigned(Args.size()) + 2;
4190 unsigned Values = 1 + Args.size();
39294191 return new (Values)
3930 CatchPadInst(IfNormal, IfException, Args, Values, NameStr, InsertAtEnd);
3931 }
3932
3933 /// Provide fast operand accessors
3934 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
3935
3936 /// getNumArgOperands - Return the number of catchpad arguments.
3937 ///
3938 unsigned getNumArgOperands() const { return getNumOperands() - 2; }
3939
3940 /// getArgOperand/setArgOperand - Return/set the i-th catchpad argument.
3941 ///
3942 Value *getArgOperand(unsigned i) const { return getOperand(i); }
3943 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
3944
3945 /// arg_operands - iteration adapter for range-for loops.
3946 iterator_range arg_operands() {
3947 return make_range(op_begin(), op_end() - 2);
3948 }
3949
3950 /// arg_operands - iteration adapter for range-for loops.
3951 iterator_range arg_operands() const {
3952 return make_range(op_begin(), op_end() - 2);
3953 }
3954
3955 /// \brief Wrappers for getting the \c Use of a catchpad argument.
3956 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
3957 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
3958
3959 // get*Dest - Return the destination basic blocks...
3960 BasicBlock *getNormalDest() const { return cast(Op<-2>()); }
3961 BasicBlock *getUnwindDest() const { return cast(Op<-1>()); }
3962 void setNormalDest(BasicBlock *B) { Op<-2>() = B; }
3963 void setUnwindDest(BasicBlock *B) { Op<-1>() = B; }
3964
3965 BasicBlock *getSuccessor(unsigned i) const {
3966 assert(i < 2 && "Successor # out of range for catchpad!");
3967 return i == 0 ? getNormalDest() : getUnwindDest();
3968 }
3969
3970 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3971 assert(idx < 2 && "Successor # out of range for catchpad!");
3972 *(&Op<-2>() + idx) = NewSucc;
3973 }
3974
3975 unsigned getNumSuccessors() const { return 2; }
3976
3977 // Methods for support type inquiry through isa, cast, and dyn_cast:
4192 CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore);
4193 }
4194 static CatchPadInst *Create(Value *CatchSwitch, ArrayRef Args,
4195 const Twine &NameStr, BasicBlock *InsertAtEnd) {
4196 unsigned Values = 1 + Args.size();
4197 return new (Values)
4198 CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertAtEnd);
4199 }
4200
4201 /// Convenience accessors
4202 CatchSwitchInst *getCatchSwitch() const {
4203 return cast(Op<-1>());
4204 }
4205 void setCatchSwitch(Value *CatchSwitch) {
4206 assert(CatchSwitch);
4207 Op<-1>() = CatchSwitch;
4208 }
4209
4210 /// \brief Methods for support type inquiry through isa, cast, and dyn_cast:
39784211 static inline bool classof(const Instruction *I) {
39794212 return I->getOpcode() == Instruction::CatchPad;
39804213 }
39814214 static inline bool classof(const Value *V) {
39824215 return isa(V) && classof(cast(V));
39834216 }
3984
3985 private:
3986 BasicBlock *getSuccessorV(unsigned idx) const override;
3987 unsigned getNumSuccessorsV() const override;
3988 void setSuccessorV(unsigned idx, BasicBlock *B) override;
3989 };
3990
3991 template <>
3992 struct OperandTraits
3993 : public VariadicOperandTraits {};
3994
3995 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchPadInst, Value)
3996
3997 //===----------------------------------------------------------------------===//
3998 // TerminatePadInst Class
3999 //===----------------------------------------------------------------------===//
4000
4001 class TerminatePadInst : public TerminatorInst {
4002 private:
4003 void init(BasicBlock *BB, ArrayRef Args);
4004
4005 TerminatePadInst(const TerminatePadInst &TPI);
4006
4007 explicit TerminatePadInst(LLVMContext &C, BasicBlock *BB,
4008 ArrayRef Args, unsigned Values,
4009 Instruction *InsertBefore);
4010 explicit TerminatePadInst(LLVMContext &C, BasicBlock *BB,
4011 ArrayRef Args, unsigned Values,
4012 BasicBlock *InsertAtEnd);
4013
4014 protected:
4015 // Note: Instruction needs to be a friend here to call cloneImpl.
4016 friend class Instruction;
4017 TerminatePadInst *cloneImpl() const;
4018
4019 public:
4020 static TerminatePadInst *Create(LLVMContext &C, BasicBlock *BB = nullptr,
4021 ArrayRef Args = None,
4022 Instruction *InsertBefore = nullptr) {
4023 unsigned Values = unsigned(Args.size());
4024 if (BB)
4025 ++Values;
4026 return new (Values) TerminatePadInst(C, BB, Args, Values, InsertBefore);
4027 }
4028 static TerminatePadInst *Create(LLVMContext &C, BasicBlock *BB,
4029 ArrayRef Args,
4030 BasicBlock *InsertAtEnd) {
4031 unsigned Values = unsigned(Args.size());
4032 if (BB)
4033 ++Values;
4034 return new (Values) TerminatePadInst(C, BB, Args, Values, InsertAtEnd);
4035 }
4036
4037 /// Provide fast operand accessors
4038 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4039
4040 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4041 bool unwindsToCaller() const { return !hasUnwindDest(); }
4042
4043 /// getNumArgOperands - Return the number of terminatepad arguments.
4044 ///
4045 unsigned getNumArgOperands() const {
4046 unsigned NumOperands = getNumOperands();
4047 if (hasUnwindDest())
4048 return NumOperands - 1;
4049 return NumOperands;
4050 }
4051
4052 /// getArgOperand/setArgOperand - Return/set the i-th terminatepad argument.
4053 ///
4054 Value *getArgOperand(unsigned i) const { return getOperand(i); }
4055 void setArgOperand(unsigned i, Value *v) { setOperand(i, v); }
4056
4057 const_op_iterator arg_end() const {
4058 if (hasUnwindDest())
4059 return op_end() - 1;
4060 return op_end();
4061 }
4062
4063 op_iterator arg_end() {
4064 if (hasUnwindDest())
4065 return op_end() - 1;
4066 return op_end();
4067 }
4068
4069 /// arg_operands - iteration adapter for range-for loops.
4070 iterator_range arg_operands() {
4071 return make_range(op_begin(), arg_end());
4072 }
4073
4074 /// arg_operands - iteration adapter for range-for loops.
4075 iterator_range arg_operands() const {
4076 return make_range(op_begin(), arg_end());
4077 }
4078
4079 /// \brief Wrappers for getting the \c Use of a terminatepad argument.
4080 const Use &getArgOperandUse(unsigned i) const { return getOperandUse(i); }
4081 Use &getArgOperandUse(unsigned i) { return getOperandUse(i); }
4082
4083 // get*Dest - Return the destination basic blocks...
4084 BasicBlock *getUnwindDest() const {
4085 if (!hasUnwindDest())
4086 return nullptr;
4087 return cast(Op<-1>());
4088 }
4089 void setUnwindDest(BasicBlock *B) {
4090 assert(B && hasUnwindDest());
4091 Op<-1>() = B;
4092 }
4093
4094 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4095
4096 // Methods for support type inquiry through isa, cast, and dyn_cast:
4097 static inline bool classof(const Instruction *I) {
4098 return I->getOpcode() == Instruction::TerminatePad;
4099 }
4100 static inline bool classof(const Value *V) {
4101 return isa(V) && classof(cast(V));
4102 }
4103
4104 private:
4105 BasicBlock *getSuccessorV(unsigned idx) const override;
4106 unsigned getNumSuccessorsV() const override;
4107 void setSuccessorV(unsigned idx, BasicBlock *B) override;
4108
4109 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4110 // method so that subclasses cannot accidentally use it.
4111 void setInstructionSubclassData(unsigned short D) {
4112 Instruction::setInstructionSubclassData(D);
4113 }
4114 };
4115
4116 template <>
4117 struct OperandTraits
4118 : public VariadicOperandTraits {};
4119
4120 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(TerminatePadInst, Value)
4121
4122 //===----------------------------------------------------------------------===//
4123 // CleanupPadInst Class
4124 //===----------------------------------------------------------------------===//
4125
4126 class CleanupPadInst : public Instruction {
4127 private:
4128 void init(ArrayRef Args, const Twine &NameStr);
4129
4130 CleanupPadInst(const CleanupPadInst &CPI);
4131
4132 explicit CleanupPadInst(LLVMContext &C, ArrayRef Args,
4133 const Twine &NameStr, Instruction *InsertBefore);
4134 explicit CleanupPadInst(LLVMContext &C, ArrayRef Args,
4135 const Twine &NameStr, BasicBlock *InsertAtEnd);
4136
4137 protected:
4138 // Note: Instruction needs to be a friend here to call cloneImpl.
4139 friend class Instruction;
4140 CleanupPadInst *cloneImpl() const;
4141
4142 public:
4143 static CleanupPadInst *Create(LLVMContext &C, ArrayRef Args,
4144 const Twine &NameStr = "",
4145 Instruction *InsertBefore = nullptr) {
4146 return new (Args.size()) CleanupPadInst(C, Args, NameStr, InsertBefore);
4147 }
4148 static CleanupPadInst *Create(LLVMContext &C, ArrayRef Args,
4149 const Twine &NameStr, BasicBlock *InsertAtEnd) {
4150 return new (Args.size()) CleanupPadInst(C, Args, NameStr, InsertAtEnd);
4151 }
4152
4153 /// Provide fast operand accessors
4154 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4155
4156 // Methods for support type inquiry through isa, cast, and dyn_cast:
4157 static inline bool classof(const Instruction *I) {
4158 return I->getOpcode() == Instruction::CleanupPad;
4159 }
4160 static inline bool classof(const Value *V) {
4161 return isa(V) && classof(cast(V));
4162 }
4163 };
4164
4165 template <>
4166 struct OperandTraits
4167 : public VariadicOperandTraits {};
4168
4169 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupPadInst, Value)
4217 };
41704218
41714219 //===----------------------------------------------------------------------===//
41724220 // CatchReturnInst Class
41754223 class CatchReturnInst : public TerminatorInst {
41764224 CatchReturnInst(const CatchReturnInst &RI);
41774225
4178 void init(CatchPadInst *CatchPad, BasicBlock *BB);
4179 CatchReturnInst(CatchPadInst *CatchPad, BasicBlock *BB,
4180 Instruction *InsertBefore);
4181 CatchReturnInst(CatchPadInst *CatchPad, BasicBlock *BB,
4182 BasicBlock *InsertAtEnd);
4226 void init(Value *CatchPad, BasicBlock *BB);
4227 CatchReturnInst(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore);
4228 CatchReturnInst(Value *CatchPad, BasicBlock *BB, BasicBlock *InsertAtEnd);
41834229
41844230 protected:
41854231 // Note: Instruction needs to be a friend here to call cloneImpl.
41874233 CatchReturnInst *cloneImpl() const;
41884234
41894235 public:
4190 static CatchReturnInst *Create(CatchPadInst *CatchPad, BasicBlock *BB,
4236 static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
41914237 Instruction *InsertBefore = nullptr) {
41924238 assert(CatchPad);
41934239 assert(BB);
41944240 return new (2) CatchReturnInst(CatchPad, BB, InsertBefore);
41954241 }
4196 static CatchReturnInst *Create(CatchPadInst *CatchPad, BasicBlock *BB,
4242 static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
41974243 BasicBlock *InsertAtEnd) {
41984244 assert(CatchPad);
41994245 assert(BB);
42174263 }
42184264 unsigned getNumSuccessors() const { return 1; }
42194265
4266 Value *getParentPad() const {
4267 return getCatchPad()->getCatchSwitch()->getParentPad();
4268 }
4269
42204270 // Methods for support type inquiry through isa, cast, and dyn_cast:
42214271 static inline bool classof(const Instruction *I) {
42224272 return (I->getOpcode() == Instruction::CatchRet);
42384288 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchReturnInst, Value)
42394289
42404290 //===----------------------------------------------------------------------===//
4241 // CleanupEndPadInst Class
4242 //===----------------------------------------------------------------------===//
4243
4244 class CleanupEndPadInst : public TerminatorInst {
4245 private:
4246 CleanupEndPadInst(const CleanupEndPadInst &CEPI);
4247
4248 void init(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB);
4249 CleanupEndPadInst(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB,
4250 unsigned Values, Instruction *InsertBefore = nullptr);
4251 CleanupEndPadInst(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB,
4252 unsigned Values, BasicBlock *InsertAtEnd);
4253
4254 protected:
4255 // Note: Instruction needs to be a friend here to call cloneImpl.
4256 friend class Instruction;
4257 CleanupEndPadInst *cloneImpl() const;
4258
4259 public:
4260 static CleanupEndPadInst *Create(CleanupPadInst *CleanupPad,
4261 BasicBlock *UnwindBB = nullptr,
4262 Instruction *InsertBefore = nullptr) {
4263 unsigned Values = UnwindBB ? 2 : 1;
4264 return new (Values)
4265 CleanupEndPadInst(CleanupPad, UnwindBB, Values, InsertBefore);
4266 }
4267 static CleanupEndPadInst *Create(CleanupPadInst *CleanupPad,
4268 BasicBlock *UnwindBB,
4269 BasicBlock *InsertAtEnd) {
4270 unsigned Values = UnwindBB ? 2 : 1;
4271 return new (Values)
4272 CleanupEndPadInst(CleanupPad, UnwindBB, Values, InsertAtEnd);
4273 }
4274
4275 /// Provide fast operand accessors
4276 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
4277
4278 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4279 bool unwindsToCaller() const { return !hasUnwindDest(); }
4280
4281 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4282
4283 /// Convenience accessors
4284 CleanupPadInst *getCleanupPad() const {
4285 return cast(Op<-1>());
4286 }
4287 void setCleanupPad(CleanupPadInst *CleanupPad) {
4288 assert(CleanupPad);
4289 Op<-1>() = CleanupPad;
4290 }
4291
4292 BasicBlock *getUnwindDest() const {
4293 return hasUnwindDest() ? cast(Op<-2>()) : nullptr;
4294 }
4295 void setUnwindDest(BasicBlock *NewDest) {
4296 assert(hasUnwindDest());
4297 assert(NewDest);
4298 Op<-2>() = NewDest;
4299 }
4300
4301 // Methods for support type inquiry through isa, cast, and dyn_cast:
4302 static inline bool classof(const Instruction *I) {
4303 return (I->getOpcode() == Instruction::CleanupEndPad);
4304 }
4305 static inline bool classof(const Value *V) {
4306 return isa(V) && classof(cast(V));
4307 }
4308
4309 private:
4310 BasicBlock *getSuccessorV(unsigned Idx) const override;
4311 unsigned getNumSuccessorsV() const override;
4312 void setSuccessorV(unsigned Idx, BasicBlock *B) override;
4313
4314 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4315 // method so that subclasses cannot accidentally use it.
4316 void setInstructionSubclassData(unsigned short D) {
4317 Instruction::setInstructionSubclassData(D);
4318 }
4319 };
4320
4321 template <>
4322 struct OperandTraits
4323 : public VariadicOperandTraits {};
4324
4325 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupEndPadInst, Value)
4326
4327 //===----------------------------------------------------------------------===//
43284291 // CleanupReturnInst Class
43294292 //===----------------------------------------------------------------------===//
43304293
43324295 private:
43334296 CleanupReturnInst(const CleanupReturnInst &RI);
43344297
4335 void init(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB);
4336 CleanupReturnInst(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB,
4337 unsigned Values, Instruction *InsertBefore = nullptr);
4338 CleanupReturnInst(CleanupPadInst *CleanupPad, BasicBlock *UnwindBB,
4339 unsigned Values, BasicBlock *InsertAtEnd);
4298 void init(Value *CleanupPad, BasicBlock *UnwindBB);
4299 CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
4300 Instruction *InsertBefore = nullptr);
4301 CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
4302 BasicBlock *InsertAtEnd);
43404303
43414304 protected:
43424305 // Note: Instruction needs to be a friend here to call cloneImpl.
43444307 CleanupReturnInst *cloneImpl() const;
43454308
43464309 public:
4347 static CleanupReturnInst *Create(CleanupPadInst *CleanupPad,
4310 static CleanupReturnInst *Create(Value *CleanupPad,
43484311 BasicBlock *UnwindBB = nullptr,
43494312 Instruction *InsertBefore = nullptr) {
43504313 assert(CleanupPad);
43544317 return new (Values)
43554318 CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore);
43564319 }
4357 static CleanupReturnInst *Create(CleanupPadInst *CleanupPad,
4358 BasicBlock *UnwindBB,
4320 static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB,
43594321 BasicBlock *InsertAtEnd) {
43604322 assert(CleanupPad);
43614323 unsigned Values = 1;
43734335
43744336 /// Convenience accessor.
43754337 CleanupPadInst *getCleanupPad() const {
4376 return cast(Op<-1>());
4338 return cast(Op<0>());
43774339 }
43784340 void setCleanupPad(CleanupPadInst *CleanupPad) {
43794341 assert(CleanupPad);
4380 Op<-1>() = CleanupPad;
4342 Op<0>() = CleanupPad;
43814343 }
43824344
43834345 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
43844346
43854347 BasicBlock *getUnwindDest() const {
4386 return hasUnwindDest() ? cast(Op<-2>()) : nullptr;
4348 return hasUnwindDest() ? cast(Op<1>()) : nullptr;
43874349 }
43884350 void setUnwindDest(BasicBlock *NewDest) {
43894351 assert(NewDest);
43904352 assert(hasUnwindDest());
4391 Op<-2>() = NewDest;
4353 Op<1>() = NewDest;
43924354 }
43934355
43944356 // Methods for support type inquiry through isa, cast, and dyn_cast:
288288 DIBuilder &Builder, bool Deref, int Offset = 0);
289289
290290 /// Replace 'BB's terminator with one that does not have an unwind successor
291 /// block. Rewrites `invoke` to `call`, `catchendpad unwind label %foo` to
292 /// `catchendpad unwind to caller`, etc. Updates any PHIs in unwind successor.
291 /// block. Rewrites `invoke` to `call`, `terminatepad unwind label %foo` to
292 /// `terminatepad unwind to caller`, etc. Updates any PHIs in unwind successor.
293293 ///
294294 /// \param BB Block whose terminator will be replaced. Its terminator must
295295 /// have an unwind successor.
253253 LLVMCatchPad = 63,
254254 LLVMTerminatePad = 64,
255255 LLVMCleanupPad = 65,
256 LLVMCatchEndPad = 66,
257 LLVMCleanupEndPad = 67
256 LLVMCatchSwitch = 66
258257 } LLVMOpcode;
259258
260259 typedef enum {
12101209 macro(InsertElementInst) \
12111210 macro(InsertValueInst) \
12121211 macro(LandingPadInst) \
1213 macro(CleanupPadInst) \
12141212 macro(PHINode) \
12151213 macro(SelectInst) \
12161214 macro(ShuffleVectorInst) \
12251223 macro(ResumeInst) \
12261224 macro(CleanupReturnInst) \
12271225 macro(CatchReturnInst) \
1226 macro(TerminatePadInst) \
1227 macro(FuncletPadInst) \
12281228 macro(CatchPadInst) \
1229 macro(TerminatePadInst) \
1230 macro(CatchEndPadInst) \
1231 macro(CleanupEndPadInst) \
1229 macro(CleanupPadInst) \
12321230 macro(UnaryInstruction) \
12331231 macro(AllocaInst) \
12341232 macro(CastInst) \
7979 if (BB == BeforeHere->getParent()) {
8080 // 'I' dominates 'BeforeHere' => not safe to prune.
8181 //
82 // The value defined by an invoke/catchpad dominates an instruction only
82 // The value defined by an invoke dominates an instruction only
8383 // if it dominates every instruction in UseBB. A PHI is dominated only
8484 // if the instruction dominates every possible use in the UseBB. Since
8585 // UseBB == BB, avoid pruning.
86 if (isa(BeforeHere) || isa(BeforeHere) ||
87 isa(I) || I == BeforeHere)
86 if (isa(BeforeHere) || isa(I) || I == BeforeHere)
8887 return false;
8988 if (!OrderedBB->dominates(BeforeHere, I))
9089 return false;
88
99 #include "llvm/Analysis/EHPersonalities.h"
1010 #include "llvm/ADT/StringSwitch.h"
11 #include "llvm/IR/CFG.h"
12 #include "llvm/IR/Constants.h"
1113 #include "llvm/IR/Function.h"
14 #include "llvm/IR/Instructions.h"
15 #include "llvm/Support/Debug.h"
1216 using namespace llvm;
1317
1418 /// See if the given exception handling personality function is one that we
3842 // implies that the function does not throw synchronous exceptions.
3943 return !isAsynchronousEHPersonality(Personality);
4044 }
45
46 DenseMap llvm::colorEHFunclets(Function &F) {
47 SmallVector, 16> Worklist;
48 BasicBlock *EntryBlock = &F.getEntryBlock();
49 DenseMap BlockColors;
50
51 // Build up the color map, which maps each block to its set of 'colors'.
52 // For any block B the "colors" of B are the set of funclets F (possibly
53 // including a root "funclet" representing the main function) such that
54 // F will need to directly contain B or a copy of B (where the term "directly
55 // contain" is used to distinguish from being "transitively contained" in
56 // a nested funclet).
57 //
58 // Note: Despite not being funclets in the truest sense, terminatepad and
59 // catchswitch are considered to belong to their own funclet for the purposes
60 // of coloring.
61
62 DEBUG_WITH_TYPE("winehprepare-coloring", dbgs() << "\nColoring funclets for "
63 << F.getName() << "\n");
64
65 Worklist.push_back({EntryBlock, EntryBlock});
66
67 while (!Worklist.empty()) {
68 BasicBlock *Visiting;
69 BasicBlock *Color;
70 std::tie(Visiting, Color) = Worklist.pop_back_val();
71 DEBUG_WITH_TYPE("winehprepare-coloring",
72 dbgs() << "Visiting " << Visiting->getName() << ", "
73 << Color->getName() << "\n");
74 Instruction *VisitingHead = Visiting->getFirstNonPHI();
75 if (VisitingHead->isEHPad()) {
76 // Mark this funclet head as a member of itself.
77 Color = Visiting;
78 }
79 // Note that this is a member of the given color.
80 ColorVector &Colors = BlockColors[Visiting];
81 if (std::find(Colors.begin(), Colors.end(), Color) == Colors.end())
82 Colors.push_back(Color);
83 else
84 continue;
85
86 DEBUG_WITH_TYPE("winehprepare-coloring",
87 dbgs() << " Assigned color \'" << Color->getName()
88 << "\' to block \'" << Visiting->getName()
89 << "\'.\n");
90
91 BasicBlock *SuccColor = Color;
92 TerminatorInst *Terminator = Visiting->getTerminator();
93 if (auto *CatchRet = dyn_cast(Terminator)) {
94 Value *ParentPad = CatchRet->getParentPad();
95 if (isa(ParentPad))
96 SuccColor = EntryBlock;
97 else
98 SuccColor = cast(ParentPad)->getParent();
99 }
100
101 for (BasicBlock *Succ : successors(Visiting))
102 Worklist.push_back({Succ, SuccColor});
103 }
104 return BlockColors;
105 }
121121 return DT->dominates(I, P);
122122 }
123123
124 // Otherwise, if the instruction is in the entry block, and is not an invoke,
125 // and is not a catchpad, then it obviously dominates all phi nodes.
124 // Otherwise, if the instruction is in the entry block and is not an invoke,
125 // then it obviously dominates all phi nodes.
126126 if (I->getParent() == &I->getParent()->getParent()->getEntryBlock() &&
127 !isa(I) && !isa(I))
127 !isa(I))
128128 return true;
129129
130130 return false;
226226 if (isa((*I)->getTerminator()))
227227 return false;
228228
229 if (const InvokeInst *II = dyn_cast((*I)->getTerminator()))
229 if (const InvokeInst *II = dyn_cast((*I)->getTerminator())) {
230230 if (II->cannotDuplicate())
231231 return false;
232 // Return false if any loop blocks contain invokes to EH-pads other than
233 // landingpads; we don't know how to split those edges yet.
234 auto *FirstNonPHI = II->getUnwindDest()->getFirstNonPHI();
235 if (FirstNonPHI->isEHPad() && !isa(FirstNonPHI))
236 return false;
237 }
232238
233239 for (BasicBlock::iterator BI = (*I)->begin(), BE = (*I)->end(); BI != BE; ++BI) {
234240 if (const CallInst *CI = dyn_cast(BI)) {
9090 BasicBlock::iterator IP = ++I->getIterator();
9191 if (auto *II = dyn_cast(I))
9292 IP = II->getNormalDest()->begin();
93 if (auto *CPI = dyn_cast(I))
94 IP = CPI->getNormalDest()->begin();
9593
9694 while (isa(IP))
9795 ++IP;
9896
9997 while (IP->isEHPad()) {
100 if (isa<LandingPadInst>(IP) || isaPadInst>(IP)) {
98 if (isa<FuncletPadInst>(IP) || isaPadInst>(IP)) {
10199 ++IP;
102100 } else if (auto *TPI = dyn_cast(IP)) {
103101 IP = TPI->getUnwindDest()->getFirstNonPHI()->getIterator();
104 } else if (auto *CEPI = dyn_cast(IP)) {
105 IP = CEPI->getUnwindDest()->getFirstNonPHI()->getIterator();
106 } else if (auto *CEPI = dyn_cast(IP)) {
107 IP = CEPI->getUnwindDest()->getFirstNonPHI()->getIterator();
108 } else if (isaPadInst>(IP)) {
102 } else if (isaSwitchInst>(IP)) {
109103 IP = MustDominate->getFirstInsertionPt();
110104 } else {
111105 llvm_unreachable("unexpected eh pad!");
34303430 case Instruction::AtomicCmpXchg:
34313431 case Instruction::LandingPad:
34323432 case Instruction::Resume:
3433 case Instruction::CatchSwitch:
34333434 case Instruction::CatchPad:
3434 case Instruction::CatchEndPad:
34353435 case Instruction::CatchRet:
34363436 case Instruction::CleanupPad:
3437 case Instruction::CleanupEndPad:
34383437 case Instruction::CleanupRet:
34393438 case Instruction::TerminatePad:
34403439 return false; // Misc instructions which have effects
525525 KEYWORD(none);
526526 KEYWORD(to);
527527 KEYWORD(caller);
528 KEYWORD(within);
529 KEYWORD(from);
528530 KEYWORD(tail);
529531 KEYWORD(musttail);
530532 KEYWORD(notail);
758760 INSTKEYWORD(landingpad, LandingPad);
759761 INSTKEYWORD(cleanupret, CleanupRet);
760762 INSTKEYWORD(catchret, CatchRet);
763 INSTKEYWORD(catchswitch, CatchSwitch);
761764 INSTKEYWORD(catchpad, CatchPad);
762765 INSTKEYWORD(terminatepad, TerminatePad);
763766 INSTKEYWORD(cleanuppad, CleanupPad);
764 INSTKEYWORD(catchendpad, CatchEndPad);
765 INSTKEYWORD(cleanupendpad, CleanupEndPad);
766767 #undef INSTKEYWORD
767768
768769 #define DWKEYWORD(TYPE, TOKEN) \
23142314 /// forward reference record if needed. This can return null if the value
23152315 /// exists but does not have the right type.
23162316 Value *LLParser::PerFunctionState::GetVal(const std::string &Name, Type *Ty,
2317 LocTy Loc, OperatorConstraint OC) {
2317 LocTy Loc) {
23182318 // Look this name up in the normal function symbol table.
23192319 Value *Val = F.getValueSymbolTable().lookup(Name);
23202320
23282328
23292329 // If we have the value in the symbol table or fwd-ref table, return it.
23302330 if (Val) {
2331 // Check operator constraints.
2332 switch (OC) {
2333 case OC_None:
2334 // no constraint
2335 break;
2336 case OC_CatchPad:
2337 if (!isa(Val)) {
2338 P.Error(Loc, "'%" + Name + "' is not a catchpad");
2339 return nullptr;
2340 }
2341 break;
2342 case OC_CleanupPad:
2343 if (!isa(Val)) {
2344 P.Error(Loc, "'%" + Name + "' is not a cleanuppad");
2345 return nullptr;
2346 }
2347 break;
2348 }
23492331 if (Val->getType() == Ty) return Val;
23502332 if (Ty->isLabelTy())
23512333 P.Error(Loc, "'%" + Name + "' is not a basic block");
23642346 // Otherwise, create a new forward reference for this value and remember it.
23652347 Value *FwdVal;
23662348 if (Ty->isLabelTy()) {
2367 assert(!OC);
23682349 FwdVal = BasicBlock::Create(F.getContext(), Name, &F);
2369 } else if (!OC) {
2350 } else {
23702351 FwdVal = new Argument(Ty, Name);
2371 } else {
2372 switch (OC) {
2373 case OC_CatchPad:
2374 FwdVal = CatchPadInst::Create(&F.getEntryBlock(), &F.getEntryBlock(), {},
2375 Name);
2376 break;
2377 case OC_CleanupPad:
2378 FwdVal = CleanupPadInst::Create(F.getContext(), {}, Name);
2379 break;
2380 default:
2381 llvm_unreachable("unexpected constraint");
2382 }
23832352 }
23842353
23852354 ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
23862355 return FwdVal;
23872356 }
23882357
2389 Value *LLParser::PerFunctionState::GetVal(unsigned ID, Type *Ty, LocTy Loc,
2390 OperatorConstraint OC) {
2358 Value *LLParser::PerFunctionState::GetVal(unsigned ID, Type *Ty, LocTy Loc) {
23912359 // Look this name up in the normal function symbol table.
23922360 Value *Val = ID < NumberedVals.size() ? NumberedVals[ID] : nullptr;
23932361
24012369
24022370 // If we have the value in the symbol table or fwd-ref table, return it.
24032371 if (Val) {
2404 // Check operator constraint.
2405 switch (OC) {
2406 case OC_None:
2407 // no constraint
2408 break;
2409 case OC_CatchPad:
2410 if (!isa(Val)) {
2411 P.Error(Loc, "'%" + Twine(ID) + "' is not a catchpad");
2412 return nullptr;
2413 }
2414 break;
2415 case OC_CleanupPad:
2416 if (!isa(Val)) {
2417 P.Error(Loc, "'%" + Twine(ID) + "' is not a cleanuppad");
2418 return nullptr;
2419 }
2420 break;
2421 }
24222372 if (Val->getType() == Ty) return Val;
24232373 if (Ty->isLabelTy())
24242374 P.Error(Loc, "'%" + Twine(ID) + "' is not a basic block");
24362386 // Otherwise, create a new forward reference for this value and remember it.
24372387 Value *FwdVal;
24382388 if (Ty->isLabelTy()) {
2439 assert(!OC);
24402389 FwdVal = BasicBlock::Create(F.getContext(), "", &F);
2441 } else if (!OC) {
2390 } else {
24422391 FwdVal = new Argument(Ty);
2443 } else {
2444 switch (OC) {
2445 case OC_CatchPad:
2446 FwdVal = CatchPadInst::Create(&F.getEntryBlock(), &F.getEntryBlock(), {});
2447 break;
2448 case OC_CleanupPad:
2449 FwdVal = CleanupPadInst::Create(F.getContext(), {});
2450 break;
2451 default:
2452 llvm_unreachable("unexpected constraint");
2453 }
24542392 }
24552393
24562394 ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
24862424 if (Sentinel->getType() != Inst->getType())
24872425 return P.Error(NameLoc, "instruction forward referenced with type '" +
24882426 getTypeString(FI->second.first->getType()) + "'");
2489 // Check operator constraints. We only put cleanuppads or catchpads in
2490 // the forward value map if the value is constrained to match.
2491 if (isa(Sentinel)) {
2492 if (!isa(Inst))
2493 return P.Error(FI->second.second,
2494 "'%" + Twine(NameID) + "' is not a catchpad");
2495 } else if (isa(Sentinel)) {
2496 if (!isa(Inst))
2497 return P.Error(FI->second.second,
2498 "'%" + Twine(NameID) + "' is not a cleanuppad");
2499 }
25002427
25012428 Sentinel->replaceAllUsesWith(Inst);
25022429 delete Sentinel;
25142441 if (Sentinel->getType() != Inst->getType())
25152442 return P.Error(NameLoc, "instruction forward referenced with type '" +
25162443 getTypeString(FI->second.first->getType()) + "'");
2517 // Check operator constraints. We only put cleanuppads or catchpads in
2518 // the forward value map if the value is constrained to match.
2519 if (isa(Sentinel)) {
2520 if (!isa(Inst))
2521 return P.Error(FI->second.second,
2522 "'%" + NameStr + "' is not a catchpad");
2523 } else if (isa(Sentinel)) {
2524 if (!isa(Inst))
2525 return P.Error(FI->second.second,
2526 "'%" + NameStr + "' is not a cleanuppad");
2527 }
25282444
25292445 Sentinel->replaceAllUsesWith(Inst);
25302446 delete Sentinel;
42344150 //===----------------------------------------------------------------------===//
42354151
42364152 bool LLParser::ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
4237 PerFunctionState *PFS,
4238 OperatorConstraint OC) {
4153 PerFunctionState *PFS) {
42394154 if (Ty->isFunctionTy())
42404155 return Error(ID.Loc, "functions are not values, refer to them as pointers");
4241
4242 if (OC && ID.Kind != ValID::t_LocalID && ID.Kind != ValID::t_LocalName) {
4243 switch (OC) {
4244 case OC_CatchPad:
4245 return Error(ID.Loc, "Catchpad value required in this position");
4246 case OC_CleanupPad:
4247 return Error(ID.Loc, "Cleanuppad value required in this position");
4248 default:
4249 llvm_unreachable("Unexpected constraint kind");
4250 }
4251 }
42524156
42534157 switch (ID.Kind) {
42544158 case ValID::t_LocalID:
42554159 if (!PFS) return Error(ID.Loc, "invalid use of function-local name");
4256 V = PFS->GetVal(ID.UIntVal, Ty, ID.Loc, OC);
4160 V = PFS->GetVal(ID.UIntVal, Ty, ID.Loc);
42574161 return V == nullptr;
42584162 case ValID::t_LocalName:
42594163 if (!PFS) return Error(ID.Loc, "invalid use of function-local name");
4260 V = PFS->GetVal(ID.StrVal, Ty, ID.Loc, OC);
4164 V = PFS->GetVal(ID.StrVal, Ty, ID.Loc);
42614165 return V == nullptr;
42624166 case ValID::t_InlineAsm: {
42634167 if (!ID.FTy || !InlineAsm::Verify(ID.FTy, ID.StrVal2))
43844288 }
43854289 }
43864290
4387 bool LLParser::ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS,
4388 OperatorConstraint OC) {
4291 bool LLParser::ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS) {
43894292 V = nullptr;
43904293 ValID ID;
4391 return ParseValID(ID, PFS) || ConvertValIDToValue(Ty, ID, V, PFS, OC);
4294 return ParseValID(ID, PFS) || ConvertValIDToValue(Ty, ID, V, PFS);
43924295 }
43934296
43944297 bool LLParser::ParseTypeAndValue(Value *&V, PerFunctionState *PFS) {
48174720 case lltok::kw_resume: return ParseResume(Inst, PFS);
48184721 case lltok::kw_cleanupret: return ParseCleanupRet(Inst, PFS);
48194722 case lltok::kw_catchret: return ParseCatchRet(Inst, PFS);
4820 case lltok::kw_catchpad: return ParseCatchPad(Inst, PFS);
4821 case lltok::kw_terminatepad: return ParseTerminatePad(Inst, PFS);
4822 case lltok::kw_cleanuppad: return ParseCleanupPad(Inst, PFS);
4823 case lltok::kw_catchendpad: return ParseCatchEndPad(Inst, PFS);
4824 case lltok::kw_cleanupendpad: return ParseCleanupEndPad(Inst, PFS);
4723 case lltok::kw_catchswitch: return ParseCatchSwitch(Inst, PFS);
4724 case lltok::kw_catchpad: return ParseCatchPad(Inst, PFS);
4725 case lltok::kw_terminatepad:return ParseTerminatePad(Inst, PFS);
4726 case lltok::kw_cleanuppad: return ParseCleanupPad(Inst, PFS);
48254727 // Binary Operators.
48264728 case lltok::kw_add:
48274729 case lltok::kw_sub:
52615163 }
52625164
52635165 /// ParseCleanupRet
5264 /// ::= 'cleanupret' Value unwind ('to' 'caller' | TypeAndValue)
5166 /// ::= 'cleanupret' from Value unwind ('to' 'caller' | TypeAndValue)
52655167 bool LLParser::ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS) {
52665168 Value *CleanupPad = nullptr;
52675169
5268 if (ParseValue(Type::getTokenTy(Context), CleanupPad, PFS, OC_CleanupPad))
5170 if (ParseToken(lltok::kw_from, "expected 'from' after cleanupret"))
5171 return true;
5172
5173 if (ParseValue(Type::getTokenTy(Context), CleanupPad, PFS))
52695174 return true;
52705175
52715176 if (ParseToken(lltok::kw_unwind, "expected 'unwind' in cleanupret"))
52825187 }
52835188 }
52845189
5285 Inst = CleanupReturnInst::Create(cast(CleanupPad), UnwindBB);
5190 Inst = CleanupReturnInst::Create(CleanupPad, UnwindBB);
52865191 return false;
52875192 }
52885193
52895194 /// ParseCatchRet
5290 /// ::= 'catchret' Value 'to' TypeAndValue
5195 /// ::= 'catchret' from Parent Value 'to' TypeAndValue
52915196 bool LLParser::ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS) {
52925197 Value *CatchPad = nullptr;
52935198
5294 if (ParseValue(Type::getTokenTy(Context), CatchPad, PFS, OC_CatchPad))
5199 if (ParseToken(lltok::kw_from, "expected 'from' after catchret"))
5200 return true;
5201
5202 if (ParseValue(Type::getTokenTy(Context), CatchPad, PFS))
52955203 return true;
52965204
52975205 BasicBlock *BB;
52995207 ParseTypeAndBasicBlock(BB, PFS))
53005208 return true;
53015209
5302 Inst = CatchReturnInst::Create(cast(CatchPad), BB);
5210 Inst = CatchReturnInst::Create(CatchPad, BB);
5211 return false;
5212 }
5213
5214 /// ParseCatchSwitch
5215 /// ::= 'catchswitch' within Parent
5216 bool LLParser::ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS) {
5217 Value *ParentPad;
5218 LocTy BBLoc;
5219
5220 if (ParseToken(lltok::kw_within, "expected 'within' after catchswitch"))
5221 return true;
5222
5223 if (Lex.getKind() != lltok::kw_none && Lex.getKind() != lltok::LocalVar &&
5224 Lex.getKind() != lltok::LocalVarID)
5225 return TokError("expected scope value for catchswitch");
5226
5227 if (ParseValue(Type::getTokenTy(Context), ParentPad, PFS))
5228 return true;
5229
5230 if (ParseToken(lltok::lsquare, "expected '[' with catchswitch labels"))
5231 return true;
5232
5233 SmallVector Table;
5234 do {
5235 BasicBlock *DestBB;
5236 if (ParseTypeAndBasicBlock(DestBB, PFS))
5237 return true;
5238 Table.push_back(DestBB);
5239 } while (EatIfPresent(lltok::comma));
5240
5241 if (ParseToken(lltok::rsquare, "expected ']' after catchswitch labels"))
5242 return true;
5243
5244 if (ParseToken(lltok::kw_unwind,
5245 "expected 'unwind' after catchswitch scope"))
5246 return true;
5247
5248 BasicBlock *UnwindBB = nullptr;
5249 if (EatIfPresent(lltok::kw_to)) {
5250 if (ParseToken(lltok::kw_caller, "expected 'caller' in catchswitch"))
5251 return true;
5252 } else {
5253 if (ParseTypeAndBasicBlock(UnwindBB, PFS))
5254 return true;
5255 }
5256
5257 auto *CatchSwitch =
5258 CatchSwitchInst::Create(ParentPad, UnwindBB, Table.size());
5259 for (BasicBlock *DestBB : Table)
5260 CatchSwitch->addHandler(DestBB);
5261 Inst = CatchSwitch;
53035262 return false;
53045263 }
53055264
53065265 /// ParseCatchPad
53075266 /// ::= 'catchpad' ParamList 'to' TypeAndValue 'unwind' TypeAndValue
53085267 bool LLParser::ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS) {
5268 Value *CatchSwitch = nullptr;
5269
5270 if (ParseToken(lltok::kw_within, "expected 'within' after catchpad"))
5271 return true;
5272
5273 if (Lex.getKind() != lltok::LocalVar && Lex.getKind() != lltok::LocalVarID)
5274 return TokError("expected scope value for catchpad");
5275
5276 if (ParseValue(Type::getTokenTy(Context), CatchSwitch, PFS))
5277 return true;
5278
53095279 SmallVector Args;
53105280 if (ParseExceptionArgs(Args, PFS))
53115281 return true;
53125282
5313 BasicBlock *NormalBB, *UnwindBB;
5314 if (ParseToken(lltok::kw_to, "expected 'to' in catchpad") ||
5315 ParseTypeAndBasicBlock(NormalBB, PFS) ||
5316 ParseToken(lltok::kw_unwind, "expected 'unwind' in catchpad") ||
5317 ParseTypeAndBasicBlock(UnwindBB, PFS))
5318 return true;
5319
5320 Inst = CatchPadInst::Create(NormalBB, UnwindBB, Args);
5283 Inst = CatchPadInst::Create(CatchSwitch, Args);
53215284 return false;
53225285 }
53235286
53245287 /// ParseTerminatePad
5325 /// ::= 'terminatepad' ParamList 'to' TypeAndValue
5288 /// ::= 'terminatepad' within Parent ParamList 'to' TypeAndValue
53265289 bool LLParser::ParseTerminatePad(Instruction *&Inst, PerFunctionState &PFS) {
5290 Value *ParentPad = nullptr;
5291
5292 if (ParseToken(lltok::kw_within, "expected 'within' after terminatepad"))
5293 return true;
5294
5295 if (Lex.getKind() != lltok::kw_none && Lex.getKind() != lltok::LocalVar &&
5296 Lex.getKind() != lltok::LocalVarID)
5297 return TokError("expected scope value for terminatepad");
5298
5299 if (ParseValue(Type::getTokenTy(Context), ParentPad, PFS))
5300 return true;
5301
53275302 SmallVector Args;
53285303 if (ParseExceptionArgs(Args, PFS))
53295304 return true;
53425317 }
53435318 }
53445319
5345 Inst = TerminatePadInst::Create(Context, UnwindBB, Args);
5320 Inst = TerminatePadInst::Create(ParentPad, UnwindBB, Args);
53465321 return false;
53475322 }
53485323
53495324 /// ParseCleanupPad
5350 /// ::= 'cleanuppad' ParamList
5325 /// ::= 'cleanuppad' within Parent ParamList
53515326 bool LLParser::ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS) {
5327 Value *ParentPad = nullptr;
5328
5329 if (ParseToken(lltok::kw_within, "expected 'within' after cleanuppad"))
5330 return true;
5331
5332 if (Lex.getKind() != lltok::kw_none && Lex.getKind() != lltok::LocalVar &&
5333 Lex.getKind() != lltok::LocalVarID)
5334 return TokError("expected scope value for cleanuppad");
5335
5336 if (ParseValue(Type::getTokenTy(Context), ParentPad, PFS))
5337 return true;
5338
53525339 SmallVector Args;
53535340 if (ParseExceptionArgs(Args, PFS))
53545341 return true;
53555342
5356 Inst = CleanupPadInst::Create(Context, Args);
5357 return false;
5358 }
5359
5360 /// ParseCatchEndPad
5361 /// ::= 'catchendpad' unwind ('to' 'caller' | TypeAndValue)
5362 bool LLParser::ParseCatchEndPad(Instruction *&Inst, PerFunctionState &PFS) {
5363 if (ParseToken(lltok::kw_unwind, "expected 'unwind' in catchendpad"))
5364 return true;
5365
5366 BasicBlock *UnwindBB = nullptr;
5367 if (Lex.getKind() == lltok::kw_to) {
5368 Lex.Lex();
5369 if (Lex.getKind() == lltok::kw_caller) {
5370 Lex.Lex();
5371 } else {
5372 return true;
5373 }
5374 } else {
5375 if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
5376 return true;
5377 }
5378 }
5379
5380 Inst = CatchEndPadInst::Create(Context, UnwindBB);
5381 return false;
5382 }
5383
5384 /// ParseCatchEndPad
5385 /// ::= 'cleanupendpad' Value unwind ('to' 'caller' | TypeAndValue)
5386 bool LLParser::ParseCleanupEndPad(Instruction *&Inst, PerFunctionState &PFS) {
5387 Value *CleanupPad = nullptr;
5388
5389 if (ParseValue(Type::getTokenTy(Context), CleanupPad, PFS, OC_CleanupPad))
5390 return true;
5391
5392 if (ParseToken(lltok::kw_unwind, "expected 'unwind' in catchendpad"))
5393 return true;
5394
5395 BasicBlock *UnwindBB = nullptr;
5396 if (Lex.getKind() == lltok::kw_to) {
5397 Lex.Lex();
5398 if (Lex.getKind() == lltok::kw_caller) {
5399 Lex.Lex();
5400 } else {
5401 return true;
5402 }
5403 } else {
5404 if (ParseTypeAndBasicBlock(UnwindBB, PFS)) {
5405 return true;
5406 }
5407 }
5408
5409 Inst = CleanupEndPadInst::Create(cast(CleanupPad), UnwindBB);
5343 Inst = CleanupPadInst::Create(ParentPad, Args);
54105344 return false;
54115345 }
54125346
105105 struct MDRef {
106106 SMLoc Loc;
107107 unsigned MDKind, MDSlot;
108 };
109
110 /// Indicates which operator an operand allows (for the few operands that
111 /// may only reference a certain operator).
112 enum OperatorConstraint {
113 OC_None = 0, // No constraint
114 OC_CatchPad, // Must be CatchPadInst
115 OC_CleanupPad // Must be CleanupPadInst
116108 };
117109
118110 SmallVector InstsWithTBAATag;
336328 /// GetVal - Get a value with the specified name or ID, creating a
337329 /// forward reference record if needed. This can return null if the value
338330 /// exists but does not have the right type.
339 Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc,
340 OperatorConstraint OC = OC_None);
341 Value *GetVal(unsigned ID, Type *Ty, LocTy Loc,
342 OperatorConstraint OC = OC_None);
331 Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc);
332 Value *GetVal(unsigned ID, Type *Ty, LocTy Loc);
343333
344334 /// SetInstName - After an instruction is parsed and inserted into its
345335 /// basic block, this installs its name.
361351 };
362352
363353 bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V,
364 PerFunctionState *PFS,
365 OperatorConstraint OC = OC_None);
354 PerFunctionState *PFS);
366355
367356 bool parseConstantValue(Type *Ty, Constant *&C);
368 bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS,
369 OperatorConstraint OC = OC_None);
370 bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS,
371 OperatorConstraint OC = OC_None) {
372 return ParseValue(Ty, V, &PFS, OC);
373 }
357 bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS);
358 bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) {
359 return ParseValue(Ty, V, &PFS);
360 }
361
374362 bool ParseValue(Type *Ty, Value *&V, LocTy &Loc,
375363 PerFunctionState &PFS) {
376364 Loc = Lex.getLoc();
474462 bool ParseResume(Instruction *&Inst, PerFunctionState &PFS);
475463 bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS);
476464 bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS);
465 bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS);
477466 bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS);
478467 bool ParseTerminatePad(Instruction *&Inst, PerFunctionState &PFS);
479468 bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS);
480 bool ParseCatchEndPad(Instruction *&Inst, PerFunctionState &PFS);
481 bool ParseCleanupEndPad(Instruction *&Inst, PerFunctionState &PFS);
482469
483470 bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc,
484471 unsigned OperandType);
5151 kw_undef, kw_null, kw_none,
5252 kw_to,
5353 kw_caller,
54 kw_within,
55 kw_from,
5456 kw_tail,
5557 kw_musttail,
5658 kw_notail,
181183 kw_landingpad, kw_personality, kw_cleanup, kw_catch, kw_filter,
182184
183185 kw_ret, kw_br, kw_switch, kw_indirectbr, kw_invoke, kw_resume,
184 kw_unreachable, kw_cleanupret, kw_catchret, kw_catchpad,
185 kw_terminatepad, kw_cleanuppad, kw_catchendpad, kw_cleanupendpad,
186 kw_unreachable, kw_cleanupret, kw_catchswitch, kw_catchret, kw_catchpad,
187 kw_terminatepad, kw_cleanuppad,
186188
187189 kw_alloca, kw_load, kw_store, kw_fence, kw_cmpxchg, kw_atomicrmw,
188190 kw_getelementptr,
4141 SWITCH_INST_MAGIC = 0x4B5 // May 2012 => 1205 => Hex
4242 };
4343
44 /// Indicates which operator an operand allows (for the few operands that may
45 /// only reference a certain operator).
46 enum OperatorConstraint {
47 OC_None = 0, // No constraint
48 OC_CatchPad, // Must be CatchPadInst
49 OC_CleanupPad // Must be CleanupPadInst
50 };
51
5244 class BitcodeReaderValueList {
5345 std::vector ValuePtrs;
5446
9284 }
9385
9486 Constant *getConstantFwdRef(unsigned Idx, Type *Ty);
95 Value *getValueFwdRef(unsigned Idx, Type *Ty,
96 OperatorConstraint OC = OC_None);
97
98 bool assignValue(Value *V, unsigned Idx);
87 Value *getValueFwdRef(unsigned Idx, Type *Ty);
88
89 void assignValue(Value *V, unsigned Idx);
9990
10091 /// Once all constants are read, this method bulk resolves any forward
10192 /// references.
296287 StructType *createIdentifiedStructType(LLVMContext &Context);
297288
298289 Type *getTypeByID(unsigned ID);
299 Value *getFnValueByID(unsigned ID, Type *Ty,
300 OperatorConstraint OC = OC_None) {
290 Value *getFnValueByID(unsigned ID, Type *Ty) {
301291 if (Ty && Ty->isMetadataTy())
302292 return MetadataAsValue::get(Ty->getContext(), getFnMetadataByID(ID));
303 return ValueList.getValueFwdRef(ID, Ty, OC);
293 return ValueList.getValueFwdRef(ID, Ty);
304294 }
305295 Metadata *getFnMetadataByID(unsigned ID) {
306296 return MDValueList.getValueFwdRef(ID);
343333 /// past the number of slots used by the value in the record. Return true if
344334 /// there is an error.
345335 bool popValue(SmallVectorImpl &Record, unsigned &Slot,
346 unsigned InstNum, Type *Ty, Value *&ResVal,
347 OperatorConstraint OC = OC_None) {
348 if (getValue(Record, Slot, InstNum, Ty, ResVal, OC))
336 unsigned InstNum, Type *Ty, Value *&ResVal) {
337 if (getValue(Record, Slot, InstNum, Ty, ResVal))
349338 return true;
350339 // All values currently take a single record slot.
351340 ++Slot;
354343
355344 /// Like popValue, but does not increment the Slot number.
356345 bool getValue(SmallVectorImpl &Record, unsigned Slot,
357 unsigned InstNum, Type *Ty, Value *&ResVal,
358 OperatorConstraint OC = OC_None) {
359 ResVal = getValue(Record, Slot, InstNum, Ty, OC);
346 unsigned InstNum, Type *Ty, Value *&ResVal) {
347 ResVal = getValue(Record, Slot, InstNum, Ty);
360348 return ResVal == nullptr;
361349 }
362350
363351 /// Version of getValue that returns ResVal directly, or 0 if there is an
364352 /// error.
365353 Value *getValue(SmallVectorImpl &Record, unsigned Slot,
366 unsigned InstNum, Type *Ty, OperatorConstraint OC = OC_None) {
354 unsigned InstNum, Type *Ty) {
367355 if (Slot == Record.size()) return nullptr;
368356 unsigned ValNo = (unsigned)Record[Slot];
369357 // Adjust the ValNo, if it was encoded relative to the InstNum.
370358 if (UseRelativeIDs)
371359 ValNo = InstNum - ValNo;
372 return getFnValueByID(ValNo, Ty, OC);
360 return getFnValueByID(ValNo, Ty);
373361 }
374362
375363 /// Like getValue, but decodes signed VBRs.
376364 Value *getValueSigned(SmallVectorImpl &Record, unsigned Slot,
377 unsigned InstNum, Type *Ty,
378 OperatorConstraint OC = OC_None) {
365 unsigned InstNum, Type *Ty) {
379366 if (Slot == Record.size()) return nullptr;
380367 unsigned ValNo = (unsigned)decodeSignRotatedValue(Record[Slot]);
381368 // Adjust the ValNo, if it was encoded relative to the InstNum.
382369 if (UseRelativeIDs)
383370 ValNo = InstNum - ValNo;
384 return getFnValueByID(ValNo, Ty, OC);
371 return getFnValueByID(ValNo, Ty);
385372 }
386373
387374 /// Converts alignment exponent (i.e. power of two (or zero)) to the
897884 DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ConstantPlaceHolder, Value)
898885 }
899886
900 bool BitcodeReaderValueList::assignValue(Value *V, unsigned Idx) {
887 void BitcodeReaderValueList::assignValue(Value *V, unsigned Idx) {
901888 if (Idx == size()) {
902889 push_back(V);
903 return false;
890 return;
904891 }
905892
906893 if (Idx >= size())
909896 WeakVH &OldV = ValuePtrs[Idx];
910897 if (!OldV) {
911898 OldV = V;
912 return false;
899 return;
913900 }
914901
915902 // Handle constants and non-constants (e.g. instrs) differently for
920907 } else {
921908 // If there was a forward reference to this value, replace it.
922909 Value *PrevVal = OldV;
923 // Check operator constraints. We only put cleanuppads or catchpads in
924 // the forward value map if the value is constrained to match.
925 if (CatchPadInst *CatchPad = dyn_cast(PrevVal)) {
926 if (!isa(V))
927 return true;
928 // Delete the dummy basic block that was created with the sentinel
929 // catchpad.
930 BasicBlock *DummyBlock = CatchPad->getUnwindDest();
931 assert(DummyBlock == CatchPad->getNormalDest());
932 CatchPad->dropAllReferences();
933 delete DummyBlock;
934 } else if (isa(PrevVal)) {
935 if (!isa(V))
936 return true;
937 }
938910 OldV->replaceAllUsesWith(V);
939911 delete PrevVal;
940912 }
941913
942 return false;
914 return;
943915 }
944916
945917
960932 return C;
961933 }
962934
963 Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty,
964 OperatorConstraint OC) {
935 Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty) {
965936 // Bail out for a clearly invalid value. This would make us call resize(0)
966937 if (Idx == UINT_MAX)
967938 return nullptr;
973944 // If the types don't match, it's invalid.
974945 if (Ty && Ty != V->getType())
975946 return nullptr;
976 if (!OC)
977 return V;
978 // Use dyn_cast to enforce operator constraints
979 switch (OC) {
980 case OC_CatchPad:
981 return dyn_cast(V);
982 case OC_CleanupPad:
983 return dyn_cast(V);
984 default:
985 llvm_unreachable("Unexpected operator constraint");
986 }
947 return V;
987948 }
988949
989950 // No type specified, must be invalid reference.
990951 if (!Ty) return nullptr;
991952
992953 // Create and return a placeholder, which will later be RAUW'd.
993 Value *V;
994 switch (OC) {
995 case OC_None:
996 V = new Argument(Ty);
997 break;
998 case OC_CatchPad: {
999 BasicBlock *BB = BasicBlock::Create(Context);
1000 V = CatchPadInst::Create(BB, BB, {});
1001 break;
1002 }
1003 default:
1004 assert(OC == OC_CleanupPad && "unexpected operator constraint");
1005 V = CleanupPadInst::Create(Context, {});
1006 break;
1007 }
1008
954 Value *V = new Argument(Ty);
1009955 ValuePtrs[Idx] = V;
1010956 return V;
1011957 }
30222968 }
30232969 }
30242970
3025 if (ValueList.assignValue(V, NextCstNo))
3026 return error("Invalid forward reference");
2971 ValueList.assignValue(V, NextCstNo);
30272972 ++NextCstNo;
30282973 }
30292974 }
44694414 if (Record.size() != 1 && Record.size() != 2)
44704415 return error("Invalid record");
44714416 unsigned Idx = 0;
4472 Value *CleanupPad = getValue(Record, Idx++, NextValueNo,
4473 Type::getTokenTy(Context), OC_CleanupPad);
4417 Value *CleanupPad =
4418 getValue(Record, Idx++, NextValueNo, Type::getTokenTy(Context));
44744419 if (!CleanupPad)
44754420 return error("Invalid record");
44764421 BasicBlock *UnwindDest = nullptr;
44804425 return error("Invalid record");
44814426 }
44824427
4483 I = CleanupReturnInst::Create(cast(CleanupPad),
4484 UnwindDest);
4428 I = CleanupReturnInst::Create(CleanupPad, UnwindDest);
44854429 InstructionList.push_back(I);
44864430 break;
44874431 }
44894433 if (Record.size() != 2)
44904434 return error("Invalid record");
44914435 unsigned Idx = 0;
4492 Value *CatchPad = getValue(Record, Idx++, NextValueNo,
4493 Type::getTokenTy(Context), OC_CatchPad);
4436 Value *CatchPad =
4437 getValue(Record, Idx++, NextValueNo, Type::getTokenTy(Context));
44944438 if (!CatchPad)
44954439 return error("Invalid record");
44964440 BasicBlock *BB = getBasicBlock(Record[Idx++]);
44974441 if (!BB)
44984442 return error("Invalid record");
44994443
4500 I = CatchReturnInst::Create(cast(CatchPad), BB);
4444 I = CatchReturnInst::Create(CatchPad, BB);
45014445 InstructionList.push_back(I);
45024446 break;
45034447 }
4504 case bitc::FUNC_CODE_INST_CATCHPAD: { // CATCHPAD: [bb#,bb#,num,(ty,val)*]
4505 if (Record.size() < 3)
4506 return error("Invalid record");
4448 case bitc::FUNC_CODE_INST_CATCHSWITCH: { // CATCHSWITCH: [tok,num,(bb)*,bb?]
4449 // We must have, at minimum, the outer scope and the number of arguments.
4450 if (Record.size() < 2)
4451 return error("Invalid record");
4452
45074453 unsigned Idx = 0;
4508 BasicBlock *NormalBB = getBasicBlock(Record[Idx++]);
4509 if (!NormalBB)
4510 return error("Invalid record");
4511 BasicBlock *UnwindBB = getBasicBlock(Record[Idx++]);
4512 if (!UnwindBB)
4513 return error("Invalid record");
4454
4455 Value *ParentPad =
4456 getValue(Record, Idx++, NextValueNo, Type::getTokenTy(Context));
4457
4458 unsigned NumHandlers = Record[Idx++];
4459
4460 SmallVector Handlers;
4461 for (unsigned Op = 0; Op != NumHandlers; ++Op) {
4462 BasicBlock *BB = getBasicBlock(Record[Idx++]);
4463 if (!BB)
4464 return error("Invalid record");
4465 Handlers.push_back(BB);
4466 }
4467
4468 BasicBlock *UnwindDest = nullptr;
4469 if (Idx + 1 == Record.size()) {
4470 UnwindDest = getBasicBlock(Record[Idx++]);
4471 if (!UnwindDest)
4472 return error("Invalid record");
4473 }
4474
4475 if (Record.size() != Idx)
4476 return error("Invalid record");
4477
4478 auto *CatchSwitch =
4479 CatchSwitchInst::Create(ParentPad, UnwindDest, NumHandlers);
4480 for (BasicBlock *Handler : Handlers)
4481 CatchSwitch->addHandler(Handler);
4482 I = CatchSwitch;
4483 InstructionList.push_back(I);
4484 break;
4485 }
4486 case bitc::FUNC_CODE_INST_TERMINATEPAD: { // TERMINATEPAD: [tok,bb#,num,(ty,val)*]
4487 // We must have, at minimum, the outer scope and the number of arguments.
4488 if (Record.size() < 2)
4489 return error("Invalid record");
4490
4491 unsigned Idx = 0;
4492
4493 Value *ParentPad =
4494 getValue(Record, Idx++, NextValueNo, Type::getTokenTy(Context));
4495
45144496 unsigned NumArgOperands = Record[Idx++];
4497
45154498 SmallVector Args;
45164499 for (unsigned Op = 0; Op != NumArgOperands; ++Op) {
45174500 Value *Val;
45194502 return error("Invalid record");
45204503 Args.push_back(Val);
45214504 }
4522 if (Record.size() != Idx)
4523 return error("Invalid record");
4524
4525 I = CatchPadInst::Create(NormalBB, UnwindBB, Args);
4526 InstructionList.push_back(I);
4527 break;
4528 }
4529 case bitc::FUNC_CODE_INST_TERMINATEPAD: { // TERMINATEPAD: [bb#,num,(ty,val)*]
4530 if (Record.size() < 1)
4531 return error("Invalid record");
4532 unsigned Idx = 0;
4533 bool HasUnwindDest = !!Record[Idx++];
4505
45344506 BasicBlock *UnwindDest = nullptr;
4535 if (HasUnwindDest) {
4536 if (Idx == Record.size())
4537 return error("Invalid record");
4507 if (Idx + 1 == Record.size()) {
45384508 UnwindDest = getBasicBlock(Record[Idx++]);
45394509 if (!UnwindDest)
45404510 return error("Invalid record");
45414511 }
4512
4513 if (Record.size() != Idx)
4514 return error("Invalid record");
4515
4516 I = TerminatePadInst::Create(ParentPad, UnwindDest, Args);
4517 InstructionList.push_back(I);
4518 break;
4519 }
4520 case bitc::FUNC_CODE_INST_CATCHPAD:
4521 case bitc::FUNC_CODE_INST_CLEANUPPAD: { // [tok,num,(ty,val)*]
4522 // We must have, at minimum, the outer scope and the number of arguments.
4523 if (Record.size() < 2)
4524 return error("Invalid record");
4525
4526 unsigned Idx = 0;
4527
4528 Value *ParentPad =
4529 getValue(Record, Idx++, NextValueNo, Type::getTokenTy(Context));
4530
45424531 unsigned NumArgOperands = Record[Idx++];
4532
45434533 SmallVector Args;
45444534 for (unsigned Op = 0; Op != NumArgOperands; ++Op) {
45454535 Value *Val;
45474537 return error("Invalid record");
45484538 Args.push_back(Val);
45494539 }
4540
45504541 if (Record.size() != Idx)
45514542 return error("Invalid record");
45524543
4553 I = TerminatePadInst::Create(Context, UnwindDest, Args);
4554 InstructionList.push_back(I);
4555 break;
4556 }
4557 case bitc::FUNC_CODE_INST_CLEANUPPAD: { // CLEANUPPAD: [num,(ty,val)*]
4558 if (Record.size() < 1)
4559 return error("Invalid record");
4560 unsigned Idx = 0;
4561 unsigned NumArgOperands = Record[Idx++];
4562 SmallVector Args;
4563 for (unsigned Op = 0; Op != NumArgOperands; ++Op) {
4564 Value *Val;
4565 if (getValueTypePair(Record, Idx, NextValueNo, Val))
4566 return error("Invalid record");
4567 Args.push_back(Val);
4568 }
4569 if (Record.size() != Idx)
4570 return error("Invalid record");
4571
4572 I = CleanupPadInst::Create(Context, Args);
4573 InstructionList.push_back(I);
4574 break;
4575 }
4576 case bitc::FUNC_CODE_INST_CATCHENDPAD: { // CATCHENDPADINST: [bb#] or []
4577 if (Record.size() > 1)
4578 return error("Invalid record");
4579 BasicBlock *BB = nullptr;
4580 if (Record.size() == 1) {
4581 BB = getBasicBlock(Record[0]);
4582 if (!BB)
4583 return error("Invalid record");
4584 }
4585 I = CatchEndPadInst::Create(Context, BB);
4586 InstructionList.push_back(I);
4587 break;
4588 }
4589 case bitc::FUNC_CODE_INST_CLEANUPENDPAD: { // CLEANUPENDPADINST: [val] or [val,bb#]
4590 if (Record.size() != 1 && Record.size() != 2)
4591 return error("Invalid record");
4592 unsigned Idx = 0;
4593 Value *CleanupPad = getValue(Record, Idx++, NextValueNo,
4594 Type::getTokenTy(Context), OC_CleanupPad);
4595 if (!CleanupPad)
4596 return error("Invalid record");
4597
4598 BasicBlock *BB = nullptr;
4599 if (Record.size() == 2) {
4600 BB = getBasicBlock(Record[Idx++]);
4601 if (!BB)
4602 return error("Invalid record");
4603 }
4604 I = CleanupEndPadInst::Create(cast(CleanupPad), BB);
4544 if (BitCode == bitc::FUNC_CODE_INST_CLEANUPPAD)
4545 I = CleanupPadInst::Create(ParentPad, Args);
4546 else
4547 I = CatchPadInst::Create(ParentPad, Args);
46054548 InstructionList.push_back(I);
46064549 break;
46074550 }
52235166
52245167 // Non-void values get registered in the value table for future use.
52255168 if (I && !I->getType()->isVoidTy())
5226 if (ValueList.assignValue(I, NextValueNo++))
5227 return error("Invalid forward reference");
5169 ValueList.assignValue(I, NextValueNo++);
52285170 }
52295171
52305172 OutOfRecordLoop:
19961996 Vals.push_back(VE.getValueID(CRI.getSuccessor()));
19971997 break;
19981998 }
1999 case Instruction::CleanupPad:
19992000 case Instruction::CatchPad: {
2000 Code = bitc::FUNC_CODE_INST_CATCHPAD;
2001 const auto &CPI = cast(I);
2002 Vals.push_back(VE.getValueID(CPI.getNormalDest()));
2003 Vals.push_back(VE.getValueID(CPI.getUnwindDest()));
2004 unsigned NumArgOperands = CPI.getNumArgOperands();
2001 const auto &FuncletPad = cast(I);
2002 Code = isa(FuncletPad) ? bitc::FUNC_CODE_INST_CATCHPAD
2003 : bitc::FUNC_CODE_INST_CLEANUPPAD;
2004 pushValue(FuncletPad.getParentPad(), InstID, Vals, VE);
2005
2006 unsigned NumArgOperands = FuncletPad.getNumArgOperands();
20052007 Vals.push_back(NumArgOperands);
20062008 for (unsigned Op = 0; Op != NumArgOperands; ++Op)
2007 PushValueAndType(CPI.getArgOperand(Op), InstID, Vals, VE);
2009 PushValueAndType(FuncletPad.getArgOperand(Op), InstID, Vals, VE);
2010 break;
2011 }
2012 case Instruction::CatchSwitch: {
2013 Code = bitc::FUNC_CODE_INST_CATCHSWITCH;
2014 const auto &CatchSwitch = cast(I);
2015
2016 pushValue(CatchSwitch.getParentPad(), InstID, Vals, VE);
2017
2018 unsigned NumHandlers = CatchSwitch.getNumHandlers();
2019 Vals.push_back(NumHandlers);
2020 for (const BasicBlock *CatchPadBB : CatchSwitch.handlers())
2021 Vals.push_back(VE.getValueID(CatchPadBB));
2022
2023 if (CatchSwitch.hasUnwindDest())
2024 Vals.push_back(VE.getValueID(CatchSwitch.getUnwindDest()));
20082025 break;
20092026 }
20102027 case Instruction::TerminatePad: {
20112028 Code = bitc::FUNC_CODE_INST_TERMINATEPAD;
20122029 const auto &TPI = cast(I);
2013 Vals.push_back(TPI.hasUnwindDest());
2014 if (TPI.hasUnwindDest())
2015 Vals.push_back(VE.getValueID(TPI.getUnwindDest()));
2030
2031 pushValue(TPI.getParentPad(), InstID, Vals, VE);
2032
20162033 unsigned NumArgOperands = TPI.getNumArgOperands();
20172034 Vals.push_back(NumArgOperands);
20182035 for (unsigned Op = 0; Op != NumArgOperands; ++Op)
20192036 PushValueAndType(TPI.getArgOperand(Op), InstID, Vals, VE);
2020 break;
2021 }
2022 case Instruction::CleanupPad: {
2023 Code = bitc::FUNC_CODE_INST_CLEANUPPAD;
2024 const auto &CPI = cast(I);
2025 unsigned NumOperands = CPI.getNumOperands();
2026 Vals.push_back(NumOperands);
2027 for (unsigned Op = 0; Op != NumOperands; ++Op)
2028 PushValueAndType(CPI.getOperand(Op), InstID, Vals, VE);
2029 break;
2030 }
2031 case Instruction::CatchEndPad: {
2032 Code = bitc::FUNC_CODE_INST_CATCHENDPAD;
2033 const auto &CEPI = cast(I);
2034 if (CEPI.hasUnwindDest())
2035 Vals.push_back(VE.getValueID(CEPI.getUnwindDest()));
2036 break;
2037 }
2038 case Instruction::CleanupEndPad: {
2039 Code = bitc::FUNC_CODE_INST_CLEANUPENDPAD;
2040 const auto &CEPI = cast(I);
2041 pushValue(CEPI.getCleanupPad(), InstID, Vals, VE);
2042 if (CEPI.hasUnwindDest())
2043 Vals.push_back(VE.getValueID(CEPI.getUnwindDest()));
2037
2038 if (TPI.hasUnwindDest())
2039 Vals.push_back(VE.getValueID(TPI.getUnwindDest()));
20442040 break;
20452041 }
20462042 case Instruction::Unreachable:
343343 InvokeStateChangeIterator(const WinEHFuncInfo &EHInfo,
344344 MachineFunction::const_iterator MFI,
345345 MachineFunction::const_iterator MFE,
346 MachineBasicBlock::const_iterator MBBI)
347 : EHInfo(EHInfo), MFI(MFI), MFE(MFE), MBBI(MBBI) {
346 MachineBasicBlock::const_iterator MBBI,
347 int BaseState)
348 : EHInfo(EHInfo), MFI(MFI), MFE(MFE), MBBI(MBBI), BaseState(BaseState) {
348349 LastStateChange.PreviousEndLabel = nullptr;
349350 LastStateChange.NewStartLabel = nullptr;
350