Skip to content

Commit 443dff2

Browse files
committed
Update format.
1 parent 8f92fee commit 443dff2

File tree

2 files changed

+36
-42
lines changed

2 files changed

+36
-42
lines changed

mlir/include/mlir/Analysis/DataFlow/LivenessAnalysis.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,19 @@ struct RunLivenessAnalysis {
102102
RunLivenessAnalysis(Operation *op);
103103

104104
const Liveness *getLiveness(Value val);
105-
// This only mark Liveness results are stale.
105+
// This only remarks that Liveness results are stale.
106106
void invalidate() { valid = false; }
107107
/// Return the configuration of the solver used for this analysis.
108108
const DataFlowConfig &getSolverConfig() const { return solver.getConfig(); }
109109
/// The function is called by analysis_impl::isInvalidated.
110-
bool isInvalidated(AnalysisManager::PreservedAnalyses&) const { return !valid; }
110+
bool isInvalidated(AnalysisManager::PreservedAnalyses &) const {
111+
return !valid;
112+
}
111113

112114
private:
113115
/// Stores the result of the liveness analysis that was run.
114116
DataFlowSolver solver;
115-
bool valid {true};
117+
bool valid{true};
116118
};
117119

118120
} // end namespace mlir::dataflow

mlir/lib/Transforms/RemoveDeadValues.cpp

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -870,18 +870,20 @@ struct RemoveDeadValues : public impl::RemoveDeadValuesBase<RemoveDeadValues> {
870870
};
871871
} // namespace
872872

873-
/// If the target of CallOP is a public function and at least one argument is NonLive,
874-
/// privatize the function.
875-
/// Our strategy here is separation interface and implementation. eg.
873+
/// If the target of CallOp is a public function and at least one argument is
874+
/// NonLive, privatize the function. Our strategy here is separation interface
875+
/// and implementation. eg.
876876
///
877877
/// public void foo(int unused){...}
878878
/// =>
879879
/// public void foo(int unused) { // old function, interface
880-
/// return __foo_impl(unused);
880+
/// return __foo_privatized(unused);
881881
/// }
882882
///
883-
/// private void __foo_impl(int unused) { // the new private function, or implementation.
884-
/// ... // the function body of the original function.
883+
/// private void __foo_privatized(int unused) { // the new private function, or
884+
/// implementation.
885+
/// ... // the function body of the
886+
/// original function.
885887
/// }
886888
///
887889
/// Returns true if any IR changes were made, false otherwise.
@@ -893,8 +895,8 @@ static bool processCallOp(CallOpInterface callOp, Operation *module,
893895
return false;
894896
}
895897

896-
LDBG() << "Processing callOp " << callOp
897-
<< " target is a public function: " << funcOp.getOperation()->getName();
898+
LDBG() << "Processing callOp " << callOp << " target is a public function: "
899+
<< funcOp.getOperation()->getName();
898900

899901
// Get the list of unnecessary (non-live) arguments in `nonLiveArgs`.
900902
SmallVector<Value> arguments(callOp.getArgOperands());
@@ -910,30 +912,29 @@ static bool processCallOp(CallOpInterface callOp, Operation *module,
910912

911913
// Set visibility = 'private' and a new name for the cloned function
912914
SymbolTable::setSymbolVisibility(clonedFunc,
913-
SymbolTable::Visibility::Private);
915+
SymbolTable::Visibility::Private);
914916
std::string newName = "__" + funcOp.getName().str() + "_privatized";
915917
clonedFunc.setName(newName);
916918

917919
// Insert the cloned function into the module
918920
rewriter.setInsertionPointAfter(funcOp);
919921
rewriter.insert(clonedFunc);
920922

921-
// Replace ALL callsites of the original function to call the cloned function directly
923+
// Replace ALL callsites of the original function to call the cloned
924+
// function directly
922925
LogicalResult result = SymbolTable::replaceAllSymbolUses(
923-
funcOp,
924-
clonedFunc.getNameAttr(),
925-
moduleOp
926-
);
926+
funcOp, clonedFunc.getNameAttr(), moduleOp);
927927

