]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/AMDGPUFixFunctionBitcasts.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / AMDGPUFixFunctionBitcasts.cpp
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"
19 #include "llvm/Transforms/Utils/CallPromotionUtils.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;
38     auto Callee = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
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
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)
54
55 ModulePass *llvm::createAMDGPUFixFunctionBitcastsPass() {
56   return new AMDGPUFixFunctionBitcasts();
57 }
58
59 bool AMDGPUFixFunctionBitcasts::runOnModule(Module &M) {
60   Modified = false;
61   visit(M);
62   return Modified;
63 }