llvm.org GIT mirror llvm / b2d4143
Make llvm.eh.actions an intrinsic and add docs for it These docs *don't* match the way WinEHPrepare uses them yet, and verifier support isn't implemented either. The implementation will come after the documentation text is reviewed and agreed upon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232003 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 5 years ago
3 changed file(s) with 47 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
497497 intrinsic serves as a placeholder to delimit code before a catch handler is
498498 outlined. After the handler is outlined, this intrinsic is simply removed.
500 .. _llvm.eh.actions:
502 ``llvm.eh.actions``
503 ----------------------
505 .. code-block:: llvm
507 void @llvm.eh.actions()
509 This intrinsic represents the list of actions to take when an exception is
510 thrown. It is typically used by Windows exception handling schemes where cleanup
511 outlining is required by the runtime. The arguments are a sequence of ``i32``
512 sentinels indicating the action type followed by some pre-determined number of
513 arguments required to implement that action.
515 A code of ``i32 0`` indicates a cleanup action, which expects one additional
516 argument. The argument is a pointer to a function that implements the cleanup
517 action.
519 A code of ``i32 1`` indicates a catch action, which expects three additional
520 arguments. Different EH schemes give different meanings to the three arguments,
521 but the first argument indicates whether the catch should fire, the second is a
522 pointer to stack object where the exception object should be stored, and the
523 third is the code to run to catch the exception.
525 For Windows C++ exception handling, the first argument for a catch handler is a
526 pointer to the RTTI type descriptor for the object to catch. The third argument
527 is a pointer to a function implementing the catch. This function returns the
528 address of the basic block where execution should resume after handling the
529 exception.
531 For Windows SEH, the first argument is a pointer to the filter function, which
532 indicates if the exception should be caught or not. The second argument is
533 typically null. The third argument is the address of a basic block where the
534 exception will be handled. In other words, catch handlers are not outlined in
535 SEH. After running cleanups, execution immediately resumes at this PC.
537 In order to preserve the structure of the CFG, a call to '``llvm.eh.actions``'
538 must be followed by an ':ref:`indirectbr `' instruction that jumps
539 to the result of the intrinsic call.
501542 SJLJ Intrinsics
502543 ---------------
417417 [NoCapture<0>, NoCapture<1>]>;
418418 def int_eh_endcatch : Intrinsic<[], []>;
420 // Represents the list of actions to take when an exception is thrown.
421 def int_eh_actions : Intrinsic<[llvm_ptr_ty], [llvm_vararg_ty], []>;
420423 // __builtin_unwind_init is an undocumented GCC intrinsic that causes all
421424 // callee-saved registers to be saved and restored (regardless of whether they
422425 // are used) in the calling function. It is used by libgcc_eh.
382382 Module *M = F.getParent();
383383 LLVMContext &Context = M->getContext();
385 // FIXME: Make this an intrinsic.
386385 // Create a new function to receive the handler contents.
387386 PointerType *Int8PtrType = Type::getInt8PtrTy(Context);
388387 Type *Int32Type = Type::getInt32Ty(Context);
389 FunctionType *ActionTy = FunctionType::get(Int8PtrType, true);
390 Value *ActionIntrin = M->getOrInsertFunction("llvm.eh.actions", ActionTy);
388 Function *ActionIntrin = Intrinsic::getDeclaration(M, Intrinsic::eh_actions);
392390 for (LandingPadInst *LPad : LPads) {
393391 // Look for evidence that this landingpad has already been processed.
395393 BasicBlock *LPadBB = LPad->getParent();
396394 for (Instruction &Inst : LPadBB->getInstList()) {
397395 // FIXME: Make this an intrinsic.
398 if (auto *Call = dyn_cast(&Inst)) {
399 if (Call->getCalledFunction()->getName() == "llvm.eh.actions") {
396 if (auto *IntrinCall = dyn_cast(&Inst)) {
397 if (IntrinCall->getIntrinsicID() == Intrinsic::eh_actions) {
400398 LPadHasActionList = true;
401399 break;
402400 }