1 //===- ConvergenceVerifier.cpp - Verify convergence control -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/ConvergenceVerifier.h"
10 #include "llvm/IR/Dominators.h"
11 #include "llvm/IR/GenericConvergenceVerifierImpl.h"
12 #include "llvm/IR/Instructions.h"
13 #include "llvm/IR/SSAContext.h"
18 auto GenericConvergenceVerifier
<SSAContext
>::getConvOp(const Instruction
&I
)
20 const auto *CB
= dyn_cast
<CallBase
>(&I
);
23 switch (CB
->getIntrinsicID()) {
26 case Intrinsic::experimental_convergence_anchor
:
28 case Intrinsic::experimental_convergence_entry
:
30 case Intrinsic::experimental_convergence_loop
:
36 void GenericConvergenceVerifier
<SSAContext
>::checkConvergenceTokenProduced(
37 const Instruction
&I
) {
43 GenericConvergenceVerifier
<SSAContext
>::findAndCheckConvergenceTokenUsed(
44 const Instruction
&I
) {
45 auto *CB
= dyn_cast
<CallBase
>(&I
);
50 CB
->countOperandBundlesOfType(LLVMContext::OB_convergencectrl
);
51 CheckOrNull(Count
<= 1,
52 "The 'convergencectrl' bundle can occur at most once on a call",
57 auto Bundle
= CB
->getOperandBundle(LLVMContext::OB_convergencectrl
);
58 CheckOrNull(Bundle
->Inputs
.size() == 1 &&
59 Bundle
->Inputs
[0]->getType()->isTokenTy(),
60 "The 'convergencectrl' bundle requires exactly one token use.",
62 auto *Token
= Bundle
->Inputs
[0].get();
63 auto *Def
= dyn_cast
<Instruction
>(Token
);
65 CheckOrNull(Def
&& getConvOp(*Def
) != CONV_NONE
,
66 "Convergence control tokens can only be produced by calls to the "
67 "convergence control intrinsics.",
68 {Context
.print(Token
), Context
.print(&I
)});
77 bool GenericConvergenceVerifier
<SSAContext
>::isInsideConvergentFunction(
78 const Instruction
&I
) {
79 auto *F
= I
.getFunction();
80 return F
->isConvergent();
84 bool GenericConvergenceVerifier
<SSAContext
>::isConvergent(
85 const Instruction
&I
) {
86 if (auto *CB
= dyn_cast
<CallBase
>(&I
)) {
87 return CB
->isConvergent();
92 template class llvm::GenericConvergenceVerifier
<SSAContext
>;