[PATCH] D85494: [WebAssembly] Allow inlining functions with different features

Thomas Lively via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 20:24:04 PDT 2020


tlively created this revision.
tlively added reviewers: aheejin, alexcrichton.
Herald added subscribers: llvm-commits, sunfish, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: LLVM.
tlively requested review of this revision.

Because WebAssembly modules have to validate, having different feature
sets in different functions is not useful. As such, there is no reason
to prevent any function from being inlined into any other function due
to their enabled target features. This patch relaxes the inlining
restrictions for WebAssembly accordingly.

Frontends need to be careful, however, to set up their TargetMachines
with all the necessary features so that a feature will not be
"forgotten" because all the functions that used it were inlined and
removed from the module.

Requested in PR46812.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85494

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.h
  llvm/test/Transforms/Inline/WebAssembly/inline-target-features.ll


Index: llvm/test/Transforms/Inline/WebAssembly/inline-target-features.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/WebAssembly/inline-target-features.ll
@@ -0,0 +1,27 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -mtriple=wasm32-unknown-unknown -S -inline | FileCheck %s
+
+; Check that having different target attributes or cpus does not
+; inhibit inlining.
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+define void @bar() #0 {
+; CHECK-LABEL: @bar(
+; CHECK-NEXT:    tail call void @foo()
+; CHECK-NEXT:    ret void
+;
+  tail call fastcc void @inline_me()
+  ret void
+}
+
+define internal void @inline_me() #1 {
+  tail call void @foo()
+  ret void
+}
+
+declare void @foo()
+
+attributes #0 = { "target-cpu"="mvp" "target-features"="+simd128" }
+attributes #1 = { "target-cpu"="bleeding-edge" "target-features"="+multivalue" }
Index: llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.h
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.h
+++ llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.h
@@ -67,6 +67,18 @@
   unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index);
 
   /// @}
+
+  bool areInlineCompatible(const Function *Caller,
+                           const Function *Callee) const {
+    // Since WebAssembly supports target features at the module level rather
+    // than the function level, the backend will take the union of all features
+    // and apply it to each function. That means that any function can be
+    // inlined into any other function regardless of the features
+    // used. Frontends should set features on the target machine properly to
+    // prevent features from being "forgotten" because all the functions that
+    // use them were inlined and removed from the module.
+    return true;
+  }
 };
 
 } // end namespace llvm


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85494.283800.patch
Type: text/x-patch
Size: 2069 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200807/12b50cfe/attachment.bin>


More information about the llvm-commits mailing list