1 //===-- AMDGPUFixFunctionBitcasts.cpp - Fix function bitcasts -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
18 #include "llvm/IR/InstVisitor.h"
19 #include "llvm/Transforms/Utils/CallPromotionUtils.h"
23 #define DEBUG_TYPE "amdgpu-fix-function-bitcasts"
26 class AMDGPUFixFunctionBitcasts final
28 public InstVisitor<AMDGPUFixFunctionBitcasts> {
30 bool runOnModule(Module &M) override;
35 void visitCallSite(CallSite CS) {
36 if (CS.getCalledFunction())
38 auto Callee = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
39 if (Callee && isLegalToPromote(CS, Callee)) {
40 promoteCall(CS, Callee);
46 AMDGPUFixFunctionBitcasts() : ModulePass(ID) {}
48 } // End anonymous namespace
50 char AMDGPUFixFunctionBitcasts::ID = 0;
51 char &llvm::AMDGPUFixFunctionBitcastsID = AMDGPUFixFunctionBitcasts::ID;
52 INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE,
53 "Fix function bitcasts for AMDGPU", false, false)
55 ModulePass *llvm::createAMDGPUFixFunctionBitcastsPass() {
56 return new AMDGPUFixFunctionBitcasts();
59 bool AMDGPUFixFunctionBitcasts::runOnModule(Module &M) {