From: Matt Arsenault Date: Wed, 2 Nov 2022 21:46:00 +0000 (-0700) Subject: WebAssembly: Remove MachineFunction reference from MFI X-Git-Tag: upstream/17.0.6~27883 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff2b60bbcb28701c86b200b0c03439a2e6ef6b44;p=platform%2Fupstream%2Fllvm.git WebAssembly: Remove MachineFunction reference from MFI The MachineFunctionInfo here is a bit awkward because WasmEHInfo is in the MachineFunction but handled from the target code. Either everything should move into WebAssembly or into the MachineFunction for MIR serialization. --- diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index cd3aa93..4d2e5d3 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -280,6 +280,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { // Keep track of the function section. MCSection *Section = nullptr; + // Catchpad unwind destination info for wasm EH. // Keeps track of Wasm exception handling related data. This will be null for // functions that aren't using a wasm EH personality. WasmEHFuncInfo *WasmEHInfo = nullptr; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp index 96284687..7207fbe 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp @@ -28,10 +28,9 @@ MachineFunctionInfo *WebAssemblyFunctionInfo::clone( BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap &Src2DstMBB) const { - WebAssemblyFunctionInfo *Clone = - DestMF.cloneInfo(*this); - Clone->MF = &DestMF; - return Clone; + // TODO: Implement cloning for WasmEHFuncInfo. This will have invalid block + // references. + return DestMF.cloneInfo(*this); } void WebAssemblyFunctionInfo::initWARegs(MachineRegisterInfo &MRI) { @@ -122,11 +121,8 @@ llvm::signatureFromMVTs(const SmallVectorImpl &Results, } yaml::WebAssemblyFunctionInfo::WebAssemblyFunctionInfo( - const llvm::WebAssemblyFunctionInfo &MFI) + const llvm::MachineFunction &MF, const llvm::WebAssemblyFunctionInfo &MFI) : 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()) @@ -134,7 +130,8 @@ yaml::WebAssemblyFunctionInfo::WebAssemblyFunctionInfo( // MFI.getWasmEHFuncInfo() is non-null only for functions with the // personality function. - if (EHInfo) { + + if (auto *EHInfo = MF.getWasmEHFuncInfo()) { // 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. @@ -155,15 +152,19 @@ void yaml::WebAssemblyFunctionInfo::mappingImpl(yaml::IO &YamlIO) { } void WebAssemblyFunctionInfo::initializeBaseYamlFields( - const yaml::WebAssemblyFunctionInfo &YamlMFI) { + MachineFunction &MF, 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) { + + // FIXME: WasmEHInfo is defined in the MachineFunction, but serialized + // here. Either WasmEHInfo should be moved out of MachineFunction, or the + // serialization handling should be moved to MachineFunction. + if (WasmEHFuncInfo *WasmEHInfo = MF.getWasmEHFuncInfo()) { for (auto KV : YamlMFI.SrcToUnwindDest) - WasmEHInfo->setUnwindDest(MF->getBlockNumbered(KV.first), - MF->getBlockNumbered(KV.second)); + WasmEHInfo->setUnwindDest(MF.getBlockNumbered(KV.first), + MF.getBlockNumbered(KV.second)); } } diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h index 6196170..00bacbf 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h @@ -31,8 +31,6 @@ struct WebAssemblyFunctionInfo; /// This class is derived from MachineFunctionInfo and contains private /// WebAssembly-specific information for each MachineFunction. class WebAssemblyFunctionInfo final : public MachineFunctionInfo { - const MachineFunction *MF; - std::vector Params; std::vector Results; std::vector Locals; @@ -66,12 +64,8 @@ class WebAssemblyFunctionInfo final : public MachineFunctionInfo { // Function properties. bool CFGStackified = false; - // Catchpad unwind destination info for wasm EH. - WasmEHFuncInfo *WasmEHInfo = nullptr; - public: - explicit WebAssemblyFunctionInfo(MachineFunction &MF_) - : MF(&MF_), WasmEHInfo(MF_.getWasmEHFuncInfo()) {} + explicit WebAssemblyFunctionInfo(MachineFunction &) {} ~WebAssemblyFunctionInfo() override; MachineFunctionInfo * @@ -79,9 +73,8 @@ public: const DenseMap &Src2DstMBB) const override; - const MachineFunction &getMachineFunction() const { return *MF; } - - void initializeBaseYamlFields(const yaml::WebAssemblyFunctionInfo &YamlMFI); + void initializeBaseYamlFields(MachineFunction &MF, + const yaml::WebAssemblyFunctionInfo &YamlMFI); void addParam(MVT VT) { Params.push_back(VT); } const std::vector &getParams() const { return Params; } @@ -166,9 +159,6 @@ public: bool isCFGStackified() const { return CFGStackified; } void setCFGStackified(bool Value = true) { CFGStackified = Value; } - - WasmEHFuncInfo *getWasmEHFuncInfo() const { return WasmEHInfo; } - void setWasmEHFuncInfo(WasmEHFuncInfo *Info) { WasmEHInfo = Info; } }; void computeLegalValueVTs(const WebAssemblyTargetLowering &TLI, @@ -205,7 +195,8 @@ struct WebAssemblyFunctionInfo final : public yaml::MachineFunctionInfo { BBNumberMap SrcToUnwindDest; WebAssemblyFunctionInfo() = default; - WebAssemblyFunctionInfo(const llvm::WebAssemblyFunctionInfo &MFI); + WebAssemblyFunctionInfo(const llvm::MachineFunction &MF, + const llvm::WebAssemblyFunctionInfo &MFI); void mappingImpl(yaml::IO &YamlIO) override; ~WebAssemblyFunctionInfo() = default; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 76f0363..9e4a303 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -585,7 +585,7 @@ WebAssemblyTargetMachine::createDefaultFuncInfoYAML() const { yaml::MachineFunctionInfo *WebAssemblyTargetMachine::convertFuncInfoToYAML( const MachineFunction &MF) const { const auto *MFI = MF.getInfo(); - return new yaml::WebAssemblyFunctionInfo(*MFI); + return new yaml::WebAssemblyFunctionInfo(MF, *MFI); } bool WebAssemblyTargetMachine::parseMachineFunctionInfo( @@ -593,6 +593,6 @@ bool WebAssemblyTargetMachine::parseMachineFunctionInfo( SMDiagnostic &Error, SMRange &SourceRange) const { const auto &YamlMFI = static_cast(MFI); MachineFunction &MF = PFS.MF; - MF.getInfo()->initializeBaseYamlFields(YamlMFI); + MF.getInfo()->initializeBaseYamlFields(MF, YamlMFI); return false; }