Index: lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp +++ lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp @@ -874,5 +874,6 @@ .isOSBinFormatELF()) appendEndToFunction(MF, TII); + MF.getInfo()->setCFGStackified(); return true; } Index: lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h =================================================================== --- lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h +++ lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h @@ -17,11 +17,16 @@ #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" #include "llvm/BinaryFormat/Wasm.h" +#include "llvm/CodeGen/MIRYamlMapping.h" #include "llvm/CodeGen/MachineRegisterInfo.h" #include "llvm/MC/MCSymbolWasm.h" namespace llvm { +namespace yaml { +struct WebAssemblyFunctionInfo; +} + /// This class is derived from MachineFunctionInfo and contains private /// WebAssembly-specific information for each MachineFunction. class WebAssemblyFunctionInfo final : public MachineFunctionInfo { @@ -51,9 +56,13 @@ // overaligned values on the user stack. unsigned BasePtrVreg = -1U; + // Function properties. + bool CFGStackified = false; + public: explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {} ~WebAssemblyFunctionInfo() override; + void initializeBaseYamlFields(const yaml::WebAssemblyFunctionInfo &YamlMFI); void addParam(MVT VT) { Params.push_back(VT); } const std::vector &getParams() const { return Params; } @@ -117,6 +126,9 @@ assert(Reg & INT32_MIN); return Reg & INT32_MAX; } + + bool isCFGStackified() const { return CFGStackified; } + void setCFGStackified(bool Value = true) { CFGStackified = Value; } }; void computeLegalValueVTs(const Function &F, const TargetMachine &TM, Type *Ty, @@ -135,6 +147,26 @@ signatureFromMVTs(const SmallVectorImpl &Results, const SmallVectorImpl &Params); +namespace yaml { + +struct WebAssemblyFunctionInfo final : public yaml::MachineFunctionInfo { + bool CFGStackified = false; + + WebAssemblyFunctionInfo() = default; + WebAssemblyFunctionInfo(const llvm::WebAssemblyFunctionInfo &MFI); + + void mappingImpl(yaml::IO &YamlIO) override; + ~WebAssemblyFunctionInfo() = default; +}; + +template <> struct MappingTraits { + static void mapping(IO &YamlIO, WebAssemblyFunctionInfo &MFI) { + YamlIO.mapOptional("isCFGStackified", MFI.CFGStackified, false); + } +}; + +} // end namespace yaml + } // end namespace llvm #endif Index: lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp +++ lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp @@ -77,3 +77,16 @@ valTypesFromMVTs(Params, Sig->Params); return Sig; } + +yaml::WebAssemblyFunctionInfo::WebAssemblyFunctionInfo( + const llvm::WebAssemblyFunctionInfo &MFI) + : CFGStackified(MFI.isCFGStackified()) {} + +void yaml::WebAssemblyFunctionInfo::mappingImpl(yaml::IO &YamlIO) { + MappingTraits::mapping(YamlIO, *this); +} + +void WebAssemblyFunctionInfo::initializeBaseYamlFields( + const yaml::WebAssemblyFunctionInfo &YamlMFI) { + CFGStackified = YamlMFI.CFGStackified; +} Index: lib/Target/WebAssembly/WebAssemblyTargetMachine.h =================================================================== --- lib/Target/WebAssembly/WebAssemblyTargetMachine.h +++ lib/Target/WebAssembly/WebAssemblyTargetMachine.h @@ -51,6 +51,14 @@ TargetTransformInfo getTargetTransformInfo(const Function &F) override; bool usesPhysRegsForPEI() const override { return false; } + + yaml::MachineFunctionInfo *createDefaultFuncInfoYAML() const override; + yaml::MachineFunctionInfo * + convertFuncInfoToYAML(const MachineFunction &MF) const override; + bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, + PerFunctionMIParsingState &PFS, + SMDiagnostic &Error, + SMRange &SourceRange) const override; }; } // end namespace llvm Index: lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp =================================================================== --- lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -14,8 +14,10 @@ #include "WebAssemblyTargetMachine.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" #include "WebAssembly.h" +#include "WebAssemblyMachineFunctionInfo.h" #include "WebAssemblyTargetObjectFile.h" #include "WebAssemblyTargetTransformInfo.h" +#include "llvm/CodeGen/MIRParser/MIParser.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/RegAllocRegistry.h" @@ -367,3 +369,24 @@ // Create a mapping from LLVM CodeGen virtual registers to wasm registers. addPass(createWebAssemblyRegNumbering()); } + +yaml::MachineFunctionInfo * +WebAssemblyTargetMachine::createDefaultFuncInfoYAML() const { + return new yaml::WebAssemblyFunctionInfo(); +} + +yaml::MachineFunctionInfo *WebAssemblyTargetMachine::convertFuncInfoToYAML( + const MachineFunction &MF) const { + const auto *MFI = MF.getInfo(); + return new yaml::WebAssemblyFunctionInfo(*MFI); +} + +bool WebAssemblyTargetMachine::parseMachineFunctionInfo( + const yaml::MachineFunctionInfo &MFI, PerFunctionMIParsingState &PFS, + SMDiagnostic &Error, SMRange &SourceRange) const { + const auto &YamlMFI = + reinterpret_cast(MFI); + MachineFunction &MF = PFS.MF; + MF.getInfo()->initializeBaseYamlFields(YamlMFI); + return false; +} Index: test/CodeGen/WebAssembly/function-info.mir =================================================================== --- /dev/null +++ test/CodeGen/WebAssembly/function-info.mir @@ -0,0 +1,12 @@ +# RUN: llc -mtriple=wasm32-unknown-unknown -run-pass wasm-cfg-stackify %s -o - | FileCheck %s + +# CHECK-LABEL: function_property_test +# CHECK: machineFunctionInfo: +# CHECK: isCFGStackified: true +name: function_property_test +liveins: + - { reg: '$arguments' } +body: | + bb.0: + RETURN_VOID implicit-def dead $arguments +...