Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions SwiftCompilerSources/Sources/Optimizer/Utilities/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ private func functionTestThunk(
let invocation = castToInvocation(fromOpaquePointer: erasedInvocation)
let context = FunctionPassContext(_bridged: BridgedPassContext(invocation: passInvocation.invocation))
invocation(function.function, arguments.native, context)
fflush(stdout)
}

/// Bitcast a thin test closure to void *.
Expand Down Expand Up @@ -202,46 +203,36 @@ private func castToInvocation(fromOpaquePointer erasedInvocation: UnsafeMutableR
// - something to identify the instance (mostly this means calling dump)
let parseTestSpecificationTest =
FunctionTest(name: "test_specification_parsing") { function, arguments, context in
struct _Stderr : TextOutputStream {
public init() {}

public mutating func write(_ string: String) {
for c in string.utf8 {
writeCharToStderr(CInt(c))
}
}
}
var stderr = _Stderr()
let expectedFields = arguments.takeString()
for expectedField in expectedFields.string {
switch expectedField {
case "A":
let argument = arguments.takeArgument()
print("argument:\n\(argument)", to: &stderr)
print("argument:\n\(argument)")
case "F":
let function = arguments.takeFunction()
print("function: \(function.name)", to: &stderr)
print("function: \(function.name)")
case "B":
let block = arguments.takeBlock()
print("block:\n\(block)", to: &stderr)
print("block:\n\(block)")
case "I":
let instruction = arguments.takeInstruction()
print("instruction: \(instruction)", to: &stderr)
print("instruction: \(instruction)")
case "V":
let value = arguments.takeValue()
print("value: \(value)", to: &stderr)
print("value: \(value)")
case "O":
let operand = arguments.takeOperand()
print("operand: \(operand)", to: &stderr)
print("operand: \(operand)")
case "u":
let u = arguments.takeInt()
print("uint: \(u)", to: &stderr)
print("uint: \(u)")
case "b":
let b = arguments.takeBool()
print("bool: \(b)", to: &stderr)
print("bool: \(b)")
case "s":
let s = arguments.takeString()
print("string: \(s)", to: &stderr)
print("string: \(s)")
default:
fatalError("unknown field type was expected?!");
}
Expand Down
4 changes: 2 additions & 2 deletions lib/SIL/IR/SILValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ static FunctionTest IsLexicalTest("is-lexical", [](auto &function,
auto &test) {
auto value = arguments.takeValue();
auto isLexical = value->isLexical();
value->dump();
value->print(llvm::outs());
auto *boolString = isLexical ? "true" : "false";
llvm::errs() << boolString << "\n";
llvm::outs() << boolString << "\n";
});
} // end namespace swift::test

Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2758,7 +2758,7 @@ static FunctionTest PrintTypeLowering("print-type-lowering", [](auto &function,
auto &test) {
auto value = arguments.takeValue();
auto ty = value->getType();
function.getModule().Types.getTypeLowering(ty, function).print(llvm::dbgs());
function.getModule().Types.getTypeLowering(ty, function).print(llvm::outs());
});
} // end namespace swift::test

Expand Down
4 changes: 2 additions & 2 deletions lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,12 +1024,12 @@ static FunctionTest FieldSensitiveMultiDefUseLiveRangeTest(
TypeTreeLeafTypeRange range(begin, end);
liveness.updateForUse(inst, range, lifetimeEnding);
}
liveness.print(llvm::errs());
liveness.print(llvm::outs());

FieldSensitivePrunedLivenessBoundary boundary(
liveness.getNumSubElements());
liveness.computeBoundary(boundary);
boundary.print(llvm::errs());
boundary.print(llvm::outs());
});
} // end namespace swift::test

