1 //===- CallPromotionUtils.h - Utilities for call promotion ------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file declares utilities useful for promoting indirect call sites to 11 // direct call sites. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H 16 #define LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H 17 18 #include "llvm/IR/CallSite.h" 19 20 namespace llvm { 21 22 /// Return true if the given indirect call site can be made to call \p Callee. 23 /// 24 /// This function ensures that the number and type of the call site's arguments 25 /// and return value match those of the given function. If the types do not 26 /// match exactly, they must at least be bitcast compatible. If \p FailureReason 27 /// is non-null and the indirect call cannot be promoted, the failure reason 28 /// will be stored in it. 29 bool isLegalToPromote(CallSite CS, Function *Callee, 30 const char **FailureReason = nullptr); 31 32 /// Promote the given indirect call site to unconditionally call \p Callee. 33 /// 34 /// This function promotes the given call site, returning the direct call or 35 /// invoke instruction. If the function type of the call site doesn't match that 36 /// of the callee, bitcast instructions are inserted where appropriate. If \p 37 /// RetBitCast is non-null, it will be used to store the return value bitcast, 38 /// if created. 39 Instruction *promoteCall(CallSite CS, Function *Callee, 40 CastInst **RetBitCast = nullptr); 41 42 /// Promote the given indirect call site to conditionally call \p Callee. 43 /// 44 /// This function creates an if-then-else structure at the location of the call 45 /// site. The original call site is moved into the "else" block. A clone of the 46 /// indirect call site is promoted, placed in the "then" block, and returned. If 47 /// \p BranchWeights is non-null, it will be used to set !prof metadata on the 48 /// new conditional branch. 49 Instruction *promoteCallWithIfThenElse(CallSite CS, Function *Callee, 50 MDNode *BranchWeights = nullptr); 51 52 } // end namespace llvm 53 54 #endif // LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H 55