| 1 |
//===- SPIRVLLVMUtil.h - SPIR-V LLVM-specific Utility Functions -*- C++ -*-===// |
| 2 |
// |
| 3 |
// Has inclusions from the LLVM Project, under the Apache License v2.0 with LLVM |
| 4 |
// Exceptions. See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
/// \file |
| 9 |
/// |
| 10 |
/// This file defines utility functions dedicated to processing LLVM classes |
| 11 |
/// |
| 12 |
//===----------------------------------------------------------------------===// |
| 13 |
|
| 14 |
#ifndef SPIRV_LIBSPIRV_SPIRVLLVMUTIL_H |
| 15 |
#define SPIRV_LIBSPIRV_SPIRVLLVMUTIL_H |
| 16 |
|
| 17 |
#include "llvm/IR/Constants.h" |
| 18 |
#include "llvm/Support/Casting.h" |
| 19 |
|
| 20 |
namespace SPIRV { |
| 21 |
inline bool isManifestConstant(const llvm::Constant *C) { |
| 22 |
if (llvm::isa<llvm::ConstantData>(C)) { |
| 23 |
return true; |
| 24 |
} else if (llvm::isa<llvm::ConstantAggregate>(C) || |
| 25 |
llvm::isa<llvm::ConstantExpr>(C)) { |
| 26 |
for (const llvm::Value *Subc : C->operand_values()) { |
| 27 |
if (!isManifestConstant(llvm::cast<llvm::Constant>(Subc))) |
| 28 |
return false; |
| 29 |
} |
| 30 |
return true; |
| 31 |
} |
| 32 |
return false; |
| 33 |
} |
| 34 |
} // namespace SPIRV |
| 35 |
|
| 36 |
#endif // SPIRV_LIBSPIRV_SPIRVLLVMUTIL_H |