llvm.org GIT mirror llvm / d0b2625 include / llvm / CodeGen / WinEHFuncInfo.h
d0b2625

Tree @d0b2625 (Download .tar.gz)

WinEHFuncInfo.h @d0b2625

0a8ff29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69d051c
 
0a8ff29
 
 
 
dff7549
0a8ff29
1114aa2
0a8ff29
 
0f696bb
5f50442
675e22e
0a8ff29
c181443
0a8ff29
c0e64ad
0a8ff29
 
c839e94
 
0a8ff29
7577188
 
c839e94
0a8ff29
a03aa8f
0a8ff29
 
c839e94
69d051c
 
 
 
 
646073b
 
69d051c
 
 
 
 
 
 
0a8ff29
 
595419d
 
66ef931
 
 
 
 
a03aa8f
0a8ff29
 
 
69d051c
 
42be08a
6438662
0a8ff29
 
7d21fd6
 
 
 
 
 
 
 
 
0a8ff29
42be08a
8cec2f2
 
68754da
 
8cec2f2
c839e94
0a8ff29
69d051c
7d21fd6
3e16bd3
a736fb5
0a8ff29
c839e94
42be08a
8cec2f2
c181443
 
dff7549
66ef931
d0b2625
d480d30
3e16bd3
0a8ff29
 
5f50442
 
 
 
 
 
69d051c
 
68754da
7d21fd6
 
68754da
 
cd52a7a
0a8ff29
//===-- llvm/CodeGen/WinEHFuncInfo.h ----------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Data structures and associated state for Windows exception handling schemes.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CODEGEN_WINEHFUNCINFO_H
#define LLVM_CODEGEN_WINEHFUNCINFO_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/TinyPtrVector.h"

namespace llvm {
class AllocaInst;
class BasicBlock;
class CatchReturnInst;
class Constant;
class Function;
class GlobalVariable;
class InvokeInst;
class IntrinsicInst;
class LandingPadInst;
class MCExpr;
class MCSymbol;
class MachineBasicBlock;
class Value;

// The following structs respresent the .xdata tables for various
// Windows-related EH personalities.

typedef PointerUnion<const BasicBlock *, MachineBasicBlock *> MBBOrBasicBlock;

struct CxxUnwindMapEntry {
  int ToState;
  MBBOrBasicBlock Cleanup;
};

/// Similar to CxxUnwindMapEntry, but supports SEH filters.
struct SEHUnwindMapEntry {
  /// If unwinding continues through this handler, transition to the handler at
  /// this state. This indexes into SEHUnwindMap.
  int ToState = -1;

  bool IsFinally = false;

  /// Holds the filter expression function.
  const Function *Filter = nullptr;

  /// Holds the __except or __finally basic block.
  MBBOrBasicBlock Handler;
};

struct WinEHHandlerType {
  int Adjectives;
  /// The CatchObj starts out life as an LLVM alloca and is eventually turned
  /// frame index.
  union {
    const AllocaInst *Alloca;
    int FrameIndex;
  } CatchObj = {};
  GlobalVariable *TypeDescriptor;
  MBBOrBasicBlock Handler;
};

struct WinEHTryBlockMapEntry {
  int TryLow = -1;
  int TryHigh = -1;
  int CatchHigh = -1;
  SmallVector<WinEHHandlerType, 1> HandlerArray;
};

enum class ClrHandlerType { Catch, Finally, Fault, Filter };

struct ClrEHUnwindMapEntry {
  MBBOrBasicBlock Handler;
  uint32_t TypeToken;
  int Parent;
  ClrHandlerType HandlerType;
};

struct WinEHFuncInfo {
  DenseMap<const Instruction *, int> EHPadStateMap;
  DenseMap<const FuncletPadInst *, int> FuncletBaseStateMap;
  DenseMap<const InvokeInst *, int> InvokeStateMap;
  DenseMap<const CatchReturnInst *, const BasicBlock *>
      CatchRetSuccessorColorMap;
  DenseMap<MCSymbol *, std::pair<int, MCSymbol *>> LabelToStateMap;
  SmallVector<CxxUnwindMapEntry, 4> CxxUnwindMap;
  SmallVector<WinEHTryBlockMapEntry, 4> TryBlockMap;
  SmallVector<SEHUnwindMapEntry, 4> SEHUnwindMap;
  SmallVector<ClrEHUnwindMapEntry, 4> ClrEHUnwindMap;
  int UnwindHelpFrameIdx = INT_MAX;
  int PSPSymFrameIdx = INT_MAX;

  int getLastStateNumber() const { return CxxUnwindMap.size() - 1; }

  void addIPToStateRange(const InvokeInst *II, MCSymbol *InvokeBegin,
                         MCSymbol *InvokeEnd);

  int EHRegNodeFrameIndex = INT_MAX;
  int EHRegNodeEndOffset = INT_MAX;
  int SEHSetFrameOffset = INT_MAX;

  WinEHFuncInfo() {}
};

/// Analyze the IR in ParentFn and it's handlers to build WinEHFuncInfo, which
/// describes the state numbers and tables used by __CxxFrameHandler3. This
/// analysis assumes that WinEHPrepare has already been run.
void calculateWinCXXEHStateNumbers(const Function *ParentFn,
                                   WinEHFuncInfo &FuncInfo);

void calculateSEHStateNumbers(const Function *ParentFn,
                              WinEHFuncInfo &FuncInfo);

void calculateClrEHStateNumbers(const Function *Fn, WinEHFuncInfo &FuncInfo);

void calculateCatchReturnSuccessorColors(const Function *Fn,
                                         WinEHFuncInfo &FuncInfo);
}
#endif // LLVM_CODEGEN_WINEHFUNCINFO_H