summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h
AgeCommit message (Collapse)Author
2025-11-08[WebAssembly] Clean up CustomMappingTraits<BBNumberMap> (NFC) (#167155)Kazu Hirata
This patch does two things for readability: - Use structured bindings. - Remove extraneous .c_str(). Note that YamlIO.mapRequired takes StringRef as the key type. As such, we can implicitly construct StringRef from std::string.
2025-11-01[llvm] Remove redundant str() and c_str() (NFC) (#166012)Kazu Hirata
io.mapRequired takes StringRef as the key type. As such, we do not need to create extraneous copies with str().c_str() or str(). Identified with readability-redundant-string-cstr.
2025-10-25[Target] Add "override" where appropriate (NFC) (#165083)Kazu Hirata
Note that "override" makes "virtual" redundant. Identified with modernize-use-override.
2025-02-24[WebAssembly] Use Register instead of unsigned. NFCCraig Topper
2025-02-22[WebAssembly] Use Register instead of unsigned. NFCCraig Topper
2025-02-19[CodeGen] Remove static member function Register::virtReg2Index. NFC (#127962)Craig Topper
Use the nonstatic member instead. I'm pretty sure the code in SPRIV is a layering violation. MC layer files are using a CodeGen header.
2024-04-02[WebAssembly] Allocate MCSymbolWasm data on MCContext (#85866)Tim Neumann
Fixes #85578, a use-after-free caused by some `MCSymbolWasm` data being freed too early. Previously, `WebAssemblyAsmParser` owned the data that is moved to `MCContext` by this PR, which caused problems when handling module ASM, because the ASM parser was destroyed after parsing the module ASM, but the symbols persisted. The added test passes locally with an LLVM build with AddressSanitizer enabled. Implementation notes: * I've called the added method <code>allocate<b><i>Generic</i></b>String</code> and added the second paragraph of its documentation to maybe guide people a bit on when to use this method (based on my (limited) understanding of the `MCContext` class). We could also just call it `allocateString` and remove that second paragraph. * The added `createWasmSignature` method does not support taking the return and parameter types as arguments: Specifying them afterwards is barely any longer and prevents them from being accidentally specified in the wrong order. * This removes a _"TODO: Do the uniquing of Signatures here instead of ObjectFileWriter?"_ since the field it's attached to is also removed. Let me know if you think that TODO should be preserved somewhere.
2024-03-19[WebAssembly] Pass ArrayRef by value (NFC) (#85732)Heejin Ahn
`ArrayRef` is supposed to be passed by value: https://github.com/llvm/llvm-project/blob/bda05140fb758156ae35f3919e6283d94bfa3905/llvm/include/llvm/ADT/ArrayRef.h#L38-L39
2023-08-18[WebAssembly] Create separation between MC and CodeGen layersReid Kleckner
Move WebAssemblyUtilities from Utils to the CodeGen library. It primarily deals in MIR layer types, so it really lives in the CodeGen library. Move a variety of other things around to try create better separation. See issue #64166 for more info on layering. Move llvm/include/CodeGen/WasmAddressSpaces.h back to llvm/lib/Target/WebAssembly/Utils. Differential Revision: https://reviews.llvm.org/D156472
2022-12-21CodeGen: Don't lazily construct MachineFunctionInfoMatt Arsenault
This fixes what I consider to be an API flaw I've tripped over multiple times. The point this is constructed isn't well defined, so depending on where this is first called, you can conclude different information based on the MachineFunction. For example, the AMDGPU implementation inspected the MachineFrameInfo on construction for the stack objects and if the frame has calls. This kind of worked in SelectionDAG which visited all allocas up front, but broke in GlobalISel which hasn't visited any of the IR when arguments are lowered. I've run into similar problems before with the MIR parser and trying to make use of other MachineFunction fields, so I think it's best to just categorically disallow dependency on the MachineFunction state in the constructor and to always construct this at the same time as the MachineFunction itself. A missing feature I still could use is a way to access an custom analysis pass on the IR here.
2022-11-11WebAssembly: Remove MachineFunction reference from MFIMatt Arsenault
The MachineFunctionInfo here is a bit awkward because WasmEHInfo is in the MachineFunction but handled from the target code. Either everything should move into WebAssembly or into the MachineFunction for MIR serialization.
2022-06-07llvm-reduce: Add cloning of target MachineFunctionInfoMatt Arsenault
MIR support is totally unusable for AMDGPU without this, since the set of reserved registers is set from fields here. Add a clone method to MachineFunctionInfo. This is a subtle variant of the copy constructor that is required if there are any MIR constructs that use pointers. Specifically, at minimum fields that reference MachineBasicBlocks or the MachineFunction need to be adjusted to the values in the new function.
2022-01-29[WebAssembly][NFC] Refactor WasmSymbol type setting codePaulo Matos
This refactors some code dealing with setting Wasm symbol types. Some of the code dealing with types was moved from `WebAssemblyUtilities` to `WebAssemblyTypeUtilities`. Reviewed By: sbc100 Differential Revision: https://reviews.llvm.org/D118121
2021-04-22[WebAssembly] Serialize params/results in MachineFunctionInfoHeejin Ahn
This adds support for YAML serialization of `Params` and `Results` fields in `WebAssemblyMachineFunctionInfo`. Types are printed as `MVT`'s string representation. This is for writing MIR tests easier. The tests added are testing simple parsing and printing of `params` / `results` fields under `machineFunctionInfo`. Reviewed By: tlively Differential Revision: https://reviews.llvm.org/D101029
2021-04-22[WebAssembly] Put utility functions in Utils directory (NFC)Heejin Ahn
This CL 1. Creates Utils/ directory under lib/Target/WebAssembly 2. Moves existing WebAssemblyUtilities.cpp|h into the Utils/ directory 3. Creates Utils/WebAssemblyTypeUtilities.cpp|h and put type declarataions and type conversion functions scattered in various places into this single place. It has been suggested several times that it is not easy to share utility functions between subdirectories (AsmParser, DIsassembler, MCTargetDesc, ...). Sometimes we ended up [[ https://reviews.llvm.org/D92840#2478863 | duplicating ]] the same function because of this. There are already other targets doing this: AArch64, AMDGPU, and ARM have Utils/ subdirectory under their target directory. This extracts the utility functions into a single directory Utils/ and make them sharable among all passes in WebAssembly/ and its subdirectories. Also I believe gathering all type-related conversion functionalities into a single place makes it more usable. (Actually I was working on another CL that uses various type conversion functions scattered in multiple places, which became the motivation for this CL.) Reviewed By: dschuff, aardappel Differential Revision: https://reviews.llvm.org/D100995
2021-02-22[WebAssembly] Support WasmEHFuncInfo serializationHeejin Ahn
This adds support for serialization of `WasmEHFuncInfo`, in the form of <Source BB Number, Unwind destination BB number>. To make YAML mapping work, we needed to make a copy of the existing `SrcToUnwindDest` map within `yaml::WebAssemblyMachineFunctionInfo`. It was hard to add EH MIR tests for CFGStackify because `WasmEHFuncInfo` could not be read from test MIR files. This adds the serialization support for that to make EH MIR tests easier. Reviewed By: dschuff Differential Revision: https://reviews.llvm.org/D97174
2020-06-24WebAssembly: Don't store MachineFunction in MachineFunctionInfoMatt Arsenault
Soon it will be disallowed to depend on MachineFunction state in the constructor. This was only being used to get the MachineRegisterInfo for an assert, which I'm not sure is necessarily worth it. I would think any missing defs would be caught by the verifier later instead.
2020-03-19[WebAssembly] Support swiftself and swifterror for WebAssembly targetYuta Saito
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-01-28[WebAssembly] Preserve debug frame base information through register coloringDerek Schuff
2 fixes: Register coloring can re-assign virtual registers. When the frame base register is colored, update the DwarfFrameBase accordingly When the frame base register is stackified, do not attempt to encode DW_AT_frame_base as a local In the future we will presumably want to handle this case better but for now we can emit worse debug info rather than crashing. Differential Revision: https://reviews.llvm.org/D73581
2020-01-17[WebAssembly] Track frame registers through VReg and local allocationDerek Schuff
This change has 2 components: Target-independent: add a method getDwarfFrameBase to TargetFrameLowering. It describes how the Dwarf frame base will be encoded. That can be a register (the default), the CFA (which replaces NVPTX-specific logic in DwarfCompileUnit), or a DW_OP_WASM_location descriptr. WebAssembly: Allow WebAssemblyFunctionInfo::getFrameRegister to return the correct virtual register instead of FP32/SP32 after WebAssemblyReplacePhysRegs has run. Make WebAssemblyExplicitLocals store the local it allocates for the frame register. Use this local information to implement getDwarfFrameBase The result is that the DW_AT_frame_base attribute is correctly encoded for each subprogram, and each param and local variable has a correct DW_AT_location that uses DW_OP_fbreg to refer to the frame base. This is a reland of rG3a05c3969c18 with fixes for the expensive-checks and Windows builds Differential Revision: https://reviews.llvm.org/D71681
2020-01-16Revert "[WebAssembly] Track frame registers through VReg and local allocation"Derek Schuff
This reverts commit 3a05c3969c18b5520e360b78fc63cda39a6be98f. It breaks under expensive-checks and on Windows
2020-01-16[WebAssembly] Track frame registers through VReg and local allocationDerek Schuff
This change has 2 components: Target-independent: add a method getDwarfFrameBase to TargetFrameLowering. It describes how the Dwarf frame base will be encoded. That can be a register (the default), the CFA (which replaces NVPTX-specific logic in DwarfCompileUnit), or a DW_OP_WASM_location descriptr. WebAssembly: Allow WebAssemblyFunctionInfo::getFrameRegister to return the correct virtual register instead of FP32/SP32 after WebAssemblyReplacePhysRegs has run. Make WebAssemblyExplicitLocals store the local it allocates for the frame register. Use this local information to implement getDwarfFrameBase The result is that the DW_AT_frame_base attribute is correctly encoded for each subprogram, and each param and local variable has a correct DW_AT_location that uses DW_OP_fbreg to refer to the frame base. Differential Revision: https://reviews.llvm.org/D71681
2019-10-01[WebAssembly] Unstackify regs after fixing unwinding mismatchesHeejin Ahn
Summary: Fixing unwind mismatches for exception handling can result in splicing existing BBs and moving some of instructions to new BBs. In this case some of stackified def registers in the original BB can be used in the split BB. For example, we have this BB and suppose %r0 is a stackified register. ``` bb.1: %r0 = call @foo ... use %r0 ... ``` After fixing unwind mismatches in CFGStackify, `bb.1` can be split and some instructions can be moved to a newly created BB: ``` bb.1: %r0 = call @foo bb.split (new): ... use %r0 ... ``` In this case we should make %r0 un-stackified, because its use is now in another BB. When spliting a BB, this CL unstackifies all def registers that have uses in the new split BB. Reviewers: dschuff Subscribers: sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68218 llvm-svn: 373301
2019-08-01Finish moving TargetRegisterInfo::isVirtualRegister() and friends to ↵Daniel Sanders
llvm::Register as started by r367614. NFC llvm-svn: 367633
2019-03-26[WebAssembly] Add CFGStacikfied field to WebAssemblyFunctionInfoHeejin Ahn
Summary: This adds `CFGStackified` field and its serialization to WebAssemblyFunctionInfo. Reviewers: dschuff Subscribers: sunfish, sbc100, jgravelle-google, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59747 llvm-svn: 357011
2019-03-26[WebAssembly] Support WebAssemblyFunctionInfo serializationHeejin Ahn
Summary: The framework for supporting target-specific MachineFunctionInfo was added in r356215. This adds serialization support for WebAssemblyFunctionInfo on top of that. This patch only adds the framework and does not actually serialize anything at this point; we have to add YAML mapping later for the fields in WebAssemblyFunctionInfo we want to serialize if necessary. Reviewers: dschuff, arsenm Subscribers: sunfish, wdng, sbc100, jgravelle-google, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59737 llvm-svn: 357009
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-11-19[WebAssembly] replaced .param/.result by .functypeWouter van Oortmerssen
Summary: This makes it easier/cleaner to generate a single signature from this directive. Also: - Adds the symbol name, such that we don't depend on the location of this directive anymore. - Actually constructs the signature in the assembler, and make the assembler own it. - Refactor the use of MVT vs ValType in the streamer and assembler to require less conversions overall. - Changed 700 or so tests to use it. Reviewers: sbc100, dschuff Subscribers: jgravelle-google, eraman, aheejin, sunfish, jfb, llvm-commits Differential Revision: https://reviews.llvm.org/D54652 llvm-svn: 347228
2018-10-03[WebAssembly] Refactor WasmSignature and use it for MCSymbolWasmDerek Schuff
MCContext does not destroy MCSymbols on shutdown. So, rather than putting SmallVectors (which may heap-allocate) inside MCSymbolWasm, use unowned pointer to a WasmSignature instead. The signatures are now owned by the AsmPrinter. Also uses WasmSignature instead of param and result vectors in TargetStreamer, and leaves some TODOs for further simplification. Differential Revision: https://reviews.llvm.org/D52580 llvm-svn: 343733
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-06-18[WebAssembly] Cleaned up register accessors in WebAssemblyMachineFunctionInfo.hWouter van Oortmerssen
Tested: llvm-lit -v `find test -name WebAssembly` (This is a commit access "test commit" :) llvm-svn: 334979
2018-05-22[WebAssembly] Fix fast-isel lowering illegal argument and return types.Dan Gohman
For both argument and return types, promote illegal types like i24 to i32, and if a type can't be easily promoted, clear out the signature before bailing out, so avoid leaving it in a partially complete state. Fixes PR37546. llvm-svn: 332947
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
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
2016-11-07[WebAssembly] Emit a BasePointer when we have overly-aligned stack objectsDerek Schuff
Because we shift the stack pointer by an unknown amount, we need an additional pointer. In the case where we have variable-size objects as well, we can't reuse the frame pointer, thus three pointers. Patch by Jacob Gravelle Differential Revision: https://reviews.llvm.org/D26263 llvm-svn: 286160
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-10-06[WebAssemby] Implement block signatures.Dan Gohman
Per spec changes, this implements block signatures, and adds just enough logic to produce correct block signatures at the ends of functions. Differential Revision: https://reviews.llvm.org/D25144 llvm-svn: 283503
2016-06-06Remove dead function with incredibly broken assert.Benjamin Kramer
Found by clang-tidy's misc-assert-side-effect. llvm-svn: 271887
2016-05-21[WebAssembly] Optimize away return instructions using fallthroughs.Dan Gohman
This saves a small amount of code size, and is a first small step toward passing values on the stack across block boundaries. Differential Review: http://reviews.llvm.org/D20450 llvm-svn: 270294
2016-05-10[WebAssembly] Move register stackification and coloring to a late phase.Dan Gohman
Move the register stackification and coloring passes to run very late, after PEI, tail duplication, and most other passes. This means that all code emitted and expanded by those passes is now exposed to these passes. This also eliminates the need for prologue/epilogue code to be manually stackified, which significantly simplifies the code. This does require running LiveIntervals a second time. It's useful to think of these late passes not as late optimization passes, but as a domain-specific compression algorithm based on knowledge of liveness information. It's used to compress the code after all conventional optimizations are complete, which is why it uses LiveIntervals at a phase when actual optimization passes don't typically need it. Differential Revision: http://reviews.llvm.org/D20075 llvm-svn: 269012
2016-02-10[WebAssembly] Switch varags calling convention to use a registerDerek Schuff
Instead of passing varargs directly on the user stack, allocate a buffer in the caller's stack frame and pass a pointer to it. This simplifies the C ABI (e.g. non-C callers of C functions do not need to use C's user stack if they have their own mechanism) and allows further optimizations in the future (e.g. fewer functions may need to use the stack). Differential Revision: http://reviews.llvm.org/D17048 llvm-svn: 260421
2016-01-26[WebAssembly] Implement unaligned loads and stores.Dan Gohman
Differential Revision: http://reviews.llvm.org/D16534 llvm-svn: 258779
2015-12-16Iterate over phys regs insteadDerek Schuff
llvm-svn: 255816
2015-12-11[WebAssembly] Implement prolog/epilog insertion and FrameIndex eliminationDerek Schuff
Summary: Use the SP32 physical register as the base for FrameIndex lowering. Update it and the __stack_pointer global var in the prolog and epilog. Extend the mapping of virtual registers to wasm locals to include the physical registers. Rather than modify the target-independent PrologEpilogInserter (which asserts that there are no virtual registers left) include a slightly-modified copy for Wasm that does not have this assertion and only clears the virtual registers if scavenging was needed (which of course it isn't for wasm). Differential Revision: http://reviews.llvm.org/D15344 llvm-svn: 255392
2015-12-08[WebAssembly] Trim some unneeded #includes.Dan Gohman
llvm-svn: 254994
2015-12-02[WebAssembly] Fix comments to say "LIFO" instead of "FIFO" when describing a ↵Dan Gohman
stack. llvm-svn: 254523
2015-11-25[WebAssembly] Fix WebAssembly register numbering for registers added late.Dan Gohman
If virtual registers are created late, mappings to WebAssembly registers need to be added explicitly. This patch adds a function to do so and teaches WebAssemblyPeephole to use it. This fixes an out-of-bounds access on the WARegs vector. llvm-svn: 254094
2015-11-16[WebAssembly] Fix function return type printingDerek Schuff
Summary: Previously return type information for a function was derived from return dag nodes. But this didn't work for dags with != return node. So instead compute it directly from the LLVM function as is done for imports. Differential Revision: http://reviews.llvm.org/D14593 llvm-svn: 253251