Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce pruning in the constant synthesis loop #460

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
59 changes: 35 additions & 24 deletions lib/Infer/ExhaustiveSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,35 +631,14 @@ bool isBigQuerySat(SynthesisContext &SC,
return BigQueryIsSat;
}

void generateAndSortGuesses(InstContext &IC, Inst *LHS,
std::vector<Inst *> &Guesses) {
std::vector<Inst *> Inputs;
findCands(LHS, Inputs, /*WidthMustMatch=*/false, /*FilterVars=*/false, MaxLHSCands);
if (DebugLevel > 1)
llvm::errs() << "got " << Inputs.size() << " candidates from LHS\n";

void generateAndSortGuesses(InstContext &IC, Inst *LHS, const std::vector<Inst *> Inputs,
std::vector<Inst *> &Guesses, PruneFunc PruneCallback) {
int LHSCost = souper::cost(LHS, /*IgnoreDepsWithExternalUses=*/true);

int TooExpensive = 0;

dataflow::DataflowPruningManager DataflowPruning
(LHS, Inputs, DebugLevel);
// Cheaper tests go first
std::vector<PruneFunc> PruneFuncs = {CostPrune};
if (EnableDataflowPruning) {
PruneFuncs.push_back(DataflowPruning.getPruneFunc());
}
auto PruneCallback = MkPruneFunc(PruneFuncs);
// TODO(zhengyangl): Refactor the syntactic pruning into a
// prune function here, between Cost and Dataflow
// TODO(manasij7479) : If RHS is concrete, evaluate both sides
// TODO(regehr?) : Solver assisted pruning (should be the last component)

getGuesses(Guesses, Inputs, LHS->Width,
LHSCost, IC, nullptr, nullptr, TooExpensive, PruneCallback);
if (DebugLevel >= 1) {
DataflowPruning.printStats(llvm::outs());
}

// add nops guesses separately
for (auto I : Inputs) {
Expand Down Expand Up @@ -822,7 +801,29 @@ ExhaustiveSynthesis::synthesize(SMTLIBSolver *SMTSolver,

std::vector<Inst *> Guesses;
std::error_code EC;
generateAndSortGuesses(IC, LHS, Guesses);

std::vector<Inst *> Inputs;
findCands(LHS, Inputs, /*WidthMustMatch=*/false, /*FilterVars=*/false, MaxLHSCands);
if (DebugLevel > 1)
llvm::errs() << "got " << Inputs.size() << " candidates from LHS\n";

dataflow::DataflowPruningManager DataflowPruning
(LHS, Inputs, DebugLevel);
// Cheaper tests go first
std::vector<PruneFunc> PruneFuncs = {CostPrune};
if (EnableDataflowPruning) {
PruneFuncs.push_back(DataflowPruning.getPruneFunc());
}
auto PruneCallback = MkPruneFunc(PruneFuncs);
// TODO(zhengyangl): Refactor the syntactic pruning into a
// prune function here, between Cost and Dataflow
// TODO(manasij7479) : If RHS is concrete, evaluate both sides
// TODO(regehr?) : Solver assisted pruning (should be the last component)

generateAndSortGuesses(IC, LHS, Inputs, Guesses, PruneCallback);
if (DebugLevel >= 1) {
DataflowPruning.printStats(llvm::outs());
}

if (Guesses.empty()) {
return EC;
Expand Down Expand Up @@ -883,6 +884,16 @@ ExhaustiveSynthesis::synthesize(SMTLIBSolver *SMTSolver,
// TODO Utilize this for the mysterious constant synthesis 'loop'
}

// Avoids calling isConcreteCandidateSat
std::vector<Inst *> Empty;
if (!PruneCallback(ConcreteRHS, Empty)) {
if (DebugLevel > 3)
llvm::errs() << "Constant proved infeasible with inequivalence checks\n";
Tries++;
if (GuessHasConstant && Tries < MaxTries)
goto again; // TODO: Remove goto.
}

bool SecondSmallQueryIsSat;
EC = isConcreteCandidateSat(SC, ConstMap, ConcreteRHS, SecondSmallQueryIsSat);
if (EC) {
Expand Down