[llvm] [SandboxIR] Boilerplate code (PR #95814)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 17:07:34 PDT 2024
================
@@ -0,0 +1,154 @@
+//===- SandboxIR.h ----------------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Sandbox IR is a lightweight overlay transactional IR on top of LLVM IR.
+// Features:
+// - You can save/rollback the state of the IR at any time.
+// - Any changes made to Sandbox IR will automatically update the underlying
+// LLVM IR so both IRs are always in sync.
+// - Feels like LLVM IR, similar API.
+//
+// SandboxIR forms a class hierarcy that resembles that of LLVM IR
+// but is in the `sandboxir` namespace:
+//
+// namespace sandboxir {
+//
+// +- Argument +- BinaryOperator
+// | |
+// Value -+- BasicBlock +- BranchInst
+// | |
+// +- Function +- Constant +- CastInst
+// | | |
+// +- User ------+- Instruction -+- CallInst
+// |
+// +- CmpInst
+// |
+// +- ExtractElementInst
+// |
+// +- GetElementPtrInst
+// |
+// +- InsertElementInst
+// |
+// +- LoadInst
+// |
+// +- OpaqueInst
+// |
+// +- PHINode
+// |
+// +- RetInst
+// |
+// +- SelectInst
+// |
+// +- ShuffleVectorInst
+// |
+// +- StoreInst
+// |
+// +- UnaryOperator
+//
+// Use
+//
+// } // namespace sandboxir
+//
+
+#ifndef LLVM_TRANSFORMS_SANDBOXIR_SANDBOXIR_H
+#define LLVM_TRANSFORMS_SANDBOXIR_SANDBOXIR_H
+
+#include "llvm/IR/User.h"
+#include "llvm/IR/Value.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+
+namespace sandboxir {
+
+class Context;
+
+/// A SandboxIR Value has users. This is the base class.
+class Value {
+public:
+ enum class ClassID : unsigned {
+#define DEF_VALUE(ID, CLASS) ID,
+#define DEF_USER(ID, CLASS) ID,
+#define DEF_INSTR(ID, OPC, CLASS) ID,
+#include "llvm/Transforms/SandboxIR/SandboxIRValues.def"
+ };
+
+protected:
+ static const char *getSubclassIDStr(ClassID ID) {
+ switch (ID) {
+ // clang-format off
----------------
vporpo wrote:
It looks like this with clang-format:
```
#define DEF_VALUE(ID, CLASS) \
case ClassID::ID: \
return #ID;
#define DEF_USER(ID, CLASS) \
case ClassID::ID: \
return #ID;
#define DEF_INSTR(ID, OPC, CLASS) \
case ClassID::ID: \
return #ID;
```
which I find it quite a bit harder to read than with clang-format off, but I don't feel to strongly about it.
https://github.com/llvm/llvm-project/pull/95814
More information about the llvm-commits
mailing list