Skip to content

Commit 968e06d

Browse files
committed
Tidy up debug printing and dumping a bit, moving from errs() to dbgs() (#17398)
Tidy up debug printing and dumping a bit, moving from errs() to dbgs() in a few places.
1 parent f738d23 commit 968e06d

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

lib/SILOptimizer/Mandatory/TFConstExpr.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ namespace {
228228
}
229229

230230
void setValue(SILValue value, SymbolicValue symVal) {
231-
assert(!value->getType().isAddress() &&"addresses are tracked separately");
231+
assert(!value->getType().isAddress() &&
232+
"addresses are tracked separately");
232233
calculatedValues.insert({ value, symVal });
233234
}
234235

@@ -398,7 +399,7 @@ SymbolicValue ConstExprFunctionState::computeConstantValue(SILValue value) {
398399
if (fn)
399400
return SymbolicValue::getFunction(fn, conf);
400401

401-
DEBUG(llvm::errs() << "ConstExpr Unresolved witness: " << *value << "\n");
402+
DEBUG(llvm::dbgs() << "ConstExpr Unresolved witness: " << *value << "\n");
402403
return SymbolicValue::getUnknown(value, UnknownReason::Default);
403404
}
404405

@@ -416,7 +417,7 @@ SymbolicValue ConstExprFunctionState::computeConstantValue(SILValue value) {
416417
return calculatedValues[apply];
417418
}
418419

419-
DEBUG(llvm::errs() << "ConstExpr Unknown simple: " << *value << "\n");
420+
DEBUG(llvm::dbgs() << "ConstExpr Unknown simple: " << *value << "\n");
420421

421422
// Otherwise, we don't know how to handle this.
422423
return SymbolicValue::getUnknown(value, UnknownReason::Default);
@@ -753,7 +754,7 @@ ConstExprFunctionState::computeConstantValueBuiltin(BuiltinInst *inst) {
753754
}
754755

755756

756-
DEBUG(llvm::errs() << "ConstExpr Unknown Builtin: " << *inst << "\n");
757+
DEBUG(llvm::dbgs() << "ConstExpr Unknown Builtin: " << *inst << "\n");
757758

758759
// Otherwise, we don't know how to handle this builtin.
759760
return unknownResult();
@@ -780,7 +781,7 @@ ConstExprFunctionState::computeOpaqueCallResult(ApplyInst *apply,
780781
UnknownReason::Trap);
781782
}
782783

