LLVM  8.0.1
AMDGPUFixFunctionBitcasts.cpp
Go to the documentation of this file.
1 //===-- AMDGPUFixFunctionBitcasts.cpp - Fix function bitcasts -------------===//
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 /// \file
11 /// Promote indirect (bitcast) calls to direct calls when they are statically
12 /// known to be direct. Required when InstCombine is not run (e.g. at OptNone)
13 /// because AMDGPU does not support indirect calls.
14 ///
15 //===----------------------------------------------------------------------===//
16 
17 #include "AMDGPU.h"
18 #include "llvm/IR/InstVisitor.h"
20 
21 using namespace llvm;
22 
23 #define DEBUG_TYPE "amdgpu-fix-function-bitcasts"
24 
25 namespace {
26 class AMDGPUFixFunctionBitcasts final
27  : public ModulePass,
28  public InstVisitor<AMDGPUFixFunctionBitcasts> {
29 
30  bool runOnModule(Module &M) override;
31 
32  bool Modified;
33 
34 public:
35  void visitCallSite(CallSite CS) {
36  if (CS.getCalledFunction())
37  return;
39  if (Callee && isLegalToPromote(CS, Callee)) {
40  promoteCall(CS, Callee);
41  Modified = true;
42  }
43  }
44 
45  static char ID;
46  AMDGPUFixFunctionBitcasts() : ModulePass(ID) {}
47 };
48 } // End anonymous namespace
49 
52 INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE,
53  "Fix function bitcasts for AMDGPU", false, false)
54 
56  return new AMDGPUFixFunctionBitcasts();
57 }
58 
59 bool AMDGPUFixFunctionBitcasts::runOnModule(Module &M) {
60  Modified = false;
61  visit(M);
62  return Modified;
63 }
#define DEBUG_TYPE
Base class for instruction visitors.
Definition: InstVisitor.h:81
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
Definition: CallSite.h:100
amdgpu Simplify well known AMD library false Value * Callee
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()
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:225
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:323
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:107
INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE, "Fix function bitcasts for AMDGPU", false, false) ModulePass *llvm
char & AMDGPUFixFunctionBitcastsID