From b389cd0209d3939cd36cd8eb1cee2b4c4f0b09fd Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Thu, 27 Jun 2019 18:58:26 +0000 Subject: [PATCH] [WebAssembly] AsmParser: better atomic inst detection Summary: Previously missed atomic.notify. Fixes https://bugs.llvm.org/show_bug.cgi?id=40728 Reviewers: aheejin Subscribers: sbc100, jgravelle-google, sunfish, jfb, llvm-commits, dschuff Tags: #llvm Differential Revision: https://reviews.llvm.org/D63747 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364576 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 49 ++++++++++------------ test/MC/WebAssembly/basic-assembly.s | 8 +++- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp index 705d18aaf63..196ef2d9b91 100644 --- a/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -348,9 +348,9 @@ public: StringRef InstName) { parseSingleInteger(IsNegative, Operands); // FIXME: there is probably a cleaner way to do this. - auto IsLoadStore = InstName.startswith("load") || - InstName.startswith("store"); - auto IsAtomic = InstName.startswith("atomic"); + auto IsLoadStore = InstName.find(".load") != StringRef::npos || + InstName.find(".store") != StringRef::npos; + auto IsAtomic = InstName.find("atomic.") != StringRef::npos; if (IsLoadStore || IsAtomic) { // Parse load/store operands of the form: offset:p2align=align if (IsLoadStore && isNext(AsmToken::Colon)) { @@ -413,48 +413,45 @@ public: Operands.push_back(make_unique( WebAssemblyOperand::Token, NameLoc, SMLoc::getFromPointer(Name.end()), WebAssemblyOperand::TokOp{Name})); - auto NamePair = Name.split('.'); - // If no '.', there is no type prefix. - auto BaseName = NamePair.second.empty() ? NamePair.first : NamePair.second; // If this instruction is part of a control flow structure, ensure // proper nesting. bool ExpectBlockType = false; - if (BaseName == "block") { + if (Name == "block") { push(Block); ExpectBlockType = true; - } else if (BaseName == "loop") { + } else if (Name == "loop") { push(Loop); ExpectBlockType = true; - } else if (BaseName == "try") { + } else if (Name == "try") { push(Try); ExpectBlockType = true; - } else if (BaseName == "if") { + } else if (Name == "if") { push(If); ExpectBlockType = true; - } else if (BaseName == "else") { - if (pop(BaseName, If)) + } else if (Name == "else") { + if (pop(Name, If)) return true; push(Else); - } else if (BaseName == "catch") { - if (pop(BaseName, Try)) + } else if (Name == "catch") { + if (pop(Name, Try)) return true; push(Try); - } else if (BaseName == "end_if") { - if (pop(BaseName, If, Else)) + } else if (Name == "end_if") { + if (pop(Name, If, Else)) return true; - } else if (BaseName == "end_try") { - if (pop(BaseName, Try)) + } else if (Name == "end_try") { + if (pop(Name, Try)) return true; - } else if (BaseName == "end_loop") { - if (pop(BaseName, Loop)) + } else if (Name == "end_loop") { + if (pop(Name, Loop)) return true; - } else if (BaseName == "end_block") { - if (pop(BaseName, Block)) + } else if (Name == "end_block") { + if (pop(Name, Block)) return true; - } else if (BaseName == "end_function") { + } else if (Name == "end_function") { CurrentState = EndFunction; - if (pop(BaseName, Function) || ensureEmptyNestingStack()) + if (pop(Name, Function) || ensureEmptyNestingStack()) return true; } @@ -486,11 +483,11 @@ public: Parser.Lex(); if (Lexer.isNot(AsmToken::Integer)) return error("Expected integer instead got: ", Lexer.getTok()); - if (parseOperandStartingWithInteger(true, Operands, BaseName)) + if (parseOperandStartingWithInteger(true, Operands, Name)) return true; break; case AsmToken::Integer: - if (parseOperandStartingWithInteger(false, Operands, BaseName)) + if (parseOperandStartingWithInteger(false, Operands, Name)) return true; break; case AsmToken::Real: { diff --git a/test/MC/WebAssembly/basic-assembly.s b/test/MC/WebAssembly/basic-assembly.s index 87648f09206..b0583cdb2ef 100644 --- a/test/MC/WebAssembly/basic-assembly.s +++ b/test/MC/WebAssembly/basic-assembly.s @@ -1,6 +1,6 @@ -# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+atomics,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s # Check that it converts to .o without errors, but don't check any output: -# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling -o %t.o < %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+atomics,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling -o %t.o < %s test0: # Test all types: @@ -68,6 +68,8 @@ test0: #i32x4.trunc_sat_f32x4_s i32.trunc_f32_s try except_ref + i32.atomic.load 0 + atomic.notify 0 .LBB0_3: catch local.set 0 @@ -153,6 +155,8 @@ test0: # CHECK-NEXT: f32x4.add # CHECK-NEXT: i32.trunc_f32_s # CHECK-NEXT: try except_ref +# CHECK-NEXT: i32.atomic.load 0 +# CHECK-NEXT: atomic.notify 0 # CHECK-NEXT: .LBB0_3: # CHECK-NEXT: catch # CHECK-NEXT: local.set 0 -- 2.11.0