summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-07-29 20:15:26 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-07-29 20:15:26 +0000
commit344a3780b2e33f6ca763666c380202b18aab72a3 (patch)
treef0b203ee6eb71d7fdd792373e3c81eb18d6934dd /llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
parentb60736ec1405bb0a8dd40989f67ef4c93da068ab (diff)
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
index adee2f0553f9..00b11321fdb2 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp
@@ -13,9 +13,12 @@
//===----------------------------------------------------------------------===//
#include "WebAssemblyMachineFunctionInfo.h"
+#include "MCTargetDesc/WebAssemblyInstPrinter.h"
+#include "Utils/WebAssemblyTypeUtilities.h"
#include "WebAssemblyISelLowering.h"
#include "WebAssemblySubtarget.h"
#include "llvm/CodeGen/Analysis.h"
+#include "llvm/CodeGen/WasmEHFuncInfo.h"
#include "llvm/Target/TargetMachine.h"
using namespace llvm;
@@ -104,7 +107,32 @@ llvm::signatureFromMVTs(const SmallVectorImpl<MVT> &Results,
yaml::WebAssemblyFunctionInfo::WebAssemblyFunctionInfo(
const llvm::WebAssemblyFunctionInfo &MFI)
- : CFGStackified(MFI.isCFGStackified()) {}
+ : CFGStackified(MFI.isCFGStackified()) {
+ auto *EHInfo = MFI.getWasmEHFuncInfo();
+ const llvm::MachineFunction &MF = MFI.getMachineFunction();
+
+ for (auto VT : MFI.getParams())
+ Params.push_back(EVT(VT).getEVTString());
+ for (auto VT : MFI.getResults())
+ Results.push_back(EVT(VT).getEVTString());
+
+ // MFI.getWasmEHFuncInfo() is non-null only for functions with the
+ // personality function.
+ if (EHInfo) {
+ // SrcToUnwindDest can contain stale mappings in case BBs are removed in
+ // optimizations, in case, for example, they are unreachable. We should not
+ // include their info.
+ SmallPtrSet<const MachineBasicBlock *, 16> MBBs;
+ for (const auto &MBB : MF)
+ MBBs.insert(&MBB);
+ for (auto KV : EHInfo->SrcToUnwindDest) {
+ auto *SrcBB = KV.first.get<MachineBasicBlock *>();
+ auto *DestBB = KV.second.get<MachineBasicBlock *>();
+ if (MBBs.count(SrcBB) && MBBs.count(DestBB))
+ SrcToUnwindDest[SrcBB->getNumber()] = DestBB->getNumber();
+ }
+ }
+}
void yaml::WebAssemblyFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
MappingTraits<WebAssemblyFunctionInfo>::mapping(YamlIO, *this);
@@ -113,4 +141,13 @@ void yaml::WebAssemblyFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
void WebAssemblyFunctionInfo::initializeBaseYamlFields(
const yaml::WebAssemblyFunctionInfo &YamlMFI) {
CFGStackified = YamlMFI.CFGStackified;
+ for (auto VT : YamlMFI.Params)
+ addParam(WebAssembly::parseMVT(VT.Value));
+ for (auto VT : YamlMFI.Results)
+ addResult(WebAssembly::parseMVT(VT.Value));
+ if (WasmEHInfo) {
+ for (auto KV : YamlMFI.SrcToUnwindDest)
+ WasmEHInfo->setUnwindDest(MF.getBlockNumbered(KV.first),
+ MF.getBlockNumbered(KV.second));
+ }
}