[Codegen] Alter the default promotion for saturating adds and subs
[llvm-complete.git] / lib / Target / AMDGPU / AMDGPUFixFunctionBitcasts.cpp
blob9ba04d113c7021d03e895dd2e0ea66937774fec9
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 //===----------------------------------------------------------------------===//
16 #include "AMDGPU.h"
17 #include "llvm/IR/InstVisitor.h"
18 #include "llvm/Transforms/Utils/CallPromotionUtils.h"
20 using namespace llvm;
22 #define DEBUG_TYPE "amdgpu-fix-function-bitcasts"
24 namespace {
25 class AMDGPUFixFunctionBitcasts final
26 : public ModulePass,
27 public InstVisitor<AMDGPUFixFunctionBitcasts> {
29 bool runOnModule(Module &M) override;
31 bool Modified;
33 public:
34 void visitCallSite(CallSite CS) {
35 if (CS.getCalledFunction())
36 return;
37 auto Callee = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
38 if (Callee && isLegalToPromote(CS, Callee)) {
39 promoteCall(CS, Callee);
40 Modified = true;
44 static char ID;
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) {
59 Modified = false;
60 visit(M);
61 return Modified;