-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TargetVerifier][AMDGPU] Add TargetVerifier.
This pass verifies the IR for an individual backend. This is different than Lint because it consolidates all checks for a given backend in a single pass. A check for Lint may be undefined behavior across all targets, whereas a check in TargetVerifier would only pertain to the specified target but can check more than just undefined behavior such are IR validity. A use case of this would be to reject programs with invalid IR while fuzzing.
- Loading branch information
Showing
10 changed files
with
631 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//===-- llvm/Target/TargetVerifier.h - 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_TARGET_VERIFIER_H | ||
#define LLVM_TARGET_VERIFIER_H | ||
|
||
#include "llvm/IR/PassManager.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/TargetParser/Triple.h" | ||
|
||
namespace llvm { | ||
|
||
class Function; | ||
|
||
class TargetVerifierPass : public PassInfoMixin<TargetVerifierPass> { | ||
public: | ||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {} | ||
}; | ||
|
||
class TargetVerify { | ||
protected: | ||
void WriteValues(ArrayRef<const Value *> Vs) { | ||
for (const Value *V : Vs) { | ||
if (!V) | ||
continue; | ||
if (isa<Instruction>(V)) { | ||
MessagesStr << *V << '\n'; | ||
} else { | ||
V->printAsOperand(MessagesStr, true, Mod); | ||
MessagesStr << '\n'; | ||
} | ||
} | ||
} | ||
|
||
/// A check failed, so printout out the condition and the message. | ||
/// | ||
/// This provides a nice place to put a breakpoint if you want to see why | ||
/// something is not correct. | ||
void CheckFailed(const Twine &Message) { MessagesStr << Message << '\n'; } | ||
|
||
/// A check failed (with values to print). | ||
/// | ||
/// This calls the Message-only version so that the above is easier to set | ||
/// a breakpoint on. | ||
template <typename T1, typename... Ts> | ||
void CheckFailed(const Twine &Message, const T1 &V1, const Ts &... Vs) { | ||
CheckFailed(Message); | ||
WriteValues({V1, Vs...}); | ||
} | ||
public: | ||
Module *Mod; | ||
Triple TT; | ||
|
||
std::string Messages; | ||
raw_string_ostream MessagesStr; | ||
|
||
TargetVerify(Module *Mod) | ||
: Mod(Mod), TT(Triple::normalize(Mod->getTargetTriple())), | ||
MessagesStr(Messages) {} | ||
|
||
void run(Function &F) {}; | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_TARGET_VERIFIER_H |
36 changes: 36 additions & 0 deletions
36
llvm/include/llvm/Target/TargetVerify/AMDGPUTargetVerifier.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//===-- llvm/Target/TargetVerify/AMDGPUTargetVerifier.h - AMDGPU ---*- 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 an individual backend's | ||
//// TargetVerifier. | ||
//// | ||
////===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_AMDGPU_TARGET_VERIFIER_H | ||
#define LLVM_AMDGPU_TARGET_VERIFIER_H | ||
|
||
#include "llvm/Target/TargetVerifier.h" | ||
|
||
namespace llvm { | ||
|
||
class Function; | ||
|
||
class AMDGPUTargetVerifierPass : public TargetVerifierPass { | ||
public: | ||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); | ||
}; | ||
|
||
} // namespace llvm | ||
|
||
#endif // LLVM_AMDGPU_TARGET_VERIFIER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.