MLIR  20.0.0git
SPIRVOpUtils.h
Go to the documentation of this file.
1 //===- SPIRVOpUtils.h - MLIR SPIR-V Dialect Op Definition Utilities -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 namespace mlir::spirv {
12 
13 /// Returns the bit width of the `type`.
14 inline unsigned getBitWidth(Type type) {
15  if (isa<spirv::PointerType>(type)) {
16  // Just return 64 bits for pointer types for now.
17  // TODO: Make sure not caller relies on the actual pointer width value.
18  return 64;
19  }
20 
21  if (type.isIntOrFloat())
22  return type.getIntOrFloatBitWidth();
23 
24  if (auto vectorType = dyn_cast<VectorType>(type)) {
25  assert(vectorType.getElementType().isIntOrFloat());
26  return vectorType.getNumElements() *
27  vectorType.getElementType().getIntOrFloatBitWidth();
28  }
29  llvm_unreachable("unhandled bit width computation for type");
30 }
31 
33  SmallVectorImpl<StringRef> &elidedAttrs);
34 
35 LogicalResult extractValueFromConstOp(Operation *op, int32_t &value);
36 
37 LogicalResult verifyMemorySemantics(Operation *op,
38  spirv::MemorySemantics memorySemantics);
39 
40 } // namespace mlir::spirv
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
Definition: Types.cpp:127
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
Definition: Types.cpp:133
LogicalResult verifyMemorySemantics(Operation *op, spirv::MemorySemantics memorySemantics)
Definition: SPIRVOps.cpp:70
void printVariableDecorations(Operation *op, OpAsmPrinter &printer, SmallVectorImpl< StringRef > &elidedAttrs)
Definition: SPIRVOps.cpp:94
LogicalResult extractValueFromConstOp(Operation *op, int32_t &value)
Definition: SPIRVOps.cpp:50
unsigned getBitWidth(Type type)
Returns the bit width of the type.
Definition: SPIRVOpUtils.h:14