summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCCodeEmitter.cpp
AgeCommit message (Collapse)Author
2025-08-04[Target] Remove unnecessary casts (NFC) (#151902)Kazu Hirata
getImm() already returns int64_t.
2025-07-05MC: Remove unneeded MCFixupKind castsFangrui Song
2025-07-04MCFixup: Remove unused Loc argumentFangrui Song
MCFixup::Loc has been removed in favor of MCExpr::Loc through `const MCExpr *Value` (commit 777391a2164b89d2030ca013562151ca3c3676d1).
2024-11-15[WebAssembly] Remove unused includes (NFC) (#116318)Kazu Hirata
Identified with misc-include-cleaner.
2024-09-17[WebAssembly] Support binary generation for new EH (#109027)Heejin Ahn
This adds support for binary generation for the new EH proposal. So far the only case that we emitted variable immediate operands in binary has been `br_table`'s destinations. (Other `variable_ops` uses in TableGen files are register operands, such as the operands of `call`, so they don't get emitted in binary as a part of the same instruction.) With this PR, variable immediate operands can include `try_table`'s operands: - The number of of catch clauses - catch clauses sub-opcodes - `catch`: 0x00 - `catch_ref`: 0x01 - `catch_all`: 0x02 - `catch_all_ref`: 0x03 - catch clauses' destinations With `try_table`, we now have variable expr operands for `try_table`'s catch clauses' tags. We treat their fixups in the same way we do for tags in other instructions such as in `throw`. Diff without whitespace will be easier to view.
2023-10-12Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata
Note that llvm::support::endianness has been renamed to llvm::endianness while becoming an enum class as opposed to an enum. This patch replaces support::{big,little,native} with llvm::endianness::{big,little,native}.
2023-07-11[WebAssembly] Fix implicit fallthrough in encodeInstructionBryan Chan
2023-07-11[WebAssembly] Report error for inline assembly with unsupported opcodesDavid Mo
For inline WebAssembly, passing a numeric operand to global.get is unsupported. This causes encodeInstruction to reach an llvm_unreachable call, leading to undefined behaviors. This patch fixes the issue for this invalid instruction encoding, making it report an error by adding an MCContext field in class WebAssemblyMCCodeEmitter. Reviewed By: sbc100, bryanpkc Differential Revision: https://reviews.llvm.org/D154734
2023-06-09[AMDGPU,BPF,SystemZ,WebAssembly] Migrate to new encodeInstruction that uses ↵Fangrui Song
SmallVectorImpl<char>. NFC
2023-01-23[MC] Make more use of MCInstrDesc::operands. NFC.Jay Foad
Change MCInstrDesc::operands to return an ArrayRef so we can easily use it everywhere instead of the (IMHO ugly) opInfo_begin and opInfo_end. A future patch will remove opInfo_begin and opInfo_end. Also use it instead of raw access to the OpInfo pointer. A future patch will remove this pointer. Differential Revision: https://reviews.llvm.org/D142213
2021-12-06[WebAssembly] Implementation of intrinsic for ref.null and HeapType removalPaulo Matos
This patch implements the intrinsic for ref.null. In the process of implementing int_wasm_ref_null_func() and int_wasm_ref_null_extern() intrinsics, it removes the redundant HeapType. This also causes the textual assembler syntax for ref.null to change. Instead of receiving an argument: `func` or `extern`, the instruction mnemonic is either ref.null_func or ref.null_extern, without the need for a further operand. Reviewed By: tlively Differential Revision: https://reviews.llvm.org/D114979
2021-06-17[WebAssembly] Rename event to tagHeejin Ahn
We recently decided to change 'event' to 'tag', and 'event section' to 'tag section', out of the rationale that the section contains a generalized tag that references a type, which may be used for something other than exceptions, and the name 'event' can be confusing in the web context. See - https://github.com/WebAssembly/exception-handling/issues/159#issuecomment-857910130 - https://github.com/WebAssembly/exception-handling/pull/161 Reviewed By: tlively Differential Revision: https://reviews.llvm.org/D104423
2021-02-04[WebAssembly] Support single-floating-point immediate valueDan Gohman
As mentioned in TODO comment, casting double to float causes NaNs to change bits. To avoid the change, this patch adds support for single-floating-point immediate value on MachineCode. Patch by Yuta Saito. Differential Revision: https://reviews.llvm.org/D77384
2020-11-03[WebAssembly] Implement ref.nullAndy Wingo
This patch adds a new "heap type" operand kind to the WebAssembly MC layer, used by ref.null. Currently the possible values are "extern" and "func"; when typed function references come, though, this operand may be a type index. Note that the "heap type" production is still known as "refedtype" in the draft proposal; changing its name in the spec is ongoing (https://github.com/WebAssembly/reference-types/issues/123). The register form of ref.null is still untested. Differential Revision: https://reviews.llvm.org/D90608
2020-10-28[WebAssembly] Prototype extending multiplication SIMD instructionsThomas Lively
As proposed in https://github.com/WebAssembly/simd/pull/376. This commit implements new builtin functions and intrinsics for these instructions, but does not yet add them to wasm_simd128.h because they have not yet been merged to the proposal. These are the first instructions with opcodes greater than 0xff, so this commit updates the MC layer and disassembler to handle that correctly. Differential Revision: https://reviews.llvm.org/D90253
2020-10-23[WebAssembly] Implementation of (most) table instructionsPaulo Matos
Implementation of instructions table.get, table.set, table.grow, table.size, table.fill, table.copy. Missing instructions are table.init and elem.drop as they deal with element sections which are not yet implemented. Added more tests to tables.s Differential Revision: https://reviews.llvm.org/D89797
2020-06-15[WebAssembly] Adding 64-bit version of R_WASM_MEMORY_ADDR_* relocsWouter van Oortmerssen
This adds 4 new reloc types. A lot of code that previously assumed any memory or offset values could be contained in a uint32_t (and often truncated results from functions returning 64-bit values) have been upgraded to uint64_t. This is not comprehensive: it is only the values that come in contact with the new relocation values and their dependents. A new tablegen mapping was added to automatically upgrade loads/stores in the assembler, which otherwise has no way to select for these instructions (since they are indentical other than for the offset immediate). It follows a similar technique to https://reviews.llvm.org/D53307 Differential Revision: https://reviews.llvm.org/D81704
2020-06-15[WebAssembly] Adding 64-bit versions of all load & store ops.Wouter van Oortmerssen
Context: https://github.com/WebAssembly/memory64/blob/master/proposals/memory64/Overview.md This is just a first step, adding the new instruction variants while keeping the existing 32-bit functionality working. Some of the basic load/store tests have new wasm64 versions that show that the basics of the target are working. Further features need implementation, but these will be added in followups to keep things reviewable. Differential Revision: https://reviews.llvm.org/D80769
2019-10-15[WebAssembly] Allow multivalue types in block signature operandsThomas Lively
Summary: Renames `ExprType` to the more apt `BlockType` and adds a variant for multivalue blocks. Currently non-void blocks are only generated at the end of functions where the block return type needs to agree with the function return type, and that remains true for multivalue blocks. That invariant means that the actual signature does not need to be stored in the block signature `MachineOperand` because it can be inferred by `WebAssemblyMCInstLower` from the return type of the parent function. `WebAssemblyMCInstLower` continues to lower block signature operands to immediates when possible but lowers multivalue signatures to function type symbols. The AsmParser and Disassembler are updated to handle multivalue block types as well. Reviewers: aheejin, dschuff, aardappel Subscribers: sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68889 llvm-svn: 374933
2019-03-28[WebAssembly] Rename wasm fixup kindsSam Clegg
These fixup kinds are not explicitly related to the code section. They are there to signal how to apply the fixup. Also, a couple of other minor wasm cleanups. Differential Revision: https://reviews.llvm.org/D59908 llvm-svn: 357145
2019-02-04[WebAssembly] clang-tidy (NFC)Heejin Ahn
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-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-12-17[WebAssembly] Fix assembler parsing of br_table.Wouter van Oortmerssen
Summary: We use `variable_ops` in the tablegen defs to denote the list of branch targets in `br_table`, but unlike other uses of `variable_ops` (e.g. call) the these branch targets need to actually be encoded in the instruction. The existing tables for `variable_ops` cause not operands to be accepted by the assembly matcher. Following the example of ARM: https://github.com/llvm-mirror/llvm/blob/2cc0a7da876c1d8c32775b0119e1e15aaa759b9e/lib/Target/ARM/ARMInstrInfo.td#L550-L555 we introduce a new operand type to capture this list, and we use the same {} syntax as ARM as well to differentiate them from regular integer operands. Also removed definition and use of TSFlags in tablegen defs, since `br_table` now has a non-variable_ops immediate operand, so the previous logic of only the variable_ops arguments being labels didn't make sense anymore. Reviewers: dschuff, aheejin, sunfish Subscribers: javed.absar, sbc100, jgravelle-google, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D55401 llvm-svn: 349405
2018-11-14[WebAssembly] Add support for the event sectionHeejin Ahn
Summary: This adds support for the 'event section' specified in the exception handling proposal. (This was named 'exception section' first, but later renamed to 'event section' to take possibilities of other kinds of events into consideration. But currently we only store exception info in this section.) The event section is added between the global section and the export section. This is for ease of validation per request of the V8 team. This patch: - Creates the event symbol type, which is a weak symbol - Makes 'throw' instruction take the event symbol '__cpp_exception' - Adds relocation support for events - Adds WasmObjectWriter / WasmObjectFile (Reader) support - Adds obj2yaml / yaml2obj support - Adds '.eventtype' printing support Reviewers: dschuff, sbc100, aardappel Subscribers: jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D54096 llvm-svn: 346825
2018-11-09[WebAssembly] Renumber and LEB128-encode SIMD opcodesThomas Lively
Reviewers: aheejin, dschuff, aardappel Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D54126 llvm-svn: 346463
2018-09-05[WebAssembly] clang-format (NFC)Heejin Ahn
Summary: This patch runs clang-format on all wasm-only files. Reviewers: aardappel, dschuff, sunfish, tlively Subscribers: MatzeB, sbc100, jgravelle-google, llvm-commits Differential Revision: https://reviews.llvm.org/D51447 llvm-svn: 341439
2018-08-27[WebAssembly] Added default stack-only instruction mode for MC.Wouter van Oortmerssen
Summary: Made it convert from register to stack based instructions, and removed the registers. Fixes to related code that was expecting register based instructions. Added the correct testing flag to all tests, depending on what the format they were expecting so far. Translated one test to stack format as example: reg-stackify-stack.ll tested: llvm-lit -v `find test -name WebAssembly` unittests/MC/* Reviewers: dschuff, sunfish Subscribers: sbc100, jgravelle-google, eraman, aheejin, llvm-commits, jfb Differential Revision: https://reviews.llvm.org/D51241 llvm-svn: 340750
2018-08-21[WebAssembly] v128.constThomas Lively
Summary: This CL implements v128.const for each vector type. New operand types are added to ensure the vector contents can be serialized without LEB encoding. Tests are added for instruction selection, encoding, assembly and disassembly. Reviewers: aheejin, dschuff, aardappel Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D50873 llvm-svn: 340336
2018-08-03[WebAssembly] Cleanup of the way globals and global flags are handledNicholas Wilson
Differential Revision: https://reviews.llvm.org/D44030 llvm-svn: 338894
2018-05-18Support: Simplify endian stream interface. NFCI.Peter Collingbourne
Provide some free functions to reduce verbosity of endian-writing a single value, and replace the endianness template parameter with a field. Part of PR37466. Differential Revision: https://reviews.llvm.org/D47032 llvm-svn: 332757
2018-05-14Rename DEBUG macro to LLVM_DEBUG.Nicola Zaghen
The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM - Manual change to APInt - Manually chage DOCS as regex doesn't match it. In the transition period the DEBUG() macro is still present and aliased to the LLVM_DEBUG() one. Differential Revision: https://reviews.llvm.org/D43624 llvm-svn: 332240
2018-05-01Remove \brief commands from doxygen comments.Adrian Prantl
We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46290 llvm-svn: 331272
2018-04-04[WebAssembly] Only write 32-bits for WebAssembly::OPERAND_OFFSET32Sam Clegg
A bug was found where an offset of -1 would generate an encoding of max int64 which is invalid in the binary format. Differential Revision: https://reviews.llvm.org/D45280 llvm-svn: 329238
2018-03-02Reland "[WebAssembly] More uses of uint8_t for single byte values"Heejin Ahn
Summary: Original change was D43991 (rL326541) and was reverted by rL326571 and rL326572. This adds also the necessary MCCodeEmitter patch. Reviewers: sbc100 Subscribers: jfb, dschuff, sbc100, jgravelle-google, sunfish, llvm-commits, ncw Differential Revision: https://reviews.llvm.org/D44034 llvm-svn: 326614
2017-11-28[WebAssembly] Fix trapping behavior in fptosi/fptoui.Dan Gohman
This adds code to protect WebAssembly's `trunc_s` family of opcodes from values outside their domain. Even though such conversions have full undefined behavior in C/C++, LLVM IR's `fptosi` and `fptoui` do not, and only return undef. This also implements the proposed non-trapping float-to-int conversion feature and uses that instead when available. llvm-svn: 319128
2017-09-15Change encodeU/SLEB128 to pad to certain number of bytesSam Clegg
Previously the 'Padding' argument was the number of padding bytes to add. However most callers that use 'Padding' know how many overall bytes they need to write. With the previous code this would mean encoding the LEB once to find out how many bytes it would occupy and then using this to calulate the 'Padding' value. See: https://reviews.llvm.org/D36595 Differential Revision: https://reviews.llvm.org/D37494 llvm-svn: 313393
2017-06-16[WebAssembly] Use __stack_pointer global when writing wasm binarySam Clegg
This ensures that symbolic relocations are generated for stack pointer manipulations. These relocations are of type R_WEBASSEMBLY_GLOBAL_INDEX_LEB. This change also adds support for reading relocations of this type in WasmObjectFile.cpp. Since its a globally imported symbol this does mean that the get_global/set_global instruction won't be valid until the objects are linked that global used in no longer an imported global. Differential Revision: https://reviews.llvm.org/D34172 llvm-svn: 305616
2017-06-06Sort the remaining #include lines in include/... and lib/....Chandler Carruth
I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
2017-04-17[WebAssembly] Encode block signatures as SLEB instead of ULEBDerek Schuff
Use SLEB (varint) for block_type immediates in accordance with the spec. Patch by Yury Delendik llvm-svn: 300490
2017-02-24[WebAssembly] Basic support for Wasm object file encoding.Dan Gohman
With the "wasm32-unknown-unknown-wasm" triple, this allows writing out simple wasm object files, and is another step in a larger series toward migrating from ELF to general wasm object support. Note that this code and the binary format itself is still experimental. llvm-svn: 296190
2017-02-16[WebAssembly] Add a cast to void to fix an unused private member warning, ↵Dan Gohman
for now. llvm-svn: 295327
2017-02-10[WebAssembly] Pass an MCContext to WebAssemblyMCCodeEmitter. NFC.Dan Gohman
llvm-svn: 294679
2016-12-22[WebAssembly] Add an "explicit" keyword to a constructor.Dan Gohman
llvm-svn: 290345
2016-10-24[WebAssembly] Implement more WebAssembly binary encoding.Dan Gohman
This changes locals from being declared by the emitLocal hook in WebAssemblyTargetStreamer, rather than with an instruction. After exploring the infastructure in LLVM more, this seems to make more sense since declaring locals doesn't use an encoded opcode. This also adds more 0xd opcodes, type encodings, and miscellaneous binary encoding bits. llvm-svn: 285040
2016-10-24[WebAssembly] Add an option to make get_local/set_local explicit.Dan Gohman
This patch adds a pass, controlled by an option and off by default for now, for making implicit get_local/set_local explicit. This simplifies emitting wasm with MC. Differential Revision: https://reviews.llvm.org/D25836 llvm-svn: 285009
2016-06-23Fix the wasm build by including EndianStream.hReid Kleckner
llvm-svn: 273591
2016-01-20[WebAssembly] Minor code cleanups. NFC.Dan Gohman
llvm-svn: 258294
2016-01-19[WebAssembly] Remove an unused data member. NFC.Dan Gohman
llvm-svn: 258192
2016-01-12[WebAssembly] Implement a prototype instruction encoder and disassembler.Dan Gohman
This is using an extremely simple temporary made-up binary format, not the official binary format (which isn't defined yet). llvm-svn: 257440
2016-01-08[WebAssembly] Minor code cleanups. NFC.Dan Gohman
llvm-svn: 257131