2015-07-23 05:28:15 +08:00
|
|
|
//===-- WebAssemblyAsmPrinter.cpp - WebAssembly LLVM assembly writer ------===//
|
|
|
|
//
|
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-07-23 05:28:15 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 23:54:18 +08:00
|
|
|
/// This file contains a printer that converts from our internal
|
2015-07-23 05:28:15 +08:00
|
|
|
/// representation of machine-dependent LLVM code to the WebAssembly assembly
|
|
|
|
/// language.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-02-25 07:18:00 +08:00
|
|
|
#include "WebAssemblyAsmPrinter.h"
|
2019-05-13 11:32:41 +08:00
|
|
|
#include "MCTargetDesc/WebAssemblyInstPrinter.h"
|
2015-11-13 01:04:33 +08:00
|
|
|
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
|
2016-01-13 04:30:51 +08:00
|
|
|
#include "MCTargetDesc/WebAssemblyTargetStreamer.h"
|
2019-05-15 09:03:00 +08:00
|
|
|
#include "TargetInfo/WebAssemblyTargetInfo.h"
|
2016-08-02 06:25:02 +08:00
|
|
|
#include "WebAssembly.h"
|
2015-11-13 01:04:33 +08:00
|
|
|
#include "WebAssemblyMCInstLower.h"
|
2015-07-23 05:28:15 +08:00
|
|
|
#include "WebAssemblyMachineFunctionInfo.h"
|
|
|
|
#include "WebAssemblyRegisterInfo.h"
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
#include "WebAssemblyTargetMachine.h"
|
2019-01-17 10:29:55 +08:00
|
|
|
#include "llvm/ADT/SmallSet.h"
|
2015-10-06 08:27:55 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
#include "llvm/BinaryFormat/Wasm.h"
|
2015-11-11 09:33:02 +08:00
|
|
|
#include "llvm/CodeGen/Analysis.h"
|
2015-07-23 05:28:15 +08:00
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
2015-08-26 07:19:49 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2015-07-23 05:28:15 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2017-02-25 07:46:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
2015-07-23 05:28:15 +08:00
|
|
|
#include "llvm/IR/DataLayout.h"
|
2019-01-18 10:47:48 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2017-02-25 07:18:00 +08:00
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
#include "llvm/IR/Metadata.h"
|
2015-11-13 01:04:33 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2018-04-06 01:01:39 +08:00
|
|
|
#include "llvm/MC/MCSectionWasm.h"
|
2015-07-23 05:28:15 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2015-08-26 06:58:05 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2018-04-06 01:01:39 +08:00
|
|
|
#include "llvm/MC/MCSymbolWasm.h"
|
2015-07-23 05:28:15 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2019-02-20 06:56:19 +08:00
|
|
|
|
2015-07-23 05:28:15 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
[WebAssembly] Exception handling: Switch to the new proposal
Summary:
This switches the EH implementation to the new proposal:
https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md
(The previous proposal was
https://github.com/WebAssembly/exception-handling/blob/master/proposals/old/Exceptions.md)
- Instruction changes
- Now we have one single `catch` instruction that returns a except_ref
value
- `throw` now can take variable number of operations
- `rethrow` does not have 'depth' argument anymore
- `br_on_exn` queries an except_ref to see if it matches the tag and
branches to the given label if true.
- `extract_exception` is a pseudo instruction that simulates popping
values from wasm stack. This is to make `br_on_exn`, a very special
instruction, work: `br_on_exn` puts values onto the stack only if it
is taken, and the # of values can vay depending on the tag.
- Now there's only one `catch` per `try`, this patch removes all special
handling for terminate pad with a call to `__clang_call_terminate`.
Before it was the only case there are two catch clauses (a normal
`catch` and `catch_all` per `try`).
- Make `rethrow` act as a terminator like `throw`. This splits BB after
`rethrow` in WasmEHPrepare, and deletes an unnecessary `unreachable`
after `rethrow` in LateEHPrepare.
- Now we stop at all catchpads (because we add wasm `catch` instruction
that catches all exceptions), this creates new
`findWasmUnwindDestinations` function in SelectionDAGBuilder.
- Now we use `br_on_exn` instrution to figure out if an except_ref
matches the current tag or not, LateEHPrepare generates this sequence
for catch pads:
```
catch
block i32
br_on_exn $__cpp_exception
end_block
extract_exception
```
- Branch analysis for `br_on_exn` in WebAssemblyInstrInfo
- Other various misc. changes to switch to the new proposal.
Reviewers: dschuff
Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D57134
llvm-svn: 352598
2019-01-30 11:21:57 +08:00
|
|
|
extern cl::opt<bool> WasmKeepRegisters;
|
|
|
|
|
2015-08-27 06:09:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Helpers.
|
2015-07-23 05:28:15 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-11-24 00:50:18 +08:00
|
|
|
MVT WebAssemblyAsmPrinter::getRegType(unsigned RegNo) const {
|
2017-04-25 03:51:12 +08:00
|
|
|
const TargetRegisterInfo *TRI = Subtarget->getRegisterInfo();
|
2016-05-10 12:24:02 +08:00
|
|
|
const TargetRegisterClass *TRC = MRI->getRegClass(RegNo);
|
2016-08-03 07:16:09 +08:00
|
|
|
for (MVT T : {MVT::i32, MVT::i64, MVT::f32, MVT::f64, MVT::v16i8, MVT::v8i16,
|
2018-08-08 05:24:01 +08:00
|
|
|
MVT::v4i32, MVT::v2i64, MVT::v4f32, MVT::v2f64})
|
2017-04-25 03:51:12 +08:00
|
|
|
if (TRI->isTypeLegalForClass(*TRC, T))
|
2015-11-24 00:50:18 +08:00
|
|
|
return T;
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(errs() << "Unknown type for register number: " << RegNo);
|
2015-10-16 08:53:49 +08:00
|
|
|
llvm_unreachable("Unknown register type");
|
2015-11-24 00:50:18 +08:00
|
|
|
return MVT::Other;
|
2015-10-16 08:53:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string WebAssemblyAsmPrinter::regToString(const MachineOperand &MO) {
|
[webassembly] Apply llvm-prefer-register-over-unsigned from clang-tidy to LLVM
Summary:
This clang-tidy check is looking for unsigned integer variables whose initializer
starts with an implicit cast from llvm::Register and changes the type of the
variable to llvm::Register (dropping the llvm:: where possible).
Reviewers: aheejin
Subscribers: jholewinski, MatzeB, qcolombet, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, wdng, nhaehnle, sbc100, jgravelle-google, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, javed.absar, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, MaskRay, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, tpr, PkmX, jocewei, jsji, Petar.Avramovic, asbirlea, Jim, s.egerton, llvm-commits
Tags: #llvm
Differential Revision for whole review: https://reviews.llvm.org/D65962
llvm-svn: 368627
2019-08-13 06:40:45 +08:00
|
|
|
Register RegNo = MO.getReg();
|
2019-08-02 07:27:28 +08:00
|
|
|
assert(Register::isVirtualRegister(RegNo) &&
|
2015-11-20 11:13:31 +08:00
|
|
|
"Unlowered physical register encountered during assembly printing");
|
2015-11-19 00:12:01 +08:00
|
|
|
assert(!MFI->isVRegStackified(RegNo));
|
2015-11-13 08:21:05 +08:00
|
|
|
unsigned WAReg = MFI->getWAReg(RegNo);
|
|
|
|
assert(WAReg != WebAssemblyFunctionInfo::UnusedReg);
|
2015-11-19 00:12:01 +08:00
|
|
|
return '$' + utostr(WAReg);
|
2015-10-06 08:27:55 +08:00
|
|
|
}
|
|
|
|
|
2016-01-25 23:12:05 +08:00
|
|
|
WebAssemblyTargetStreamer *WebAssemblyAsmPrinter::getTargetStreamer() {
|
2016-01-13 04:30:51 +08:00
|
|
|
MCTargetStreamer *TS = OutStreamer->getTargetStreamer();
|
|
|
|
return static_cast<WebAssemblyTargetStreamer *>(TS);
|
2015-09-01 06:24:11 +08:00
|
|
|
}
|
|
|
|
|
2015-08-27 06:09:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// WebAssemblyAsmPrinter Implementation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-11-17 05:12:41 +08:00
|
|
|
|
2020-02-14 05:10:49 +08:00
|
|
|
void WebAssemblyAsmPrinter::emitEndOfAsmFile(Module &M) {
|
2018-11-02 08:45:00 +08:00
|
|
|
for (auto &It : OutContext.getSymbols()) {
|
2018-11-14 10:46:21 +08:00
|
|
|
// Emit a .globaltype and .eventtype declaration.
|
2018-11-02 08:45:00 +08:00
|
|
|
auto Sym = cast<MCSymbolWasm>(It.getValue());
|
2018-11-14 10:46:21 +08:00
|
|
|
if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_GLOBAL)
|
2018-11-02 08:45:00 +08:00
|
|
|
getTargetStreamer()->emitGlobalType(Sym);
|
2018-11-14 10:46:21 +08:00
|
|
|
else if (Sym->getType() == wasm::WASM_SYMBOL_TYPE_EVENT)
|
|
|
|
getTargetStreamer()->emitEventType(Sym);
|
2018-11-02 08:45:00 +08:00
|
|
|
}
|
|
|
|
|
2016-06-04 02:34:36 +08:00
|
|
|
for (const auto &F : M) {
|
2019-11-06 02:15:56 +08:00
|
|
|
if (F.isIntrinsic())
|
|
|
|
continue;
|
|
|
|
|
2016-06-04 02:34:36 +08:00
|
|
|
// Emit function type info for all undefined functions
|
2019-11-06 02:15:56 +08:00
|
|
|
if (F.isDeclarationForLinker()) {
|
2016-10-07 06:29:32 +08:00
|
|
|
SmallVector<MVT, 4> Results;
|
|
|
|
SmallVector<MVT, 4> 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
|
|
|
computeSignatureVTs(F.getFunctionType(), &F, F, TM, Params, Results);
|
2018-10-04 06:22:48 +08:00
|
|
|
auto *Sym = cast<MCSymbolWasm>(getSymbol(&F));
|
2018-12-11 08:53:59 +08:00
|
|
|
Sym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
|
2018-10-04 06:22:48 +08:00
|
|
|
if (!Sym->getSignature()) {
|
[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
|
|
|
auto Signature = signatureFromMVTs(Results, Params);
|
2018-10-04 06:22:48 +08:00
|
|
|
Sym->setSignature(Signature.get());
|
|
|
|
addSignature(std::move(Signature));
|
|
|
|
}
|
|
|
|
// FIXME: this was originally intended for post-linking and was only used
|
|
|
|
// for imports that were only called indirectly (i.e. s2wasm could not
|
|
|
|
// infer the type from a call). With object files it applies to all
|
|
|
|
// imports. so fix the names and the tests, or rethink how import
|
|
|
|
// delcarations work in asm files.
|
2018-11-20 01:10:36 +08:00
|
|
|
getTargetStreamer()->emitFunctionType(Sym);
|
2018-02-10 07:13:22 +08:00
|
|
|
|
2018-02-13 05:41:12 +08:00
|
|
|
if (TM.getTargetTriple().isOSBinFormatWasm() &&
|
|
|
|
F.hasFnAttribute("wasm-import-module")) {
|
2018-09-05 09:27:38 +08:00
|
|
|
StringRef Name =
|
|
|
|
F.getFnAttribute("wasm-import-module").getValueAsString();
|
2020-04-07 11:46:11 +08:00
|
|
|
Sym->setImportModule(storeName(Name));
|
2018-10-04 06:22:48 +08:00
|
|
|
getTargetStreamer()->emitImportModule(Sym, Name);
|
2018-02-10 07:13:22 +08:00
|
|
|
}
|
2019-02-02 06:27:34 +08:00
|
|
|
if (TM.getTargetTriple().isOSBinFormatWasm() &&
|
|
|
|
F.hasFnAttribute("wasm-import-name")) {
|
|
|
|
StringRef Name =
|
|
|
|
F.getFnAttribute("wasm-import-name").getValueAsString();
|
2020-04-07 11:46:11 +08:00
|
|
|
Sym->setImportName(storeName(Name));
|
2019-02-02 06:27:34 +08:00
|
|
|
getTargetStreamer()->emitImportName(Sym, Name);
|
|
|
|
}
|
2016-06-04 02:34:36 +08:00
|
|
|
}
|
2019-11-06 02:15:56 +08:00
|
|
|
|
|
|
|
if (F.hasFnAttribute("wasm-export-name")) {
|
|
|
|
auto *Sym = cast<MCSymbolWasm>(getSymbol(&F));
|
|
|
|
StringRef Name = F.getFnAttribute("wasm-export-name").getValueAsString();
|
2020-04-07 11:46:11 +08:00
|
|
|
Sym->setExportName(storeName(Name));
|
2019-11-06 02:15:56 +08:00
|
|
|
getTargetStreamer()->emitExportName(Sym, Name);
|
|
|
|
}
|
2016-06-04 02:34:36 +08:00
|
|
|
}
|
2018-11-02 08:45:00 +08:00
|
|
|
|
2016-12-01 08:11:15 +08:00
|
|
|
for (const auto &G : M.globals()) {
|
|
|
|
if (!G.hasInitializer() && G.hasExternalLinkage()) {
|
2017-12-07 08:14:30 +08:00
|
|
|
if (G.getValueType()->isSized()) {
|
|
|
|
uint16_t Size = M.getDataLayout().getTypeAllocSize(G.getValueType());
|
|
|
|
OutStreamer->emitELFSize(getSymbol(&G),
|
|
|
|
MCConstantExpr::create(Size, OutContext));
|
|
|
|
}
|
2016-12-01 08:11:15 +08:00
|
|
|
}
|
|
|
|
}
|
2018-04-06 01:01:39 +08:00
|
|
|
|
|
|
|
if (const NamedMDNode *Named = M.getNamedMetadata("wasm.custom_sections")) {
|
|
|
|
for (const Metadata *MD : Named->operands()) {
|
[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
|
|
|
const auto *Tuple = dyn_cast<MDTuple>(MD);
|
2018-04-06 01:01:39 +08:00
|
|
|
if (!Tuple || Tuple->getNumOperands() != 2)
|
|
|
|
continue;
|
|
|
|
const MDString *Name = dyn_cast<MDString>(Tuple->getOperand(0));
|
|
|
|
const MDString *Contents = dyn_cast<MDString>(Tuple->getOperand(1));
|
|
|
|
if (!Name || !Contents)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
OutStreamer->PushSection();
|
|
|
|
std::string SectionName = (".custom_section." + Name->getString()).str();
|
[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
|
|
|
MCSectionWasm *MySection =
|
2018-04-06 01:01:39 +08:00
|
|
|
OutContext.getWasmSection(SectionName, SectionKind::getMetadata());
|
[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
|
|
|
OutStreamer->SwitchSection(MySection);
|
2020-02-15 10:16:24 +08:00
|
|
|
OutStreamer->emitBytes(Contents->getString());
|
2018-04-06 01:01:39 +08:00
|
|
|
OutStreamer->PopSection();
|
|
|
|
}
|
|
|
|
}
|
2019-01-17 10:29:55 +08:00
|
|
|
|
2019-01-18 10:47:48 +08:00
|
|
|
EmitProducerInfo(M);
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
EmitTargetFeatures(M);
|
2019-01-18 10:47:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebAssemblyAsmPrinter::EmitProducerInfo(Module &M) {
|
|
|
|
llvm::SmallVector<std::pair<std::string, std::string>, 4> Languages;
|
|
|
|
if (const NamedMDNode *Debug = M.getNamedMetadata("llvm.dbg.cu")) {
|
[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::SmallSet<StringRef, 4> SeenLanguages;
|
|
|
|
for (size_t I = 0, E = Debug->getNumOperands(); I < E; ++I) {
|
|
|
|
const auto *CU = cast<DICompileUnit>(Debug->getOperand(I));
|
2019-01-18 10:47:48 +08:00
|
|
|
StringRef Language = dwarf::LanguageString(CU->getSourceLanguage());
|
|
|
|
Language.consume_front("DW_LANG_");
|
|
|
|
if (SeenLanguages.insert(Language).second)
|
|
|
|
Languages.emplace_back(Language.str(), "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::SmallVector<std::pair<std::string, std::string>, 4> Tools;
|
2019-01-17 10:29:55 +08:00
|
|
|
if (const NamedMDNode *Ident = M.getNamedMetadata("llvm.ident")) {
|
|
|
|
llvm::SmallSet<StringRef, 4> SeenTools;
|
[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 (size_t I = 0, E = Ident->getNumOperands(); I < E; ++I) {
|
|
|
|
const auto *S = cast<MDString>(Ident->getOperand(I)->getOperand(0));
|
2019-01-17 10:29:55 +08:00
|
|
|
std::pair<StringRef, StringRef> Field = S->getString().split("version");
|
|
|
|
StringRef Name = Field.first.trim();
|
|
|
|
StringRef Version = Field.second.trim();
|
2019-01-18 10:47:48 +08:00
|
|
|
if (SeenTools.insert(Name).second)
|
|
|
|
Tools.emplace_back(Name.str(), Version.str());
|
2019-01-17 10:29:55 +08:00
|
|
|
}
|
2019-01-18 10:47:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int FieldCount = int(!Languages.empty()) + int(!Tools.empty());
|
|
|
|
if (FieldCount != 0) {
|
2019-01-17 10:29:55 +08:00
|
|
|
MCSectionWasm *Producers = OutContext.getWasmSection(
|
|
|
|
".custom_section.producers", SectionKind::getMetadata());
|
|
|
|
OutStreamer->PushSection();
|
|
|
|
OutStreamer->SwitchSection(Producers);
|
2020-02-14 05:26:21 +08:00
|
|
|
OutStreamer->emitULEB128IntValue(FieldCount);
|
2019-01-18 10:47:48 +08:00
|
|
|
for (auto &Producers : {std::make_pair("language", &Languages),
|
|
|
|
std::make_pair("processed-by", &Tools)}) {
|
|
|
|
if (Producers.second->empty())
|
|
|
|
continue;
|
2020-02-14 05:26:21 +08:00
|
|
|
OutStreamer->emitULEB128IntValue(strlen(Producers.first));
|
2020-02-15 10:16:24 +08:00
|
|
|
OutStreamer->emitBytes(Producers.first);
|
2020-02-14 05:26:21 +08:00
|
|
|
OutStreamer->emitULEB128IntValue(Producers.second->size());
|
2019-01-18 10:47:48 +08:00
|
|
|
for (auto &Producer : *Producers.second) {
|
2020-02-14 05:26:21 +08:00
|
|
|
OutStreamer->emitULEB128IntValue(Producer.first.size());
|
2020-02-15 10:16:24 +08:00
|
|
|
OutStreamer->emitBytes(Producer.first);
|
2020-02-14 05:26:21 +08:00
|
|
|
OutStreamer->emitULEB128IntValue(Producer.second.size());
|
2020-02-15 10:16:24 +08:00
|
|
|
OutStreamer->emitBytes(Producer.second);
|
2019-01-18 10:47:48 +08:00
|
|
|
}
|
2019-01-17 10:29:55 +08:00
|
|
|
}
|
|
|
|
OutStreamer->PopSection();
|
|
|
|
}
|
2016-06-04 02:34:36 +08:00
|
|
|
}
|
|
|
|
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
void WebAssemblyAsmPrinter::EmitTargetFeatures(Module &M) {
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
struct FeatureEntry {
|
|
|
|
uint8_t Prefix;
|
[WebAssembly] Disallow 'shared-mem' rather than 'atomics'
Summary:
The WebAssembly backend automatically lowers atomic operations and TLS
to nonatomic operations and non-TLS data when either are present and
the atomics or bulk-memory features are not present, respectively. The
resulting object is no longer thread-safe, so the linker has to be
told not to allow it to be linked into a module with shared
memory. This was previously done by disallowing the 'atomics' feature,
which prevented any objct with its atomic operations or TLS removed
from being linked with any object containing atomics or TLS, and
therefore preventing it from being linked into a module with shared
memory since shared memory requires atomics.
However, as of https://github.com/WebAssembly/threads/issues/144, the
validation rules are relaxed to allow atomic operations to validate
with unshared memories, which makes it perfectly safe to link an
object with stripped atomics and TLS with another object that still
contains TLS and atomics as long as the resulting module has an
unshared memory. To allow this kind of link, this patch disallows a
pseudo-feature 'shared-mem' rather than 'atomics' to communicate to
the linker that the object is not thread-safe. This means that the
'atomics' feature is available to accurately reflect whether or not an
object has atomics enabled.
As a drive-by tweak, this change also requires that bulk-memory be
enabled in addition to atomics in order to use shared memory. This is
because initializing shared memories requires bulk-memory operations.
Reviewers: aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79542
2020-05-07 10:33:24 +08:00
|
|
|
std::string Name;
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
};
|
|
|
|
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
// Read target features and linkage policies from module metadata
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
SmallVector<FeatureEntry, 4> EmittedFeatures;
|
[WebAssembly] Disallow 'shared-mem' rather than 'atomics'
Summary:
The WebAssembly backend automatically lowers atomic operations and TLS
to nonatomic operations and non-TLS data when either are present and
the atomics or bulk-memory features are not present, respectively. The
resulting object is no longer thread-safe, so the linker has to be
told not to allow it to be linked into a module with shared
memory. This was previously done by disallowing the 'atomics' feature,
which prevented any objct with its atomic operations or TLS removed
from being linked with any object containing atomics or TLS, and
therefore preventing it from being linked into a module with shared
memory since shared memory requires atomics.
However, as of https://github.com/WebAssembly/threads/issues/144, the
validation rules are relaxed to allow atomic operations to validate
with unshared memories, which makes it perfectly safe to link an
object with stripped atomics and TLS with another object that still
contains TLS and atomics as long as the resulting module has an
unshared memory. To allow this kind of link, this patch disallows a
pseudo-feature 'shared-mem' rather than 'atomics' to communicate to
the linker that the object is not thread-safe. This means that the
'atomics' feature is available to accurately reflect whether or not an
object has atomics enabled.
As a drive-by tweak, this change also requires that bulk-memory be
enabled in addition to atomics in order to use shared memory. This is
because initializing shared memories requires bulk-memory operations.
Reviewers: aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79542
2020-05-07 10:33:24 +08:00
|
|
|
auto EmitFeature = [&](std::string Feature) {
|
|
|
|
std::string MDKey = (StringRef("wasm-feature-") + Feature).str();
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
Metadata *Policy = M.getModuleFlag(MDKey);
|
|
|
|
if (Policy == nullptr)
|
[WebAssembly] Disallow 'shared-mem' rather than 'atomics'
Summary:
The WebAssembly backend automatically lowers atomic operations and TLS
to nonatomic operations and non-TLS data when either are present and
the atomics or bulk-memory features are not present, respectively. The
resulting object is no longer thread-safe, so the linker has to be
told not to allow it to be linked into a module with shared
memory. This was previously done by disallowing the 'atomics' feature,
which prevented any objct with its atomic operations or TLS removed
from being linked with any object containing atomics or TLS, and
therefore preventing it from being linked into a module with shared
memory since shared memory requires atomics.
However, as of https://github.com/WebAssembly/threads/issues/144, the
validation rules are relaxed to allow atomic operations to validate
with unshared memories, which makes it perfectly safe to link an
object with stripped atomics and TLS with another object that still
contains TLS and atomics as long as the resulting module has an
unshared memory. To allow this kind of link, this patch disallows a
pseudo-feature 'shared-mem' rather than 'atomics' to communicate to
the linker that the object is not thread-safe. This means that the
'atomics' feature is available to accurately reflect whether or not an
object has atomics enabled.
As a drive-by tweak, this change also requires that bulk-memory be
enabled in addition to atomics in order to use shared memory. This is
because initializing shared memories requires bulk-memory operations.
Reviewers: aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79542
2020-05-07 10:33:24 +08:00
|
|
|
return;
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
FeatureEntry Entry;
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
Entry.Prefix = 0;
|
[WebAssembly] Disallow 'shared-mem' rather than 'atomics'
Summary:
The WebAssembly backend automatically lowers atomic operations and TLS
to nonatomic operations and non-TLS data when either are present and
the atomics or bulk-memory features are not present, respectively. The
resulting object is no longer thread-safe, so the linker has to be
told not to allow it to be linked into a module with shared
memory. This was previously done by disallowing the 'atomics' feature,
which prevented any objct with its atomic operations or TLS removed
from being linked with any object containing atomics or TLS, and
therefore preventing it from being linked into a module with shared
memory since shared memory requires atomics.
However, as of https://github.com/WebAssembly/threads/issues/144, the
validation rules are relaxed to allow atomic operations to validate
with unshared memories, which makes it perfectly safe to link an
object with stripped atomics and TLS with another object that still
contains TLS and atomics as long as the resulting module has an
unshared memory. To allow this kind of link, this patch disallows a
pseudo-feature 'shared-mem' rather than 'atomics' to communicate to
the linker that the object is not thread-safe. This means that the
'atomics' feature is available to accurately reflect whether or not an
object has atomics enabled.
As a drive-by tweak, this change also requires that bulk-memory be
enabled in addition to atomics in order to use shared memory. This is
because initializing shared memories requires bulk-memory operations.
Reviewers: aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79542
2020-05-07 10:33:24 +08:00
|
|
|
Entry.Name = Feature;
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
|
|
|
|
if (auto *MD = cast<ConstantAsMetadata>(Policy))
|
|
|
|
if (auto *I = cast<ConstantInt>(MD->getValue()))
|
|
|
|
Entry.Prefix = I->getZExtValue();
|
|
|
|
|
|
|
|
// Silently ignore invalid metadata
|
|
|
|
if (Entry.Prefix != wasm::WASM_FEATURE_PREFIX_USED &&
|
|
|
|
Entry.Prefix != wasm::WASM_FEATURE_PREFIX_REQUIRED &&
|
|
|
|
Entry.Prefix != wasm::WASM_FEATURE_PREFIX_DISALLOWED)
|
[WebAssembly] Disallow 'shared-mem' rather than 'atomics'
Summary:
The WebAssembly backend automatically lowers atomic operations and TLS
to nonatomic operations and non-TLS data when either are present and
the atomics or bulk-memory features are not present, respectively. The
resulting object is no longer thread-safe, so the linker has to be
told not to allow it to be linked into a module with shared
memory. This was previously done by disallowing the 'atomics' feature,
which prevented any objct with its atomic operations or TLS removed
from being linked with any object containing atomics or TLS, and
therefore preventing it from being linked into a module with shared
memory since shared memory requires atomics.
However, as of https://github.com/WebAssembly/threads/issues/144, the
validation rules are relaxed to allow atomic operations to validate
with unshared memories, which makes it perfectly safe to link an
object with stripped atomics and TLS with another object that still
contains TLS and atomics as long as the resulting module has an
unshared memory. To allow this kind of link, this patch disallows a
pseudo-feature 'shared-mem' rather than 'atomics' to communicate to
the linker that the object is not thread-safe. This means that the
'atomics' feature is available to accurately reflect whether or not an
object has atomics enabled.
As a drive-by tweak, this change also requires that bulk-memory be
enabled in addition to atomics in order to use shared memory. This is
because initializing shared memories requires bulk-memory operations.
Reviewers: aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79542
2020-05-07 10:33:24 +08:00
|
|
|
return;
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
|
|
|
|
EmittedFeatures.push_back(Entry);
|
[WebAssembly] Disallow 'shared-mem' rather than 'atomics'
Summary:
The WebAssembly backend automatically lowers atomic operations and TLS
to nonatomic operations and non-TLS data when either are present and
the atomics or bulk-memory features are not present, respectively. The
resulting object is no longer thread-safe, so the linker has to be
told not to allow it to be linked into a module with shared
memory. This was previously done by disallowing the 'atomics' feature,
which prevented any objct with its atomic operations or TLS removed
from being linked with any object containing atomics or TLS, and
therefore preventing it from being linked into a module with shared
memory since shared memory requires atomics.
However, as of https://github.com/WebAssembly/threads/issues/144, the
validation rules are relaxed to allow atomic operations to validate
with unshared memories, which makes it perfectly safe to link an
object with stripped atomics and TLS with another object that still
contains TLS and atomics as long as the resulting module has an
unshared memory. To allow this kind of link, this patch disallows a
pseudo-feature 'shared-mem' rather than 'atomics' to communicate to
the linker that the object is not thread-safe. This means that the
'atomics' feature is available to accurately reflect whether or not an
object has atomics enabled.
As a drive-by tweak, this change also requires that bulk-memory be
enabled in addition to atomics in order to use shared memory. This is
because initializing shared memories requires bulk-memory operations.
Reviewers: aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79542
2020-05-07 10:33:24 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
|
|
|
|
EmitFeature(KV.Key);
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
}
|
[WebAssembly] Disallow 'shared-mem' rather than 'atomics'
Summary:
The WebAssembly backend automatically lowers atomic operations and TLS
to nonatomic operations and non-TLS data when either are present and
the atomics or bulk-memory features are not present, respectively. The
resulting object is no longer thread-safe, so the linker has to be
told not to allow it to be linked into a module with shared
memory. This was previously done by disallowing the 'atomics' feature,
which prevented any objct with its atomic operations or TLS removed
from being linked with any object containing atomics or TLS, and
therefore preventing it from being linked into a module with shared
memory since shared memory requires atomics.
However, as of https://github.com/WebAssembly/threads/issues/144, the
validation rules are relaxed to allow atomic operations to validate
with unshared memories, which makes it perfectly safe to link an
object with stripped atomics and TLS with another object that still
contains TLS and atomics as long as the resulting module has an
unshared memory. To allow this kind of link, this patch disallows a
pseudo-feature 'shared-mem' rather than 'atomics' to communicate to
the linker that the object is not thread-safe. This means that the
'atomics' feature is available to accurately reflect whether or not an
object has atomics enabled.
As a drive-by tweak, this change also requires that bulk-memory be
enabled in addition to atomics in order to use shared memory. This is
because initializing shared memories requires bulk-memory operations.
Reviewers: aheejin, sbc100
Subscribers: dschuff, jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D79542
2020-05-07 10:33:24 +08:00
|
|
|
// This pseudo-feature tells the linker whether shared memory would be safe
|
|
|
|
EmitFeature("shared-mem");
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
|
[WebAssembly] Merge used feature sets, update atomics linkage policy
Summary:
It does not currently make sense to use WebAssembly features in some functions
but not others, so this CL adds an IR pass that takes the union of all used
feature sets and applies it to each function in the module. This allows us to
prevent atomics from being lowered away if some function has opted in to using
them. When atomics is not enabled anywhere, we detect whether there exists any
atomic operations or thread local storage that would be stripped and disallow
linking with objects that contain atomics if and only if atomics or tls are
stripped. When atomics is enabled, mark it as used but do not require it of
other objects in the link. These changes allow libraries that do not use atomics
to be built once and linked into both single-threaded and multithreaded
binaries.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, jfb, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59625
llvm-svn: 357226
2019-03-29 08:14:01 +08:00
|
|
|
if (EmittedFeatures.size() == 0)
|
|
|
|
return;
|
|
|
|
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
// Emit features and linkage policies into the "target_features" section
|
|
|
|
MCSectionWasm *FeaturesSection = OutContext.getWasmSection(
|
|
|
|
".custom_section.target_features", SectionKind::getMetadata());
|
|
|
|
OutStreamer->PushSection();
|
|
|
|
OutStreamer->SwitchSection(FeaturesSection);
|
|
|
|
|
2020-02-14 05:26:21 +08:00
|
|
|
OutStreamer->emitULEB128IntValue(EmittedFeatures.size());
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
for (auto &F : EmittedFeatures) {
|
2020-02-15 14:40:47 +08:00
|
|
|
OutStreamer->emitIntValue(F.Prefix, 1);
|
2020-02-14 05:26:21 +08:00
|
|
|
OutStreamer->emitULEB128IntValue(F.Name.size());
|
2020-02-15 10:16:24 +08:00
|
|
|
OutStreamer->emitBytes(F.Name);
|
[WebAssembly] Target features section
Summary:
Implements a new target features section in assembly and object files
that records what features are used, required, and disallowed in
WebAssembly objects. The linker uses this information to ensure that
all objects participating in a link are feature-compatible and records
the set of used features in the output binary for use by optimizers
and other tools later in the toolchain.
The "atomics" feature is always required or disallowed to prevent
linking code with stripped atomics into multithreaded binaries. Other
features are marked used if they are enabled globally or on any
function in a module.
Future CLs will add linker flags for ignoring feature compatibility
checks and for specifying the set of allowed features, implement using
the presence of the "atomics" feature to control the type of memory
and segments in the linked binary, and add front-end flags for
relaxing the linkage policy for atomics.
Reviewers: aheejin, sbc100, dschuff
Subscribers: jgravelle-google, hiraditya, sunfish, mgrang, jfb, jdoerfert, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D59173
llvm-svn: 356610
2019-03-21 04:26:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OutStreamer->PopSection();
|
|
|
|
}
|
|
|
|
|
2020-02-14 08:36:27 +08:00
|
|
|
void WebAssemblyAsmPrinter::emitConstantPool() {
|
2016-06-04 02:34:36 +08:00
|
|
|
assert(MF->getConstantPool()->getConstants().empty() &&
|
|
|
|
"WebAssembly disables constant pools");
|
|
|
|
}
|
|
|
|
|
2020-02-14 08:36:27 +08:00
|
|
|
void WebAssemblyAsmPrinter::emitJumpTableInfo() {
|
2016-06-04 02:34:36 +08:00
|
|
|
// Nothing to do; jump tables are incorporated into the instruction stream.
|
|
|
|
}
|
|
|
|
|
2020-02-14 05:10:49 +08:00
|
|
|
void WebAssemblyAsmPrinter::emitFunctionBodyStart() {
|
2017-12-16 07:52:06 +08:00
|
|
|
const Function &F = MF->getFunction();
|
2018-10-04 06:22:48 +08:00
|
|
|
SmallVector<MVT, 1> ResultVTs;
|
|
|
|
SmallVector<MVT, 4> ParamVTs;
|
[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
|
|
|
computeSignatureVTs(F.getFunctionType(), &F, F, TM, ParamVTs, ResultVTs);
|
|
|
|
|
[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
|
|
|
auto Signature = signatureFromMVTs(ResultVTs, ParamVTs);
|
2018-10-04 06:22:48 +08:00
|
|
|
auto *WasmSym = cast<MCSymbolWasm>(CurrentFnSym);
|
|
|
|
WasmSym->setSignature(Signature.get());
|
|
|
|
addSignature(std::move(Signature));
|
2018-12-11 08:53:59 +08:00
|
|
|
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
|
2018-10-04 06:22:48 +08:00
|
|
|
|
|
|
|
// FIXME: clean up how params and results are emitted (use signatures)
|
2018-11-20 01:10:36 +08:00
|
|
|
getTargetStreamer()->emitFunctionType(WasmSym);
|
2016-08-02 06:25:02 +08:00
|
|
|
|
|
|
|
// Emit the function index.
|
|
|
|
if (MDNode *Idx = F.getMetadata("wasm.index")) {
|
|
|
|
assert(Idx->getNumOperands() == 1);
|
|
|
|
|
|
|
|
getTargetStreamer()->emitIndIdx(AsmPrinter::lowerConstant(
|
|
|
|
cast<ConstantAsMetadata>(Idx->getOperand(0))->getValue()));
|
|
|
|
}
|
|
|
|
|
2018-11-20 01:10:36 +08:00
|
|
|
SmallVector<wasm::ValType, 16> Locals;
|
[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(MFI->getLocals(), Locals);
|
2018-11-20 01:10:36 +08:00
|
|
|
getTargetStreamer()->emitLocal(Locals);
|
2015-10-16 08:53:49 +08:00
|
|
|
|
2020-02-14 05:10:49 +08:00
|
|
|
AsmPrinter::emitFunctionBodyStart();
|
2015-08-26 06:58:05 +08:00
|
|
|
}
|
|
|
|
|
2020-02-14 13:58:16 +08:00
|
|
|
void WebAssemblyAsmPrinter::emitInstruction(const MachineInstr *MI) {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "EmitInstruction: " << *MI << '\n');
|
2015-07-23 05:28:15 +08:00
|
|
|
|
2015-10-06 08:27:55 +08:00
|
|
|
switch (MI->getOpcode()) {
|
2018-10-13 15:09:10 +08:00
|
|
|
case WebAssembly::ARGUMENT_i32:
|
|
|
|
case WebAssembly::ARGUMENT_i32_S:
|
|
|
|
case WebAssembly::ARGUMENT_i64:
|
|
|
|
case WebAssembly::ARGUMENT_i64_S:
|
|
|
|
case WebAssembly::ARGUMENT_f32:
|
|
|
|
case WebAssembly::ARGUMENT_f32_S:
|
|
|
|
case WebAssembly::ARGUMENT_f64:
|
|
|
|
case WebAssembly::ARGUMENT_f64_S:
|
2016-08-03 07:16:09 +08:00
|
|
|
case WebAssembly::ARGUMENT_v16i8:
|
2018-08-27 23:45:51 +08:00
|
|
|
case WebAssembly::ARGUMENT_v16i8_S:
|
2016-08-03 07:16:09 +08:00
|
|
|
case WebAssembly::ARGUMENT_v8i16:
|
2018-08-27 23:45:51 +08:00
|
|
|
case WebAssembly::ARGUMENT_v8i16_S:
|
2016-08-03 07:16:09 +08:00
|
|
|
case WebAssembly::ARGUMENT_v4i32:
|
2018-08-27 23:45:51 +08:00
|
|
|
case WebAssembly::ARGUMENT_v4i32_S:
|
2018-08-08 05:24:01 +08:00
|
|
|
case WebAssembly::ARGUMENT_v2i64:
|
2018-08-27 23:45:51 +08:00
|
|
|
case WebAssembly::ARGUMENT_v2i64_S:
|
2016-08-03 07:16:09 +08:00
|
|
|
case WebAssembly::ARGUMENT_v4f32:
|
2018-08-27 23:45:51 +08:00
|
|
|
case WebAssembly::ARGUMENT_v4f32_S:
|
2018-08-08 05:24:01 +08:00
|
|
|
case WebAssembly::ARGUMENT_v2f64:
|
2018-08-27 23:45:51 +08:00
|
|
|
case WebAssembly::ARGUMENT_v2f64_S:
|
2015-11-13 01:04:33 +08:00
|
|
|
// These represent values which are live into the function entry, so there's
|
|
|
|
// no instruction to emit.
|
2015-10-06 08:27:55 +08:00
|
|
|
break;
|
2019-10-10 05:42:08 +08:00
|
|
|
case WebAssembly::FALLTHROUGH_RETURN: {
|
2016-05-21 08:21:56 +08:00
|
|
|
// These instructions represent the implicit return at the end of a
|
2019-10-10 05:42:08 +08:00
|
|
|
// function body.
|
2016-05-21 08:21:56 +08:00
|
|
|
if (isVerbose()) {
|
2019-10-10 05:42:08 +08:00
|
|
|
OutStreamer->AddComment("fallthrough-return");
|
2016-05-21 08:21:56 +08:00
|
|
|
OutStreamer->AddBlankLine();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-05-29 06:09:12 +08:00
|
|
|
case WebAssembly::COMPILER_FENCE:
|
|
|
|
// This is a compiler barrier that prevents instruction reordering during
|
|
|
|
// backend compilation, and should not be emitted.
|
|
|
|
break;
|
[WebAssembly] Exception handling: Switch to the new proposal
Summary:
This switches the EH implementation to the new proposal:
https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md
(The previous proposal was
https://github.com/WebAssembly/exception-handling/blob/master/proposals/old/Exceptions.md)
- Instruction changes
- Now we have one single `catch` instruction that returns a except_ref
value
- `throw` now can take variable number of operations
- `rethrow` does not have 'depth' argument anymore
- `br_on_exn` queries an except_ref to see if it matches the tag and
branches to the given label if true.
- `extract_exception` is a pseudo instruction that simulates popping
values from wasm stack. This is to make `br_on_exn`, a very special
instruction, work: `br_on_exn` puts values onto the stack only if it
is taken, and the # of values can vay depending on the tag.
- Now there's only one `catch` per `try`, this patch removes all special
handling for terminate pad with a call to `__clang_call_terminate`.
Before it was the only case there are two catch clauses (a normal
`catch` and `catch_all` per `try`).
- Make `rethrow` act as a terminator like `throw`. This splits BB after
`rethrow` in WasmEHPrepare, and deletes an unnecessary `unreachable`
after `rethrow` in LateEHPrepare.
- Now we stop at all catchpads (because we add wasm `catch` instruction
that catches all exceptions), this creates new
`findWasmUnwindDestinations` function in SelectionDAGBuilder.
- Now we use `br_on_exn` instrution to figure out if an except_ref
matches the current tag or not, LateEHPrepare generates this sequence
for catch pads:
```
catch
block i32
br_on_exn $__cpp_exception
end_block
extract_exception
```
- Branch analysis for `br_on_exn` in WebAssemblyInstrInfo
- Other various misc. changes to switch to the new proposal.
Reviewers: dschuff
Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D57134
llvm-svn: 352598
2019-01-30 11:21:57 +08:00
|
|
|
case WebAssembly::EXTRACT_EXCEPTION_I32:
|
|
|
|
case WebAssembly::EXTRACT_EXCEPTION_I32_S:
|
|
|
|
// These are pseudo instructions that simulates popping values from stack.
|
|
|
|
// We print these only when we have -wasm-keep-registers on for assembly
|
|
|
|
// readability.
|
|
|
|
if (!WasmKeepRegisters)
|
|
|
|
break;
|
|
|
|
LLVM_FALLTHROUGH;
|
2015-10-06 08:27:55 +08:00
|
|
|
default: {
|
2015-11-13 01:04:33 +08:00
|
|
|
WebAssemblyMCInstLower MCInstLowering(OutContext, *this);
|
|
|
|
MCInst TmpInst;
|
[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
|
|
|
MCInstLowering.lower(MI, TmpInst);
|
2015-11-13 01:04:33 +08:00
|
|
|
EmitToStreamer(*OutStreamer, TmpInst);
|
2015-10-06 08:27:55 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-09-09 08:52:47 +08:00
|
|
|
}
|
2015-07-23 05:28:15 +08:00
|
|
|
}
|
|
|
|
|
2015-11-13 09:42:29 +08:00
|
|
|
bool WebAssemblyAsmPrinter::PrintAsmOperand(const MachineInstr *MI,
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
unsigned OpNo,
|
2015-11-13 09:42:29 +08:00
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &OS) {
|
2015-12-17 01:15:17 +08:00
|
|
|
// First try the generic code, which knows about modifiers like 'c' and 'n'.
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
if (!AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS))
|
2015-12-17 01:15:17 +08:00
|
|
|
return false;
|
|
|
|
|
2015-11-13 09:42:29 +08:00
|
|
|
if (!ExtraCode) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(OpNo);
|
2015-12-17 01:15:17 +08:00
|
|
|
switch (MO.getType()) {
|
|
|
|
case MachineOperand::MO_Immediate:
|
2015-11-13 09:42:29 +08:00
|
|
|
OS << MO.getImm();
|
2015-12-17 01:15:17 +08:00
|
|
|
return false;
|
|
|
|
case MachineOperand::MO_Register:
|
2018-08-27 23:45:51 +08:00
|
|
|
// FIXME: only opcode that still contains registers, as required by
|
|
|
|
// MachineInstr::getDebugVariable().
|
|
|
|
assert(MI->getOpcode() == WebAssembly::INLINEASM);
|
2015-11-13 09:42:29 +08:00
|
|
|
OS << regToString(MO);
|
2015-12-17 01:15:17 +08:00
|
|
|
return false;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
[AsmPrinter] refactor to support %c w/ GlobalAddress'
Summary:
Targets like ARM, MSP430, PPC, and SystemZ have complex behavior when
printing the address of a MachineOperand::MO_GlobalAddress. Move that
handling into a new overriden method in each base class. A virtual
method was added to the base class for handling the generic case.
Refactors a few subclasses to support the target independent %a, %c, and
%n.
The patch also contains small cleanups for AVRAsmPrinter and
SystemZAsmPrinter.
It seems that NVPTXTargetLowering is possibly missing some logic to
transform GlobalAddressSDNodes for
TargetLowering::LowerAsmOperandForConstraint to handle with "i" extended
inline assembly asm constraints.
Fixes:
- https://bugs.llvm.org/show_bug.cgi?id=41402
- https://github.com/ClangBuiltLinux/linux/issues/449
Reviewers: echristo, void
Reviewed By: void
Subscribers: void, craig.topper, jholewinski, dschuff, jyknight, dylanmckay, sdardis, nemanjai, javed.absar, sbc100, jgravelle-google, eraman, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, jrtc27, atanasyan, jsji, llvm-commits, kees, tpimh, nathanchance, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60887
llvm-svn: 359337
2019-04-27 02:45:04 +08:00
|
|
|
PrintSymbolOperand(MO, OS);
|
2015-12-17 01:15:17 +08:00
|
|
|
return false;
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
GetExternalSymbolSymbol(MO.getSymbolName())->print(OS, MAI);
|
|
|
|
printOffset(MO.getOffset(), OS);
|
|
|
|
return false;
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
MO.getMBB()->getSymbol()->print(OS, MAI);
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-11-13 09:42:29 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 01:15:17 +08:00
|
|
|
return true;
|
2015-11-13 09:42:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool WebAssemblyAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
|
|
|
unsigned OpNo,
|
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &OS) {
|
2017-11-09 03:18:08 +08:00
|
|
|
// The current approach to inline asm is that "r" constraints are expressed
|
|
|
|
// as local indices, rather than values on the operand stack. This simplifies
|
|
|
|
// using "r" as it eliminates the need to push and pop the values in a
|
|
|
|
// particular order, however it also makes it impossible to have an "m"
|
|
|
|
// constraint. So we don't support it.
|
2015-11-13 09:42:29 +08:00
|
|
|
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-11 00:38:43 +08:00
|
|
|
return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, ExtraCode, OS);
|
2015-11-13 09:42:29 +08:00
|
|
|
}
|
|
|
|
|
2015-07-23 05:28:15 +08:00
|
|
|
// Force static initialization.
|
CMake: Make most target symbols hidden by default
Summary:
For builds with LLVM_BUILD_LLVM_DYLIB=ON and BUILD_SHARED_LIBS=OFF
this change makes all symbols in the target specific libraries hidden
by default.
A new macro called LLVM_EXTERNAL_VISIBILITY has been added to mark symbols in these
libraries public, which is mainly needed for the definitions of the
LLVMInitialize* functions.
This patch reduces the number of public symbols in libLLVM.so by about
25%. This should improve load times for the dynamic library and also
make abi checker tools, like abidiff require less memory when analyzing
libLLVM.so
One side-effect of this change is that for builds with
LLVM_BUILD_LLVM_DYLIB=ON and LLVM_LINK_LLVM_DYLIB=ON some unittests that
access symbols that are no longer public will need to be statically linked.
Before and after public symbol counts (using gcc 8.2.1, ld.bfd 2.31.1):
nm before/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l
36221
nm after/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l
26278
Reviewers: chandlerc, beanz, mgorny, rnk, hans
Reviewed By: rnk, hans
Subscribers: merge_guards_bot, luismarques, smeenai, ldionne, lenary, s.egerton, pzheng, sameer.abuasal, MaskRay, wuzish, echristo, Jim, hiraditya, michaelplatings, chapuni, jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, javed.absar, sbc100, jgravelle-google, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, mgrang, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, kristina, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D54439
2020-01-15 11:15:07 +08:00
|
|
|
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyAsmPrinter() {
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterAsmPrinter<WebAssemblyAsmPrinter> X(getTheWebAssemblyTarget32());
|
|
|
|
RegisterAsmPrinter<WebAssemblyAsmPrinter> Y(getTheWebAssemblyTarget64());
|
2015-07-23 05:28:15 +08:00
|
|
|
}
|