From 77a7a38006eed3dda8f63b1a352f3f60398bda41 Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Wed, 3 Oct 2018 22:22:48 +0000 Subject: [WebAssembly] Refactor WasmSignature and use it for MCSymbolWasm MCContext does not destroy MCSymbols on shutdown. So, rather than putting SmallVectors (which may heap-allocate) inside MCSymbolWasm, use unowned pointer to a WasmSignature instead. The signatures are now owned by the AsmPrinter. Also uses WasmSignature instead of param and result vectors in TargetStreamer, and leaves some TODOs for further simplification. Differential Revision: https://reviews.llvm.org/D52580 llvm-svn: 343733 --- .../WebAssembly/WebAssemblyMachineFunctionInfo.cpp | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp') diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp index e511e574050..073706e567e 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.cpp @@ -43,20 +43,34 @@ void llvm::ComputeLegalValueVTs(const Function &F, const TargetMachine &TM, } } -void llvm::ComputeSignatureVTs(const Function &F, const TargetMachine &TM, +void llvm::ComputeSignatureVTs(const FunctionType *Ty, const Function &F, + const TargetMachine &TM, SmallVectorImpl &Params, SmallVectorImpl &Results) { - ComputeLegalValueVTs(F, TM, F.getReturnType(), Results); + ComputeLegalValueVTs(F, TM, Ty->getReturnType(), Results); + MVT PtrVT = MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits()); if (Results.size() > 1) { // WebAssembly currently can't lower returns of multiple values without // demoting to sret (see WebAssemblyTargetLowering::CanLowerReturn). So // replace multiple return values with a pointer parameter. Results.clear(); - Params.push_back( - MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits())); + Params.push_back(PtrVT); } - for (auto &Arg : F.args()) - ComputeLegalValueVTs(F, TM, Arg.getType(), Params); + for (auto *Param : Ty->params()) + ComputeLegalValueVTs(F, TM, Param, Params); + if (Ty->isVarArg()) + Params.push_back(PtrVT); +} + +std::unique_ptr +llvm::SignatureFromMVTs(const SmallVectorImpl &Results, + const SmallVectorImpl &Params) { + auto Sig = make_unique(); + for (MVT Ty : Results) + Sig->Returns.push_back(WebAssembly::toValType(Ty)); + for (MVT Ty : Params) + Sig->Params.push_back(WebAssembly::toValType(Ty)); + return Sig; } -- cgit v1.2.3