Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:38

0001 //===--- llvm/CodeGen/WasmEHFuncInfo.h --------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // Data structures for Wasm exception handling schemes.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CODEGEN_WASMEHFUNCINFO_H
0014 #define LLVM_CODEGEN_WASMEHFUNCINFO_H
0015 
0016 #include "llvm/ADT/DenseMap.h"
0017 #include "llvm/ADT/PointerUnion.h"
0018 #include "llvm/ADT/SmallPtrSet.h"
0019 
0020 namespace llvm {
0021 
0022 class BasicBlock;
0023 class Function;
0024 class MachineBasicBlock;
0025 
0026 namespace WebAssembly {
0027 enum Tag { CPP_EXCEPTION = 0, C_LONGJMP = 1 };
0028 }
0029 
0030 using BBOrMBB = PointerUnion<const BasicBlock *, MachineBasicBlock *>;
0031 
0032 struct WasmEHFuncInfo {
0033   // When there is an entry <A, B>, if an exception is not caught by A, it
0034   // should next unwind to the EH pad B.
0035   DenseMap<BBOrMBB, BBOrMBB> SrcToUnwindDest;
0036   DenseMap<BBOrMBB, SmallPtrSet<BBOrMBB, 4>> UnwindDestToSrcs; // reverse map
0037 
0038   // Helper functions
0039   const BasicBlock *getUnwindDest(const BasicBlock *BB) const {
0040     assert(hasUnwindDest(BB));
0041     return cast<const BasicBlock *>(SrcToUnwindDest.lookup(BB));
0042   }
0043   SmallPtrSet<const BasicBlock *, 4> getUnwindSrcs(const BasicBlock *BB) const {
0044     assert(hasUnwindSrcs(BB));
0045     const auto &Set = UnwindDestToSrcs.lookup(BB);
0046     SmallPtrSet<const BasicBlock *, 4> Ret;
0047     for (const auto P : Set)
0048       Ret.insert(cast<const BasicBlock *>(P));
0049     return Ret;
0050   }
0051   void setUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
0052     SrcToUnwindDest[BB] = Dest;
0053     UnwindDestToSrcs[Dest].insert(BB);
0054   }
0055   bool hasUnwindDest(const BasicBlock *BB) const {
0056     return SrcToUnwindDest.count(BB);
0057   }
0058   bool hasUnwindSrcs(const BasicBlock *BB) const {
0059     return UnwindDestToSrcs.count(BB);
0060   }
0061 
0062   MachineBasicBlock *getUnwindDest(MachineBasicBlock *MBB) const {
0063     assert(hasUnwindDest(MBB));
0064     return cast<MachineBasicBlock *>(SrcToUnwindDest.lookup(MBB));
0065   }
0066   SmallPtrSet<MachineBasicBlock *, 4>
0067   getUnwindSrcs(MachineBasicBlock *MBB) const {
0068     assert(hasUnwindSrcs(MBB));
0069     const auto &Set = UnwindDestToSrcs.lookup(MBB);
0070     SmallPtrSet<MachineBasicBlock *, 4> Ret;
0071     for (const auto P : Set)
0072       Ret.insert(cast<MachineBasicBlock *>(P));
0073     return Ret;
0074   }
0075   void setUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) {
0076     SrcToUnwindDest[MBB] = Dest;
0077     UnwindDestToSrcs[Dest].insert(MBB);
0078   }
0079   bool hasUnwindDest(MachineBasicBlock *MBB) const {
0080     return SrcToUnwindDest.count(MBB);
0081   }
0082   bool hasUnwindSrcs(MachineBasicBlock *MBB) const {
0083     return UnwindDestToSrcs.count(MBB);
0084   }
0085 };
0086 
0087 // Analyze the IR in the given function to build WasmEHFuncInfo.
0088 void calculateWasmEHInfo(const Function *F, WasmEHFuncInfo &EHInfo);
0089 
0090 } // namespace llvm
0091 
0092 #endif // LLVM_CODEGEN_WASMEHFUNCINFO_H