Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
78 changes: 78 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#taken from https://gist.github.com/airglow923/1fa3bda42f2b193920d7f46ee8345e04
CheckOptions:
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassMemberCase
value: lower_case
- key: readability-identifier-naming.ConstexprVariableCase
value: lower_case
#no enforce
- key: readability-identifier-naming.ConstexprVariablePrefix
value: ""
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.EnumConstantCase
value: CamelCase
#no enforce
- key: readability-identifier-naming.EnumConstantPrefix
value: ""
- key: readability-identifier-naming.FunctionCase
value: CamelCase
- key: readability-identifier-naming.GlobalConstantCase
value: CamelCase
#no enforce
- key: readability-identifier-naming.GlobalConstantPrefix
value: ""
- key: readability-identifier-naming.StaticConstantCase
value: CamelCase
#no enforce
- key: readability-identifier-naming.StaticConstantPrefix
value: ""
- key: readability-identifier-naming.StaticVariableCase
value: lower_case
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: readability-identifier-naming.MacroDefinitionIgnoredRegexp
value: "^[A-Z]+(_[A-Z]+)*_$"
# when enabling case it needs also suffix defined(and (_)? doesn't help)
# - key: readability-identifier-naming.MemberCase
# value: lower_case
# - key: readability-identifier-naming.MemberSuffix
# value: ""

- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: readability-identifier-naming.ParameterCase
value: lower_case
- key: readability-identifier-naming.TypeAliasCase
value: CamelCase
- key: readability-identifier-naming.TypedefCase
value: CamelCase
- key: readability-identifier-naming.VariableCase
value: lower_case
- key: readability-identifier-naming.IgnoreMainLikeFunctions
value: 1

