mirror of
https://github.com/RPCS3/llvm.git
synced 2026-01-31 01:25:19 +01:00
This patch modifies the indirect call promotion utilities by exposing and using an unconditional call promotion interface. The unconditional promotion interface (i.e., call promotion without creating an if-then-else) can be used if it's known that an indirect call has only one possible callee. The existing conditional promotion interface uses this unconditional interface to promote an indirect call after it has been versioned and placed within the "then" block. A consequence of unconditional promotion is that the fix-up operations for phi nodes in the normal destination of invoke instructions are changed. This is necessary because the existing implementation assumed that an invoke had been versioned, creating a "merge" block where a return value bitcast could be placed. In the new implementation, the edge between a promoted invoke's parent block and its normal destination is split if needed to add a bitcast for the return value. If the invoke is also versioned, the phi node merging the return value of the promoted and original invoke instructions is placed in the "merge" block. Differential Revision: https://reviews.llvm.org/D40751 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321210 91177308-0d34-0410-b5e6-96231b3b80d8
55 lines
2.3 KiB
C++
55 lines
2.3 KiB
C++
//===- CallPromotionUtils.h - Utilities for call promotion ------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file declares utilities useful for promoting indirect call sites to
|
|
// direct call sites.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
|
|
#define LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
|
|
|
|
#include "llvm/IR/CallSite.h"
|
|
|
|
namespace llvm {
|
|
|
|
/// Return true if the given indirect call site can be made to call \p Callee.
|
|
///
|
|
/// This function ensures that the number and type of the call site's arguments
|
|
/// and return value match those of the given function. If the types do not
|
|
/// match exactly, they must at least be bitcast compatible. If \p FailureReason
|
|
/// is non-null and the indirect call cannot be promoted, the failure reason
|
|
/// will be stored in it.
|
|
bool isLegalToPromote(CallSite CS, Function *Callee,
|
|
const char **FailureReason = nullptr);
|
|
|
|
/// Promote the given indirect call site to unconditionally call \p Callee.
|
|
///
|
|
/// This function promotes the given call site, returning the direct call or
|
|
/// invoke instruction. If the function type of the call site doesn't match that
|
|
/// of the callee, bitcast instructions are inserted where appropriate. If \p
|
|
/// RetBitCast is non-null, it will be used to store the return value bitcast,
|
|
/// if created.
|
|
Instruction *promoteCall(CallSite CS, Function *Callee,
|
|
CastInst **RetBitCast = nullptr);
|
|
|
|
/// Promote the given indirect call site to conditionally call \p Callee.
|
|
///
|
|
/// This function creates an if-then-else structure at the location of the call
|
|
/// site. The original call site is moved into the "else" block. A clone of the
|
|
/// indirect call site is promoted, placed in the "then" block, and returned. If
|
|
/// \p BranchWeights is non-null, it will be used to set !prof metadata on the
|
|
/// new conditional branch.
|
|
Instruction *promoteCallWithIfThenElse(CallSite CS, Function *Callee,
|
|
MDNode *BranchWeights = nullptr);
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_TRANSFORMS_UTILS_CALLPROMOTIONUTILS_H
|