Skip to content

Commit

Permalink
fix(misc): remove tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Aug 17, 2023
1 parent 881addb commit 8cc54d5
Show file tree
Hide file tree
Showing 587 changed files with 29,671 additions and 32,738 deletions.
6 changes: 4 additions & 2 deletions cmmc/CodeGen/CodeGenUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ void dumpAssembly(std::ostream& out, const CodeGenContext& ctx, const MIRModule&
out << ".data\n"sv;
emitData();
const auto dumpSymbol = [&](const MIRGlobal& global) {
if(!global.reloc->isFunc())
out << ".align " << global.alignment << std::endl;
if(!global.reloc->isFunc()) {
if(global.alignment > 1)
out << ".p2align " << ilog2(global.alignment) << std::endl;
}
auto symbol = global.reloc->symbol();
if(global.linkage == Linkage::Global)
out << ".globl "sv << symbol << '\n';
Expand Down
12 changes: 6 additions & 6 deletions cmmc/Runtime/cmmc_sysy_rt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace {

Futex ready, done;
};
std::array<Worker, maxThreads> workers; // NOLINT
Worker workers[maxThreads]; // NOLINT

static_assert(std::atomic_uint32_t::is_always_lock_free);
static_assert(std::atomic_int32_t::is_always_lock_free);
Expand Down Expand Up @@ -122,17 +122,17 @@ using Time = int64_t;
struct ParallelForEntry final {
CmmcForLoop func;
uint32_t size;
bool valid = false;
uint32_t hitCount = 0;
bool valid;
uint32_t hitCount;
static constexpr uint32_t sampleThreshold = 100;
static constexpr uint32_t sampleCount = 20;
static constexpr uint32_t stopSampleThreshold = sampleThreshold + 3 * sampleCount;
Time times[3]; // 1T 2T 4T
uint32_t bestThreads = 0;
uint32_t bestThreads;
};
constexpr uint32_t entryCount = 16;
static std::array<ParallelForEntry, entryCount> parallelCache; // NOLINT
static uint32_t lookupPtr = 0; // NOLINT
static ParallelForEntry parallelCache[entryCount]; // NOLINT
static uint32_t lookupPtr; // NOLINT
static ParallelForEntry& selectEntry(CmmcForLoop func, uint32_t size) {
for(uint32_t i = 0; i < entryCount; ++i, ++lookupPtr) {
if(lookupPtr == entryCount)
Expand Down
45 changes: 24 additions & 21 deletions cmmc/Support/Tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,31 @@ void initTune(const std::string_view& name, const std::string_view& target) {
return;
}

if(target == "riscv") {
const std::string_view table[][2] = {
{ "/01_mm",
"loop_unswitch 1 loop_parallel 1 unroll_block_size 8 max_unroll_body_size 128 max_constant_hoist_count 9" },
{ "/conv", "prob_predict 1" },
{ "/brainfuck",
"loop_unswitch 1 loop_parallel 0 loop_extract 0 loop_unroll 0 dyn_loop_unroll 0 max_constant_hoist_count 4" },
{ "/crypto",
"loop_unswitch 0 loop_parallel 0 unroll_block_size 8 max_unroll_body_size 128 max_constant_hoist_count 6" },
{ "/sl", "loop_unswitch 1 loop_parallel 1 unroll_block_size 2 max_unroll_body_size 128 max_constant_hoist_count 3" },
{ "/gameoflife", "loop_parallel 1 unroll_block_size 16 max_unroll_body_size 128 max_constant_hoist_count 6" }
};
for(auto& [key, value] : table) {
if(key.empty())
continue;
CMMC_UNUSED(name);
CMMC_UNUSED(target);
// Tuning is illegal in the competition
// if(target == "riscv") {
// const std::string_view table[][2] = {
// { "/01_mm",
// "loop_unswitch 1 loop_parallel 1 unroll_block_size 8 max_unroll_body_size 128 max_constant_hoist_count 9" },
// { "/conv", "prob_predict 1" },
// { "/brainfuck",
// "loop_unswitch 1 loop_parallel 0 loop_extract 0 loop_unroll 0 dyn_loop_unroll 0 max_constant_hoist_count 4" },
// { "/crypto",
// "loop_unswitch 0 loop_parallel 0 unroll_block_size 8 max_unroll_body_size 128 max_constant_hoist_count 6" },
// { "/sl", "loop_unswitch 1 loop_parallel 1 unroll_block_size 2 max_unroll_body_size 128 max_constant_hoist_count 3"
// }, { "/gameoflife", "loop_parallel 1 unroll_block_size 16 max_unroll_body_size 128 max_constant_hoist_count 6" }
// };
// for(auto& [key, value] : table) {
// if(key.empty())
// continue;

if(name.find(key) != std::string_view::npos) {
parseTune(value);
return;
}
}
}
// if(name.find(key) != std::string_view::npos) {
// parseTune(value);
// return;
// }
// }
// }
}

int32_t queryTuneOpt(const std::string_view& key, int32_t defaultValue) {
Expand Down
4 changes: 2 additions & 2 deletions cmmc/Target/RISCV/RISCVScheduleModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ static bool earlyFoldStore(MIRBasicBlock& block, CodeGenContext& ctx) {
return modified;
}

static bool earlyFoldDualWordCopy(MIRFunction& func, CodeGenContext& ctx) {
static bool earlyFoldDoubleWordCopy(MIRFunction& func, CodeGenContext& ctx) {
std::unordered_map<MIROperand, uint32_t, MIROperandHasher> useCount;
std::unordered_map<MIROperand, MIRInst*, MIROperandHasher> addressDef;
for(auto& block : func.blocks()) {
Expand Down Expand Up @@ -1137,7 +1137,7 @@ bool RISCVScheduleModel_sifive_u74::peepholeOpt(MIRFunction& func, CodeGenContex
modified |= removeSExtW(func, ctx);
modified |= expandMulWithConstant(func, ctx, static_cast<uint32_t>(queryTuneOpt("max_mul_constant_cost", 2)));
if(ctx.flags.inSSAForm)
modified |= earlyFoldDualWordCopy(func, ctx);
modified |= earlyFoldDoubleWordCopy(func, ctx);
return modified;
}

Expand Down
2 changes: 1 addition & 1 deletion cmmc/Target/RISCV/RISCVTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class RISCVTarget final : public Target {
.branchLimit = static_cast<uint32_t>(queryTuneOpt("branch_limit", 400)),
.disableSelectionOpt = true,
.branchPredictionWarmupThreshold = static_cast<uint32_t>(queryTuneOpt("branch_prediction_warmup_threshold", 2)),
.maxConstantHoistCount = static_cast<uint32_t>(queryTuneOpt("max_constant_hoist_count", 12)),
.maxConstantHoistCount = static_cast<uint32_t>(queryTuneOpt("max_constant_hoist_count", 8)),
};

return defaultHeuristic;
Expand Down
2 changes: 1 addition & 1 deletion cmmc/Transforms/IPO/Inlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class FuncInlining final : public TransformPass<Function> {

public:
bool run(Function& func, AnalysisPassManager&) const override {
if(func.getSymbol().prefix().find("_inline_wrapped") != std::string_view::npos) {
if(func.getSymbol().prefix().find("_cmmc_inline_wrapped") != std::string_view::npos) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion cmmc/Transforms/IPO/ShrinkWrapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CMMC_NAMESPACE_BEGIN

class ShrinkWrapping final : public TransformPass<Function> {
static Function* cloneFunc(Function& func) {
auto newFunc = make<Function>(String::get(std::string(func.getSymbol().prefix()) + "_inline_wrapped"),
auto newFunc = make<Function>(String::get(std::string(func.getSymbol().prefix()) + "_cmmc_inline_wrapped"),
func.getType()->as<FunctionType>());
newFunc->setLinkage(Linkage::Internal);

Expand Down
2 changes: 1 addition & 1 deletion cmmc/Transforms/Misc/ImmutableScalarRefArg2Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class ImmutableScalarRefArg2Value final : public TransformPass<Module> {
}

for(auto [func, type] : wrappers) {
const auto wrapperFunc = make<Function>(String::get(std::string(func->getSymbol().prefix()) + "_wrapper"), type);
const auto wrapperFunc = make<Function>(String::get(std::string(func->getSymbol().prefix()) + "_cmmc_wrapper"), type);
wrapperFunc->setLinkage(Linkage::Internal);
std::vector<Value*> args;
auto& argTypes = type->getArgTypes();
Expand Down
2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/arithmetic.mips.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/arithmetic.riscv.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/call.arm.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/Regression/CodeGen/call.mips.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/call.riscv.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/constant.arm.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/Regression/CodeGen/constant.mips.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/constant.riscv.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/llvmTests/2009-04-24.arm.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/llvmTests/2009-04-24.mips.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/Regression/CodeGen/llvmTests/2009-04-24.riscv.s

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8cc54d5

Please sign in to comment.