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

Improvements to dumpstats performance #660

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
24 changes: 20 additions & 4 deletions clang/include/clang/3C/3CInteractiveData.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ class ConstraintsInfo {
std::set<std::string> ValidSourceFiles;
std::map<ConstraintKey, const PersistentSourceLoc *> AtomSourceMap;

void addRootCause(ConstraintKey Var, ConstraintKey RootCause) {
RootCauses[Var].insert(RootCause);
}

CVars& getConstrainedBy(VarAtom *Var) {
return getConstrainedBy(Var->getLoc());
}

CVars& getConstrainedBy(ConstraintKey Var) {
return ConstrainedBy[Var];
}

private:
// Root cause map: This is the map of a Constraint var and a set of
// Constraint vars (that are directly assigned WILD) which are the reason
Expand All @@ -65,15 +77,19 @@ class ConstraintsInfo {
// \ /
// s
// Here: s -> {p, q} and r -> {q}
std::map<ConstraintKey, CVars> RCMap;
// IE: Maps a constraint variables to the set of root causes of wildness
std::map<ConstraintKey, CVars> RootCauses;
// This is source map: Map of Constraint var (which are directly
// assigned WILD) and the set of constraint vars which are WILD because of
// the above constraint.
// For the above case, this contains: p -> {s}, q -> {r, s}
std::map<ConstraintKey, CVars> SrcWMap;
// IE: Maps a root cause to the set of variables it constrains
std::map<ConstraintKey, CVars> ConstrainedBy;

std::map<ConstraintVariable *, CVars> PtrRCMap;
std::map<ConstraintKey, std::set<ConstraintVariable *>> PtrSrcWMap;
// PTR versions of the above maps
// TODO understand this better
std::map<ConstraintVariable *, CVars> PtrRootCauses;
std::map<ConstraintKey, std::set<ConstraintVariable *>> PtrConstrainedBy;

// Get score for each of the ConstraintKeys, which are wild.
// For the above example, the score of s would be 0.5, similarly
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/3C/ConstraintVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ class ConstraintVariable {
std::string getRewritableOriginalTy() const;
std::string getName() const { return Name; }

// TODO is the word `valid` doing any real work here? or can it be dropped?
void setValidDecl() { IsForDecl = true; }
bool isForValidDecl() const { return IsForDecl; }

Expand Down
13 changes: 13 additions & 0 deletions clang/include/clang/3C/Constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ class VarAtom : public Atom {
return false;
}

// TODO this should be renamed to something more informative, like "id"
uint32_t getLoc() const { return Loc; }



std::string getName() const { return Name; }
VarKind getVarKind() const { return KindV; }

Expand All @@ -138,10 +142,19 @@ class VarAtom : public Atom {
return Constraints;
}

void setForDecl(void) {
IsForDecl = true;
}

bool isForDecl(void) const {
return IsForDecl;
}

private:
uint32_t Loc;
std::string Name;
const VarKind KindV;
bool IsForDecl = false;
// The constraint expressions where this variable is mentioned on the
// LHS of an equality.
std::set<Constraint *, PComp<Constraint *>> Constraints;
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/3C/ProgramInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ class ProgramInfo : public ProgramVariableAdder {
FVConstraint *getStaticFuncConstraint(std::string FuncName,
std::string FileName) const;

void doRootCauseAnalysis(CVars &RelevantVarsKey,
std::set<Atom *> &DirectWildVarAtoms,
ConstraintsGraph &CG);


// Called when we are done adding constraints and visiting ASTs.
// Links information about global symbols together and adds
// constraints where appropriate.
Expand Down
14 changes: 7 additions & 7 deletions clang/lib/3C/3CInteractiveData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ void ConstraintsInfo::clear() {
AllWildAtoms.clear();
TotalNonDirectWildAtoms.clear();
ValidSourceFiles.clear();
RCMap.clear();
SrcWMap.clear();
RootCauses.clear();
ConstrainedBy.clear();
}

CVars &ConstraintsInfo::getRCVars(ConstraintKey Ckey) { return RCMap[Ckey]; }
CVars &ConstraintsInfo::getRCVars(ConstraintKey Ckey) { return RootCauses[Ckey]; }

CVars &ConstraintsInfo::getSrcCVars(ConstraintKey Ckey) {
return SrcWMap[Ckey];
return ConstrainedBy[Ckey];
}

CVars ConstraintsInfo::getWildAffectedCKeys(const CVars &DWKeys) {
Expand All @@ -50,7 +50,7 @@ float ConstraintsInfo::getPtrAffectedScore(
const std::set<ConstraintVariable *> CVs) {
float TS = 0.0;
for (auto *CV : CVs)
TS += (1.0 / PtrRCMap[CV].size());
TS += (1.0 / PtrRootCauses[CV].size());
return TS;
}

Expand Down Expand Up @@ -127,12 +127,12 @@ void ConstraintsInfo::printConstraintStats(llvm::raw_ostream &O,
O << "\"AtomsAffected\":" << AtomsAffected.size() << ", ";
O << "\"AtomsScore\":" << getAtomAffectedScore(AtomsAffected) << ", ";

std::set<ConstraintVariable *> PtrsAffected = PtrSrcWMap[Cause];
std::set<ConstraintVariable *> PtrsAffected = PtrConstrainedBy[Cause];
O << "\"PtrsAffected\":" << PtrsAffected.size() << ",";
O << "\"PtrsScore\":" << getPtrAffectedScore(PtrsAffected);
O << "}";
}

int ConstraintsInfo::getNumPtrsAffected(ConstraintKey CK) {
return PtrSrcWMap[CK].size();
return PtrConstrainedBy[CK].size();
}
Loading