[llvm] [SandboxIR] Implement SandboxIR Type (PR #106294)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 15:47:05 PDT 2024
================
@@ -0,0 +1,288 @@
+//===- llvm/SandboxIR/Type.h - Classes for handling data types --*- 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 is a thin wrapper over llvm::Type.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SANDBOXIR_TYPE_H
+#define LLVM_SANDBOXIR_TYPE_H
+
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Type.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm::sandboxir {
+
+class Context;
+// Forward declare friend classes for MSVC.
+class PointerType;
+class VectorType;
+class FunctionType;
+#define DEF_INSTR(ID, OPCODE, CLASS) class CLASS;
+#include "llvm/SandboxIR/SandboxIRValues.def"
+
+/// Just like llvm::Type these are immutable, unique, never get freed and can
+/// only be created via static factory methods.
+class Type {
+protected:
+ llvm::Type *LLVMTy;
+ friend class VectorType; // For LLVMTy.
+ friend class PointerType; // For LLVMTy.
+ friend class FunctionType; // For LLVMTy.
+ friend class Function; // For LLVMTy.
+ friend class CallBase; // For LLVMTy.
+ friend class ConstantInt; // For LLVMTy.
+ // Friend all instruction classes because `create()` functions use LLVMTy.
+#define DEF_INSTR(ID, OPCODE, CLASS) friend class CLASS;
+ // TODO: Friend DEF_CONST()
+#include "llvm/SandboxIR/SandboxIRValues.def"
+ Context &Ctx;
+
+ Type(llvm::Type *LLVMTy, Context &Ctx) : LLVMTy(LLVMTy), Ctx(Ctx) {}
+ friend class Context; // For constructor and ~Type().
+ ~Type() = default;
+
+public:
+ Context &getContext() const { return Ctx; }
+
+ /// Return true if this is 'void'.
+ bool isVoidTy() const { return LLVMTy->isVoidTy(); }
+
+ /// Return true if this is 'half', a 16-bit IEEE fp type.
+ bool isHalfTy() const { return LLVMTy->isHalfTy(); }
+
+ /// Return true if this is 'bfloat', a 16-bit bfloat type.
+ bool isBFloatTy() const { return LLVMTy->isBFloatTy(); }
+
+ /// Return true if this is a 16-bit float type.
+ bool is16bitFPTy() const { return LLVMTy->is16bitFPTy(); }
+
+ /// Return true if this is 'float', a 32-bit IEEE fp type.
+ bool isFloatTy() const { return LLVMTy->isFloatTy(); }
+
+ /// Return true if this is 'double', a 64-bit IEEE fp type.
+ bool isDoubleTy() const { return LLVMTy->isDoubleTy(); }
+
+ /// Return true if this is x86 long double.
+ bool isX86_FP80Ty() const { return LLVMTy->isX86_FP80Ty(); }
+
+ /// Return true if this is 'fp128'.
+ bool isFP128Ty() const { return LLVMTy->isFP128Ty(); }
+
+ /// Return true if this is powerpc long double.
+ bool isPPC_FP128Ty() const { return LLVMTy->isPPC_FP128Ty(); }
+
+ /// Return true if this is a well-behaved IEEE-like type, which has a IEEE
+ /// compatible layout as defined by APFloat::isIEEE(), and does not have
+ /// non-IEEE values, such as x86_fp80's unnormal values.
+ bool isIEEELikeFPTy() const { return LLVMTy->isIEEELikeFPTy(); }
+
+ /// Return true if this is one of the floating-point types
+ bool isFloatingPointTy() const { return LLVMTy->isFloatingPointTy(); }
+
+ /// Returns true if this is a floating-point type that is an unevaluated sum
+ /// of multiple floating-point units.
+ /// An example of such a type is ppc_fp128, also known as double-double, which
+ /// consists of two IEEE 754 doubles.
+ bool isMultiUnitFPType() const { return LLVMTy->isMultiUnitFPType(); }
+
+ const fltSemantics &getFltSemantics() const {
+ return LLVMTy->getFltSemantics();
+ }
+
+ /// Return true if this is X86 AMX.
+ bool isX86_AMXTy() const { return LLVMTy->isX86_AMXTy(); }
+
+ /// Return true if this is a target extension type.
+ bool isTargetExtTy() const { return LLVMTy->isTargetExtTy(); }
+
+ /// Return true if this is a target extension type with a scalable layout.
+ bool isScalableTargetExtTy() const { return LLVMTy->isScalableTargetExtTy(); }
+
+ /// Return true if this is a type whose size is a known multiple of vscale.
+ bool isScalableTy() const { return LLVMTy->isScalableTy(); }
+
+ /// Return true if this is a FP type or a vector of FP.
+ bool isFPOrFPVectorTy() const { return LLVMTy->isFPOrFPVectorTy(); }
+
+ /// Return true if this is 'label'.
+ bool isLabelTy() const { return LLVMTy->isLabelTy(); }
+
+ /// Return true if this is 'metadata'.
+ bool isMetadataTy() const { return LLVMTy->isMetadataTy(); }
+
+ /// Return true if this is 'token'.
+ bool isTokenTy() const { return LLVMTy->isTokenTy(); }
+
+ /// True if this is an instance of IntegerType.
+ bool isIntegerTy() const { return LLVMTy->isIntegerTy(); }
+
+ /// Return true if this is an IntegerType of the given width.
+ bool isIntegerTy(unsigned Bitwidth) const {
+ return LLVMTy->isIntegerTy(Bitwidth);
+ }
+
+ /// Return true if this is an integer type or a vector of integer types.
+ bool isIntOrIntVectorTy() const { return LLVMTy->isIntOrIntVectorTy(); }
+
+ /// Return true if this is an integer type or a vector of integer types of
+ /// the given width.
+ bool isIntOrIntVectorTy(unsigned BitWidth) const {
+ return LLVMTy->isIntOrIntVectorTy(BitWidth);
+ }
+
+ /// Return true if this is an integer type or a pointer type.
+ bool isIntOrPtrTy() const { return LLVMTy->isIntOrPtrTy(); }
+
+ /// True if this is an instance of FunctionType.
+ bool isFunctionTy() const { return LLVMTy->isFunctionTy(); }
+
+ /// True if this is an instance of StructType.
+ bool isStructTy() const { return LLVMTy->isStructTy(); }
+
+ /// True if this is an instance of ArrayType.
+ bool isArrayTy() const { return LLVMTy->isArrayTy(); }
+
+ /// True if this is an instance of PointerType.
+ bool isPointerTy() const { return LLVMTy->isPointerTy(); }
+
----------------
vporpo wrote:
Yes, it is deprecated. I think everything is an OpaquePtrTy now.
https://github.com/llvm/llvm-project/pull/106294
More information about the llvm-commits
mailing list