Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
Value.cpp
Go to the documentation of this file.
1//===- Value.cpp - The Value class of Sandbox IR --------------------------===//
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#include "llvm/SandboxIR/Value.h"
10#include "llvm/SandboxIR/Context.h"
11#include "llvm/SandboxIR/User.h"
12#include <sstream>
13
14namespacellvm::sandboxir {
15
16Value::Value(ClassID SubclassID,llvm::Value *Val,Context &Ctx)
17 : SubclassID(SubclassID), Val(Val), Ctx(Ctx) {
18#ifndef NDEBUG
19UID =Ctx.getNumValues();
20#endif
21}
22
23Value::use_iteratorValue::use_begin() {
24llvm::Use *LLVMUse =nullptr;
25if (Val->use_begin() !=Val->use_end())
26 LLVMUse = &*Val->use_begin();
27User *User = LLVMUse !=nullptr ? cast_or_null<sandboxir::User>(Ctx.getValue(
28Val->use_begin()->getUser()))
29 :nullptr;
30returnuse_iterator(Use(LLVMUse,User,Ctx));
31}
32
33Value::user_iteratorValue::user_begin() {
34auto UseBegin =Val->use_begin();
35auto UseEnd =Val->use_end();
36bool AtEnd = UseBegin == UseEnd;
37llvm::Use *LLVMUse = AtEnd ? nullptr : &*UseBegin;
38User *User =
39 AtEnd ? nullptr
40 : cast_or_null<sandboxir::User>(Ctx.getValue(&*LLVMUse->getUser()));
41returnuser_iterator(Use(LLVMUse,User,Ctx), UseToUser());
42}
43
44unsignedValue::getNumUses() const{returnrange_size(Val->users()); }
45
46Type *Value::getType() const{returnCtx.getType(Val->getType()); }
47
48voidValue::replaceUsesWithIf(
49Value *OtherV,llvm::function_ref<bool(constUse &)> ShouldReplace) {
50assert(getType() == OtherV->getType() &&"Can't replace with different type");
51llvm::Value *OtherVal = OtherV->Val;
52// We are delegating RUWIf to LLVM IR's RUWIf.
53Val->replaceUsesWithIf(
54 OtherVal, [&ShouldReplace,this](llvm::Use &LLVMUse) ->bool {
55User *DstU = cast_or_null<User>(Ctx.getValue(LLVMUse.getUser()));
56if (DstU ==nullptr)
57returnfalse;
58Use UseToReplace(&LLVMUse, DstU,Ctx);
59if (!ShouldReplace(UseToReplace))
60returnfalse;
61Ctx.getTracker().emplaceIfTracking<UseSet>(UseToReplace);
62returntrue;
63 });
64}
65
66voidValue::replaceAllUsesWith(Value *Other) {
67assert(getType() ==Other->getType() &&
68"Replacing with Value of different type!");
69auto &Tracker =Ctx.getTracker();
70if (Tracker.isTracking()) {
71for (autoUse :uses())
72Tracker.track(std::make_unique<UseSet>(Use));
73 }
74// We are delegating RAUW to LLVM IR's RAUW.
75Val->replaceAllUsesWith(Other->Val);
76}
77
78#ifndef NDEBUG
79std::stringValue::getUid() const{
80 std::stringstream SS;
81 SS <<"SB" <<UID <<".";
82return SS.str();
83}
84
85voidValue::dumpCommonHeader(raw_ostream &OS) const{
86OS <<getUid() <<" " <<getSubclassIDStr(SubclassID) <<" ";
87}
88
89voidValue::dumpCommonFooter(raw_ostream &OS) const{
90OS.indent(2) <<"Val: ";
91if (Val)
92OS << *Val;
93else
94OS <<"NULL";
95OS <<"\n";
96}
97
98voidValue::dumpCommonPrefix(raw_ostream &OS) const{
99if (Val)
100OS << *Val;
101else
102OS <<"NULL ";
103}
104
105voidValue::dumpCommonSuffix(raw_ostream &OS) const{
106OS <<" ; " <<getUid() <<" (" <<getSubclassIDStr(SubclassID) <<")";
107}
108
109voidValue::printAsOperandCommon(raw_ostream &OS) const{
110if (Val)
111Val->printAsOperand(OS);
112else
113OS <<"NULL ";
114}
115
116voidValue::dump() const{
117dumpOS(dbgs());
118dbgs() <<"\n";
119}
120#endif// NDEBUG
121
122}// namespace llvm::sandboxir
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
Context.h
User.h
Value.h
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition:Use.h:43
llvm::Use::getUser
User * getUser() const
Returns the User that contains this Use.
Definition:Use.h:72
llvm::User
Definition:User.h:44
llvm::Value
LLVM Value Representation.
Definition:Value.h:74
llvm::Value::getType
Type * getType() const
All values are typed, get the type of this value.
Definition:Value.h:255
llvm::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition:Value.cpp:534
llvm::Value::users
iterator_range< user_iterator > users()
Definition:Value.h:421
llvm::Value::use_begin
use_iterator use_begin()
Definition:Value.h:360
llvm::Value::printAsOperand
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
Definition:AsmWriter.cpp:5144
llvm::Value::replaceUsesWithIf
void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
Definition:Value.cpp:542
llvm::Value::use_end
use_iterator use_end()
Definition:Value.h:368
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition:STLFunctionalExtras.h:37
llvm::mapped_iterator
Definition:STLExtras.h:353
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
llvm::raw_ostream::indent
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
Definition:raw_ostream.cpp:495
llvm::sandboxir::Context
Definition:Context.h:30
llvm::sandboxir::Context::getValue
sandboxir::Value * getValue(llvm::Value *V) const
Definition:Context.cpp:601
llvm::sandboxir::Context::getType
Type * getType(llvm::Type *LLVMTy)
Definition:Context.h:239
llvm::sandboxir::Context::getTracker
Tracker & getTracker()
Definition:Context.h:222
llvm::sandboxir::Context::getNumValues
size_t getNumValues() const
\Returns the number of values registered with Context.
Definition:Context.h:260
llvm::sandboxir::Tracker
The tracker collects all the change objects and implements the main API for saving / reverting / acce...
Definition:Tracker.h:440
llvm::sandboxir::Tracker::isTracking
bool isTracking() const
\Returns true if the tracker is recording changes.
Definition:Tracker.h:502
llvm::sandboxir::Tracker::track
void track(std::unique_ptr< IRChangeBase > &&Change)
Record Change and take ownership.
Definition:Tracker.h:478
llvm::sandboxir::Tracker::emplaceIfTracking
bool emplaceIfTracking(ArgsT... Args)
A convenience wrapper for track() that constructs and tracks the Change object if tracking is enabled...
Definition:Tracker.h:495
llvm::sandboxir::Type
Just like llvm::Type these are immutable, unique, never get freed and can only be created via static ...
Definition:Type.h:43
llvm::sandboxir::Use
Represents a Def-use/Use-def edge in SandboxIR.
Definition:Use.h:32
llvm::sandboxir::UserUseIterator
Iterator for the Use edges of a Value's users.
Definition:Value.h:37
llvm::sandboxir::User
A sandboxir::User has operands.
Definition:User.h:58
llvm::sandboxir::Value
A SandboxIR Value has users. This is the base class.
Definition:Value.h:63
llvm::sandboxir::Value::user_iterator
mapped_iterator< sandboxir::UserUseIterator, UseToUser > user_iterator
Definition:Value.h:211
llvm::sandboxir::Value::Val
llvm::Value * Val
The LLVM Value that corresponds to this SandboxIR Value.
Definition:Value.h:103
llvm::sandboxir::Value::dumpCommonFooter
void dumpCommonFooter(raw_ostream &OS) const
Definition:Value.cpp:89
llvm::sandboxir::Value::dumpCommonHeader
virtual void dumpCommonHeader(raw_ostream &OS) const
Definition:Value.cpp:85
llvm::sandboxir::Value::dumpCommonSuffix
void dumpCommonSuffix(raw_ostream &OS) const
Definition:Value.cpp:105
llvm::sandboxir::Value::replaceAllUsesWith
void replaceAllUsesWith(Value *Other)
Definition:Value.cpp:66
llvm::sandboxir::Value::getNumUses
unsigned getNumUses() const
\Returns the number of user edges (not necessarily to unique users).
Definition:Value.cpp:44
llvm::sandboxir::Value::use_iterator
UserUseIterator use_iterator
Definition:Value.h:187
llvm::sandboxir::Value::printAsOperandCommon
void printAsOperandCommon(raw_ostream &OS) const
Definition:Value.cpp:109
llvm::sandboxir::Value::Ctx
Context & Ctx
All values point to the context.
Definition:Value.h:173
llvm::sandboxir::Value::SubclassID
ClassID SubclassID
For isa/dyn_cast.
Definition:Value.h:94
llvm::sandboxir::Value::dump
LLVM_DUMP_METHOD void dump() const
Definition:Value.cpp:116
llvm::sandboxir::Value::getType
Type * getType() const
Definition:Value.cpp:46
llvm::sandboxir::Value::Value
Value(ClassID SubclassID, llvm::Value *Val, Context &Ctx)
Definition:Value.cpp:16
llvm::sandboxir::Value::Use
friend class Use
Definition:Value.h:107
llvm::sandboxir::Value::getUid
std::string getUid() const
Returns the unique id in the form 'SB<number>.' like 'SB1.'.
Definition:Value.cpp:79
llvm::sandboxir::Value::replaceUsesWithIf
void replaceUsesWithIf(Value *OtherV, llvm::function_ref< bool(const Use &)> ShouldReplace)
Definition:Value.cpp:48
llvm::sandboxir::Value::UID
unsigned UID
A unique ID used for forming the name (used for debugging).
Definition:Value.h:97
llvm::sandboxir::Value::dumpOS
virtual void dumpOS(raw_ostream &OS) const =0
llvm::sandboxir::Value::dumpCommonPrefix
void dumpCommonPrefix(raw_ostream &OS) const
Definition:Value.cpp:98
llvm::sandboxir::Value::uses
iterator_range< use_iterator > uses()
Definition:Value.h:199
llvm::sandboxir::Value::getSubclassIDStr
static const char * getSubclassIDStr(ClassID ID)
Definition:Value.h:74
llvm::sandboxir::Value::use_begin
use_iterator use_begin()
Definition:Value.cpp:23
llvm::sandboxir::Value::user_begin
user_iterator user_begin()
Definition:Value.cpp:33
llvm::sandboxir::Value::ClassID
ClassID
Definition:Value.h:65
llvm::sandboxir
Definition:Argument.h:15
llvm::range_size
constexpr size_t range_size(R &&Range)
Returns the size of the Range, i.e., the number of elements.
Definition:STLExtras.h:1722
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::IRMemLocation::Other
@ Other
Any other memory.

Generated on Thu Jul 17 2025 12:31:01 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp