1- // ===-- AMDGPUTargetVerifier.cpp - AMDGPU ------------------------- *- 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 file defines target verifier interfaces that can be used for some
10- // // validation of input to the system, and for checking that transformations
11- // // haven't done something bad. In contrast to the Verifier or Lint, the
12- // // TargetVerifier looks for constructions invalid to a particular target
13- // // machine.
14- // //
15- // // To see what specifically is checked, look at an individual backend's
16- // // TargetVerifier.
17- // //
18- // // ===----------------------------------------------------------------------===//
1+ // ===-- AMDGPUTargetVerifier.cpp - AMDGPU -----------------------*- 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 file defines target verifier interfaces that can be used for some
10+ // validation of input to the system, and for checking that transformations
11+ // haven't done something bad. In contrast to the Verifier or Lint, the
12+ // TargetVerifier looks for constructions invalid to a particular target
13+ // machine.
14+ //
15+ // To see what specifically is checked, look at an individual backend's
16+ // TargetVerifier.
17+ //
18+ // ===----------------------------------------------------------------------===//
1919
20- #include " AMDGPU.h"
2120#include " llvm/Target/TargetVerify/AMDGPUTargetVerifier.h"
21+ #include " AMDGPU.h"
2222
23- #include " llvm/Analysis/UniformityAnalysis.h"
2423#include " llvm/Analysis/PostDominators.h"
25- #include " llvm/Support/Debug .h"
24+ #include " llvm/Analysis/UniformityAnalysis .h"
2625#include " llvm/IR/Dominators.h"
2726#include " llvm/IR/Function.h"
2827#include " llvm/IR/IntrinsicInst.h"
2928#include " llvm/IR/IntrinsicsAMDGPU.h"
3029#include " llvm/IR/Module.h"
3130#include " llvm/IR/Value.h"
31+ #include " llvm/Support/Debug.h"
3232
3333#include " llvm/Support/raw_ostream.h"
3434
@@ -39,53 +39,52 @@ using namespace llvm;
3939 do { \
4040 if (!(C)) { \
4141 TargetVerify::CheckFailed (__VA_ARGS__); \
42- return false ; \
4342 } \
4443 } while (false )
4544
4645namespace llvm {
4746
4847static bool isShader (CallingConv::ID CC) {
49- switch (CC) {
50- case CallingConv::AMDGPU_VS:
51- case CallingConv::AMDGPU_LS:
52- case CallingConv::AMDGPU_HS:
53- case CallingConv::AMDGPU_ES:
54- case CallingConv::AMDGPU_GS:
55- case CallingConv::AMDGPU_PS:
56- case CallingConv::AMDGPU_CS_Chain:
57- case CallingConv::AMDGPU_CS_ChainPreserve:
58- case CallingConv::AMDGPU_CS:
59- return true ;
60- default :
61- return false ;
48+ switch (CC) {
49+ case CallingConv::AMDGPU_VS:
50+ case CallingConv::AMDGPU_LS:
51+ case CallingConv::AMDGPU_HS:
52+ case CallingConv::AMDGPU_ES:
53+ case CallingConv::AMDGPU_GS:
54+ case CallingConv::AMDGPU_PS:
55+ case CallingConv::AMDGPU_CS_Chain:
56+ case CallingConv::AMDGPU_CS_ChainPreserve:
57+ case CallingConv::AMDGPU_CS:
58+ return true ;
59+ default :
60+ return false ;
6261 }
6362}
6463
6564bool AMDGPUTargetVerify::run (Function &F) {
6665 // Ensure shader calling convention returns void
6766 if (isShader (F.getCallingConv ()))
68- Check (F.getReturnType () == Type::getVoidTy (F.getContext ()), " Shaders must return void" );
67+ Check (F.getReturnType () == Type::getVoidTy (F.getContext ()),
68+ " Shaders must return void" );
6969
7070 for (auto &BB : F) {
7171
7272 for (auto &I : BB) {
7373
74- if (auto *CI = dyn_cast<CallInst>(&I))
75- {
74+ if (auto *CI = dyn_cast<CallInst>(&I)) {
7675 // Ensure no kernel to kernel calls.
7776 CallingConv::ID CalleeCC = CI->getCallingConv ();
78- if (CalleeCC == CallingConv::AMDGPU_KERNEL)
79- {
80- CallingConv::ID CallerCC = CI->getParent ()->getParent ()->getCallingConv ();
77+ if (CalleeCC == CallingConv::AMDGPU_KERNEL) {
78+ CallingConv::ID CallerCC =
79+ CI->getParent ()->getParent ()->getCallingConv ();
8180 Check (CallerCC != CallingConv::AMDGPU_KERNEL,
82- " A kernel may not call a kernel" , CI->getParent ()->getParent ());
81+ " A kernel may not call a kernel" , CI->getParent ()->getParent ());
8382 }
8483
8584 // Ensure chain intrinsics are followed by unreachables.
8685 if (CI->getIntrinsicID () == Intrinsic::amdgcn_cs_chain)
8786 Check (isa_and_present<UnreachableInst>(CI->getNextNode ()),
88- " llvm.amdgcn.cs.chain must be followed by unreachable" , CI);
87+ " llvm.amdgcn.cs.chain must be followed by unreachable" , CI);
8988 }
9089 }
9190 }
@@ -98,7 +97,8 @@ bool AMDGPUTargetVerify::run(Function &F) {
9897 return true ;
9998}
10099
101- PreservedAnalyses AMDGPUTargetVerifierPass::run (Function &F, FunctionAnalysisManager &AM) {
100+ PreservedAnalyses AMDGPUTargetVerifierPass::run (Function &F,
101+ FunctionAnalysisManager &AM) {
102102 auto *Mod = F.getParent ();
103103
104104 auto UA = &AM.getResult <UniformityInfoAnalysis>(F);
@@ -122,9 +122,10 @@ struct AMDGPUTargetVerifierLegacyPass : public FunctionPass {
122122 std::unique_ptr<AMDGPUTargetVerify> TV;
123123 bool FatalErrors = false ;
124124
125- AMDGPUTargetVerifierLegacyPass (bool FatalErrors) : FunctionPass(ID),
126- FatalErrors (FatalErrors) {
127- initializeAMDGPUTargetVerifierLegacyPassPass (*PassRegistry::getPassRegistry ());
125+ AMDGPUTargetVerifierLegacyPass (bool FatalErrors)
126+ : FunctionPass(ID), FatalErrors(FatalErrors) {
127+ initializeAMDGPUTargetVerifierLegacyPassPass (
128+ *PassRegistry::getPassRegistry ());
128129 }
129130
130131 bool doInitialization (Module &M) override {
@@ -167,4 +168,5 @@ FunctionPass *createAMDGPUTargetVerifierLegacyPass(bool FatalErrors) {
167168 return new AMDGPUTargetVerifierLegacyPass (FatalErrors);
168169}
169170} // namespace llvm
170- INITIALIZE_PASS (AMDGPUTargetVerifierLegacyPass, " amdgpu-tgtverifier" , " AMDGPU Target Verifier" , false , false )
171+ INITIALIZE_PASS (AMDGPUTargetVerifierLegacyPass, " amdgpu-tgtverifier" ,
172+ " AMDGPU Target Verifier" , false , false )
0 commit comments