mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
NOTE: debug_value [moved] appearing in the source code implies a _move was
used. So this will not effect current stable swift code.
This is just a first version of this that I am using to commit/bring up tests
for IRGen supporting a full dataflow version of this patch.
Big picture is that there is a bunch of work that is done in the LLVM level in
the coroutine splitter to work around communicating live variables in the
various coroutine func-lets. This logic is all done with debug.declare and we
would need to update that logic in the coroutine splitter to handle
debug.addr. Rather than do this, after some conversation, AdrianP and I realized
that we could get the same effect of a debug.declare by just redeclaring the
current live set of debug_value after each possible coroutine funclet start. To
do this in full generality, we need a full dataflow but just to bring this up we
initially perform a dominance propagation algorithm of the following sort:
1. We walk the CFG along successors. By doing this we guarantee that we visit
blocks after their dominators.
2. When we visit a block, we walk the block from start->end. During this walk:
a. We grab a new block state from the centralized block->blockState map. This
state is a [SILDebugVariable : DebugValueInst].
b. If we see a debug_value, we map blockState[debug_value.getDbgVar()] =
debug_value. This ensures that when we get to the bottom of the block, we
have pairs of SILDebugVariable + last debug_value on it.
c. If we see any coroutine funclet boundaries, we clone the current tracked
set of our block state and then walk up the dom tree dumping in each block
any debug_value with a SILDebugVariable that we have not already
dumped. This is maintained by using a visited set of SILDebugVariable for
each funclet boundary.
The end result is that at the beginning of each funclet we will basically
declare the debug info for an addr.
This is insufficient of course for moves that are in conditional control flow,
e.x.:
```
let x = Klass()
if boolValue {
await asyncCall()
let _ = _move(x)
}
```
but this at least lets me begin to write tests for this in lldb using straight
line code and work out the rest of the issues in CodeGen using those tests.
110 lines
4.0 KiB
C++
110 lines
4.0 KiB
C++
//===--- SILDebugVariable.h -----------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2021 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_SIL_SILDEBUGVARIABLE_H
|
|
#define SWIFT_SIL_SILDEBUGVARIABLE_H
|
|
|
|
#include "swift/Basic/LLVM.h"
|
|
#include "swift/SIL/SILDebugInfoExpression.h"
|
|
#include "swift/SIL/SILLocation.h"
|
|
#include "swift/SIL/SILType.h"
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
namespace swift {
|
|
|
|
class AllocationInst;
|
|
|
|
/// Holds common debug information about local variables and function
|
|
/// arguments that are needed by DebugValueInst, AllocStackInst,
|
|
/// and AllocBoxInst.
|
|
struct SILDebugVariable;
|
|
inline llvm::hash_code hash_value(const SILDebugVariable &P);
|
|
|
|
/// Holds common debug information about local variables and function
|
|
/// arguments that are needed by DebugValueInst, AllocStackInst,
|
|
/// and AllocBoxInst.
|
|
struct SILDebugVariable {
|
|
friend llvm::hash_code hash_value(const SILDebugVariable &P);
|
|
|
|
StringRef Name;
|
|
unsigned ArgNo : 16;
|
|
unsigned Constant : 1;
|
|
unsigned Implicit : 1;
|
|
unsigned isDenseMapSingleton : 2;
|
|
Optional<SILType> Type;
|
|
Optional<SILLocation> Loc;
|
|
const SILDebugScope *Scope;
|
|
SILDebugInfoExpression DIExpr;
|
|
|
|
// Use vanilla copy ctor / operator
|
|
SILDebugVariable(const SILDebugVariable &) = default;
|
|
SILDebugVariable &operator=(const SILDebugVariable &) = default;
|
|
|
|
enum class IsDenseMapSingleton { No, IsEmpty, IsTombstone };
|
|
SILDebugVariable(IsDenseMapSingleton inputIsDenseMapSingleton)
|
|
: SILDebugVariable() {
|
|
assert(inputIsDenseMapSingleton != IsDenseMapSingleton::No &&
|
|
"Should only pass IsEmpty or IsTombstone");
|
|
isDenseMapSingleton = unsigned(inputIsDenseMapSingleton);
|
|
}
|
|
|
|
SILDebugVariable()
|
|
: ArgNo(0), Constant(false), Implicit(false), isDenseMapSingleton(0),
|
|
Scope(nullptr) {}
|
|
SILDebugVariable(bool Constant, uint16_t ArgNo)
|
|
: ArgNo(ArgNo), Constant(Constant), Implicit(false),
|
|
isDenseMapSingleton(0), Scope(nullptr) {}
|
|
SILDebugVariable(StringRef Name, bool Constant, unsigned ArgNo,
|
|
bool IsImplicit = false, Optional<SILType> AuxType = {},
|
|
Optional<SILLocation> DeclLoc = {},
|
|
const SILDebugScope *DeclScope = nullptr,
|
|
llvm::ArrayRef<SILDIExprElement> ExprElements = {})
|
|
: Name(Name), ArgNo(ArgNo), Constant(Constant), Implicit(IsImplicit),
|
|
isDenseMapSingleton(0), Type(AuxType), Loc(DeclLoc), Scope(DeclScope),
|
|
DIExpr(ExprElements) {}
|
|
|
|
/// Created from either AllocStack or AllocBox instruction
|
|
static Optional<SILDebugVariable>
|
|
createFromAllocation(const AllocationInst *AI);
|
|
|
|
// We're not comparing DIExpr here because strictly speaking,
|
|
// DIExpr is not part of the debug variable. We simply piggyback
|
|
// it in this class so that's it's easier to carry DIExpr around.
|
|
bool operator==(const SILDebugVariable &V) const {
|
|
return ArgNo == V.ArgNo && Constant == V.Constant && Name == V.Name &&
|
|
Implicit == V.Implicit && Type == V.Type && Loc == V.Loc &&
|
|
Scope == V.Scope && isDenseMapSingleton == V.isDenseMapSingleton &&
|
|
DIExpr == V.DIExpr;
|
|
}
|
|
|
|
SILDebugVariable withoutDIExpr() const {
|
|
auto result = *this;
|
|
result.DIExpr = {};
|
|
return result;
|
|
}
|
|
|
|
bool isLet() const { return Name.size() && Constant; }
|
|
|
|
bool isVar() const { return Name.size() && !Constant; }
|
|
};
|
|
|
|
/// Returns the hashcode for the new projection path.
|
|
inline llvm::hash_code hash_value(const SILDebugVariable &P) {
|
|
return llvm::hash_combine(P.ArgNo, P.Constant, P.Name, P.Implicit,
|
|
P.isDenseMapSingleton, P.Type, P.Loc, P.Scope,
|
|
P.DIExpr);
|
|
}
|
|
|
|
} // namespace swift
|
|
|
|
#endif
|