LLVM  14.0.0git
AMDGPUFixFunctionBitcasts.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
15 
16 #include "AMDGPU.h"
17 #include "llvm/IR/InstVisitor.h"
18 #include "llvm/Pass.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 visitCallBase(CallBase &CB) {
36  if (CB.getCalledFunction())
37  return;
38  auto *Callee =
39  dyn_cast<Function>(CB.getCalledOperand()->stripPointerCasts());
40  if (Callee && isLegalToPromote(CB, Callee)) {
41  promoteCall(CB, Callee);
42  Modified = true;
43  }
44  }
45 
46  static char ID;
47  AMDGPUFixFunctionBitcasts() : ModulePass(ID) {}
48 };
49 } // End anonymous namespace
50 
53 INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE,
54  "Fix function bitcasts for AMDGPU", false, false)
55 
57  return new AMDGPUFixFunctionBitcasts();
58 }
59 
60 bool AMDGPUFixFunctionBitcasts::runOnModule(Module &M) {
61  Modified = false;
62  visit(M);
63  return Modified;
64 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::ModulePass
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:238
Pass.h
llvm::AMDGPUFixFunctionBitcastsID
char & AMDGPUFixFunctionBitcastsID
Definition: AMDGPUFixFunctionBitcasts.cpp:52
llvm::CallBase::getCalledFunction
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1383
LoopDeletionResult::Modified
@ Modified
llvm::isLegalToPromote
bool isLegalToPromote(const CallBase &CB, Function *Callee, const char **FailureReason=nullptr)
Return true if the given indirect call site can be made to call Callee.
Definition: CallPromotionUtils.cpp:382
DEBUG_TYPE
#define DEBUG_TYPE
Definition: AMDGPUFixFunctionBitcasts.cpp:23
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
AMDGPU.h
InstVisitor.h
CallPromotionUtils.h
llvm::InstVisitor
Base class for instruction visitors.
Definition: InstVisitor.h:79
llvm::Value::stripPointerCasts
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:687
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:206
llvm::CallBase::getCalledOperand
Value * getCalledOperand() const
Definition: InstrTypes.h:1376
llvm::createAMDGPUFixFunctionBitcastsPass
ModulePass * createAMDGPUFixFunctionBitcastsPass()
INITIALIZE_PASS
INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE, "Fix function bitcasts for AMDGPU", false, false) ModulePass *llvm
Definition: AMDGPUFixFunctionBitcasts.cpp:53
llvm::promoteCall
CallBase & promoteCall(CallBase &CB, Function *Callee, CastInst **RetBitCast=nullptr)
Promote the given indirect call site to unconditionally call Callee.
Definition: CallPromotionUtils.cpp:456
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1161
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37