783-
DEBUG(llvm::errs() << "ConstExpr Opaque Callee: " << *callee << "\n");
784+
DEBUG(llvm::dbgs() << "ConstExpr Opaque Callee: " << *callee << "\n");
784785
return SymbolicValue::getUnknown((SILInstruction*)apply,
785786
UnknownReason::Default);
786787
}
@@ -936,8 +937,8 @@ SymbolicValue ConstExprFunctionState::getConstantValue(SILValue value) {
936937

937938
// If this is the top-level lazy interpreter, output a debug trace.
938939
if (!fn) {
939-
DEBUG(llvm::errs() << "ConstExpr top level: "; value->dump());
940-
DEBUG(llvm::errs() << " RESULT: "; result.dump());
940+
DEBUG(llvm::dbgs() << "ConstExpr top level: "; value->dump());
941+
DEBUG(llvm::dbgs() << " RESULT: "; result.dump());
941942
}
942943

943944
return calculatedValues[value] = result;
@@ -1096,7 +1097,7 @@ ConstExprFunctionState::computeSingleStoreAddressValue(SILValue addr) {
10961097
}
10971098

10981099

1099-
DEBUG(llvm::errs() << "Unknown SingleStore ConstExpr user: "
1100+
DEBUG(llvm::dbgs() << "Unknown SingleStore ConstExpr user: "
11001101
<< *user << "\n");
11011102

11021103
// If this is some other user that we don't know about, then we should
@@ -1198,7 +1199,7 @@ AddressValue ConstExprFunctionState::computeAddressValue(SILValue addr) {
11981199
if (auto *bai = dyn_cast<BeginAccessInst>(addr))
11991200
return getAddressValue(bai->getOperand());
12001201

1201-
DEBUG(llvm::errs() << "ConstExpr Unknown simple addr: " << *addr << "\n");
1202+
DEBUG(llvm::dbgs() << "ConstExpr Unknown simple addr: " << *addr << "\n");
12021203

12031204
// Otherwise, we don't know how to handle this.
12041205
return getUnknownAddress(addr, UnknownReason::Default);
@@ -1299,20 +1300,20 @@ ConstExprFunctionState::evaluateFlowSensitive(SILInstruction *inst) {
12991300
auto result = getConstantValue(oneResultVal);
13001301
if (!result.isConstant())
13011302
return result;
1302-
DEBUG(llvm::errs() << " RESULT: "; result.dump());
1303+
DEBUG(llvm::dbgs() << " RESULT: "; result.dump());
13031304
} else {
13041305
auto result = getAddressValue(oneResultVal);
13051306
// If the address could not be resolved, puts the 'unknown' code into
13061307
// the referenced memory object.
13071308
auto memVal = memoryObjects[result.getObjectID()].first;
13081309
if (memVal.isUnknown())
13091310
return memVal;
1310-
DEBUG(llvm::errs() << " RESULT: "; result.dump());
1311+
DEBUG(llvm::dbgs() << " RESULT: "; result.dump());
13111312
}
13121313
return None;
13131314
}
13141315

1315-
DEBUG(llvm::errs() << "ConstExpr Unknown FS: " << *inst << "\n");
1316+
DEBUG(llvm::dbgs() << "ConstExpr Unknown FS: " << *inst << "\n");
13161317
// If this is an unknown instruction with no results then bail out.
13171318
return SymbolicValue::getUnknown(inst, UnknownReason::Default);
13181319
}
@@ -1340,10 +1341,10 @@ evaluateAndCacheCall(SILFunction &fn, SubstitutionMap substitutionMap,
13401341
unsigned nextBBArg = 0;
13411342
const auto &argList = fn.front().getArguments();
13421343

1343-
DEBUG(llvm::errs().changeColor(raw_ostream::SAVEDCOLOR, /*bold*/true)
1344+
DEBUG(llvm::dbgs().changeColor(raw_ostream::SAVEDCOLOR, /*bold*/true)
13441345
<< "\nConstExpr call fn: "
13451346
<< Demangle::demangleSymbolAsString(fn.getName());
1346-
llvm::errs().resetColor()
1347+
llvm::dbgs().resetColor()
13471348
<< "\n");
13481349

13491350
for (unsigned i = 0, e = conventions.getNumIndirectSILResults(); i != e; ++i)
@@ -1371,7 +1372,7 @@ evaluateAndCacheCall(SILFunction &fn, SubstitutionMap substitutionMap,
13711372

13721373
while (1) {
13731374
SILInstruction *inst = &*nextInst++;
1374-
DEBUG(llvm::errs() << "ConstExpr interpret: "; inst->dump());
1375+
DEBUG(llvm::dbgs() << "ConstExpr interpret: "; inst->dump());
13751376

13761377
// Make sure we haven't exceeded our interpreter iteration cap.
13771378
if (++numInstEvaluated > ConstExprLimit)
@@ -1413,7 +1414,7 @@ evaluateAndCacheCall(SILFunction &fn, SubstitutionMap substitutionMap,
14131414

14141415
// TODO: Handle caching of results.
14151416

1416-
DEBUG(llvm::errs() << "\n");
1417+
DEBUG(llvm::dbgs() << "\n");
14171418
return None;
14181419
}
14191420

@@ -1454,7 +1455,7 @@ evaluateAndCacheCall(SILFunction &fn, SubstitutionMap substitutionMap,
14541455
continue;
14551456
}
14561457

1457-
DEBUG(llvm::errs() << "ConstExpr: Unknown Terminator: " << *inst << "\n");
1458+
DEBUG(llvm::dbgs() << "ConstExpr: Unknown Terminator: " << *inst << "\n");
14581459

14591460
// TODO: Enum switches when we support enums?
14601461
return SymbolicValue::getUnknown(inst, UnknownReason::Default);

lib/SILOptimizer/Mandatory/TFDevicePartition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class DevicePartitionerImpl
463463
if (inst->getName().str() == "tf_tensor_to_i1")
464464
return;
465465

466-
inst->print(llvm::errs());
466+
inst->dump();
467467
llvm_unreachable(
468468
"DevicePartitionerImpl cannot mark this instruction yet\n");
469469
}

lib/SILOptimizer/Mandatory/TFDifferentiation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,6 @@ class ADContext {
383383
ADContext::ADContext(SILModule &module, SILPassManager &passManager)
384384
: module(module), passManager(passManager), typeConverter(module)
385385
{
386-
auto &ctx = getASTContext();
387-
388386
// Add local witness tables to the local map.
389387
for (auto &wt : module.getWitnessTables())
390388
witnessTables.insert({wt.getConformance(), &wt});

lib/SILOptimizer/Mandatory/TFLowerGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ void TFGraphLowering::visitTFOpInst(BuiltinInst *inst) {
14921492
}
14931493

14941494
if (!hasDevice) {
1495-
inst->print(llvm::errs());
1495+
inst->dump();
14961496
llvm_unreachable("The above tensor op has no device set");
14971497
}
14981498

lib/SILOptimizer/Mandatory/TFPartition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3223,7 +3223,7 @@ void TFFunctionPartition::balanceRetainReleaseCount(SILValue oldResult,
32233223
continue;
32243224
}
32253225

3226-
oldResult->print(llvm::errs());
3226+
oldResult->dump();
32273227
llvm_unreachable("Unhandled instruction type");
32283228
}
32293229

lib/SILOptimizer/Mandatory/TFUtilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static bool tryToRemoveArrayValue(SILValue value) {
486486
}
487487

488488
// Otherwise we don't know what this is, conservatively bail out.
489-
DEBUG(llvm::errs() << "Could not remove array because of: " << *user);
489+
DEBUG(llvm::dbgs() << "Could not remove array because of: " << *user);
490490
return false;
491491
}
492492
}

0 commit comments

Comments
 (0)