Skip to content

Commit a49496f

Browse files
author
Dan Gohman
committed
[WebAssembly] Add the signature for the new llround builtin function
r360889 added new llround builtin functions. This patch adds their signatures for the WebAssembly backend. It also adds wasm32 support to utils/update_llc_test_checks.py, since that's the script other targets are using for their testcases for this feature. Differential Revision: https://reviews.llvm.org/D62207 llvm-svn: 361327
1 parent db62d37 commit a49496f

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyRuntimeLibcallSignatures.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ enum RuntimeLibcallSignature {
8686
func_iPTR_i64_i64_i64_i64_i64_i64,
8787
i32_func_i64_i64,
8888
i32_func_i64_i64_i64_i64,
89+
iPTR_func_f32,
90+
iPTR_func_f64,
91+
iPTR_func_i64_i64,
8992
unsupported
9093
};
9194

@@ -216,6 +219,12 @@ struct RuntimeLibcallSignatureTable {
216219
Table[RTLIB::ROUND_F32] = f32_func_f32;
217220
Table[RTLIB::ROUND_F64] = f64_func_f64;
218221
Table[RTLIB::ROUND_F128] = func_iPTR_i64_i64;
222+
Table[RTLIB::LROUND_F32] = iPTR_func_f32;
223+
Table[RTLIB::LROUND_F64] = iPTR_func_f64;
224+
Table[RTLIB::LROUND_F128] = iPTR_func_i64_i64;
225+
Table[RTLIB::LLROUND_F32] = i64_func_f32;
226+
Table[RTLIB::LLROUND_F64] = i64_func_f64;
227+
Table[RTLIB::LLROUND_F128] = i64_func_i64_i64;
219228
Table[RTLIB::FLOOR_F32] = f32_func_f32;
220229
Table[RTLIB::FLOOR_F64] = f64_func_f64;
221230
Table[RTLIB::FLOOR_F128] = func_iPTR_i64_i64;
@@ -843,6 +852,19 @@ void llvm::getLibcallSignature(const WebAssemblySubtarget &Subtarget,
843852
Params.push_back(wasm::ValType::I64);
844853
Params.push_back(wasm::ValType::I64);
845854
break;
855+
case iPTR_func_f32:
856+
Rets.push_back(PtrTy);
857+
Params.push_back(wasm::ValType::F32);
858+
break;
859+
case iPTR_func_f64:
860+
Rets.push_back(PtrTy);
861+
Params.push_back(wasm::ValType::F64);
862+
break;
863+
case iPTR_func_i64_i64:
864+
Rets.push_back(PtrTy);
865+
Params.push_back(wasm::ValType::I64);
866+
Params.push_back(wasm::ValType::I64);
867+
break;
846868
case unsupported:
847869
llvm_unreachable("unsupported runtime library signature");
848870
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=wasm32 | FileCheck %s
3+
4+
define i64 @testmsxs_builtin(float %x) {
5+
; CHECK-LABEL: testmsxs_builtin:
6+
; CHECK: .functype testmsxs_builtin (f32) -> (i64)
7+
; CHECK-NEXT: # %bb.0: # %entry
8+
; CHECK-NEXT: local.get 0
9+
; CHECK-NEXT: i64.call llroundf
10+
; CHECK-NEXT: # fallthrough-return-value
11+
; CHECK-NEXT: end_function
12+
entry:
13+
%0 = tail call i64 @llvm.llround.f32(float %x)
14+
ret i64 %0
15+
}
16+
17+
define i64 @testmsxd_builtin(double %x) {
18+
; CHECK-LABEL: testmsxd_builtin:
19+
; CHECK: .functype testmsxd_builtin (f64) -> (i64)
20+
; CHECK-NEXT: # %bb.0: # %entry
21+
; CHECK-NEXT: local.get 0
22+
; CHECK-NEXT: i64.call llround
23+
; CHECK-NEXT: # fallthrough-return-value
24+
; CHECK-NEXT: end_function
25+
entry:
26+
%0 = tail call i64 @llvm.llround.f64(double %x)
27+
ret i64 %0
28+
}
29+
30+
declare i64 @llvm.llround.f32(float) nounwind readnone
31+
declare i64 @llvm.llround.f64(double) nounwind readnone

llvm/utils/UpdateTestChecks/asm.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ class string:
8282
r'.Lfunc_end[0-9]+:\n',
8383
flags=(re.M | re.S))
8484

85+
ASM_FUNCTION_WASM32_RE = re.compile(
86+
r'^_?(?P<func>[^:]+):[ \t]*#+[ \t]*@(?P=func)\n'
87+
r'(?P<body>.*?)\n'
88+
r'.Lfunc_end[0-9]+:\n',
89+
flags=(re.M | re.S))
90+
8591

8692
SCRUB_LOOP_COMMENT_RE = re.compile(
8793
r'# =>This Inner Loop Header:.*|# in Loop:.*', flags=re.M)
@@ -200,6 +206,16 @@ def scrub_asm_systemz(asm, args):
200206
asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm)
201207
return asm
202208

209+
def scrub_asm_wasm32(asm, args):
210+
# Scrub runs of whitespace out of the assembly, but leave the leading
211+
# whitespace in place.
212+
asm = common.SCRUB_WHITESPACE_RE.sub(r' ', asm)
213+
# Expand the tabs used for indentation.
214+
asm = string.expandtabs(asm, 2)
215+
# Strip trailing whitespace.
216+
asm = common.SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm)
217+
return asm
218+
203219
def get_triple_from_march(march):
204220
triples = {
205221
'amdgcn': 'amdgcn',
@@ -250,6 +266,7 @@ def build_function_body_dictionary_for_triple(args, raw_tool_output, triple, pre
250266
'sparc': (scrub_asm_sparc, ASM_FUNCTION_SPARC_RE),
251267
'sparcv9': (scrub_asm_sparc, ASM_FUNCTION_SPARC_RE),
252268
's390x': (scrub_asm_systemz, ASM_FUNCTION_SYSTEMZ_RE),
269+
'wasm32': (scrub_asm_wasm32, ASM_FUNCTION_WASM32_RE),
253270
}
254271
handlers = None
255272
for prefix, s in target_handlers.items():

0 commit comments

Comments
 (0)