Skip to content

Commit b00404a

Browse files
committed
RuntimeOptimizer: Change 'why' from char* to string_view.
This adds a bit of flexibility in what we can pass.
1 parent beae086 commit b00404a

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/liboslexec/runtimeoptimize.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ RuntimeOptimizer::add_global (ustring name, const TypeSpec &type)
318318

319319
void
320320
RuntimeOptimizer::turn_into_new_op (Opcode &op, ustring newop, int newarg1,
321-
int newarg2, const char *why)
321+
int newarg2, string_view why)
322322
{
323323
int opnum = &op - &(inst()->ops()[0]);
324324
DASSERT (opnum >= 0 && opnum < (int)inst()->ops().size());
@@ -327,7 +327,7 @@ RuntimeOptimizer::turn_into_new_op (Opcode &op, ustring newop, int newarg1,
327327
<< " from " << op.opname() << " to "
328328
<< newop << ' ' << inst()->symbol(newarg1)->name() << ' '
329329
<< (newarg2<0 ? "" : inst()->symbol(newarg2)->name().c_str())
330-
<< (why ? " : " : "") << (why ? why : "") << "\n";
330+
<< (why.size() ? " : " : "") << why << "\n";
331331
op.reset (newop, newarg2<0 ? 2 : 3);
332332
op.argwriteonly (0);
333333
inst()->args()[op.firstarg()+1] = newarg1;
@@ -345,7 +345,7 @@ RuntimeOptimizer::turn_into_new_op (Opcode &op, ustring newop, int newarg1,
345345

346346

347347
void
348-
RuntimeOptimizer::turn_into_assign (Opcode &op, int newarg, const char *why)
348+
RuntimeOptimizer::turn_into_assign (Opcode &op, int newarg, string_view why)
349349
{
350350
// We don't know the op num here, so we subtract the pointers
351351
int opnum = &op - &(inst()->ops()[0]);
@@ -354,7 +354,7 @@ RuntimeOptimizer::turn_into_assign (Opcode &op, int newarg, const char *why)
354354
<< " from " << op.opname() << " to "
355355
<< opargsym(op,0)->name() << " = "
356356
<< inst()->symbol(newarg)->name()
357-
<< (why ? " : " : "") << (why ? why : "") << "\n";
357+
<< (why.size() ? " : " : "") << why << "\n";
358358
op.reset (u_assign, 2);
359359
inst()->args()[op.firstarg()+1] = newarg;
360360
op.argwriteonly (0);
@@ -371,7 +371,7 @@ RuntimeOptimizer::turn_into_assign (Opcode &op, int newarg, const char *why)
371371

372372
// Turn the current op into a simple assignment to zero (of the first arg).
373373
void
374-
RuntimeOptimizer::turn_into_assign_zero (Opcode &op, const char *why)
374+
RuntimeOptimizer::turn_into_assign_zero (Opcode &op, string_view why)
375375
{
376376
static float zero[16] = { 0, 0, 0, 0, 0, 0, 0, 0,
377377
0, 0, 0, 0, 0, 0, 0, 0 };
@@ -384,7 +384,7 @@ RuntimeOptimizer::turn_into_assign_zero (Opcode &op, const char *why)
384384

385385
// Turn the current op into a simple assignment to one (of the first arg).
386386
void
387-
RuntimeOptimizer::turn_into_assign_one (Opcode &op, const char *why)
387+
RuntimeOptimizer::turn_into_assign_one (Opcode &op, string_view why)
388388
{
389389
Symbol &R (*(inst()->argsymbol(op.firstarg()+0)));
390390
if (R.typespec().is_int()) {
@@ -403,13 +403,13 @@ RuntimeOptimizer::turn_into_assign_one (Opcode &op, const char *why)
403403

404404
// Turn the op into a no-op
405405
int
406-
RuntimeOptimizer::turn_into_nop (Opcode &op, const char *why)
406+
RuntimeOptimizer::turn_into_nop (Opcode &op, string_view why)
407407
{
408408
if (op.opname() != u_nop) {
409409
if (debug() > 1)
410410
std::cout << "turned op " << (&op - &(inst()->ops()[0]))
411411
<< " from " << op.opname() << " to nop"
412-
<< (why ? " : " : "") << (why ? why : "") << "\n";
412+
<< (why.size() ? " : " : "") << why << "\n";
413413
op.reset (u_nop, 0);
414414
return 1;
415415
}
@@ -419,7 +419,7 @@ RuntimeOptimizer::turn_into_nop (Opcode &op, const char *why)
419419

420420

421421
int
422-
RuntimeOptimizer::turn_into_nop (int begin, int end, const char *why)
422+
RuntimeOptimizer::turn_into_nop (int begin, int end, string_view why)
423423
{
424424
int changed = 0;
425425
for (int i = begin; i != end; ++i) {
@@ -431,7 +431,7 @@ RuntimeOptimizer::turn_into_nop (int begin, int end, const char *why)
431431
}
432432
if (debug() > 1 && changed)
433433
std::cout << "turned ops " << begin << "-" << (end-1) << " into nop"
434-
<< (why ? " : " : "") << (why ? why : "") << "\n";
434+
<< (why.size() ? " : " : "") << why << "\n";
435435
return changed;
436436
}
437437

@@ -1213,12 +1213,12 @@ struct ConnectionDestIs
12131213
/// no longer need; turn it into a a plain old instance-value
12141214
/// parameter.
12151215
void
1216-
RuntimeOptimizer::make_param_use_instanceval (Symbol *R, const char *why)
1216+
RuntimeOptimizer::make_param_use_instanceval (Symbol *R, string_view why)
12171217
{
12181218
if (debug() > 1)
12191219
std::cout << "Turning " << R->valuesourcename() << ' '
12201220
<< R->name() << " into an instance value "
1221-
<< (why ? why : "") << "\n";
1221+
<< why << "\n";
12221222

12231223
// Mark its source as the instance value, not connected
12241224
R->valuesource (Symbol::InstanceVal);

src/liboslexec/runtimeoptimize.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,41 +90,41 @@ class RuntimeOptimizer : public OSOProcessorBase {
9090
/// Turn the op into a simple assignment of the new symbol index to the
9191
/// previous first argument of the op. That is, changes "OP arg0 arg1..."
9292
/// into "assign arg0 newarg".
93-
void turn_into_assign (Opcode &op, int newarg, const char *why=NULL);
93+
void turn_into_assign (Opcode &op, int newarg, string_view why=NULL);
9494

9595
/// Turn the op into a simple assignment of zero to the previous
9696
/// first argument of the op. That is, changes "OP arg0 arg1 ..."
9797
/// into "assign arg0 zero".
98-
void turn_into_assign_zero (Opcode &op, const char *why=NULL);
98+
void turn_into_assign_zero (Opcode &op, string_view why=NULL);
9999

100100
/// Turn the op into a simple assignment of one to the previous
101101
/// first argument of the op. That is, changes "OP arg0 arg1 ..."
102102
/// into "assign arg0 one".
103-
void turn_into_assign_one (Opcode &op, const char *why=NULL);
103+
void turn_into_assign_one (Opcode &op, string_view why=NULL);
104104

105105
/// Turn the op into a new simple unary or binary op with arguments
106106
/// newarg1 and newarg2. If newarg2 < 0, then it's a unary op,
107107
/// otherwise a binary op. Argument 0 (the result) remains the same
108108
/// as always. The original arg list must have at least as many
109109
/// operands as the new one, since no new arg space is allocated.
110110
void turn_into_new_op (Opcode &op, ustring newop, int newarg1,
111-
int newarg2, const char *why=NULL);
111+
int newarg2, string_view why=NULL);
112112

113113
/// Turn the op into a no-op. Return 1 if it changed, 0 if it was
114114
/// already a nop.
115-
int turn_into_nop (Opcode &op, const char *why=NULL);
115+
int turn_into_nop (Opcode &op, string_view why=NULL);
116116

117117
/// Turn the whole range [begin,end) into no-ops. Return the number
118118
/// of instructions that were altered.
119-
int turn_into_nop (int begin, int end, const char *why=NULL);
119+
int turn_into_nop (int begin, int end, string_view why=NULL);
120120

121121
void simplify_params ();
122122

123123
void find_params_holding_globals ();
124124

125125
bool coerce_assigned_constant (Opcode &op);
126126

127-
void make_param_use_instanceval (Symbol *R, const char *why=NULL);
127+
void make_param_use_instanceval (Symbol *R, string_view why=NULL);
128128

129129
/// Return the index of the symbol ultimately de-aliases to (it may be
130130
/// itself, if it doesn't alias to anything else). Local block aliases

0 commit comments

Comments
 (0)