LLVM 19.0.0git
SPIRVStripConvergentIntrinsics.cpp
Go to the documentation of this file.
1//===-- SPIRVStripConvergentIntrinsics.cpp ----------------------*- C++ -*-===//
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// This pass trims convergence intrinsics as those were only useful when
10// modifying the CFG during IR passes.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SPIRV.h"
15#include "SPIRVSubtarget.h"
16#include "SPIRVTargetMachine.h"
17#include "SPIRVUtils.h"
19#include "llvm/IR/IRBuilder.h"
21#include "llvm/IR/Intrinsics.h"
22#include "llvm/IR/IntrinsicsSPIRV.h"
25
26using namespace llvm;
27
28namespace llvm {
30}
31
33public:
34 static char ID;
35
39 };
40
41 virtual bool runOnFunction(Function &F) override {
43
44 for (BasicBlock &BB : F) {
45 for (Instruction &I : BB) {
46 if (auto *II = dyn_cast<IntrinsicInst>(&I)) {
47 if (II->getIntrinsicID() !=
48 Intrinsic::experimental_convergence_entry &&
49 II->getIntrinsicID() !=
50 Intrinsic::experimental_convergence_loop &&
51 II->getIntrinsicID() !=
52 Intrinsic::experimental_convergence_anchor) {
53 continue;
54 }
55
56 II->replaceAllUsesWith(UndefValue::get(II->getType()));
57 ToRemove.insert(II);
58 } else if (auto *CI = dyn_cast<CallInst>(&I)) {
59 auto OB = CI->getOperandBundle(LLVMContext::OB_convergencectrl);
60 if (!OB.has_value())
61 continue;
62
63 auto *NewCall = CallBase::removeOperandBundle(
65 NewCall->copyMetadata(*CI);
66 CI->replaceAllUsesWith(NewCall);
67 ToRemove.insert(CI);
68 }
69 }
70 }
71
72 // All usages must be removed before their definition is removed.
73 for (Instruction *I : ToRemove)
74 I->eraseFromParent();
75
76 return ToRemove.size() != 0;
77 }
78};
79
81INITIALIZE_PASS(SPIRVStripConvergentIntrinsics, "strip-convergent-intrinsics",
82 "SPIRV strip convergent intrinsics", false, false)
83
86}
ReachingDefAnalysis InstSet & ToRemove
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:38
virtual bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
LLVM Basic Block Representation.
Definition: BasicBlock.h:60
static CallBase * removeOperandBundle(CallBase *CB, uint32_t ID, Instruction *InsertPt=nullptr)
Create a clone of CB with operand bundle ID removed.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:37
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Definition: Constants.cpp:1808
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FunctionPass * createSPIRVStripConvergenceIntrinsicsPass()
void initializeSPIRVStripConvergentIntrinsicsPass(PassRegistry &)