1 //===- CallPromotionUtils.h - Utilities for call promotion ------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file declares utilities useful for promoting indirect call sites to
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
15 #define LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
17 #include "llvm/IR/CallSite.h"
21 /// Return true if the given indirect call site can be made to call \p Callee.
23 /// This function ensures that the number and type of the call site's arguments
24 /// and return value match those of the given function. If the types do not
25 /// match exactly, they must at least be bitcast compatible. If \p FailureReason
26 /// is non-null and the indirect call cannot be promoted, the failure reason
27 /// will be stored in it.
28 bool isLegalToPromote(CallSite CS
, Function
*Callee
,
29 const char **FailureReason
= nullptr);
31 /// Promote the given indirect call site to unconditionally call \p Callee.
33 /// This function promotes the given call site, returning the direct call or
34 /// invoke instruction. If the function type of the call site doesn't match that
35 /// of the callee, bitcast instructions are inserted where appropriate. If \p
36 /// RetBitCast is non-null, it will be used to store the return value bitcast,
38 Instruction
*promoteCall(CallSite CS
, Function
*Callee
,
39 CastInst
**RetBitCast
= nullptr);
41 /// Promote the given indirect call site to conditionally call \p Callee.
43 /// This function creates an if-then-else structure at the location of the call
44 /// site. The original call site is moved into the "else" block. A clone of the
45 /// indirect call site is promoted, placed in the "then" block, and returned. If
46 /// \p BranchWeights is non-null, it will be used to set !prof metadata on the
47 /// new conditional branch.
48 Instruction
*promoteCallWithIfThenElse(CallSite CS
, Function
*Callee
,
49 MDNode
*BranchWeights
= nullptr);
51 } // end namespace llvm
53 #endif // LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H