================
@@ -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);
----------------
jofrn wrote:

We need the implementation of `run` defined in the base class even if the base 
is virtual because we want to instantiate a `TargetVerify` llc's legacy PM, 
which should be able to use `createTargetVerifierLegacyPass`.

https://github.com/llvm/llvm-project/blob/c7bf730193e39bf838a29de7617d31a900bbc576/llvm/lib/Target/TargetVerifier.cpp#L104-L107

In other words, I believe we still need to check the Triple.

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