in compiler_gym/envs/llvm/service/LlvmSession.cc [161:210]
Status LlvmSession::handleSessionParameter(const std::string& key, const std::string& value,
std::optional<std::string>& reply) {
if (key == "llvm.set_runtimes_per_observation_count") {
const int ivalue = std::stoi(value);
if (ivalue < 1) {
return Status(
StatusCode::INVALID_ARGUMENT,
fmt::format("runtimes_per_observation_count must be >= 1. Received: {}", ivalue));
}
benchmark().setRuntimesPerObservationCount(ivalue);
reply = value;
} else if (key == "llvm.get_runtimes_per_observation_count") {
reply = fmt::format("{}", benchmark().getRuntimesPerObservationCount());
} else if (key == "llvm.set_warmup_runs_count_per_runtime_observation") {
const int ivalue = std::stoi(value);
if (ivalue < 0) {
return Status(
StatusCode::INVALID_ARGUMENT,
fmt::format("warmup_runs_count_per_runtime_observation must be >= 0. Received: {}",
ivalue));
}
benchmark().setWarmupRunsPerRuntimeObservationCount(ivalue);
reply = value;
} else if (key == "llvm.get_warmup_runs_count_per_runtime_observation") {
reply = fmt::format("{}", benchmark().getWarmupRunsPerRuntimeObservationCount());
} else if (key == "llvm.set_buildtimes_per_observation_count") {
const int ivalue = std::stoi(value);
if (ivalue < 1) {
return Status(
StatusCode::INVALID_ARGUMENT,
fmt::format("buildtimes_per_observation_count must be >= 1. Received: {}", ivalue));
}
benchmark().setBuildtimesPerObservationCount(ivalue);
reply = value;
} else if (key == "llvm.get_buildtimes_per_observation_count") {
reply = fmt::format("{}", benchmark().getBuildtimesPerObservationCount());
} else if (key == "llvm.apply_baseline_optimizations") {
if (value == "-Oz") {
bool changed = benchmark().applyBaselineOptimizations(/*optLevel=*/2, /*sizeLevel=*/2);
reply = changed ? "1" : "0";
} else if (value == "-O3") {
bool changed = benchmark().applyBaselineOptimizations(/*optLevel=*/3, /*sizeLevel=*/0);
reply = changed ? "1" : "0";
} else {
return Status(StatusCode::INVALID_ARGUMENT,
fmt::format("Invalid value for llvm.apply_baseline_optimizations: {}", value));
}
}
return Status::OK;
}