Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
3885d8d
Implement Serialization
kateinoigakukun Jul 3, 2020
0fe440b
Implement encode
kateinoigakukun Jul 3, 2020
082aefd
Implement frontend
kateinoigakukun Jul 3, 2020
2611f8f
Add test case
kateinoigakukun Jul 3, 2020
c702652
Add module block
kateinoigakukun Jul 3, 2020
5cb1e6d
Add frontend mode
kateinoigakukun Jul 3, 2020
08b2fd3
Merge module summary
kateinoigakukun Jul 4, 2020
c23c02a
Add test case
kateinoigakukun Jul 4, 2020
aec688e
Mark dead symbols
kateinoigakukun Jul 4, 2020
ef0ed0a
Serialize live mark
kateinoigakukun Jul 4, 2020
26e0a00
Move option as frontend only
kateinoigakukun Jul 4, 2020
4b919cc
Add -module-summary-path option
kateinoigakukun Jul 4, 2020
6f97373
Add optimize passes
kateinoigakukun Jul 4, 2020
2fd0b68
Add option to sil-opt
kateinoigakukun Jul 4, 2020
16ee0bc
Refactor test case
kateinoigakukun Jul 4, 2020
cfce5cc
Serialize table dispatch info
kateinoigakukun Jul 5, 2020
e659a35
Index function tables
kateinoigakukun Jul 5, 2020
0613f98
Serialize virtual method info
kateinoigakukun Jul 5, 2020
0454a46
Deserialize virtual method info
kateinoigakukun Jul 5, 2020
bb22ed1
Implement table entry elimination
kateinoigakukun Jul 5, 2020
64579b4
Refactoring not to use BasicCalleeAnalysis
kateinoigakukun Jul 18, 2020
643263b
Use mangled identifier for GUID
kateinoigakukun Jul 18, 2020
3a35775
WIP
kateinoigakukun Jul 21, 2020
9462d57
Fix tests
kateinoigakukun Jul 21, 2020
1712034
WIP
kateinoigakukun Jul 21, 2020
ef4e2b5
Pass link
kateinoigakukun Jul 31, 2020
cf1cda3
it works
kateinoigakukun Aug 1, 2020
f645fd2
Collect dependency libraries recursively when the primary is sib
kateinoigakukun Aug 1, 2020
e7930d7
Remove debug prints
kateinoigakukun Aug 1, 2020
03110f8
Manage optimization passes
kateinoigakukun Aug 1, 2020
717f59f
Fix sib format for ClassSubclassScope
kateinoigakukun Aug 2, 2020
1ae41b8
Fix deserializing implicit decl deinit
kateinoigakukun Aug 3, 2020
7abda1d
Add debug options for tracing liveness
kateinoigakukun Aug 3, 2020
6a48ed1
Remove debug print
kateinoigakukun Aug 3, 2020
0631391
[Serialization] Serialize hasCReferences info
kateinoigakukun Aug 5, 2020
07f95d4
Preserve funcs which have @_cdecl or @_silgen_name because they can b…
kateinoigakukun Aug 5, 2020
23071db
[Serialization] Serialize Differentiability WT index sorted
kateinoigakukun Aug 5, 2020
80fd8d1
Refactoring
kateinoigakukun Aug 7, 2020
d54db34
[Prototype] Port refactored versions
kateinoigakukun Aug 11, 2020
60e8b93
[Protoype] Port testing tool
kateinoigakukun Aug 12, 2020
48bf5bf
[Cherry-pick me] Use SILInstructionVisitor pattern
kateinoigakukun Aug 13, 2020
00e2666
[Module Indexer] Index type reference information
kateinoigakukun Aug 13, 2020
c58fb6d
[Cleanup] Remove flagile test case
kateinoigakukun Aug 13, 2020
687ef6f
[Serialization] Serialize type ref information
kateinoigakukun Aug 13, 2020
96d1501
[Prototype] Port upstream test cases
kateinoigakukun Aug 13, 2020
25daa62
[Prototype] Add test case for type addr
kateinoigakukun Aug 13, 2020
8393088
[Prototype] Fix crashing when mangling
kateinoigakukun Aug 14, 2020
34849df
[Prototype] Mark used types and serialize them
kateinoigakukun Aug 14, 2020
639d040
[Prototype] Add test case for type ref marking
kateinoigakukun Aug 14, 2020
8ed15bd
[Prototype] Implement type ref based elimination
kateinoigakukun Aug 15, 2020
f569f7d
[Prototype] Add test for type reference from witness impl
kateinoigakukun Aug 15, 2020
86ac641
[Prototype] Fix vtable type reference
kateinoigakukun Aug 15, 2020
20e3699
[Prototype] Avoid to crash with unclear reason
kateinoigakukun Aug 15, 2020
efa5773
[Prototype] Use nominal type decl instead of canonical type to comput…
kateinoigakukun Aug 15, 2020
bcb98b9
[Prototype] Fix invalid StringRef use
kateinoigakukun Aug 15, 2020
09d81ce
[Prototype] Implement dot export feature
kateinoigakukun Aug 15, 2020
3a7b5f5
[Prototype] Keep call unique
kateinoigakukun Aug 15, 2020
4e9ba8c
[Prototype] Improve dot export stlyle
kateinoigakukun Aug 16, 2020
29c5ef3
[Prototype] Mark main entry function as preserved
kateinoigakukun Aug 16, 2020
e2a20f2
[Prototype] Create Dominator Tree
kateinoigakukun Aug 16, 2020
9400c50
[Prototype] Print dominant instruction size
kateinoigakukun Aug 16, 2020
361daa1
[Prototype] Add table header for dominator list
kateinoigakukun Aug 16, 2020
03f4a05
[Prototype] Implement eager elimination which disable debug print
kateinoigakukun Aug 16, 2020
5d22d4f
[Prototype] Fix swift-module-summary-test link libraries
kateinoigakukun Aug 17, 2020
1dea855
[Prototype] Implement public KeyPath elimination
kateinoigakukun Aug 17, 2020
0810558
[Prototype] Move test suites into LTO directory
kateinoigakukun Aug 17, 2020
20c3f42
[Prototype] Don't preserve public KeyPaths
kateinoigakukun Aug 17, 2020
159ac2b
[Prototype] Serialize instruction size to YAML
kateinoigakukun Aug 18, 2020
89d9b4d
[Prototype] Add dominator tree mode for tools
kateinoigakukun Aug 18, 2020
af4ffc1
[Prototype] Trace whole reachable call path
kateinoigakukun Aug 18, 2020
4446e0b
Merge remote-tracking branch 'katei/katei/prototype-thin-lto' into ka…
kateinoigakukun Aug 18, 2020
179aeb3
Trigger CI
kateinoigakukun Aug 28, 2020
fbeca65
Merge remote-tracking branch 'swiftwasm/swiftwasm' into katei/wasm-th…
kateinoigakukun Nov 9, 2020
16e90d7
Fix bad merge issues
kateinoigakukun Nov 9, 2020
20dd289
Fix test cases for LTO
kateinoigakukun Nov 9, 2020
08c6fd0
[WASM] Run LTO tests on CI
kateinoigakukun Nov 9, 2020
7dd2fa6
Fix -module-summary-path handling between driver and frontend
kateinoigakukun Nov 9, 2020
656ccc7
Accept LLVM BC for LLVM LTO
kateinoigakukun Nov 9, 2020
b3d242f
Minimize diff from upstream
kateinoigakukun Nov 9, 2020
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
3 changes: 3 additions & 0 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class SILOptions {
/// Enable large loadable types IRGen pass.
bool EnableLargeLoadableTypes = true;

/// The path to combined module summary file
std::string ModuleSummaryPath;

/// The name of the file to which the backend should save optimization
/// records.
std::string OptRecordFile;
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Frontend/FrontendOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class FrontendOptions {
/// The path to which we should store indexing data, if any.
std::string IndexStorePath;

/// The path to which we should emit combined module summary file
std::string ModuleSummaryOutputPath;
/// The path to look in when loading a module interface file, to see if a
/// binary module has already been built for use by the compiler.
std::string PrebuiltModuleCachePath;
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,9 @@ def emit_module_summary_path :
Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild,
ArgumentIsPath, SupplementaryOutput]>,
MetaVarName<"<path>">, HelpText<"Output module summary file to <path>">;
def module_summary_path : Separate<["-"], "module-summary-path">,
Flags<[FrontendOption, ArgumentIsPath]>, MetaVarName<"<path>">,
HelpText<"Combined module summary file <path>">;

def emit_module_interface :
Flag<["-"], "emit-module-interface">,
Expand Down
256 changes: 256 additions & 0 deletions include/swift/SIL/ModuleSummary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
//===----- ModuleSummary.h --------------------------------------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2020 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_MODULE_SUMMARY_H
#define SWIFT_SIL_MODULE_SUMMARY_H

#include "swift/AST/Decl.h"
#include "swift/SIL/SILFunction.h"
#include "llvm/Support/YAMLTraits.h"

namespace swift {

namespace modulesummary {

using GUID = uint64_t;

/// Compute globally unique identifier from the symbol.
GUID getGUIDFromUniqueName(llvm::StringRef Name);

/// Function summary information to help callee analysis
class FunctionSummary {
public:
/// Function call information
class Call {
public:
/// Kinds of callee reference.
enum KindTy {
/// The call references a function statically
Direct,
/// The call references a function via a witness table.
Witness,
/// The call references a function via a vtable.
VTable,
kindCount,
};

private:
// For import/export
friend llvm::yaml::MappingTraits<FunctionSummary::Call>;

/// The callee function GUID. This can be a static function or a virtual
/// function GUID.
GUID Callee;
/// The symbol name of the callee function only for debug and test purposes.
std::string Name;
/// Kind of the callee reference.
KindTy Kind;
public:
friend ::llvm::yaml::MappingTraits<Call>;
Call() = default;
Call(GUID callee, std::string name, KindTy kind)
: Callee(callee), Name(name), Kind(kind) {}

KindTy getKind() const { return Kind; }
GUID getCallee() const { return Callee; }
std::string getName() const { return Name; };
};

/// Function state flags
struct FlagsTy {
/// In per-module summary, always false.
/// In combined summary, indicates that the function is live.
bool Live;
/// Indicates that the function must be considered a live root for liveness
/// analysis.
bool Preserved;
};

using CallGraphEdgeListTy = std::vector<Call>;

private:
// For import/export
friend llvm::yaml::MappingTraits<FunctionSummary>;

/// The function identity.
GUID Guid;
/// The function state flags.
FlagsTy Flags;
/// List of Call from this function.
CallGraphEdgeListTy CallGraphEdgeList;
/// The symbol name of the function only for debug and test purposes.
std::string Name;

public:
FunctionSummary() = default;
FunctionSummary(GUID guid)
: Guid(guid), Flags({false, false}), CallGraphEdgeList(), Name("") {}

/// Add a call to the list.
void addCall(Call call) { CallGraphEdgeList.push_back(call); }

/// Return the list of Call from this function
ArrayRef<Call> calls() const { return CallGraphEdgeList; }

bool isLive() const { return Flags.Live; }
void setLive(bool Live) { Flags.Live = Live; }

bool isPreserved() const { return Flags.Preserved; }
void setPreserved(bool Preserved) { Flags.Preserved = Preserved; }

std::string getName() const { return Name; }
void setName(std::string name) { this->Name = name; }

GUID getGUID() const { return Guid; }
};

/// A slot in a set of virtual tables.
struct VFuncSlot {
/// Kinds of table.
enum KindTy {
Witness,
VTable,
kindCount,
};

/// Kind of table.
KindTy Kind;
/// The virtual function GUID.
GUID VFuncID;

VFuncSlot(KindTy Kind, GUID VFuncID) : Kind(Kind), VFuncID(VFuncID) {}
};

struct VFuncImpl {
GUID Guid;
GUID TypeGuid;
};

using FunctionSummaryMapTy = std::map<GUID, std::unique_ptr<FunctionSummary>>;
using VFuncToImplsMapTy = std::map<GUID, std::vector<VFuncImpl>>;

/// Module summary that consists of function summaries and virtual function
/// tables.
class ModuleSummaryIndex {
// For import/export
friend llvm::yaml::MappingTraits<ModuleSummaryIndex>;

/// Map from function GUID to function summary.
FunctionSummaryMapTy FunctionSummaryMap;
/// Map from virtual function GUID to list of implementations for witness
/// tables.
VFuncToImplsMapTy WitnessTableMethodMap;
/// Map from virtual function GUID to list of implementations for vtables.
VFuncToImplsMapTy VTableMethodMap;
/// The symbol name of the module.
std::string Name;

VFuncToImplsMapTy &getVFuncMap(VFuncSlot::KindTy kind) {
switch (kind) {
case VFuncSlot::Witness:
return WitnessTableMethodMap;
case VFuncSlot::VTable:
return VTableMethodMap;
case VFuncSlot::kindCount: {
llvm_unreachable("impossible");
}
}
}
const VFuncToImplsMapTy &getVFuncMap(VFuncSlot::KindTy kind) const {
switch (kind) {
case VFuncSlot::Witness:
return WitnessTableMethodMap;
case VFuncSlot::VTable:
return VTableMethodMap;
case VFuncSlot::kindCount: {
llvm_unreachable("impossible");
}
}
}
public:
friend ::llvm::yaml::MappingTraits<ModuleSummaryIndex>;
ModuleSummaryIndex() = default;

std::string getName() const { return this->Name; }
void setName(std::string name) { this->Name = name; }

/// Add a global value summary.
void addFunctionSummary(std::unique_ptr<FunctionSummary> summary) {
FunctionSummaryMap.insert(
std::make_pair(summary->getGUID(), std::move(summary)));
}

/// Return a FunctionSummary for GUID if it exists, otherwise return nullptr.
FunctionSummary *getFunctionSummary(GUID guid) const {
auto found = FunctionSummaryMap.find(guid);
if (found == FunctionSummaryMap.end()) {
return nullptr;
}
auto &entry = found->second;
return entry.get();
}

/// Record a implementation for the virtual function slot.
void addImplementation(VFuncSlot slot, GUID implGUID, GUID typeGUID) {
VFuncToImplsMapTy &table = getVFuncMap(slot.Kind);
auto found = table.find(slot.VFuncID);
VFuncImpl impl = {implGUID, typeGUID};
if (found == table.end()) {
table.insert(std::make_pair(slot.VFuncID, std::vector<VFuncImpl>{impl}));
return;
}
found->second.push_back(impl);
}

/// Return a list of implementations for the virtual function slot.
ArrayRef<VFuncImpl> getImplementations(VFuncSlot slot) const {
const VFuncToImplsMapTy &table = getVFuncMap(slot.Kind);
auto found = table.find(slot.VFuncID);
if (found == table.end()) {
return ArrayRef<VFuncImpl>();
}
return ArrayRef<VFuncImpl>(found->second);
}

const VFuncToImplsMapTy &getWitnessTableMethodMap() const {
return WitnessTableMethodMap;
}
const VFuncToImplsMapTy &getVTableMethodMap() const {
return VTableMethodMap;
}

FunctionSummaryMapTy::const_iterator functions_begin() const {
return FunctionSummaryMap.begin();
}
FunctionSummaryMapTy::const_iterator functions_end() const {
return FunctionSummaryMap.end();
}
};

/// Compute a \c ModuleSummaryIndex from the given SILModule.
std::unique_ptr<ModuleSummaryIndex> buildModuleSummaryIndex(SILModule &M);

/// Serializes a module summary to the given output file.
///
/// \returns false on success, true on error.
bool writeModuleSummaryIndex(const ModuleSummaryIndex &index,
DiagnosticEngine &diags, StringRef path);

/// Attempt to deserialize the module summary.
///
/// \returns false on success, true on error.
bool loadModuleSummaryIndex(llvm::MemoryBufferRef inputBuffer,
ModuleSummaryIndex &moduleSummary);
} // namespace modulesummary
} // namespace swift

#endif
5 changes: 4 additions & 1 deletion include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -2957,7 +2957,10 @@ class KeyPathPatternComponent {
void visitReferencedFunctionsAndMethods(
std::function<void (SILFunction *)> functionCallBack,
std::function<void (SILDeclRef)> methodCallBack) const;


void clearReferencedFunctions_if(
llvm::function_ref<bool(SILFunction *)> predicate);

void incrementRefCounts() const;
void decrementRefCounts() const;

Expand Down
9 changes: 8 additions & 1 deletion include/swift/SIL/SILProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ class SILProperty : public llvm::ilist_node<SILProperty>,
const Optional<KeyPathPatternComponent> &getComponent() const {
return Component;
}


void clearReferencedFunctions_if(
llvm::function_ref<bool(SILFunction *)> predicate) {
if (Component) {
Component->clearReferencedFunctions_if(predicate);
}
}

void print(SILPrintContext &Ctx) const;
void dump() const;

Expand Down
1 change: 1 addition & 0 deletions include/swift/SILOptimizer/PassManager/PassPipeline.def
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

PASSPIPELINE(Diagnostic, "Guaranteed Passes")
PASSPIPELINE(OwnershipEliminator, "Utility pass to just run the ownership eliminator pass")
PASSPIPELINE(CrossModuleEliminator, "Passes run at -module-summary-path")
PASSPIPELINE(Performance, "Passes run at -O")
PASSPIPELINE(Onone, "Passes run at -Onone")
PASSPIPELINE(InstCount, "Utility pipeline to just run the inst count pass")
Expand Down
2 changes: 2 additions & 0 deletions include/swift/SILOptimizer/PassManager/Passes.def
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ PASS(AccessEnforcementWMO, "access-enforcement-wmo",
"Access Enforcement Whole Module Optimization")
PASS(CrossModuleSerializationSetup, "cross-module-serialization-setup",
"Setup serialization flags for cross-module optimization")
PASS(CrossDeadFunctionElimination, "sil-cross-deadfuncelim",
"Cross Dead Function Elimination")
PASS(AccessSummaryDumper, "access-summary-dump",
"Dump Address Parameter Access Summary")
PASS(AccessedStorageAnalysisDumper, "accessed-storage-analysis-dump",
Expand Down
2 changes: 2 additions & 0 deletions include/swift/SILOptimizer/PassManager/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace swift {
/// Run the SIL ownership eliminator pass on \p M.
bool runSILOwnershipEliminatorPass(SILModule &M);

bool runSILCrossModuleEliminatorPass(SILModule &M);

void runSILOptimizationPassesWithFileSpecification(SILModule &Module,
StringRef FileName);

Expand Down
Loading