MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / AssignValueNumber

Method AssignValueNumber

source/opt/value_number_table.cpp:80–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80uint32_t ValueNumberTable::AssignValueNumber(Instruction* inst) {
81 // If it already has a value return that.
82 uint32_t value = GetValueNumber(inst);
83 if (value != 0) {
84 return value;
85 }
86
87 auto assign_new_number = [this](Instruction* i) {
88 const auto new_value = TakeNextValueNumber();
89 id_to_value_[i->result_id()] = new_value;
90 return new_value;
91 };
92
93 // If the instruction has other side effects, then it must
94 // have its own value number.
95 if (!context()->IsCombinatorInstruction(inst) &&
96 !inst->IsCommonDebugInstr()) {
97 return assign_new_number(inst);
98 }
99
100 // OpSampledImage and OpImage must remain in the same basic block in which
101 // they are used, because of this we will assign each one it own value number.
102 switch (inst->opcode()) {
103 case spv::Op::OpSampledImage:
104 case spv::Op::OpImage:
105 case spv::Op::OpVariable:
106 return assign_new_number(inst);
107 default:
108 break;
109 }
110
111 // A load that yields an image, sampler, or sampled image must remain in
112 // the same basic block. So assign it its own value number.
113 if (inst->IsLoad()) {
114 switch (context()->get_def_use_mgr()->GetDef(inst->type_id())->opcode()) {
115 case spv::Op::OpTypeSampledImage:
116 case spv::Op::OpTypeImage:
117 case spv::Op::OpTypeSampler:
118 return assign_new_number(inst);
119 default:
120 break;
121 }
122 }
123
124 // If it is a load from memory that can be modified, we have to assume the
125 // memory has been modified, so we give it a new value number.
126 //
127 // Note that this test will also handle volatile loads because they are not
128 // read only. However, if this is ever relaxed because we analyze stores, we
129 // will have to add a new case for volatile loads.
130 if (inst->IsLoad() && !IsReadOnlyLoad(inst)) {
131 return assign_new_number(inst);
132 }
133
134 analysis::DecorationManager* dec_mgr = context()->get_decoration_mgr();
135
136 // When we copy an object, the value numbers should be the same.
137 if (inst->opcode() == spv::Op::OpCopyObject &&

Callers

nothing calls this directly

Calls 15

spvIsIdTypeFunction · 0.85
IsCommonDebugInstrMethod · 0.80
IsLoadMethod · 0.80
NumInOperandsMethod · 0.80
AddOperandMethod · 0.80
SetInOperandsMethod · 0.80
OperandClass · 0.70
result_idMethod · 0.45

Tested by

no test coverage detected