Expand Down
20 changes: 10 additions & 10 deletions lib/SIL/Utils/MemAccessUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,10 @@ static FunctionTest
GetTypedAccessAddress("get_typed_access_address",
[](auto &function, auto &arguments, auto &test) {
auto address = arguments.takeValue();
function.dump();
llvm::dbgs() << "Address: " << address;
function.print(llvm::outs());
llvm::outs() << "Address: " << address;
auto access = getTypedAccessAddress(address);
llvm::dbgs() << "Access: " << access;
llvm::outs() << "Access: " << access;
});
} // end namespace swift::test

Expand All @@ -404,10 +404,10 @@ static FunctionTest GetAccessBaseTest("get_access_base",
[](auto &function, auto &arguments,
auto &test) {
auto address = arguments.takeValue();
function.dump();
llvm::dbgs() << "Address: " << address;
function.print(llvm::outs());
llvm::outs() << "Address: " << address;
auto base = getAccessBase(address);
llvm::dbgs() << "Base: " << base;
llvm::outs() << "Base: " << base;
});
} // end namespace swift::test

Expand Down Expand Up @@ -1196,10 +1196,10 @@ static FunctionTest ComputeAccessStorage("compute_access_storage",
[](auto &function, auto &arguments,
auto &test) {
auto address = arguments.takeValue();
function.dump();
llvm::dbgs() << "Address: " << address;
function.print(llvm::outs());
llvm::outs() << "Address: " << address;
auto accessStorage = AccessStorage::compute(address);
accessStorage.dump();
accessStorage.print(llvm::outs());
});
} // end namespace swift::test

