LLVM  9.0.0svn
AMDGPUFixFunctionBitcasts.cpp
Go to the documentation of this file.
1 //===-- AMDGPUFixFunctionBitcasts.cpp - Fix function bitcasts -------------===//
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 /// \file
10 /// Promote indirect (bitcast) calls to direct calls when they are statically
11 /// known to be direct. Required when InstCombine is not run (e.g. at OptNone)
12 /// because AMDGPU does not support indirect calls.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #include "AMDGPU.h"
17 #include "llvm/IR/InstVisitor.h"
19 
20 using namespace llvm;
21 
22 #define DEBUG_TYPE "amdgpu-fix-function-bitcasts"
23 
24 namespace {
25 class AMDGPUFixFunctionBitcasts final
26  : public ModulePass,
27  public InstVisitor<AMDGPUFixFunctionBitcasts> {
28 
29  bool runOnModule(Module &M) override;
30 
31  bool Modified;
32 
33 public:
34  void visitCallSite(CallSite CS) {
35  if (CS.getCalledFunction())
36  return;
38  if (Callee && isLegalToPromote(CS, Callee)) {
39  promoteCall(CS, Callee);
40  Modified = true;
41  }
42  }
43 
44  static char ID;
45  AMDGPUFixFunctionBitcasts() : ModulePass(ID) {}
46 };
47 } // End anonymous namespace
48 
51 INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE,
52  "Fix function bitcasts for AMDGPU", false, false)
53 
55  return new AMDGPUFixFunctionBitcasts();
56 }
57 
58 bool AMDGPUFixFunctionBitcasts::runOnModule(Module &M) {
59  Modified = false;
60  visit(M);
61  return Modified;
62 }
#define DEBUG_TYPE
Base class for instruction visitors.
Definition: InstVisitor.h:80
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
bool isLegalToPromote(CallSite CS, Function *Callee, const char **FailureReason=nullptr)
Return true if the given indirect call site can be made to call Callee.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it&#39;s an indirect...
Definition: CallSite.h:111
ValTy * getCalledValue() const
Return the pointer to function that is being called.
Definition: CallSite.h:104
Instruction * promoteCall(CallSite CS, Function *Callee, CastInst **RetBitCast=nullptr)
Promote the given indirect call site to unconditionally call Callee.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:529
ModulePass * createAMDGPUFixFunctionBitcastsPass()
amdgpu Simplify well known AMD library false FunctionCallee Callee
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:224
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE, "Fix function bitcasts for AMDGPU", false, false) ModulePass *llvm
char & AMDGPUFixFunctionBitcastsID