| 1 |
//===- SPIRVDebug.cpp - SPIR-V Debug Utility --------------------*- C++ -*-===// |
| 2 |
// |
| 3 |
// The LLVM/SPIRV Translator |
| 4 |
// |
| 5 |
// This file is distributed under the University of Illinois Open Source |
| 6 |
// License. See LICENSE.TXT for details. |
| 7 |
// |
| 8 |
// Copyright (c) 2014 Advanced Micro Devices, Inc. All rights reserved. |
| 9 |
// |
| 10 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 11 |
// copy of this software and associated documentation files (the "Software"), |
| 12 |
// to deal with the Software without restriction, including without limitation |
| 13 |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 14 |
// and/or sell copies of the Software, and to permit persons to whom the |
| 15 |
// Software is furnished to do so, subject to the following conditions: |
| 16 |
// |
| 17 |
// Redistributions of source code must retain the above copyright notice, |
| 18 |
// this list of conditions and the following disclaimers. |
| 19 |
// Redistributions in binary form must reproduce the above copyright notice, |
| 20 |
// this list of conditions and the following disclaimers in the documentation |
| 21 |
// and/or other materials provided with the distribution. |
| 22 |
// Neither the names of Advanced Micro Devices, Inc., nor the names of its |
| 23 |
// contributors may be used to endorse or promote products derived from this |
| 24 |
// Software without specific prior written permission. |
| 25 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 26 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 27 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 28 |
// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 29 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 30 |
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH |
| 31 |
// THE SOFTWARE. |
| 32 |
// |
| 33 |
//===----------------------------------------------------------------------===// |
| 34 |
/// \file |
| 35 |
/// |
| 36 |
/// This file defines variables for enabling/disabling SPIR-V debug macro. |
| 37 |
/// |
| 38 |
//===----------------------------------------------------------------------===// |
| 39 |
|
| 40 |
#include "SPIRVDebug.h" |
| 41 |
|
| 42 |
#include "llvm/IR/Verifier.h" |
| 43 |
#include "llvm/Support/CommandLine.h" |
| 44 |
#include "llvm/Support/raw_ostream.h" |
| 45 |
|
| 46 |
#define DEBUG_TYPE "spirv-regularization" |
| 47 |
|
| 48 |
using namespace SPIRV; |
| 49 |
|
| 50 |
bool SPIRV::SPIRVDbgEnable = false; |
| 51 |
SPIRV::SPIRVDbgErrorHandlingKinds SPIRV::SPIRVDbgError = |
| 52 |
SPIRVDbgErrorHandlingKinds::Exit; |
| 53 |
bool SPIRV::SPIRVDbgErrorMsgIncludesSourceInfo = true; |
| 54 |
|
| 55 |
namespace SPIRV { |
| 56 |
llvm::cl::opt<bool> VerifyRegularizationPasses( |
| 57 |
"spirv-verify-regularize-passes", llvm::cl::init(_SPIRVDBG), |
| 58 |
llvm::cl::desc( |
| 59 |
"Verify module after each pass in LLVM regularization phase")); |
| 60 |
|
| 61 |
void verifyRegularizationPass(llvm::Module &M, const std::string &PassName) { |
| 62 |
if (VerifyRegularizationPasses) { |
| 63 |
std::string Err; |
| 64 |
llvm::raw_string_ostream ErrorOS(Err); |
| 65 |
if (llvm::verifyModule(M, &ErrorOS)) { |
| 66 |
LLVM_DEBUG(llvm::errs() |
| 67 |
<< "Failed to verify module after pass: " << PassName << "\n" |
| 68 |
<< ErrorOS.str()); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
} // namespace SPIRV |