summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/AMDGPU/AMDGPUFixFunctionBitcasts.cpp
diff options
context:
space:
mode:
authorScott Linder <scott@scottlinder.com>2018-10-26 13:18:36 +0000
committerScott Linder <scott@scottlinder.com>2018-10-26 13:18:36 +0000
commit11ef7984b07b19b5e6cdc7c50daa6674b844bb27 (patch)
treecfa97662cbad9232b8e6162ed6c7797be83c3c54 /llvm/lib/Target/AMDGPU/AMDGPUFixFunctionBitcasts.cpp
parent08701ec753a64cd039957861c491cc72b06a0965 (diff)
downloadbcm5719-llvm-11ef7984b07b19b5e6cdc7c50daa6674b844bb27.tar.gz
bcm5719-llvm-11ef7984b07b19b5e6cdc7c50daa6674b844bb27.zip
[AMDGPU] Add a pass to promote bitcast calls
AMDGPU currently only supports direct calls, but at lower optimisation levels it fails to lower statically direct calls which appear indirect due to a bitcast. Add a pass to visit all CallSites and use CallPromotionUtils to "devirtualize" calls. Differential Revision: https://reviews.llvm.org/D52741 llvm-svn: 345382
Diffstat (limited to 'llvm/lib/Target/AMDGPU/AMDGPUFixFunctionBitcasts.cpp')
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPUFixFunctionBitcasts.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUFixFunctionBitcasts.cpp b/llvm/lib/Target/AMDGPU/AMDGPUFixFunctionBitcasts.cpp
new file mode 100644
index 00000000000..6e2a981d339
--- /dev/null
+++ b/llvm/lib/Target/AMDGPU/AMDGPUFixFunctionBitcasts.cpp
@@ -0,0 +1,63 @@
+//===-- AMDGPUFixFunctionBitcasts.cpp - Fix function bitcasts -------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Promote indirect (bitcast) calls to direct calls when they are statically
+/// known to be direct. Required when InstCombine is not run (e.g. at OptNone)
+/// because AMDGPU does not support indirect calls.
+///
+//===----------------------------------------------------------------------===//
+
+#include "AMDGPU.h"
+#include "llvm/IR/InstVisitor.h"
+#include "llvm/Transforms/Utils/CallPromotionUtils.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "amdgpu-fix-function-bitcasts"
+
+namespace {
+class AMDGPUFixFunctionBitcasts final
+ : public ModulePass,
+ public InstVisitor<AMDGPUFixFunctionBitcasts> {
+
+ bool runOnModule(Module &M) override;
+
+ bool Modified;
+
+public:
+ void visitCallSite(CallSite CS) {
+ if (CS.getCalledFunction())
+ return;
+ auto Callee = dyn_cast<Function>(CS.getCalledValue()->stripPointerCasts());
+ if (Callee && isLegalToPromote(CS, Callee)) {
+ promoteCall(CS, Callee);
+ Modified = true;
+ }
+ }
+
+ static char ID;
+ AMDGPUFixFunctionBitcasts() : ModulePass(ID) {}
+};
+} // End anonymous namespace
+
+char AMDGPUFixFunctionBitcasts::ID = 0;
+char &llvm::AMDGPUFixFunctionBitcastsID = AMDGPUFixFunctionBitcasts::ID;
+INITIALIZE_PASS(AMDGPUFixFunctionBitcasts, DEBUG_TYPE,
+ "Fix function bitcasts for AMDGPU", false, false)
+
+ModulePass *llvm::createAMDGPUFixFunctionBitcastsPass() {
+ return new AMDGPUFixFunctionBitcasts();
+}
+
+bool AMDGPUFixFunctionBitcasts::runOnModule(Module &M) {
+ Modified = false;
+ visit(M);
+ return Modified;
+}
OpenPOWER on IntegriCloud