Skip to content

Commit

Permalink
Merge pull request #39473 from apple/rebranch
Browse files Browse the repository at this point in the history
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
  • Loading branch information
shahmishal committed Oct 11, 2021
2 parents 0f73410 + adf8ba3 commit c2fd49c
Show file tree
Hide file tree
Showing 183 changed files with 1,039 additions and 648 deletions.
2 changes: 1 addition & 1 deletion benchmark/scripts/compare_perf_tests.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ===--- compare_perf_tests.py -------------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion benchmark/scripts/test_Benchmark_Driver.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ===--- test_Benchmark_Driver.py ----------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion benchmark/scripts/test_compare_perf_tests.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ===--- test_compare_perf_tests.py --------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion benchmark/scripts/test_utils.py
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# ===--- test_utils.py ---------------------------------------------------===//
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/ASTWalker.h
Expand Up @@ -13,6 +13,7 @@
#ifndef SWIFT_AST_ASTWALKER_H
#define SWIFT_AST_ASTWALKER_H

#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerUnion.h"
#include <utility>

Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Expand Up @@ -528,6 +528,8 @@ ERROR(sil_invalid_column_in_sil_location,none,
"column number must be a positive integer", ())
ERROR(sil_invalid_scope_slot,none,
"scope number must be a positive integer ", ())
ERROR(sil_invalid_constant,none,
"constant operand must be an integer literal ", ())
ERROR(sil_scope_undeclared,none,
"scope number %0 needs to be declared before first use", (unsigned))
ERROR(sil_scope_redefined,none,
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/Identifier.h
Expand Up @@ -20,6 +20,7 @@
#include "swift/Basic/EditorPlaceholder.h"
#include "swift/Basic/Debug.h"
#include "swift/Basic/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/Support/TrailingObjects.h"
Expand Down
9 changes: 9 additions & 0 deletions include/swift/AST/Module.h
Expand Up @@ -257,6 +257,9 @@ class ModuleDecl

AccessNotesFile accessNotes;

/// Used by the debugger to bypass resilient access to fields.
bool BypassResilience = false;

ModuleDecl(Identifier name, ASTContext &ctx, ImplicitImportInfo importInfo);

public:
Expand Down Expand Up @@ -290,6 +293,12 @@ class ModuleDecl
AccessNotesFile &getAccessNotes() { return accessNotes; }
const AccessNotesFile &getAccessNotes() const { return accessNotes; }

/// Return whether the module was imported with resilience disabled. The
/// debugger does this to access private fields.
bool getBypassResilience() const { return BypassResilience; }
/// Only to be called by MemoryBufferSerializedModuleLoader.
void setBypassResilience() { BypassResilience = true; }

ArrayRef<FileUnit *> getFiles() {
assert(!Files.empty() || failedToLoad());
return Files;
Expand Down
1 change: 1 addition & 0 deletions include/swift/AST/Ownership.h
Expand Up @@ -26,6 +26,7 @@
#include "llvm/Support/raw_ostream.h"
#include <stdint.h>
#include <assert.h>
#include <climits>

namespace swift {

Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/TBDGenRequests.h
Expand Up @@ -70,7 +70,7 @@ class TBDGenDescriptor final {
const TBDGenOptions &getOptions() const { return Opts; }
TBDGenOptions &getOptions() { return Opts; }

const llvm::DataLayout &getDataLayout() const;
const StringRef getDataLayoutString() const;
const llvm::Triple &getTarget() const;

bool operator==(const TBDGenDescriptor &other) const;
Expand Down
1 change: 1 addition & 0 deletions include/swift/Basic/BlotSetVector.h
Expand Up @@ -15,6 +15,7 @@

#include "swift/Basic/LLVM.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions include/swift/Basic/MultiMapCache.h
Expand Up @@ -14,6 +14,7 @@
#define SWIFT_BASIC_MULTIMAPCACHE_H

#include "swift/Basic/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"

namespace swift {
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Basic/Platform.h
Expand Up @@ -16,7 +16,7 @@
#include "swift/Basic/LLVM.h"
#include "swift/Config.h"
#include "llvm/ADT/StringRef.h"
#include "clang/Driver/DarwinSDKInfo.h"
#include "clang/Basic/DarwinSDKInfo.h"

namespace llvm {
class Triple;
Expand Down Expand Up @@ -105,7 +105,7 @@ namespace swift {
getSwiftRuntimeCompatibilityVersionForTarget(const llvm::Triple &Triple);

/// Retrieve the target SDK version for the given SDKInfo and target triple.
llvm::VersionTuple getTargetSDKVersion(clang::driver::DarwinSDKInfo &SDKInfo,
llvm::VersionTuple getTargetSDKVersion(clang::DarwinSDKInfo &SDKInfo,
const llvm::Triple &triple);

/// Get SDK build version.
Expand Down
1 change: 1 addition & 0 deletions include/swift/Basic/Version.h
Expand Up @@ -25,6 +25,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/VersionTuple.h"
#include <array>
#include <string>

namespace swift {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/LLVMPasses/Passes.h
Expand Up @@ -34,7 +34,7 @@ namespace swift {
using AAResultBase::getModRefInfo;
llvm::ModRefInfo getModRefInfo(const llvm::CallBase *Call,
const llvm::MemoryLocation &Loc) {
llvm::AAQueryInfo AAQI;
llvm::SimpleAAQueryInfo AAQI;
return getModRefInfo(Call, Loc, AAQI);
}
llvm::ModRefInfo getModRefInfo(const llvm::CallBase *Call,
Expand Down
1 change: 1 addition & 0 deletions include/swift/SIL/Notifications.h
Expand Up @@ -17,6 +17,7 @@
#include "swift/Basic/STLExtras.h"
#include "llvm/ADT/PointerUnion.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include <memory>

namespace swift {
Expand Down
28 changes: 24 additions & 4 deletions include/swift/SIL/SILBuilder.h
Expand Up @@ -363,16 +363,34 @@ class SILBuilder {
// SILInstruction Creation Methods
//===--------------------------------------------------------------------===//

/// Substitute anonymous function arguments with "_$ArgNo".
Optional<SILDebugVariable>
substituteAnonymousArgs(llvm::SmallString<4> Name,
Optional<SILDebugVariable> Var, SILLocation Loc) {
if (!Var || !Var->ArgNo || !Var->Name.empty())
return Var;

auto *VD = Loc.getAsASTNode<VarDecl>();
if (VD && !VD->getName().empty())
return Var;

llvm::raw_svector_ostream(Name) << '_' << (Var->ArgNo - 1);
Var->Name = Name;
return Var;
}

AllocStackInst *createAllocStack(SILLocation Loc, SILType elementType,
Optional<SILDebugVariable> Var = None,
bool hasDynamicLifetime = false,
bool isLexical = false) {
llvm::SmallString<4> Name;
Loc.markAsPrologue();
assert((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) &&
"location is a VarDecl, but SILDebugVariable is empty");
return insert(AllocStackInst::create(getSILDebugLocation(Loc), elementType,
getFunction(), Var, hasDynamicLifetime,
isLexical));
return insert(AllocStackInst::create(
getSILDebugLocation(Loc), elementType, getFunction(),
substituteAnonymousArgs(Name, Var, Loc), hasDynamicLifetime,
isLexical));
}

AllocRefInst *createAllocRef(SILLocation Loc, SILType ObjectType,
Expand Down Expand Up @@ -402,11 +420,13 @@ class SILBuilder {
AllocBoxInst *createAllocBox(SILLocation Loc, CanSILBoxType BoxType,
Optional<SILDebugVariable> Var = None,
bool hasDynamicLifetime = false) {
llvm::SmallString<4> Name;
Loc.markAsPrologue();
assert((!dyn_cast_or_null<VarDecl>(Loc.getAsASTNode<Decl>()) || Var) &&
"location is a VarDecl, but SILDebugVariable is empty");
return insert(AllocBoxInst::create(getSILDebugLocation(Loc), BoxType, *F,
Var, hasDynamicLifetime));
substituteAnonymousArgs(Name, Var, Loc),
hasDynamicLifetime));
}

AllocExistentialBoxInst *
Expand Down
49 changes: 45 additions & 4 deletions include/swift/SIL/SILDebugInfoExpression.h
Expand Up @@ -18,6 +18,7 @@
#ifndef SWIFT_SIL_DEBUGINFOEXPRESSION_H
#define SWIFT_SIL_DEBUGINFOEXPRESSION_H
#include "swift/AST/Decl.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/iterator_range.h"
Expand All @@ -36,17 +37,30 @@ enum class SILDIExprOperator : unsigned {
/// VarDecl operand pointing to the field declaration.
/// Note that this directive can only appear at the end of an
/// expression.
Fragment
Fragment,
/// Perform arithmetic addition on the top two elements of the
/// expression stack and push the result back to the stack.
Plus,
/// Subtract the top element in expression stack by the second
/// element. Then push the result back to the stack.
Minus,
/// Push an unsigned integer constant onto the stack.
ConstUInt,
/// Push a signed integer constant onto the stack.
ConstSInt
};

/// Represents a single component in a debug info expression.
/// Including operator and operand.
struct SILDIExprElement {
enum Kind {
/// A di-expression operator
/// A di-expression operator.
OperatorKind,
/// An operand that has declaration type
DeclKind
/// An operand that has declaration type.
DeclKind,
/// An integer constant value. Note that
/// we don't specify its signedness here.
ConstIntKind
};

private:
Expand All @@ -55,6 +69,7 @@ struct SILDIExprElement {
union {
SILDIExprOperator Operator;
Decl *Declaration;
uint64_t ConstantInt;
};

explicit SILDIExprElement(Kind OpK) : OpKind(OpK) {}
Expand All @@ -68,6 +83,13 @@ struct SILDIExprElement {

Decl *getAsDecl() const { return OpKind == DeclKind ? Declaration : nullptr; }

Optional<uint64_t> getAsConstInt() const {
if (OpKind == ConstIntKind)
return ConstantInt;
else
return {};
}

static SILDIExprElement createOperator(SILDIExprOperator Op) {
SILDIExprElement DIOp(OperatorKind);
DIOp.Operator = Op;
Expand All @@ -79,6 +101,12 @@ struct SILDIExprElement {
DIOp.Declaration = D;
return DIOp;
}

static SILDIExprElement createConstInt(uint64_t V) {
SILDIExprElement DIOp(ConstIntKind);
DIOp.ConstantInt = V;
return DIOp;
}
};

/// For a given SILDIExprOperator, provides information
Expand Down Expand Up @@ -231,6 +259,19 @@ class SILDebugInfoExpression {

/// Create a op_fragment expression
static SILDebugInfoExpression createFragment(VarDecl *Field);

/// Return true if this DIExpression starts with op_deref
bool startsWithDeref() const {
return Elements.size() &&
Elements[0].getAsOperator() == SILDIExprOperator::Dereference;
}

/// Return true if this DIExpression has op_fragment (at the end)
bool hasFragment() const {
return Elements.size() >= 2 &&
Elements[Elements.size() - 2].getAsOperator() ==
SILDIExprOperator::Fragment;
}
};
} // end namespace swift
#endif
12 changes: 5 additions & 7 deletions include/swift/SIL/SILInstruction.h
Expand Up @@ -1810,13 +1810,11 @@ class TailAllocatedDebugVariable {
if (!Bits.Data.HasValue)
return None;

if (VD)
return SILDebugVariable(VD->getName().empty() ? "" : VD->getName().str(),
VD->isLet(), getArgNo(), isImplicit(), AuxVarType,
DeclLoc, DeclScope, DIExprElements);
else
return SILDebugVariable(getName(buf), isLet(), getArgNo(), isImplicit(),
AuxVarType, DeclLoc, DeclScope, DIExprElements);
StringRef name = getName(buf);
if (VD && name.empty())
name = VD->getName().str();
return SILDebugVariable(name, isLet(), getArgNo(), isImplicit(), AuxVarType,
DeclLoc, DeclScope, DIExprElements);
}
};
static_assert(sizeof(TailAllocatedDebugVariable) == 4,
Expand Down
5 changes: 4 additions & 1 deletion include/swift/SIL/SILInstructionWorklist.h
Expand Up @@ -37,6 +37,7 @@
#include "swift/SIL/SILInstruction.h"
#include "swift/SIL/InstructionUtils.h"
#include "swift/SIL/SILValue.h"
#include "swift/SILOptimizer/Utils/DebugOptUtils.h"
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
Expand Down Expand Up @@ -309,7 +310,9 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
void eraseInstFromFunction(SILInstruction &instruction,
SILBasicBlock::iterator &iterator,
bool addOperandsToWorklist = true) {
// Delete any debug users first.
// Try to salvage debug info first.
swift::salvageDebugInfo(&instruction);
// Then delete old debug users.
for (auto result : instruction.getResults()) {
while (!result->use_empty()) {
auto *user = result->use_begin()->getUser();
Expand Down
13 changes: 8 additions & 5 deletions include/swift/Serialization/SerializedModuleLoader.h
Expand Up @@ -263,9 +263,11 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
MemoryBufferSerializedModuleLoader(ASTContext &ctx,
DependencyTracker *tracker,
ModuleLoadingMode loadMode,
bool IgnoreSwiftSourceInfo)
bool IgnoreSwiftSourceInfo,
bool BypassResilience)
: SerializedModuleLoaderBase(ctx, tracker, loadMode,
IgnoreSwiftSourceInfo) {}
IgnoreSwiftSourceInfo),
BypassResilience(BypassResilience) {}

std::error_code findModuleFilesInDirectory(
ImportPath::Element ModuleID,
Expand All @@ -281,6 +283,7 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
StringRef moduleName,
const SerializedModuleBaseName &BaseName) override;

bool BypassResilience;
public:
virtual ~MemoryBufferSerializedModuleLoader();

Expand Down Expand Up @@ -310,10 +313,10 @@ class MemoryBufferSerializedModuleLoader : public SerializedModuleLoaderBase {
static std::unique_ptr<MemoryBufferSerializedModuleLoader>
create(ASTContext &ctx, DependencyTracker *tracker = nullptr,
ModuleLoadingMode loadMode = ModuleLoadingMode::PreferSerialized,
bool IgnoreSwiftSourceInfo = false) {
bool IgnoreSwiftSourceInfo = false, bool BypassResilience = false) {
return std::unique_ptr<MemoryBufferSerializedModuleLoader>{
new MemoryBufferSerializedModuleLoader(ctx, tracker, loadMode,
IgnoreSwiftSourceInfo)};
new MemoryBufferSerializedModuleLoader(
ctx, tracker, loadMode, IgnoreSwiftSourceInfo, BypassResilience)};
}
};

Expand Down
5 changes: 3 additions & 2 deletions include/swift/Syntax/AbsoluteRawSyntax.h
Expand Up @@ -16,6 +16,8 @@
#include "swift/Basic/SourceLoc.h"
#include "swift/Syntax/RawSyntax.h"

#include "llvm/ADT/STLForwardCompat.h"

namespace swift {
namespace syntax {

Expand Down Expand Up @@ -388,8 +390,7 @@ class OptionalStorage<AbsoluteRawSyntax> {
OptionalStorage(OptionalStorage &&other) = default;

template <class... ArgTypes>
explicit OptionalStorage(llvm::optional_detail::in_place_t,
ArgTypes &&...Args)
explicit OptionalStorage(llvm::in_place_t, ArgTypes &&...Args)
: Storage(std::forward<ArgTypes>(Args)...) {}

void reset() { Storage = AbsoluteRawSyntax(nullptr); }
Expand Down

0 comments on commit c2fd49c

Please sign in to comment.