From 8ccfc118c67f79f20f57077e56b7cbc8c532982c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 24 Aug 2015 21:03:24 +0000 Subject: [PATCH] [WebAssembly] CodeGen support for __builtin_wasm_page_size() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245872 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | 2 +- lib/Target/WebAssembly/WebAssemblyInstrMemory.td | 7 +++++++ test/CodeGen/WebAssembly/memory-addr32.ll | 16 ++++++++++++++++ test/CodeGen/WebAssembly/memory-addr64.ll | 16 ++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/WebAssembly/memory-addr32.ll create mode 100644 test/CodeGen/WebAssembly/memory-addr64.ll diff --git a/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp index 4216fb6ebe2..6f98b4f6ed0 100644 --- a/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -79,7 +79,7 @@ private: static SmallString<32> Name(const WebAssemblyInstrInfo *TII, const MachineInstr *MI) { std::string N(StringRef(TII->getName(MI->getOpcode())).lower()); - std::string::size_type End = N.find('_'); + std::string::size_type End = N.rfind('_'); End = std::string::npos == End ? N.length() : End; return SmallString<32>(&N[0], &N[End]); } diff --git a/lib/Target/WebAssembly/WebAssemblyInstrMemory.td b/lib/Target/WebAssembly/WebAssemblyInstrMemory.td index 5ab40e826ca..8457dc89c4d 100644 --- a/lib/Target/WebAssembly/WebAssemblyInstrMemory.td +++ b/lib/Target/WebAssembly/WebAssemblyInstrMemory.td @@ -44,3 +44,10 @@ * load_global: load the value of a given global variable * store_global: store a given value to a given global variable */ + +def page_size_I32 : I<(outs Int32:$dst), (ins), + [(set Int32:$dst, (int_wasm_page_size))]>, + Requires<[HasAddr32]>; +def page_size_I64 : I<(outs Int64:$dst), (ins), + [(set Int64:$dst, (int_wasm_page_size))]>, + Requires<[HasAddr64]>; diff --git a/test/CodeGen/WebAssembly/memory-addr32.ll b/test/CodeGen/WebAssembly/memory-addr32.ll new file mode 100644 index 00000000000..b2816089ea8 --- /dev/null +++ b/test/CodeGen/WebAssembly/memory-addr32.ll @@ -0,0 +1,16 @@ +; RUN: llc < %s -asm-verbose=false | FileCheck %s + +; Test that basic memory operations assemble as expected with 32-bit addresses. + +target datalayout = "e-p:32:32-i64:64-n32:64-S128" +target triple = "wasm32-unknown-unknown" + +declare i32 @llvm.wasm.page.size.i32() nounwind readnone + +; CHECK-LABEL: page_size: +; CHECK-NEXT: (setlocal @0 (page_size)) +; CHECK-NEXT: (return @0) +define i32 @page_size() { + %a = call i32 @llvm.wasm.page.size.i32() + ret i32 %a +} diff --git a/test/CodeGen/WebAssembly/memory-addr64.ll b/test/CodeGen/WebAssembly/memory-addr64.ll new file mode 100644 index 00000000000..c726a2ccad8 --- /dev/null +++ b/test/CodeGen/WebAssembly/memory-addr64.ll @@ -0,0 +1,16 @@ +; RUN: llc < %s -asm-verbose=false | FileCheck %s + +; Test that basic memory operations assemble as expected with 64-bit addresses. + +target datalayout = "e-p:64:64-i64:64-n32:64-S128" +target triple = "wasm64-unknown-unknown" + +declare i64 @llvm.wasm.page.size.i64() nounwind readnone + +; CHECK-LABEL: page_size: +; CHECK-NEXT: (setlocal @0 (page_size)) +; CHECK-NEXT: (return @0) +define i64 @page_size() { + %a = call i64 @llvm.wasm.page.size.i64() + ret i64 %a +} -- 2.34.1