Expand Down Expand Up @@ -2070,7 +2070,7 @@ static FunctionTest AccessPathBaseTest("accesspath-base", [](auto &function,
auto &arguments,
auto &test) {
auto value = arguments.takeValue();
function.dump();
function.print(llvm::outs());
llvm::outs() << "Access path base: " << value;
auto accessPathWithBase = AccessPathWithBase::compute(value);
AccessUseTestVisitor visitor;
Expand Down
4 changes: 2 additions & 2 deletions lib/SIL/Utils/OSSALifetimeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,10 @@ static FunctionTest OSSALifetimeCompletionTest(
"ossa-lifetime-completion",
[](auto &function, auto &arguments, auto &test) {
SILValue value = arguments.takeValue();
llvm::dbgs() << "OSSA lifetime completion: " << value;
llvm::outs() << "OSSA lifetime completion: " << value;
OSSALifetimeCompletion completion(&function, /*domInfo*/ nullptr);
completion.completeOSSALifetime(value);
function.dump();
function.print(llvm::outs());
});
} // end namespace swift::test

Expand Down
12 changes: 6 additions & 6 deletions lib/SIL/Utils/OwnershipLiveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ static FunctionTest LinearLivenessTest("linear-liveness", [](auto &function,
auto &arguments,
auto &test) {
SILValue value = arguments.takeValue();
function.dump();
llvm::dbgs() << "Linear liveness: " << value;
function.print(llvm::outs());
llvm::outs() << "Linear liveness: " << value;
LinearLiveness liveness(value);
liveness.compute();
liveness.print(llvm::outs());
Expand All @@ -399,8 +399,8 @@ static FunctionTest
InteriorLivenessTest("interior-liveness",
[](auto &function, auto &arguments, auto &test) {
SILValue value = arguments.takeValue();
function.dump();
llvm::dbgs() << "Interior liveness: " << value;
function.print(llvm::outs());
llvm::outs() << "Interior liveness: " << value;
auto *domTree = test.getDominanceInfo();
InteriorLiveness liveness(value);
auto handleInnerScope = [](SILValue innerBorrow) {
Expand All @@ -423,8 +423,8 @@ static FunctionTest
static FunctionTest ExtendedLinearLivenessTest(
"extended-liveness", [](auto &function, auto &arguments, auto &test) {
SILValue value = arguments.takeValue();
function.dump();
llvm::dbgs() << "Extended liveness: " << value;
function.print(llvm::outs());
llvm::outs() << "Extended liveness: " << value;
ExtendedLinearLiveness liveness(value);
liveness.compute();
liveness.print(llvm::outs());
Expand Down
20 changes: 10 additions & 10 deletions lib/SIL/Utils/OwnershipUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ static FunctionTest OwnershipUtilsHasPointerEscape(
"has-pointer-escape", [](auto &function, auto &arguments, auto &test) {
auto value = arguments.takeValue();
auto has = findPointerEscape(value);
value->print(llvm::errs());
value->print(llvm::outs());
auto *boolString = has ? "true" : "false";
llvm::errs() << boolString << "\n";
llvm::outs() << boolString << "\n";
});
} // end namespace swift::test

Expand Down Expand Up @@ -2057,10 +2057,10 @@ namespace swift::test {
// - the enclosing defs
static FunctionTest FindEnclosingDefsTest(
"find-enclosing-defs", [](auto &function, auto &arguments, auto &test) {
function.dump();
llvm::dbgs() << "Enclosing Defs:\n";
function.print(llvm::outs());
llvm::outs() << "Enclosing Defs:\n";
visitEnclosingDefs(arguments.takeValue(), [](SILValue def) {
def->dump();
def->print(llvm::outs());
return true;
});
});
Expand All @@ -2082,10 +2082,10 @@ namespace swift::test {
// - the borrow introducers
static FunctionTest FindBorrowIntroducers(
"find-borrow-introducers", [](auto &function, auto &arguments, auto &test) {
function.dump();
llvm::dbgs() << "Introducers:\n";
function.print(llvm::outs());
llvm::outs() << "Introducers:\n";
visitBorrowIntroducers(arguments.takeValue(), [](SILValue def) {
def->dump();
def->print(llvm::outs());
return true;
});
});
Expand Down Expand Up @@ -2202,10 +2202,10 @@ namespace swift::test {
static FunctionTest VisitInnerAdjacentPhisTest(
"visit-inner-adjacent-phis",
[](auto &function, auto &arguments, auto &test) {
function.dump();
function.print(llvm::outs());
visitInnerAdjacentPhis(cast<SILPhiArgument>(arguments.takeValue()),
[](auto *argument) -> bool {
argument->dump();
argument->print(llvm::outs());
return true;
});
});
Expand Down
5 changes: 3 additions & 2 deletions lib/SIL/Utils/PrunedLiveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ static FunctionTest
while (arguments.hasUntaken()) {
boundary.lastUsers.push_back(arguments.takeInstruction());
}
boundary.visitInsertionPoints(
[](SILBasicBlock::iterator point) { point->dump(); });
boundary.visitInsertionPoints([](SILBasicBlock::iterator point) {
point->print(llvm::outs());
});
});
} // end namespace swift::test

Expand Down
1 change: 1 addition & 0 deletions lib/SIL/Utils/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void FunctionTest::run(SILFunction &function, Arguments &arguments,
auto fn = invocation.get<Invocation>();
fn(function, arguments, *this);
} else {
llvm::outs().flush();
auto *fn = invocation.get<NativeSwiftInvocation>();
Registry::get().getFunctionTestThunk()(fn, {&function}, {&arguments},
{getInvocation()});
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Analysis/BasicCalleeAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ static FunctionTest IsDeinitBarrierTest("is-deinit-barrier", [](auto &function,
auto *instruction = arguments.takeInstruction();
auto *analysis = test.template getAnalysis<BasicCalleeAnalysis>();
auto isBarrier = isDeinitBarrier(instruction, analysis);
instruction->dump();
instruction->print(llvm::outs());
auto *boolString = isBarrier ? "true" : "false";
llvm::errs() << boolString << "\n";
llvm::outs() << boolString << "\n";
});
} // namespace swift::test
14 changes: 7 additions & 7 deletions lib/SILOptimizer/UtilityPasses/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void TestRunner::printTestLifetime(bool begin, unsigned testIndex,
unsigned testCount, StringRef name,
ArrayRef<StringRef> components) {
StringRef word = begin ? "\nbegin" : "end";
llvm::errs() << word << " running test " << testIndex + 1 << " of "
llvm::outs() << word << " running test " << testIndex + 1 << " of "
<< testCount << " on " << getFunction()->getName() << ": "
<< name << " with: ";
for (unsigned long index = 0, size = components.size(); index < size;
Expand All @@ -86,18 +86,18 @@ void TestRunner::printTestLifetime(bool begin, unsigned testIndex,
if (componentString.empty())
continue;

llvm::errs() << componentString;
llvm::outs() << componentString;
if (index != size - 1) {
llvm::errs() << ", ";
llvm::outs() << ", ";
}
}
llvm::errs() << "\n";
llvm::outs() << "\n";
}

void TestRunner::runTest(StringRef name, Arguments &arguments) {
auto *test = FunctionTest::get(name);
if (!test) {
llvm::errs() << "No test named: " << name << "\n";
llvm::outs() << "No test named: " << name << "\n";
assert(false && "Invalid test name");
}
auto *function = getFunction();
Expand Down Expand Up @@ -137,15 +137,15 @@ void TestRunner::run() {
// - the function
static FunctionTest DumpFunctionTest("dump-function",
[](auto &function, auto &, auto &) {
function.dump();
function.print(llvm::outs());
});

// Arguments: NONE
// Dumps: the index of the self argument of the current function
static FunctionTest FunctionGetSelfArgumentIndex(
"function-get-self-argument-index", [](auto &function, auto &, auto &) {
auto index = BridgedFunction{&function}.getSelfArgumentIndex();
llvm::errs() << "self argument index = " << index << "\n";
llvm::outs() << "self argument index = " << index << "\n";
});

} // namespace swift::test
Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Utils/CanonicalizeBorrowScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,6 @@ static FunctionTest CanonicalizeBorrowScopeTest(
InstructionDeleter deleter;
CanonicalizeBorrowScope canonicalizer(value->getFunction(), deleter);
canonicalizer.canonicalizeBorrowScope(borrowedValue);
function.dump();
function.print(llvm::outs());
});
} // end namespace swift::test
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Utils/CanonicalizeOSSALifetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ static FunctionTest CanonicalizeOSSALifetimeTest(
calleeAnalysis, deleter);
auto value = arguments.takeValue();
canonicalizer.canonicalizeValueLifetime(value);
function.dump();
function.print(llvm::outs());
});
} // end namespace swift::test

Expand Down
6 changes: 3 additions & 3 deletions lib/SILOptimizer/Utils/InstructionDeleter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ static FunctionTest DeleterDeleteIfDeadTest(
"deleter-delete-if-dead", [](auto &function, auto &arguments, auto &test) {
auto *inst = arguments.takeInstruction();
InstructionDeleter deleter;
llvm::dbgs() << "Deleting-if-dead " << *inst;
llvm::outs() << "Deleting-if-dead " << *inst;
auto deleted = deleter.deleteIfDead(inst);
llvm::dbgs() << "deleteIfDead returned " << deleted << "\n";
function.dump();
llvm::outs() << "deleteIfDead returned " << deleted << "\n";
function.print(llvm::outs());
});
} // namespace swift::test

Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Utils/LexicalDestroyFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,6 @@ static FunctionTest LexicalDestroyFoldingTest(
auto *bbi = cast<BeginBorrowInst>(value);
InstructionDeleter deleter;
foldDestroysOfCopiedLexicalBorrow(bbi, *domTree, deleter);
function.dump();
function.print(llvm::outs());
});
} // end namespace swift::test
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Utils/LexicalDestroyHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,6 @@ static FunctionTest LexicalDestroyHoistingTest(
auto value = arguments.takeValue();
hoistDestroysOfOwnedLexicalValue(value, *value->getFunction(), deleter,
calleeAnalysis);
function.dump();
function.print(llvm::outs());
});
} // end namespace swift::test
Loading