LLVM  9.0.0svn
CallPromotionUtils.h
Go to the documentation of this file.
1 //===- CallPromotionUtils.h - Utilities for call promotion ------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares utilities useful for promoting indirect call sites to
10 // direct call sites.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
15 #define LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
16 
17 #include "llvm/IR/CallSite.h"
18 
19 namespace llvm {
20 
21 /// Return true if the given indirect call site can be made to call \p Callee.
22 ///
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);
30 
31 /// Promote the given indirect call site to unconditionally call \p Callee.
32 ///
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,
37 /// if created.
38 Instruction *promoteCall(CallSite CS, Function *Callee,
39  CastInst **RetBitCast = nullptr);
40 
41 /// Promote the given indirect call site to conditionally call \p Callee.
42 ///
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);
50 
51 } // end namespace llvm
52 
53 #endif // LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
bool isLegalToPromote(CallSite CS, Function *Callee, const char **FailureReason=nullptr)
Return true if the given indirect call site can be made to call Callee.
Instruction * promoteCall(CallSite CS, Function *Callee, CastInst **RetBitCast=nullptr)
Promote the given indirect call site to unconditionally call Callee.
Instruction * promoteCallWithIfThenElse(CallSite CS, Function *Callee, MDNode *BranchWeights=nullptr)
Promote the given indirect call site to conditionally call Callee.