2015-06-30 07:51:55 +08:00
|
|
|
//=- WebAssemblyMachineFunctionInfo.cpp - WebAssembly Machine Function Info -=//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-06-30 07:51:55 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This file implements WebAssembly-specific per-machine-function
|
2015-06-30 07:51:55 +08:00
|
|
|
/// information.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "WebAssemblyMachineFunctionInfo.h"
|
2016-10-07 06:29:32 +08:00
|
|
|
#include "WebAssemblyISelLowering.h"
|
|
|
|
#include "WebAssemblySubtarget.h"
|
|
|
|
#include "llvm/CodeGen/Analysis.h"
|
2020-05-24 02:49:38 +08:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2015-06-30 07:51:55 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
WebAssemblyFunctionInfo::~WebAssemblyFunctionInfo() = default; // anchor.
|
2015-11-13 08:21:05 +08:00
|
|
|
|
2020-06-18 22:32:32 +08:00
|
|
|
void WebAssemblyFunctionInfo::initWARegs(MachineRegisterInfo &MRI) {
|
2015-11-13 08:21:05 +08:00
|
|
|
assert(WARegs.empty());
|
|
|
|
unsigned Reg = UnusedReg;
|
2020-06-18 22:32:32 +08:00
|
|
|
WARegs.resize(MRI.getNumVirtRegs(), Reg);
|
2015-11-13 08:21:05 +08:00
|
|
|
}
|
2016-10-07 06:29:32 +08:00
|
|
|
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
void llvm::computeLegalValueVTs(const Function &F, const TargetMachine &TM,
|
2016-10-07 06:29:32 +08:00
|
|
|
Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
|
|
|
|
const DataLayout &DL(F.getParent()->getDataLayout());
|
|
|
|
const WebAssemblyTargetLowering &TLI =
|
|
|
|
*TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
|
|
|
|
SmallVector<EVT, 4> VTs;
|
|
|
|
ComputeValueVTs(TLI, DL, Ty, VTs);
|
|
|
|
|
|
|
|
for (EVT VT : VTs) {
|
|
|
|
unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT);
|
|
|
|
MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT);
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
for (unsigned I = 0; I != NumRegs; ++I)
|
2016-10-07 06:29:32 +08:00
|
|
|
ValueVTs.push_back(RegisterVT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[WebAssembly] Support swiftself and swifterror for WebAssembly target
Summary:
Swift ABI is based on basic C ABI described here https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md
Swift Calling Convention on WebAssembly is a little deffer from swiftcc
on another architectures.
On non WebAssembly arch, swiftcc accepts extra parameters that are
attributed with swifterror or swiftself by caller. Even if callee
doesn't have these parameters, the invocation succeed ignoring extra
parameters.
But WebAssembly strictly checks that callee and caller signatures are
same. https://github.com/WebAssembly/design/blob/master/Semantics.md#calls
So at WebAssembly level, all swiftcc functions end up extra arguments
and all function definitions and invocations explicitly have additional
parameters to fill swifterror and swiftself.
This patch support signature difference for swiftself and swifterror cc
is swiftcc.
e.g.
```
declare swiftcc void @foo(i32, i32)
@data = global i8* bitcast (void (i32, i32)* @foo to i8*)
define swiftcc void @bar() {
%1 = load i8*, i8** @data
%2 = bitcast i8* %1 to void (i32, i32, i32)*
call swiftcc void %2(i32 1, i32 2, i32 swiftself 3)
ret void
}
```
For swiftcc, emit additional swiftself and swifterror parameters
if there aren't while lowering. These additional parameters are added
for both callee and caller.
They are necessary to match callee and caller signature for direct and
indirect function call.
Differential Revision: https://reviews.llvm.org/D76049
2020-03-20 08:39:34 +08:00
|
|
|
void llvm::computeSignatureVTs(const FunctionType *Ty,
|
|
|
|
const Function *TargetFunc,
|
|
|
|
const Function &ContextFunc,
|
2018-10-04 06:22:48 +08:00
|
|
|
const TargetMachine &TM,
|
2016-10-07 06:29:32 +08:00
|
|
|
SmallVectorImpl<MVT> &Params,
|
|
|
|
SmallVectorImpl<MVT> &Results) {
|
[WebAssembly] Support swiftself and swifterror for WebAssembly target
Summary:
Swift ABI is based on basic C ABI described here https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md
Swift Calling Convention on WebAssembly is a little deffer from swiftcc
on another architectures.
On non WebAssembly arch, swiftcc accepts extra parameters that are
attributed with swifterror or swiftself by caller. Even if callee
doesn't have these parameters, the invocation succeed ignoring extra
parameters.
But WebAssembly strictly checks that callee and caller signatures are
same. https://github.com/WebAssembly/design/blob/master/Semantics.md#calls
So at WebAssembly level, all swiftcc functions end up extra arguments
and all function definitions and invocations explicitly have additional
parameters to fill swifterror and swiftself.
This patch support signature difference for swiftself and swifterror cc
is swiftcc.
e.g.
```
declare swiftcc void @foo(i32, i32)
@data = global i8* bitcast (void (i32, i32)* @foo to i8*)
define swiftcc void @bar() {
%1 = load i8*, i8** @data
%2 = bitcast i8* %1 to void (i32, i32, i32)*
call swiftcc void %2(i32 1, i32 2, i32 swiftself 3)
ret void
}
```
For swiftcc, emit additional swiftself and swifterror parameters
if there aren't while lowering. These additional parameters are added
for both callee and caller.
They are necessary to match callee and caller signature for direct and
indirect function call.
Differential Revision: https://reviews.llvm.org/D76049
2020-03-20 08:39:34 +08:00
|
|
|
computeLegalValueVTs(ContextFunc, TM, Ty->getReturnType(), Results);
|
2016-10-07 06:29:32 +08:00
|
|
|
|
2018-10-04 06:22:48 +08:00
|
|
|
MVT PtrVT = MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits());
|
2019-10-10 05:42:08 +08:00
|
|
|
if (Results.size() > 1 &&
|
[WebAssembly] Support swiftself and swifterror for WebAssembly target
Summary:
Swift ABI is based on basic C ABI described here https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md
Swift Calling Convention on WebAssembly is a little deffer from swiftcc
on another architectures.
On non WebAssembly arch, swiftcc accepts extra parameters that are
attributed with swifterror or swiftself by caller. Even if callee
doesn't have these parameters, the invocation succeed ignoring extra
parameters.
But WebAssembly strictly checks that callee and caller signatures are
same. https://github.com/WebAssembly/design/blob/master/Semantics.md#calls
So at WebAssembly level, all swiftcc functions end up extra arguments
and all function definitions and invocations explicitly have additional
parameters to fill swifterror and swiftself.
This patch support signature difference for swiftself and swifterror cc
is swiftcc.
e.g.
```
declare swiftcc void @foo(i32, i32)
@data = global i8* bitcast (void (i32, i32)* @foo to i8*)
define swiftcc void @bar() {
%1 = load i8*, i8** @data
%2 = bitcast i8* %1 to void (i32, i32, i32)*
call swiftcc void %2(i32 1, i32 2, i32 swiftself 3)
ret void
}
```
For swiftcc, emit additional swiftself and swifterror parameters
if there aren't while lowering. These additional parameters are added
for both callee and caller.
They are necessary to match callee and caller signature for direct and
indirect function call.
Differential Revision: https://reviews.llvm.org/D76049
2020-03-20 08:39:34 +08:00
|
|
|
!TM.getSubtarget<WebAssemblySubtarget>(ContextFunc).hasMultivalue()) {
|
2019-10-10 05:42:08 +08:00
|
|
|
// WebAssembly can't lower returns of multiple values without demoting to
|
|
|
|
// sret unless multivalue is enabled (see
|
|
|
|
// WebAssemblyTargetLowering::CanLowerReturn). So replace multiple return
|
|
|
|
// values with a poitner parameter.
|
2016-10-07 06:29:32 +08:00
|
|
|
Results.clear();
|
2018-10-04 06:22:48 +08:00
|
|
|
Params.push_back(PtrVT);
|
2016-10-07 06:29:32 +08:00
|
|
|
}
|
|
|
|
|
2018-10-04 06:22:48 +08:00
|
|
|
for (auto *Param : Ty->params())
|
[WebAssembly] Support swiftself and swifterror for WebAssembly target
Summary:
Swift ABI is based on basic C ABI described here https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md
Swift Calling Convention on WebAssembly is a little deffer from swiftcc
on another architectures.
On non WebAssembly arch, swiftcc accepts extra parameters that are
attributed with swifterror or swiftself by caller. Even if callee
doesn't have these parameters, the invocation succeed ignoring extra
parameters.
But WebAssembly strictly checks that callee and caller signatures are
same. https://github.com/WebAssembly/design/blob/master/Semantics.md#calls
So at WebAssembly level, all swiftcc functions end up extra arguments
and all function definitions and invocations explicitly have additional
parameters to fill swifterror and swiftself.
This patch support signature difference for swiftself and swifterror cc
is swiftcc.
e.g.
```
declare swiftcc void @foo(i32, i32)
@data = global i8* bitcast (void (i32, i32)* @foo to i8*)
define swiftcc void @bar() {
%1 = load i8*, i8** @data
%2 = bitcast i8* %1 to void (i32, i32, i32)*
call swiftcc void %2(i32 1, i32 2, i32 swiftself 3)
ret void
}
```
For swiftcc, emit additional swiftself and swifterror parameters
if there aren't while lowering. These additional parameters are added
for both callee and caller.
They are necessary to match callee and caller signature for direct and
indirect function call.
Differential Revision: https://reviews.llvm.org/D76049
2020-03-20 08:39:34 +08:00
|
|
|
computeLegalValueVTs(ContextFunc, TM, Param, Params);
|
2018-10-04 06:22:48 +08:00
|
|
|
if (Ty->isVarArg())
|
|
|
|
Params.push_back(PtrVT);
|
[WebAssembly] Support swiftself and swifterror for WebAssembly target
Summary:
Swift ABI is based on basic C ABI described here https://github.com/WebAssembly/tool-conventions/blob/master/BasicCABI.md
Swift Calling Convention on WebAssembly is a little deffer from swiftcc
on another architectures.
On non WebAssembly arch, swiftcc accepts extra parameters that are
attributed with swifterror or swiftself by caller. Even if callee
doesn't have these parameters, the invocation succeed ignoring extra
parameters.
But WebAssembly strictly checks that callee and caller signatures are
same. https://github.com/WebAssembly/design/blob/master/Semantics.md#calls
So at WebAssembly level, all swiftcc functions end up extra arguments
and all function definitions and invocations explicitly have additional
parameters to fill swifterror and swiftself.
This patch support signature difference for swiftself and swifterror cc
is swiftcc.
e.g.
```
declare swiftcc void @foo(i32, i32)
@data = global i8* bitcast (void (i32, i32)* @foo to i8*)
define swiftcc void @bar() {
%1 = load i8*, i8** @data
%2 = bitcast i8* %1 to void (i32, i32, i32)*
call swiftcc void %2(i32 1, i32 2, i32 swiftself 3)
ret void
}
```
For swiftcc, emit additional swiftself and swifterror parameters
if there aren't while lowering. These additional parameters are added
for both callee and caller.
They are necessary to match callee and caller signature for direct and
indirect function call.
Differential Revision: https://reviews.llvm.org/D76049
2020-03-20 08:39:34 +08:00
|
|
|
|
|
|
|
// For swiftcc, emit additional swiftself and swifterror parameters
|
|
|
|
// if there aren't. These additional parameters are also passed for caller.
|
|
|
|
// They are necessary to match callee and caller signature for indirect
|
|
|
|
// call.
|
|
|
|
|
|
|
|
if (TargetFunc && TargetFunc->getCallingConv() == CallingConv::Swift) {
|
|
|
|
MVT PtrVT = MVT::getIntegerVT(TM.createDataLayout().getPointerSizeInBits());
|
|
|
|
bool HasSwiftErrorArg = false;
|
|
|
|
bool HasSwiftSelfArg = false;
|
|
|
|
for (const auto &Arg : TargetFunc->args()) {
|
|
|
|
HasSwiftErrorArg |= Arg.hasAttribute(Attribute::SwiftError);
|
|
|
|
HasSwiftSelfArg |= Arg.hasAttribute(Attribute::SwiftSelf);
|
|
|
|
}
|
|
|
|
if (!HasSwiftErrorArg)
|
|
|
|
Params.push_back(PtrVT);
|
|
|
|
if (!HasSwiftSelfArg)
|
|
|
|
Params.push_back(PtrVT);
|
|
|
|
}
|
2018-10-04 06:22:48 +08:00
|
|
|
}
|
|
|
|
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
void llvm::valTypesFromMVTs(const ArrayRef<MVT> &In,
|
2018-11-20 01:10:36 +08:00
|
|
|
SmallVectorImpl<wasm::ValType> &Out) {
|
|
|
|
for (MVT Ty : In)
|
|
|
|
Out.push_back(WebAssembly::toValType(Ty));
|
|
|
|
}
|
|
|
|
|
2018-10-04 06:22:48 +08:00
|
|
|
std::unique_ptr<wasm::WasmSignature>
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
llvm::signatureFromMVTs(const SmallVectorImpl<MVT> &Results,
|
2018-10-04 06:22:48 +08:00
|
|
|
const SmallVectorImpl<MVT> &Params) {
|
2019-08-15 23:54:37 +08:00
|
|
|
auto Sig = std::make_unique<wasm::WasmSignature>();
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
valTypesFromMVTs(Results, Sig->Returns);
|
|
|
|
valTypesFromMVTs(Params, Sig->Params);
|
2018-10-04 06:22:48 +08:00
|
|
|
return Sig;
|
2016-10-07 06:29:32 +08:00
|
|
|
}
|
2019-03-27 01:35:35 +08:00
|
|
|
|
|
|
|
yaml::WebAssemblyFunctionInfo::WebAssemblyFunctionInfo(
|
2019-03-27 01:46:14 +08:00
|
|
|
const llvm::WebAssemblyFunctionInfo &MFI)
|
|
|
|
: CFGStackified(MFI.isCFGStackified()) {}
|
2019-03-27 01:35:35 +08:00
|
|
|
|
|
|
|
void yaml::WebAssemblyFunctionInfo::mappingImpl(yaml::IO &YamlIO) {
|
|
|
|
MappingTraits<WebAssemblyFunctionInfo>::mapping(YamlIO, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAssemblyFunctionInfo::initializeBaseYamlFields(
|
2019-03-27 01:46:14 +08:00
|
|
|
const yaml::WebAssemblyFunctionInfo &YamlMFI) {
|
|
|
|
CFGStackified = YamlMFI.CFGStackified;
|
|
|
|
}
|