Skip to content

Commit

Permalink
Add -enforce-exclusivity option to sil-opt.
Browse files Browse the repository at this point in the history
  • Loading branch information
atrick committed Apr 10, 2017
1 parent 44110e3 commit ecfff06
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/SILOptimizer/exclusivity_static_diagnostics.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all %s -enforce-exclusivity-static=true -diagnose-static-exclusivity -verify | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all %s -enforce-exclusivity=unchecked -diagnose-static-exclusivity -verify | %FileCheck %s

sil_stage raw

Expand Down
53 changes: 48 additions & 5 deletions tools/sil-opt/SILOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include <cstdio>
using namespace swift;

namespace cl = llvm::cl;

namespace {

enum class OptGroup { Unknown, Diagnostics, Performance, Lowering };
Expand Down Expand Up @@ -81,6 +83,28 @@ static llvm::cl::opt<bool>
EnableSILOpaqueValues("enable-sil-opaque-values",
llvm::cl::desc("Compile the module with sil-opaque-values enabled."));

namespace {
enum EnforceExclusivityMode {
Unchecked, // static only
Checked, // static and dynamic
DynamicOnly,
None
};
}

static cl::opt<EnforceExclusivityMode> EnforceExclusivity(
"enforce-exclusivity", cl::desc("Enforce law of exclusivity "
"(and support memory access markers)."),
cl::init(EnforceExclusivityMode::None),
cl::values(clEnumValN(EnforceExclusivityMode::Unchecked, "unchecked",
"Static checking only."),
clEnumValN(EnforceExclusivityMode::Checked, "checked",
"Static and dynamic checking."),
clEnumValN(EnforceExclusivityMode::DynamicOnly, "dynamic-only",
"Dynamic checking only."),
clEnumValN(EnforceExclusivityMode::None, "none",
"No exclusivity checking.")));

static llvm::cl::opt<std::string>
ResourceDir("resource-dir",
llvm::cl::desc("The directory that holds the compiler resource files"));
Expand Down Expand Up @@ -178,10 +202,6 @@ AssumeUnqualifiedOwnershipWhenParsing(
"assume-parsing-unqualified-ownership-sil", llvm::cl::Hidden, llvm::cl::init(false),
llvm::cl::desc("Assume all parsed functions have unqualified ownership"));

static llvm::cl::opt<bool> EnforceExclusivityStatic(
"enforce-exclusivity-static", llvm::cl::Hidden, llvm::cl::init(false),
llvm::cl::desc("Diagnose static violations of law of exclusivity."));

static void runCommandLineSelectedPasses(SILModule *Module,
irgen::IRGenModule *IRGenMod) {
SILPassManager PM(Module, IRGenMod);
Expand Down Expand Up @@ -268,7 +288,30 @@ int main(int argc, char **argv) {
SILOpts.EnableSILOwnership = EnableSILOwnershipOpt;
SILOpts.AssumeUnqualifiedOwnershipWhenParsing =
AssumeUnqualifiedOwnershipWhenParsing;
SILOpts.EnforceExclusivityStatic = EnforceExclusivityStatic;

switch (EnforceExclusivity) {
case EnforceExclusivityMode::Unchecked:
// This option is analogous to the -Ounchecked optimization setting.
// It will disable dynamic checking but still diagnose statically.
SILOpts.EnforceExclusivityStatic = true;
SILOpts.EnforceExclusivityDynamic = false;
break;
case EnforceExclusivityMode::Checked:
SILOpts.EnforceExclusivityStatic = true;
SILOpts.EnforceExclusivityDynamic = true;
break;
case EnforceExclusivityMode::DynamicOnly:
// This option is intended for staging purposes. The intent is that
// it will eventually be removed.
SILOpts.EnforceExclusivityStatic = false;
SILOpts.EnforceExclusivityDynamic = true;
break;
case EnforceExclusivityMode::None:
// This option is for staging purposes.
SILOpts.EnforceExclusivityStatic = false;
SILOpts.EnforceExclusivityDynamic = false;
break;
}

// Load the input file.
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
Expand Down

0 comments on commit ecfff06

Please sign in to comment.