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/Pass.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 visitCallBase(CallBase &CB) {
36 if (CB.getCalledFunction())
39 dyn_cast<Function>(CB.getCalledOperand()->stripPointerCasts());
40 if (Callee && isLegalToPromote(CB, Callee)) {
41 promoteCall(CB, Callee);
47 AMDGPUFixFunctionBitcasts() : ModulePass(ID) {}
49 } // End anonymous namespace
51 char AMDGPUFixFunctionBitcasts::ID = 0;
52 char &llvm::AMDGPUFixFunctionBitcastsID = AMDGPUFixFunctionBitcasts::ID;
53 INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE,
54 "Fix function bitcasts for AMDGPU", false, false)
56 ModulePass *llvm::createAMDGPUFixFunctionBitcastsPass() {
57 return new AMDGPUFixFunctionBitcasts();
60 bool AMDGPUFixFunctionBitcasts::runOnModule(Module &M) {