diff options
| author | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-06-27 18:11:15 +0000 |
|---|---|---|
| committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-06-27 18:11:15 +0000 |
| commit | 6b3f56b65fa1e5094201fedb8a9cb9cd30eac9e5 (patch) | |
| tree | ea91cf89b4cd9ddc712c24ae49759eb3db3b1df5 /llvm/lib/Target/WebAssembly/AsmParser | |
| parent | 1fd1c6097959b7ab7218cf1695adf19f6547df30 (diff) | |
| download | bcm5719-llvm-6b3f56b65fa1e5094201fedb8a9cb9cd30eac9e5.tar.gz bcm5719-llvm-6b3f56b65fa1e5094201fedb8a9cb9cd30eac9e5.zip | |
[WebAssembly] Fix p2align in assembler.
Summary:
- Match the syntax output by InstPrinter.
- Fix it always emitting 0 for align. Had to work around fact that
opcode is not available for GetDefaultP2Align while parsing.
- Updated tests that were erroneously happy with a p2align=0
Fixes https://bugs.llvm.org/show_bug.cgi?id=40752
Reviewers: aheejin, sbc100
Subscribers: jgravelle-google, sunfish, jfb, llvm-commits, dschuff
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63633
llvm-svn: 364570
Diffstat (limited to 'llvm/lib/Target/WebAssembly/AsmParser')
| -rw-r--r-- | llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp index 89dd3d8b817..705d18aaf63 100644 --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -349,21 +349,28 @@ public: parseSingleInteger(IsNegative, Operands); // FIXME: there is probably a cleaner way to do this. auto IsLoadStore = InstName.startswith("load") || - InstName.startswith("store") || - InstName.startswith("atomic"); - if (IsLoadStore) { - // Parse load/store operands of the form: offset align - auto &Offset = Lexer.getTok(); - if (Offset.is(AsmToken::Integer)) { + InstName.startswith("store"); + auto IsAtomic = InstName.startswith("atomic"); + if (IsLoadStore || IsAtomic) { + // Parse load/store operands of the form: offset:p2align=align + if (IsLoadStore && isNext(AsmToken::Colon)) { + auto Id = expectIdent(); + if (Id != "p2align") + return error("Expected p2align, instead got: " + Id); + if (expect(AsmToken::Equal, "=")) + return true; + if (!Lexer.is(AsmToken::Integer)) + return error("Expected integer constant"); parseSingleInteger(false, Operands); } else { - // Alignment not specified. - // FIXME: correctly derive a default from the instruction. + // Alignment not specified (or atomics, must use default alignment). // We can't just call WebAssembly::GetDefaultP2Align since we don't have - // an opcode until after the assembly matcher. + // an opcode until after the assembly matcher, so set a default to fix + // up later. + auto Tok = Lexer.getTok(); Operands.push_back(make_unique<WebAssemblyOperand>( - WebAssemblyOperand::Integer, Offset.getLoc(), Offset.getEndLoc(), - WebAssemblyOperand::IntOp{0})); + WebAssemblyOperand::Integer, Tok.getLoc(), Tok.getEndLoc(), + WebAssemblyOperand::IntOp{-1})); } } return false; @@ -699,6 +706,13 @@ public: *Out.getTargetStreamer()); TOut.emitLocal(SmallVector<wasm::ValType, 0>()); } + // Fix unknown p2align operands. + auto Align = WebAssembly::GetDefaultP2AlignAny(Inst.getOpcode()); + if (Align != -1U) { + auto &Op0 = Inst.getOperand(0); + if (Op0.getImm() == -1) + Op0.setImm(Align); + } Out.EmitInstruction(Inst, getSTI()); if (CurrentState == EndFunction) { onEndOfFunction(); |

