Skip to content

Commit 5210c3b

Browse files
authored
Merge pull request swiftlang#35663 from apple/pr-rebranch
Support new changes from swift/rebranch on llvm-project repo
2 parents 8ee108a + bfa06c3 commit 5210c3b

File tree

148 files changed

+643
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+643
-358
lines changed

cmake/modules/SwiftSharedCMakeConfig.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ macro(swift_common_standalone_build_config_llvm product)
9797
endif()
9898
endif()
9999

100+
if(LLVM_ENABLE_ZLIB)
101+
find_package(ZLIB REQUIRED)
102+
endif()
103+
100104
include(AddLLVM)
101105
include(AddSwiftTableGen) # This imports TableGen from LLVM.
102106
include(HandleLLVMOptions)

include/swift/ABI/TrailingObjects.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
#define SWIFT_ABI_TRAILINGOBJECTS_H
5757

5858
#include "llvm/Support/Alignment.h"
59-
#include "llvm/Support/AlignOf.h"
6059
#include "llvm/Support/Compiler.h"
6160
#include "llvm/Support/MathExtras.h"
6261
#include "llvm/Support/type_traits.h"

include/swift/AST/FineGrainedDependencyFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef SWIFT_AST_FINEGRAINEDDEPENDENCYFORMAT_H
1414
#define SWIFT_AST_FINEGRAINEDDEPENDENCYFORMAT_H
1515

16-
#include "llvm/Bitcode/RecordLayout.h"
16+
#include "llvm/Bitcode/BitcodeConvenience.h"
1717
#include "llvm/Bitstream/BitCodes.h"
1818

