Files
swift-mirror/lib/SIL/Utils/DebugUtils.cpp
Michael Gottesman e1a19e4173 [sil] Split library into subfolders, while still building as a single library still.
Specifically, I split it into 3 initial categories: IR, Utils, Verifier. I just
did this quickly, we can always split it more later if we want.

I followed the model that we use in SILOptimizer: ./lib/SIL/CMakeLists.txt vends
 a macro (sil_register_sources) to the sub-folders that register the sources of
 the subdirectory with a global state variable that ./lib/SIL/CMakeLists.txt
 defines. Then after including those subdirs, the parent cmake declares the SIL
 library. So the output is the same, but we have the flexibility of having
 subdirectories to categorize source files.
2020-03-30 11:01:00 -07:00

67 lines
2.0 KiB
C++

//===--- DebugUtils.cpp ---------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/SIL/DebugUtils.h"
#include "swift/Basic/STLExtras.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILInstruction.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallPtrSet.h"
using namespace swift;
bool swift::hasNonTrivialNonDebugTransitiveUsers(
PointerUnion<SILInstruction *, SILArgument *> V) {
llvm::SmallVector<SILInstruction *, 8> Worklist;
llvm::SmallPtrSet<SILInstruction *, 8> SeenInsts;
// Initialize our worklist.
if (auto *A = V.dyn_cast<SILArgument *>()) {
for (Operand *Op : getNonDebugUses(SILValue(A))) {
auto *User = Op->getUser();
if (!SeenInsts.insert(User).second)
continue;
Worklist.push_back(User);
}
} else {
auto *I = V.get<SILInstruction *>();
SeenInsts.insert(I);
Worklist.push_back(I);
}
while (!Worklist.empty()) {
SILInstruction *U = Worklist.pop_back_val();
assert(SeenInsts.count(U) &&
"Worklist should only contain seen instructions?!");
// If U is a terminator inst, return false.
if (isa<TermInst>(U))
return true;
// If U has side effects...
if (U->mayHaveSideEffects())
return true;
// Otherwise add all non-debug uses of I that we have not seen yet to the
// worklist.
for (SILValue Result : U->getResults()) {
for (Operand *I : getNonDebugUses(Result)) {
auto *User = I->getUser();
if (!SeenInsts.insert(User).second)
continue;
Worklist.push_back(User);
}
}
}
return false;
}