928928
if (result.failed()) {
929929
LDBG() << "Failed to replace all symbol uses for " << funcOp.getName();
930930
return false;
931931
}
932932

933-
LDBG() << "Redirected all callsites from " << funcOp.getName()
934-
<< " to " << newName;
933+
LDBG() << "Redirected all callsites from " << funcOp.getName() << " to "
934+
<< newName;
935935

936-
// Transform the original funcOp into a wrapper that calls the cloned function
936+
// Transform the original funcOp into a wrapper that calls the cloned
937+
// function
937938
Region &funcBody = funcOp.getFunctionBody();
938939

939940
// Clean the original function body
@@ -952,44 +953,35 @@ static bool processCallOp(CallOpInterface callOp, Operation *module,
952953
rewriter.setInsertionPointToStart(wrapperBlock);
953954

954955
// Clone the original call operation and update its callee
955-
Operation *clonedCallOp = callOp->clone();
956-
956+
auto clonedCallOp = cast<CallOpInterface>(callOp->clone());
957957
// Update the callee symbol reference to point to the new private function
958-
if (auto callableOp = dyn_cast<CallOpInterface>(clonedCallOp)) {
959-
auto symbolRef = SymbolRefAttr::get(funcOp.getContext(), clonedFunc.getName());
960-
callableOp.setCalleeFromCallable(symbolRef);
961-
}
962-
958+
auto symbolRef =
959+
SymbolRefAttr::get(funcOp.getContext(), clonedFunc.getName());
960+
clonedCallOp.setCalleeFromCallable(symbolRef);
963961
// Set the call arguments to use the wrapper block's arguments
964962
clonedCallOp->setOperands(wrapperBlock->getArguments());
965-
966-
// Insert the cloned call operation
967963
rewriter.insert(clonedCallOp);
968964

969-
// Create return operation of the same type as the original function's return
970-
SmallVector<Operation*> returnOps;
965+
// Create return operation of the same type as the original function's
966+
// return
967+
Operation *returnOp = nullptr;
971968
for (Block &block : clonedFunc.getFunctionBody()) {
972969
if (block.getNumSuccessors() > 0)
973970
continue;
974971

975972
Operation *terminator = block.getTerminator();
976973
if (terminator && terminator->hasTrait<OpTrait::ReturnLike>()) {
977-
returnOps.push_back(terminator);
974+
returnOp = terminator;
978975
break; // Use first return as template
979976
}
980977
}
981978

982-
if (!returnOps.empty()) {
983-
Operation *templateReturnOp = returnOps[0];
984-
Operation *newReturnOp = templateReturnOp->clone();
979+
if (returnOp) {
980+
Operation *newReturnOp = returnOp->clone();
985981
newReturnOp->setOperands(clonedCallOp->getResults());
986982
newReturnOp->setLoc(funcOp.getLoc());
987983
rewriter.insert(newReturnOp);
988984
}
989-
990-
LDBG() << "Created wrapper function " << funcOp.getName()
991-
<< " that calls " << newName;
992-
993985
return true; // Changes were made
994986
}
995987

@@ -1012,20 +1004,20 @@ void RemoveDeadValues::runOnOperation() {
10121004

10131005
if (changed) {
10141006
LDBG() << "IR has changed, invalidate RunLivenessAnalysis only";
1015-
auto & pa = getPassState().preservedAnalyses;
1007+
auto &pa = getPassState().preservedAnalyses;
10161008
bool preserved = pa.isPreserved<RunLivenessAnalysis>();
10171009
la->invalidate();
10181010
am.invalidate(pa);
10191011

10201012
la = &am.getAnalysis<RunLivenessAnalysis>();
1021-
// if RunLivenessAnalysis was previously preserved, preserved the updated results.
1013+
// If RunLivenessAnalysis was previously preserved, preserved the updated
1014+
// results.
10221015
if (preserved) {
10231016
pa.preserve<RunLivenessAnalysis>();
10241017
}
10251018
}
10261019
}
10271020

1028-
10291021
// Tracks values eligible for erasure - complements liveness analysis to
10301022
// identify "droppable" values.
10311023
DenseSet<Value> deadVals;

0 commit comments

Comments
 (0)