1919
namespace llvm {

include/swift/Basic/AnyValue.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ namespace llvm {
3030
return hash_value(ptr.getOpaqueValue());
3131
}
3232

33-
// FIXME: Belongs in LLVM itself
34-
template<typename T>
35-
hash_code hash_value(const llvm::Optional<T> &opt) {
36-
if (!opt)
37-
return 1;
38-
return hash_value(*opt);
39-
}
40-
4133
template<typename T>
4234
bool operator==(const TinyPtrVector<T> &lhs, const TinyPtrVector<T> &rhs) {
4335
if (lhs.size() != rhs.size())

include/swift/Basic/DiagnosticOptions.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class DiagnosticOptions {
4141
/// Indicates whether diagnostic passes should be skipped.
4242
bool SkipDiagnosticPasses = false;
4343

44+
/// Additional non-source files which will have diagnostics emitted in them,
45+
/// and which should be scanned for expectations by the diagnostic verifier.
46+
std::vector<std::string> AdditionalVerifierFiles;
47+
4448
/// Keep emitting subsequent diagnostics after a fatal error.
4549
bool ShowDiagnosticsAfterFatalError = false;
4650

@@ -54,22 +58,23 @@ class DiagnosticOptions {
5458
/// Treat all warnings as errors
5559
bool WarningsAsErrors = false;
5660

57-
// When printing diagnostics, include the diagnostic name at the end
61+
/// When printing diagnostics, include the diagnostic name (diag::whatever) at
62+
/// the end.
5863
bool PrintDiagnosticNames = false;
5964

6065
/// If set to true, include educational notes in printed output if available.
6166
/// Educational notes are documentation which supplement diagnostics.
6267
bool PrintEducationalNotes = false;
6368

64-
// If set to true, use the more descriptive experimental formatting style for
65-
// diagnostics.
69+
/// Whether to emit diagnostics in the terse LLVM style or in a more
70+
/// descriptive style that's specific to Swift (currently experimental).
6671
FormattingStyle PrintedFormattingStyle = FormattingStyle::LLVM;
6772

6873
std::string DiagnosticDocumentationPath = "";
6974

7075
std::string LocalizationCode = "";
7176

72-
// Diagnostic messages directory path.
77+
/// Path to a directory of diagnostic localization tables.
7378
std::string LocalizationPath = "";
7479

7580
/// Return a hash code of any components from these options that should

include/swift/ClangImporter/SwiftAbstractBasicWriter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class DataStreamBasicWriter
4444
public:
4545
using super::asImpl;
4646

47+
DataStreamBasicWriter(clang::ASTContext &ctx) : super(ctx) {}
48+
4749
/// Perform all the calls necessary to write out the given type.
4850
void writeTypeRef(const clang::Type *type) {
4951
asImpl().writeUInt64(uint64_t(type->getTypeClass()));

include/swift/Frontend/DiagnosticVerifier.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class DiagnosticVerifier : public DiagnosticConsumer {
6565
SourceManager &SM;
6666
std::vector<CapturedDiagnosticInfo> CapturedDiagnostics;
6767
ArrayRef<unsigned> BufferIDs;
68+
SmallVector<unsigned, 4> AdditionalBufferIDs;
6869
bool AutoApplyFixes;
6970
bool IgnoreUnknown;
7071

@@ -74,6 +75,10 @@ class DiagnosticVerifier : public DiagnosticConsumer {
7475
: SM(SM), BufferIDs(BufferIDs), AutoApplyFixes(AutoApplyFixes),
7576
IgnoreUnknown(IgnoreUnknown) {}
7677

78+
void appendAdditionalBufferID(unsigned bufferID) {
79+
AdditionalBufferIDs.push_back(bufferID);
80+
}
81+
7782
virtual void handleDiagnostic(SourceManager &SM,
7883
const DiagnosticInfo &Info) override;
7984

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,11 @@ class CompilerInstance {
558558
bool setUpInputs();
559559
bool setUpASTContextIfNeeded();
560560
void setupStatsReporter();
561-
void setupDiagnosticVerifierIfNeeded();
562561
void setupDependencyTrackerIfNeeded();
562+
563+
/// \return false if successsful, true on error.
564+
bool setupDiagnosticVerifierIfNeeded();
565+
563566
Optional<unsigned> setUpCodeCompletionBuffer();
564567

565568
/// Find a buffer for a given input file and ensure it is recorded in

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def tbd_is_installapi: Flag<["-"], "tbd-is-installapi">,
101101
def verify : Flag<["-"], "verify">,
102102
HelpText<"Verify diagnostics against expected-{error|warning|note} "
103103
"annotations">;
104+
def verify_additional_file : Separate<["-"], "verify-additional-file">,
105+
HelpText<"Verify diagnostics in this file in addition to source files">;
104106
def verify_apply_fixes : Flag<["-"], "verify-apply-fixes">,
105107
HelpText<"Like -verify, but updates the original source file">;
106108
def verify_ignore_unknown: Flag<["-"], "verify-ignore-unknown">,

include/swift/SIL/CFG.h

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@
1919
#define SWIFT_SIL_CFG_H
2020

2121
#include "swift/SIL/SILFunction.h"
22+
#include "swift/SIL/SILValue.h"
2223
#include "llvm/ADT/GraphTraits.h"
2324

25+
#if defined(__has_include)
26+
#if __has_include("llvm/Support/CfgTraits.h")
27+
#include "llvm/Support/CfgTraits.h"
28+
#define SWIFT_LLVM_HAS_CFGTRAITS_H
29+
#endif
30+
#endif
31+
2432
namespace llvm {
2533

2634
//===----------------------------------------------------------------------===//
@@ -119,6 +127,99 @@ template <> struct GraphTraits<Inverse<swift::SILFunction*> >
119127
static unsigned size(GraphType F) { return F.Graph->size(); }
120128
};
121129

130+
#ifdef SWIFT_LLVM_HAS_CFGTRAITS_H
131+
132+
class SILCfgTraitsBase : public CfgTraitsBase {
133+
public:
134+
using ParentType = swift::SILFunction;
135+
using BlockRef = swift::SILBasicBlock *;
136+
using ValueRef = swift::SILInstruction *;
137+
138+
static CfgBlockRef wrapRef(BlockRef block) {
139+
return makeOpaque<CfgBlockRefTag>(block);
140+
}
141+
static CfgValueRef wrapRef(ValueRef block) {
142+
return makeOpaque<CfgValueRefTag>(block);
143+
}
144+
static BlockRef unwrapRef(CfgBlockRef block) {
145+
return static_cast<BlockRef>(getOpaque(block));
146+
}
147+
static ValueRef unwrapRef(CfgValueRef block) {
148+
return static_cast<ValueRef>(getOpaque(block));
149+
}
150+
};
151+
/// \brief CFG traits for SIL IR.
152+
class SILCfgTraits : public CfgTraits<SILCfgTraitsBase, SILCfgTraits> {
153+
public:
154+
explicit SILCfgTraits(swift::SILFunction * /*parent*/) {}
155+
156+
static swift::SILFunction *getBlockParent(swift::SILBasicBlock *block) {
157+
return block->getParent();
158+
}
159+
160+
static auto predecessors(swift::SILBasicBlock *block) {
161+
return block->getPredecessorBlocks();
162+
}
163+
static auto successors(swift::SILBasicBlock *block) {
164+
return block->getSuccessors();
165+
}
166+
167+
/// Get the defining block of a value if it is an instruction, or null
168+
/// otherwise.
169+
static BlockRef getValueDefBlock(ValueRef value) {
170+
if (auto *instruction = dyn_cast<swift::SILInstruction>(value))
171+
return instruction->getParent();
172+
return nullptr;
173+
}
174+
175+
struct block_iterator
176+
: iterator_adaptor_base<block_iterator, swift::SILFunction::iterator> {
177+
using Base = iterator_adaptor_base<block_iterator, swift::SILFunction::iterator>;
178+
179+
block_iterator() = default;
180+
181+
explicit block_iterator(swift::SILFunction::iterator i) : Base(i) {}
182+
183+
swift::SILBasicBlock *operator*() const { return &Base::operator*(); }
184+
};
185+
186+
static iterator_range<block_iterator> blocks(swift::SILFunction *function) {
187+
return {block_iterator(function->begin()), block_iterator(function->end())};
188+
}
189+
190+
struct value_iterator
191+
: iterator_adaptor_base<value_iterator, swift::SILBasicBlock::iterator> {
192+
using Base = iterator_adaptor_base<value_iterator, swift::SILBasicBlock::iterator>;
193+
194+
value_iterator() = default;
195+
196+
explicit value_iterator(swift::SILBasicBlock::iterator i) : Base(i) {}
197+
198+
ValueRef operator*() const { return &Base::operator*(); }
199+
};
200+
201+
static iterator_range<value_iterator> blockdefs(BlockRef block) {
202+
return {value_iterator(block->begin()), value_iterator(block->end())};
203+
}
204+
struct Printer {
205+
explicit Printer(const SILCfgTraits &) {}
206+
~Printer(){}
207+
208+
void printBlockName(raw_ostream &out, BlockRef block) const {
209+
block->printAsOperand(out);
210+
}
211+
void printValue(raw_ostream &out, ValueRef value) const {
212+
value->print(out);
213+
}
214+
};
215+
};
216+
217+
template <> struct CfgTraitsFor<swift::SILBasicBlock> {
218+
using CfgTraits = SILCfgTraits;
219+
};
220+
221+
#endif
222+
122223
} // end llvm namespace
123224

124225
#endif

0 commit comments

Comments
 (0)