Skip to content

Commit f4bd6c1

Browse files
vporpoyuxuanchen1997
authored andcommitted
[SandboxIR][NFC] Move sandboxir::Use into a separate file (#99074)
Summary: This helps avoid circular dependencies in a follow-up patch. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251433
1 parent db8b9db commit f4bd6c1

File tree

2 files changed

+67
-39
lines changed

2 files changed

+67
-39
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@
5555
// } // namespace sandboxir
5656
//
5757

58-
#ifndef LLVM_TRANSFORMS_SANDBOXIR_SANDBOXIR_H
59-
#define LLVM_TRANSFORMS_SANDBOXIR_SANDBOXIR_H
58+
#ifndef LLVM_SANDBOXIR_SANDBOXIR_H
59+
#define LLVM_SANDBOXIR_SANDBOXIR_H
6060

6161
#include "llvm/IR/Function.h"
6262
#include "llvm/IR/User.h"
6363
#include "llvm/IR/Value.h"
64+
#include "llvm/SandboxIR/Use.h"
6465
#include "llvm/Support/raw_ostream.h"
6566
#include <iterator>
6667

@@ -75,42 +76,6 @@ class Instruction;
7576
class User;
7677
class Value;
7778

78-
/// Represents a Def-use/Use-def edge in SandboxIR.
79-
/// NOTE: Unlike llvm::Use, this is not an integral part of the use-def chains.
80-
/// It is also not uniqued and is currently passed by value, so you can have
81-
/// more than one sandboxir::Use objects for the same use-def edge.
82-
class Use {
83-
llvm::Use *LLVMUse;
84-
User *Usr;
85-
Context *Ctx;
86-
87-
/// Don't allow the user to create a sandboxir::Use directly.
88-
Use(llvm::Use *LLVMUse, User *Usr, Context &Ctx)
89-
: LLVMUse(LLVMUse), Usr(Usr), Ctx(&Ctx) {}
90-
Use() : LLVMUse(nullptr), Ctx(nullptr) {}
91-
92-
friend class Value; // For constructor
93-
friend class User; // For constructor
94-
friend class OperandUseIterator; // For constructor
95-
friend class UserUseIterator; // For accessing members
96-
97-
public:
98-
operator Value *() const { return get(); }
99-
Value *get() const;
100-
class User *getUser() const { return Usr; }
101-
unsigned getOperandNo() const;
102-
Context *getContext() const { return Ctx; }
103-
bool operator==(const Use &Other) const {
104-
assert(Ctx == Other.Ctx && "Contexts differ!");
105-
return LLVMUse == Other.LLVMUse && Usr == Other.Usr;
106-
}
107-
bool operator!=(const Use &Other) const { return !(*this == Other); }
108-
#ifndef NDEBUG
109-
void dump(raw_ostream &OS) const;
110-
void dump() const;
111-
#endif // NDEBUG
112-
};
113-
11479
/// Returns the operand edge when dereferenced.
11580
class OperandUseIterator {
11681
sandboxir::Use Use;
@@ -764,4 +729,4 @@ class Function : public sandboxir::Value {
764729
} // namespace sandboxir
765730
} // namespace llvm
766731

767-
#endif // LLVM_TRANSFORMS_SANDBOXIR_SANDBOXIR_H
732+
#endif // LLVM_SANDBOXIR_SANDBOXIR_H

llvm/include/llvm/SandboxIR/Use.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//===- Use.h ----------------------------------------------------*- C++ -*-===//
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+
//
9+
// Sandbox IR Use.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_SANDBOXIR_USE_H
14+
#define LLVM_SANDBOXIR_USE_H
15+
16+
#include "llvm/IR/Use.h"
17+
#include "llvm/Support/raw_ostream.h"
18+
19+
namespace llvm::sandboxir {
20+
21+
class Context;
22+
class Value;
23+
class User;
24+
25+
/// Represents a Def-use/Use-def edge in SandboxIR.
26+
/// NOTE: Unlike llvm::Use, this is not an integral part of the use-def chains.
27+
/// It is also not uniqued and is currently passed by value, so you can have
28+
/// more than one sandboxir::Use objects for the same use-def edge.
29+
class Use {
30+
llvm::Use *LLVMUse;
31+
User *Usr;
32+
Context *Ctx;
33+
34+
/// Don't allow the user to create a sandboxir::Use directly.
35+
Use(llvm::Use *LLVMUse, User *Usr, Context &Ctx)
36+
: LLVMUse(LLVMUse), Usr(Usr), Ctx(&Ctx) {}
37+
Use() : LLVMUse(nullptr), Ctx(nullptr) {}
38+
39+
friend class Value; // For constructor
40+
friend class User; // For constructor
41+
friend class OperandUseIterator; // For constructor
42+
friend class UserUseIterator; // For accessing members
43+
44+
public:
45+
operator Value *() const { return get(); }
46+
Value *get() const;
47+
class User *getUser() const { return Usr; }
48+
unsigned getOperandNo() const;
49+
Context *getContext() const { return Ctx; }
50+
bool operator==(const Use &Other) const {
51+
assert(Ctx == Other.Ctx && "Contexts differ!");
52+
return LLVMUse == Other.LLVMUse && Usr == Other.Usr;
53+
}
54+
bool operator!=(const Use &Other) const { return !(*this == Other); }
55+
#ifndef NDEBUG
56+
void dump(raw_ostream &OS) const;
57+
void dump() const;
58+
#endif // NDEBUG
59+
};
60+
61+
} // namespace llvm::sandboxir
62+
63+
#endif // LLVM_SANDBOXIR_USE_H

0 commit comments

Comments
 (0)