1 //===-- AMDGPUFixFunctionBitcasts.cpp - Fix function bitcasts -------------===//
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
7 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
17 #include "llvm/IR/InstVisitor.h"
18 #include "llvm/Transforms/Utils/CallPromotionUtils.h"
22 #define DEBUG_TYPE "amdgpu-fix-function-bitcasts"
25 class AMDGPUFixFunctionBitcasts final
27 public InstVisitor<AMDGPUFixFunctionBitcasts> {
29 bool runOnModule(Module &M) override;
34 void visitCallSite(CallSite CS) {
35 if (CS.getCalledFunction())
37 auto Callee = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
38 if (Callee && isLegalToPromote(CS, Callee)) {
39 promoteCall(CS, Callee);
45 AMDGPUFixFunctionBitcasts() : ModulePass(ID) {}
47 } // End anonymous namespace
49 char AMDGPUFixFunctionBitcasts::ID = 0;
50 char &llvm::AMDGPUFixFunctionBitcastsID = AMDGPUFixFunctionBitcasts::ID;
51 INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE,
52 "Fix function bitcasts for AMDGPU", false, false)
54 ModulePass *llvm::createAMDGPUFixFunctionBitcastsPass() {
55 return new AMDGPUFixFunctionBitcasts();
58 bool AMDGPUFixFunctionBitcasts::runOnModule(Module &M) {