Checks: "
-*,
readability-identifier-naming,
cppcoreguidelines-avoid-goto,
cppcoreguidelines-explicit-virtual-functions,
cppcoreguidelines-no-malloc,
cppcoreguidelines-pro-bounds-pointer-arithmetic,
cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-pro-type-union-access,
cppcoreguidelines-missing-std-forward,
modernize-avoid-c-arrays,
modernize-use-emplace,
modernize-use-override,
modernize-use-nullptr,
modernize-deprecated-headers,
modernize-use-constraints,
performance-trivially-destructible,
performance-inefficient-vector-operation,
performance-inefficient-algorithm,
performance-for-range-copy,
misc-static-assert,
misc-redundant-expression"
WarningsAsErrors: "*"
8 changes: 5 additions & 3 deletions codegen/coyieldpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ struct CoYieldInserter {
InsertCall(filt_entry, builder, true);
// Invoke instruction has unwind/normal ends so we need handle it
if (invoke) {
builder.SetInsertPoint(invoke->getNormalDest()->getFirstInsertionPt());
builder.SetInsertPoint(
invoke->getNormalDest()->getFirstInsertionPt());
InsertCall(filt_entry, builder, false);
builder.SetInsertPoint(invoke->getUnwindDest()->getFirstInsertionPt());
builder.SetInsertPoint(
invoke->getUnwindDest()->getFirstInsertionPt());
InsertCall(filt_entry, builder, false);
} else {
builder.SetInsertPoint(call->getNextNode());
Expand Down Expand Up @@ -212,7 +214,7 @@ struct CoYieldInserter {
Constant *str_const =
ConstantDataArray::getString(m.getContext(), filt.print_name, true);
auto zero = ConstantInt::get(Type::getInt32Ty(m.getContext()), 0);
Constant *ind[] = {zero, zero};
std::array<Constant *, 2> ind = {zero, zero};
GlobalVariable *global = new GlobalVariable(
m, str_const->getType(), true, GlobalValue::PrivateLinkage, str_const);
auto ptr =
Expand Down
58 changes: 29 additions & 29 deletions codegen/yieldpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ using Builder = IRBuilder<>;

using FunIndex = std::set<std::pair<StringRef, StringRef>>;

const StringRef nonatomic_attr = "ltest_nonatomic";
const StringRef NonatomicAttr = "ltest_nonatomic";

FunIndex CreateFunIndex(const Module &M) {
FunIndex CreateFunIndex(const Module &m) {
FunIndex index{};
for (auto it = M.global_begin(); it != M.global_end(); ++it) {
for (auto it = m.global_begin(); it != m.global_end(); ++it) {
if (it->getName() != "llvm.global.annotations") {
continue;
}
auto *CA = dyn_cast<ConstantArray>(it->getOperand(0));
for (auto o_it = CA->op_begin(); o_it != CA->op_end(); ++o_it) {
auto *CS = dyn_cast<ConstantStruct>(o_it->get());
auto *fun = dyn_cast<Function>(CS->getOperand(0));
auto *AnnotationGL = dyn_cast<GlobalVariable>(CS->getOperand(1));
auto *ca = dyn_cast<ConstantArray>(it->getOperand(0));
for (auto o_it = ca->op_begin(); o_it != ca->op_end(); ++o_it) {
auto *cs = dyn_cast<ConstantStruct>(o_it->get());
auto *fun = dyn_cast<Function>(cs->getOperand(0));
auto *annotation_gl = dyn_cast<GlobalVariable>(cs->getOperand(1));
auto annotation =
dyn_cast<ConstantDataArray>(AnnotationGL->getInitializer())
dyn_cast<ConstantDataArray>(annotation_gl->getInitializer())
->getAsCString();
index.insert({annotation, fun->getName()});
}
Expand All @@ -37,25 +37,25 @@ bool HasAttribute(const FunIndex &index, const StringRef name,
}

struct YieldInserter {
YieldInserter(Module &M) : M(M) {
CoroYieldF = M.getOrInsertFunction(
"CoroYield", FunctionType::get(Type::getVoidTy(M.getContext()), {}));
YieldInserter(Module &m) : M(m) {
CoroYieldF = m.getOrInsertFunction(
"CoroYield", FunctionType::get(Type::getVoidTy(m.getContext()), {}));
}

void Run(const FunIndex &index) {
for (auto &F : M) {
if (IsTarget(F.getName(), index)) {
InsertYields(F, index);
for (auto &f : M) {
if (IsTarget(f.getName(), index)) {
InsertYields(f, index);

errs() << "yields inserted to the " << F.getName() << "\n";
errs() << F << "\n";
errs() << "yields inserted to the " << f.getName() << "\n";
errs() << f << "\n";
}
}
}

private:
bool IsTarget(const StringRef fun_name, const FunIndex &index) {
return HasAttribute(index, fun_name, nonatomic_attr);
return HasAttribute(index, fun_name, NonatomicAttr);
}

bool NeedInterrupt(Instruction *insn, const FunIndex &index) {
Expand All @@ -67,13 +67,13 @@ struct YieldInserter {
return false;
}

void InsertYields(Function &F, const FunIndex &index) {
Builder Builder(&*F.begin());
for (auto &B : F) {
for (auto it = B.begin(); std::next(it) != B.end(); ++it) {
void InsertYields(Function &f, const FunIndex &index) {
Builder builder(&*f.begin());
for (auto &b : f) {
for (auto it = b.begin(); std::next(it) != b.end(); ++it) {
if (NeedInterrupt(&*it, index) && !ItsYieldInst(&*std::next(it))) {
Builder.SetInsertPoint(&*std::next(it));
Builder.CreateCall(CoroYieldF, {})->getIterator();
builder.SetInsertPoint(&*std::next(it));
builder.CreateCall(CoroYieldF, {})->getIterator();
++it;
}
}
Expand All @@ -99,7 +99,7 @@ struct YieldInserter {
namespace {

struct YieldInsertPass final : public PassInfoMixin<YieldInsertPass> {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM) {
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM) { // NOLINT
auto fun_index = CreateFunIndex(M);

YieldInserter gen{M};
Expand All @@ -116,10 +116,10 @@ llvmGetPassPluginInfo() {
return {.APIVersion = LLVM_PLUGIN_API_VERSION,
.PluginName = "yield_insert",
.PluginVersion = "v0.1",
.RegisterPassBuilderCallbacks = [](PassBuilder &PB) {
PB.registerPipelineStartEPCallback(
[](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(YieldInsertPass());
.RegisterPassBuilderCallbacks = [](PassBuilder &pb) {
pb.registerPipelineStartEPCallback(
[](ModulePassManager &mpm, OptimizationLevel level) {
mpm.addPass(YieldInsertPass());
});
}};
}
4 changes: 2 additions & 2 deletions runtime/generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace generators {
std::shared_ptr<Token> generated_token{};

// Generates empty arguments.
std::tuple<> genEmpty(size_t thread_num) { return std::tuple<>(); }
std::tuple<> GenEmpty(size_t thread_num) { return std::tuple<>(); }

// Generates runtime token.
// Can be called only once per task creation.
std::tuple<std::shared_ptr<Token>> genToken(size_t thread_num) {
std::tuple<std::shared_ptr<Token>> GenToken(size_t thread_num) {
assert(!generated_token && "forgot to reset generated_token");
generated_token = std::make_shared<Token>();
return {generated_token};
Expand Down
10 changes: 5 additions & 5 deletions runtime/include/generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ extern std::shared_ptr<Token> generated_token;

// Makes single argument from the value.
template <typename T>
auto makeSingleArg(T&& arg) {
using arg_type = typename std::remove_reference<T>::type;
return std::tuple<arg_type>{std::forward<arg_type>(arg)};
auto MakeSingleArg(T&& arg) {
using ArgType = typename std::remove_reference<T>::type;
return std::tuple<ArgType>{std::forward<ArgType>(arg)};
}

std::tuple<> genEmpty(size_t thread_num);
std::tuple<> GenEmpty(size_t thread_num);

std::tuple<std::shared_ptr<Token>> genToken(size_t thread_num);
std::tuple<std::shared_ptr<Token>> GenToken(size_t thread_num);

} // namespace generators

Expand Down
4 changes: 2 additions & 2 deletions runtime/include/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "value_wrapper.h"

#define panic() assert(false)
#define PANIC() assert(false)

struct CoroBase;
struct CoroutineStatus;
Expand All @@ -26,7 +26,7 @@ extern boost::context::fiber_context sched_ctx;

extern std::optional<CoroutineStatus> coroutine_status;

struct CoroutineStatus{
struct CoroutineStatus {
std::string_view name;
bool has_started;
};
Expand Down
15 changes: 8 additions & 7 deletions runtime/include/lincheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Invoke {
std::reference_wrapper<const Task> task;
};

typedef std::variant<Invoke, Response> HistoryEvent;
using HistoryEvent = std::variant<Invoke, Response>;

// ModelChecker is the general checker interface which is implemented by
// different checkers, each of which checks its own consistency model
Expand All @@ -45,18 +45,18 @@ using MethodName = std::string;
// get_inv_res_mapping returns map (invoke_index -> corresponding
// response_index)

std::map<size_t, size_t> get_inv_res_mapping(
std::map<size_t, size_t> GetInvResMapping(
const std::vector<HistoryEvent>& history);

std::map<size_t, size_t> get_inv_res_full_mapping(
std::map<size_t, size_t> GetInvResFullMapping(
const std::vector<HistoryEvent>& history);

std::map<size_t, size_t> get_followup_res_request_inv_mapping(
std::map<size_t, size_t> GetFollowupResRequestInvMapping(
const std::vector<HistoryEvent>& history);

// fix_history deletes invokes that don't have corresponding responses,
// this is allowed by the definition of the linearizability
std::vector<std::variant<Invoke, Response>> fix_history(
std::vector<std::variant<Invoke, Response>> FixHistory(
const std::vector<std::variant<Invoke, Response>>& history);

template <class LinearSpecificationObject,
Expand Down Expand Up @@ -138,7 +138,7 @@ bool LinearizabilityChecker<
// TODO: Can replace it with stack of hashes and map: hash ->
// LinearSpecificationObject contains previous states stack
std::vector<LinearSpecificationObject> states_stack;
std::map<size_t, size_t> inv_res = get_inv_res_mapping(history);
std::map<size_t, size_t> inv_res = GetInvResMapping(history);
std::vector<bool> linearized(history.size(), false);
size_t linearized_entries_count = 0;
std::unordered_set<
Expand Down Expand Up @@ -167,7 +167,8 @@ bool LinearizabilityChecker<
bool was_checked = false;
LinearSpecificationObject data_structure_state_copy =
data_structure_state;
ValueWrapper res = method(&data_structure_state_copy, inv.GetTask()->GetArgs());
ValueWrapper res =
method(&data_structure_state_copy, inv.GetTask()->GetArgs());

// If invoke doesn't have a response we can't check the response
bool doesnt_have_response =
Expand Down
2 changes: 1 addition & 1 deletion runtime/include/lincheck_recursive.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool LinearizabilityCheckerRecursive<
if (history.empty()) {
return true;
}
std::map<size_t, size_t> inv_res = get_inv_res_mapping(history);
std::map<size_t, size_t> inv_res = GetInvResMapping(history);

std::function<bool(const std::vector<HistoryEvent>&, std::vector<bool>&,
LinearSpecificationObject)>
Expand Down
10 changes: 5 additions & 5 deletions runtime/include/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include <iostream>

#ifdef DEBUG
#define debug(...) fprintf(__VA_ARGS__)
#define DEBUG(...) fprintf(__VA_ARGS__)
#else
#define debug(...)
#define DEBUG(...)
#endif

struct Logger {
Expand All @@ -18,9 +18,9 @@ struct Logger {
return *this;
}

void flush();
void Flush();
};

void logger_init(bool verbose);
void LoggerInit(bool verbose);

Logger& log();
Logger& Log();
6 changes: 3 additions & 3 deletions runtime/include/minimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct GreedyRoundMinimizor : public RoundMinimizor {
*/
struct SameInterleavingMinimizor : public GreedyRoundMinimizor {
protected:
virtual Scheduler::Result OnTasksRemoved(
Scheduler::Result OnTasksRemoved(
SchedulerWithReplay& sched,
const Scheduler::BothHistories& nonlinear_history,
const std::unordered_set<int>& task_ids) const override;
Expand All @@ -87,10 +87,10 @@ struct SameInterleavingMinimizor : public GreedyRoundMinimizor {
*/
struct StrategyExplorationMinimizor : public GreedyRoundMinimizor {
StrategyExplorationMinimizor() = delete;
explicit StrategyExplorationMinimizor(int runs_);
explicit StrategyExplorationMinimizor(int runs);

protected:
virtual Scheduler::Result OnTasksRemoved(
Scheduler::Result OnTasksRemoved(
SchedulerWithReplay& sched,
const Scheduler::BothHistories& nonlinear_history,
const std::unordered_set<int>& task_ids) const override;
Expand Down
Loading