Skip to content

Commit 1cb7bc1

Browse files
committed
Rework updateValueSet() and surrounding code.
a) Revise documentation strategy to avoid duplication. - Document what a method does in the header file. - Document (if not obvious) how it works in the cpp file. Idea from: https://softwareengineering.stackexchange.com/questions/84071/is-it-better-to-document-functions-in-the-header-file-or-the-source-file b) Make updateValueSet() work by reference. This means that we don't need to talk about pointers in the docstring.
1 parent 0862049 commit 1cb7bc1

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

llvm/include/llvm/Transforms/Yk/LivenessAnalysis.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ class LivenessAnalysis {
2222
/// Find the successor instructions of the specified instruction.
2323
std::set<Instruction *> getSuccessorInstructions(Instruction *I);
2424

25-
/// Replaces the value set behind the pointer `S` with the value set `R` and
26-
/// returns whether the set behind `S` changed.
27-
bool updateValueSet(std::set<Value *> *S, const std::set<Value *> R);
25+
/// Replaces the set `S` with the set `R`, returning if the set changed.
26+
bool updateValueSet(std::set<Value *> &S, const std::set<Value *> &R);
2827

2928
public:
3029
LivenessAnalysis(Function *Func);

llvm/lib/Transforms/Yk/LivenessAnalysis.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void vset_union(const std::set<Value *> &S1, const std::set<Value *> &S2,
4040
}
4141

4242
namespace llvm {
43-
/// Find the successor instructions of the specified instruction.
43+
4444
std::set<Instruction *>
4545
LivenessAnalysis::getSuccessorInstructions(Instruction *I) {
4646
Instruction *Term = I->getParent()->getTerminator();
@@ -58,12 +58,10 @@ LivenessAnalysis::getSuccessorInstructions(Instruction *I) {
5858
return SuccInsts;
5959
}
6060

61-
/// Replaces the value set behind the pointer `S` with the value set `R` and
62-
/// returns whether the set behind `S` changed.
63-
bool LivenessAnalysis::updateValueSet(std::set<Value *> *S,
64-
const std::set<Value *> R) {
65-
const bool Changed = (*S != R);
66-
*S = R;
61+
bool LivenessAnalysis::updateValueSet(std::set<Value *> &S,
62+
const std::set<Value *> &R) {
63+
const bool Changed = (S != R);
64+
S = R;
6765
return Changed;
6866
}
6967

@@ -138,22 +136,20 @@ LivenessAnalysis::LivenessAnalysis(Function *Func) {
138136
for (Instruction *SI : SuccInsts) {
139137
NewOut.insert(In[SI].begin(), In[SI].end());
140138
}
141-
Changed |= updateValueSet(&Out[I], std::move(NewOut));
139+
Changed |= updateValueSet(Out[I], NewOut);
142140

143141
// Update in[I].
144142
std::set<Value *> OutMinusDef;
145143
vset_difference(Out[I], Defs[I], OutMinusDef);
146144

147145
std::set<Value *> NewIn;
148146
vset_union(Uses[I], OutMinusDef, NewIn);
149-
Changed |= updateValueSet(&In[I], std::move(NewIn));
147+
Changed |= updateValueSet(In[I], NewIn);
150148
}
151149
}
152150
} while (Changed); // Until a fixed-point.
153151
}
154152

155-
/// Returns the set of live variables immediately before the specified
156-
/// instruction.
157153
std::set<Value *> LivenessAnalysis::getLiveVarsBefore(Instruction *I) {
158154
return In[I];
159155
}

0 commit comments

Comments
 (0)