[llvm] 6d33aff - [WebAssembly] Add comments on local.tee transformation
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 17 20:16:29 PDT 2023
Author: Heejin Ahn
Date: 2023-03-17T20:16:16-07:00
New Revision: 6d33affac05a7f30f8b3761a66f81fe63b9f44e1
URL: https://github.com/llvm/llvm-project/commit/6d33affac05a7f30f8b3761a66f81fe63b9f44e1
DIFF: https://github.com/llvm/llvm-project/commit/6d33affac05a7f30f8b3761a66f81fe63b9f44e1.diff
LOG: [WebAssembly] Add comments on local.tee transformation
We have a good comment on `TEE` transformation in `RegStackify`:
https://github.com/llvm/llvm-project/blob/547e3456660000a16fc5c2a2f819f1a2b5d35b5d/llvm/lib/Target/WebAssembly/WebAssemblyRegStackify.cpp#L613-L632
And I think it can be helpful to have some more comments on how the
`TEE`s created in `RegStackify` are converted into `LOCAL_TEE`s.
Variable `OldReg` is changed to `DefReg` to be consistent with
`RegStackify`'s comment.
Reviewed By: tlively
Differential Revision: https://reviews.llvm.org/D146084
Added:
Modified:
llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
index 08483b7935b6..84fd34d73b63 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
@@ -267,15 +267,42 @@ bool WebAssemblyExplicitLocals::runOnMachineFunction(MachineFunction &MF) {
// Replace tee instructions with local.tee. The
diff erence is that tee
// instructions have two defs, while local.tee instructions have one def
// and an index of a local to write to.
+ //
+ // - Before:
+ // TeeReg, Reg = TEE DefReg
+ // INST ..., TeeReg, ...
+ // INST ..., Reg, ...
+ // INST ..., Reg, ...
+ // * DefReg: may or may not be stackified
+ // * Reg: not stackified
+ // * TeeReg: stackified
+ //
+ // - After (when DefReg was already stackified):
+ // TeeReg = LOCAL_TEE LocalId1, DefReg
+ // INST ..., TeeReg, ...
+ // INST ..., Reg, ...
+ // INST ..., Reg, ...
+ // * Reg: mapped to LocalId1
+ // * TeeReg: stackified
+ //
+ // - After (when DefReg was not already stackified):
+ // NewReg = LOCAL_GET LocalId1
+ // TeeReg = LOCAL_TEE LocalId2, NewReg
+ // INST ..., TeeReg, ...
+ // INST ..., Reg, ...
+ // INST ..., Reg, ...
+ // * DefReg: mapped to LocalId1
+ // * Reg: mapped to LocalId2
+ // * TeeReg: stackified
if (WebAssembly::isTee(MI.getOpcode())) {
assert(MFI.isVRegStackified(MI.getOperand(0).getReg()));
assert(!MFI.isVRegStackified(MI.getOperand(1).getReg()));
- Register OldReg = MI.getOperand(2).getReg();
- const TargetRegisterClass *RC = MRI.getRegClass(OldReg);
+ Register DefReg = MI.getOperand(2).getReg();
+ const TargetRegisterClass *RC = MRI.getRegClass(DefReg);
// Stackify the input if it isn't stackified yet.
- if (!MFI.isVRegStackified(OldReg)) {
- unsigned LocalId = getLocalId(Reg2Local, MFI, CurLocal, OldReg);
+ if (!MFI.isVRegStackified(DefReg)) {
+ unsigned LocalId = getLocalId(Reg2Local, MFI, CurLocal, DefReg);
Register NewReg = MRI.createVirtualRegister(RC);
unsigned Opc = getLocalGetOpcode(RC);
BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(Opc), NewReg)
More information about the llvm-commits
mailing list