================
@@ -0,0 +1,144 @@
+//===-- TargetVerifier.cpp - LLVM IR Target Verifier ----------------*- C++ 
-*-===//
+////
+///// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+///// See https://llvm.org/LICENSE.txt for license information.
+///// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+/////
+/////===----------------------------------------------------------------------===//
+/////
+///// This file defines target verifier interfaces that can be used for some
+///// validation of input to the system, and for checking that transformations
+///// haven't done something bad. In contrast to the Verifier or Lint, the
+///// TargetVerifier looks for constructions invalid to a particular target
+///// machine.
+/////
+///// To see what specifically is checked, look at TargetVerifier.cpp or an
+///// individual backend's TargetVerifier.
+/////
+/////===----------------------------------------------------------------------===//
+
+#include "llvm/Target/TargetVerifier.h"
+#include "llvm/Target/TargetVerify/AMDGPUTargetVerifier.h"
+
+#include "llvm/InitializePasses.h"
+#include "llvm/Analysis/UniformityAnalysis.h"
+#include "llvm/Analysis/PostDominators.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/IR/Dominators.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/IntrinsicsAMDGPU.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Value.h"
+
+namespace llvm {
+
+bool TargetVerify::run(Function &F) {
+  if (TT.isAMDGPU()) {
+    AMDGPUTargetVerify TV(Mod);
+    TV.run(F);
+
+    dbgs() << TV.MessagesStr.str();
+    if (!TV.MessagesStr.str().empty()) {
+      TV.IsValid = false;
+      return false;
+    }
+    return true;
+  }
+  report_fatal_error("Target has no verification method\n");
+}
+
+bool TargetVerify::run(Function &F, FunctionAnalysisManager &AM) {
+  if (TT.isAMDGPU()) {
+    auto *UA = &AM.getResult<UniformityInfoAnalysis>(F);
+    auto *DT = &AM.getResult<DominatorTreeAnalysis>(F);
+    auto *PDT = &AM.getResult<PostDominatorTreeAnalysis>(F);
+
+    AMDGPUTargetVerify TV(Mod, DT, PDT, UA);
+    TV.run(F);
+
+    dbgs() << TV.MessagesStr.str();
+    if (!TV.MessagesStr.str().empty()) {
+      TV.IsValid = false;
+      return false;
+    }
+    return true;
+  }
+  report_fatal_error("Target has no verification method\n");
+}
+
+PreservedAnalyses TargetVerifierPass::run(Function &F, FunctionAnalysisManager 
&AM) {
+  auto TT = F.getParent()->getTargetTriple();
+
+  if (TT.isAMDGPU()) {
+    auto *Mod = F.getParent();
+
+    auto UA = &AM.getResult<UniformityInfoAnalysis>(F);
+    auto *DT = &AM.getResult<DominatorTreeAnalysis>(F);
+    auto *PDT = &AM.getResult<PostDominatorTreeAnalysis>(F);
+
+    AMDGPUTargetVerify TV(Mod, DT, PDT, UA);
----------------
emtwelve wrote:

That is correct. We aren't allowed to put state that changes in Module, so I 
resorted to checking PreservedAnalyses. It seems to work in this way, and 
adding the other classes to check doesn't change anything. All of them can be 
checked through this call somehow. I'm looking for another way to do this.

https://github.com/llvm/llvm-project/pull/123609
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to