[PATCH] D52894: Update CallSite docs and add a new function (NFC)

Scott Linder via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 8 13:01:24 PDT 2018


scott.linder updated this revision to Diff 168703.
scott.linder added a comment.

Remove update of dyn_cast in WebAssemblyFixFunctionBitcasts which does not use CallSite


https://reviews.llvm.org/D52894

Files:
  include/llvm/IR/CallSite.h
  lib/CodeGen/WinEHPrepare.cpp
  lib/IR/Verifier.cpp
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  lib/Transforms/Utils/InlineFunction.cpp


Index: lib/Transforms/Utils/InlineFunction.cpp
===================================================================
--- lib/Transforms/Utils/InlineFunction.cpp
+++ lib/Transforms/Utils/InlineFunction.cpp
@@ -2017,8 +2017,7 @@
           continue;
 
         // Skip call sites which are nounwind intrinsics.
-        auto *CalledFn =
-            dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
+        Function *CalledFn = CS.getCalledFunctionStripCasts();
         if (CalledFn && CalledFn->isIntrinsic() && CS.doesNotThrow())
           continue;
 
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -4184,7 +4184,7 @@
 /// If the callee is a constexpr cast of a function, attempt to move the cast to
 /// the arguments of the call/invoke.
 bool InstCombiner::transformConstExprCastCall(CallSite CS) {
-  auto *Callee = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
+  Function *Callee = CS.getCalledFunctionStripCasts();
   if (!Callee)
     return false;
 
Index: lib/IR/Verifier.cpp
===================================================================
--- lib/IR/Verifier.cpp
+++ lib/IR/Verifier.cpp
@@ -2743,8 +2743,7 @@
   if (Attrs.hasAttribute(AttributeList::FunctionIndex, Attribute::Speculatable)) {
     // Don't allow speculatable on call sites, unless the underlying function
     // declaration is also speculatable.
-    Function *Callee
-      = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
+    Function *Callee = CS.getCalledFunctionStripCasts();
     Assert(Callee && Callee->isSpeculatable(),
            "speculatable attribute may not apply to call sites", I);
   }
Index: lib/CodeGen/WinEHPrepare.cpp
===================================================================
--- lib/CodeGen/WinEHPrepare.cpp
+++ lib/CodeGen/WinEHPrepare.cpp
@@ -953,8 +953,7 @@
           continue;
 
         // Skip call sites which are nounwind intrinsics or inline asm.
-        auto *CalledFn =
-            dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
+        Function *CalledFn = CS.getCalledFunctionStripCasts();
         if (CalledFn && ((CalledFn->isIntrinsic() && CS.doesNotThrow()) ||
                          CS.isInlineAsm()))
           continue;
Index: include/llvm/IR/CallSite.h
===================================================================
--- include/llvm/IR/CallSite.h
+++ include/llvm/IR/CallSite.h
@@ -96,19 +96,34 @@
   /// Get the basic block containing the call site.
   BBTy* getParent() const { return getInstruction()->getParent(); }
 
-  /// Return the pointer to function that is being called.
+  /// Return the pointer to the function that is being called.
   ValTy *getCalledValue() const {
     assert(getInstruction() && "Not a call or invoke instruction!");
     return *getCallee();
   }
 
   /// Return the function being called if this is a direct call, otherwise
   /// return null (if it's an indirect call).
+  ///
+  /// See isIndirectCall() for the definition of an indirect call.
   FunTy *getCalledFunction() const {
     return dyn_cast<FunTy>(getCalledValue());
   }
 
+  /// Return the function being called if this is either a direct call or an
+  /// indirect call to a cast of a function, otherwise return null.
+  ///
+  /// See isIndirectCall() for the definition of an indirect call.
+  FunTy *getCalledFunctionStripCasts() const {
+    return dyn_cast<FunTy>(getCalledValue()->stripPointerCasts());
+  }
+
   /// Return true if the callsite is an indirect call.
+  ///
+  /// An indirect call is any call to a Value that is not a Function or
+  /// Constant, even those which are trivially, statically known to call the
+  /// same function. For example, a call to a bitcast of a function is
+  /// considered indirect.
   bool isIndirectCall() const {
     const Value *V = getCalledValue();
     if (!V)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52894.168703.patch
Type: text/x-patch
Size: 4013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181008/ed7262c2/attachment.bin>


More information about the llvm-commits mailing list