Skip to content

Commit 750c8d3

Browse files
committed
[opt-remark] Have OptEmitter store a SILFunction instead of a SILModule.
In all of these cases, we already had a SILFunction and were just grabbing its SILModule instead of passing it in. So this is just an NFC change. The reason why I am doing this is so that I can force emit opt-remarks on functions with the semantics attribute "optremark", so I need to be able to access the SILFunction in the optimization remark infrastructure.
1 parent 3cb8f9b commit 750c8d3

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

include/swift/SIL/OptimizationRemark.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ struct RemarkMissed : public Remark<RemarkMissed> {
250250
/// Used to emit the remarks. Passes reporting remarks should create an
251251
/// instance of this.
252252
class Emitter {
253-
SILModule &module;
253+
SILFunction &fn;
254254
std::string passName;
255255
bool passedEnabled;
256256
bool missedEnabled;
@@ -264,7 +264,7 @@ class Emitter {
264264
template <typename RemarkT> bool isEnabled();
265265

266266
public:
267-
Emitter(StringRef passName, SILModule &m);
267+
Emitter(StringRef passName, SILFunction &fn);
268268

269269
/// Take a lambda that returns a remark which will be emitted. The
270270
/// lambda is not evaluated unless remarks are enabled. Second argument is
@@ -273,7 +273,7 @@ class Emitter {
273273
void emit(T remarkBuilder, decltype(remarkBuilder()) * = nullptr) {
274274
using RemarkT = decltype(remarkBuilder());
275275
// Avoid building the remark unless remarks are enabled.
276-
if (isEnabled<RemarkT>() || module.getSILRemarkStreamer()) {
276+
if (isEnabled<RemarkT>() || fn.getModule().getSILRemarkStreamer()) {
277277
auto rb = remarkBuilder();
278278
rb.setPassName(passName);
279279
emit(rb);
@@ -287,8 +287,9 @@ class Emitter {
287287
decltype(remarkBuilder()) * = nullptr) {
288288
using RemarkT = decltype(remarkBuilder());
289289
// Avoid building the remark unless remarks are enabled.
290-
bool emitRemark = emitter && (emitter->isEnabled<RemarkT>() ||
291-
emitter->module.getSILRemarkStreamer());
290+
bool emitRemark =
291+
emitter && (emitter->isEnabled<RemarkT>() ||
292+
emitter->fn.getModule().getSILRemarkStreamer());
292293
// Same for DEBUG.
293294
bool shouldEmitDebug = false;
294295
#ifndef NDEBUG

lib/SIL/Utils/OptimizationRemark.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ std::string Remark<DerivedT>::getDebugMsg() const {
144144
return stream.str();
145145
}
146146

147-
Emitter::Emitter(StringRef passName, SILModule &m)
148-
: module(m), passName(passName),
147+
Emitter::Emitter(StringRef passName, SILFunction &fn)
148+
: fn(fn), passName(passName),
149149
passedEnabled(
150-
m.getASTContext().LangOpts.OptimizationRemarkPassedPattern &&
151-
m.getASTContext().LangOpts.OptimizationRemarkPassedPattern->match(
150+
fn.getASTContext().LangOpts.OptimizationRemarkPassedPattern &&
151+
fn.getASTContext().LangOpts.OptimizationRemarkPassedPattern->match(
152152
passName)),
153153
missedEnabled(
154-
m.getASTContext().LangOpts.OptimizationRemarkMissedPattern &&
155-
m.getASTContext().LangOpts.OptimizationRemarkMissedPattern->match(
154+
fn.getASTContext().LangOpts.OptimizationRemarkMissedPattern &&
155+
fn.getASTContext().LangOpts.OptimizationRemarkMissedPattern->match(
156156
passName)) {}
157157

158158
/// The user has passed us an instruction that for some reason has a source loc
@@ -240,10 +240,12 @@ SourceLoc swift::OptRemark::inferOptRemarkSourceLoc(
240240
}
241241

242242
template <typename RemarkT, typename... ArgTypes>
243-
static void emitRemark(SILModule &module, const Remark<RemarkT> &remark,
243+
static void emitRemark(SILFunction &fn, const Remark<RemarkT> &remark,
244244
Diag<ArgTypes...> id, bool diagEnabled) {
245245
if (remark.getLocation().isInvalid())
246246
return;
247+
248+
auto &module = fn.getModule();
247249
if (auto *remarkStreamer = module.getSILRemarkStreamer())
248250
remarkStreamer->emit(remark);
249251

@@ -273,13 +275,11 @@ static void emitRemark(SILModule &module, const Remark<RemarkT> &remark,
273275
}
274276

275277
void Emitter::emit(const RemarkPassed &remark) {
276-
emitRemark(module, remark, diag::opt_remark_passed,
277-
isEnabled<RemarkPassed>());
278+
emitRemark(fn, remark, diag::opt_remark_passed, isEnabled<RemarkPassed>());
278279
}
279280

280281
void Emitter::emit(const RemarkMissed &remark) {
281-
emitRemark(module, remark, diag::opt_remark_missed,
282-
isEnabled<RemarkMissed>());
282+
emitRemark(fn, remark, diag::opt_remark_missed, isEnabled<RemarkMissed>());
283283
}
284284

285285
void Emitter::emitDebug(const RemarkPassed &remark) {

lib/SILOptimizer/Transforms/Devirtualizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Devirtualizer : public SILFunctionTransform {
6060
void Devirtualizer::devirtualizeAppliesInFunction(SILFunction &F,
6161
ClassHierarchyAnalysis *CHA) {
6262
llvm::SmallVector<ApplySite, 8> NewApplies;
63-
OptRemark::Emitter ORE(DEBUG_TYPE, F.getModule());
63+
OptRemark::Emitter ORE(DEBUG_TYPE, F);
6464

6565
SmallVector<ApplySite, 16> Applies;
6666
for (auto &BB : F) {

lib/SILOptimizer/Transforms/GenericSpecializer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ bool GenericSpecializer::specializeAppliesInFunction(SILFunction &F) {
6161
SILOptFunctionBuilder FunctionBuilder(*this);
6262
DeadInstructionSet DeadApplies;
6363
llvm::SmallSetVector<SILInstruction *, 8> Applies;
64-
OptRemark::Emitter ORE(DEBUG_TYPE, F.getModule());
64+
OptRemark::Emitter ORE(DEBUG_TYPE, F);
6565

6666
bool Changed = false;
6767
for (auto &BB : F) {

lib/SILOptimizer/Transforms/OptRemarkGenerator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ struct OptRemarkGeneratorInstructionVisitor
3535
RCIdentityFunctionInfo &rcfi;
3636
OptRemark::Emitter ORE;
3737

38-
OptRemarkGeneratorInstructionVisitor(SILModule &mod,
38+
OptRemarkGeneratorInstructionVisitor(SILFunction &fn,
3939
RCIdentityFunctionInfo &rcfi)
40-
: mod(mod), rcfi(rcfi), ORE(DEBUG_TYPE, mod) {}
40+
: mod(fn.getModule()), rcfi(rcfi), ORE(DEBUG_TYPE, fn) {}
4141

4242
void visitStrongRetainInst(StrongRetainInst *sri);
4343
void visitStrongReleaseInst(StrongReleaseInst *sri);
@@ -174,13 +174,13 @@ class OptRemarkGenerator : public SILFunctionTransform {
174174
~OptRemarkGenerator() override {}
175175

176176
bool isOptRemarksEnabled() {
177+
auto *fn = getFunction();
177178
// TODO: Put this on LangOpts as a helper.
178-
auto &langOpts = getFunction()->getASTContext().LangOpts;
179+
auto &langOpts = fn->getASTContext().LangOpts;
179180

180-
// If we have a remark streamer, emit everything.
181181
return bool(langOpts.OptimizationRemarkMissedPattern) ||
182182
bool(langOpts.OptimizationRemarkPassedPattern) ||
183-
getFunction()->getModule().getSILRemarkStreamer();
183+
fn->getModule().getSILRemarkStreamer();
184184
}
185185

186186
/// The entry point to the transformation.
@@ -191,7 +191,7 @@ class OptRemarkGenerator : public SILFunctionTransform {
191191
auto *fn = getFunction();
192192
LLVM_DEBUG(llvm::dbgs() << "Visiting: " << fn->getName() << "\n");
193193
auto &rcfi = *getAnalysis<RCIdentityAnalysis>()->get(fn);
194-
OptRemarkGeneratorInstructionVisitor visitor(fn->getModule(), rcfi);
194+
OptRemarkGeneratorInstructionVisitor visitor(*fn, rcfi);
195195
for (auto &block : *fn) {
196196
for (auto &inst : block) {
197197
visitor.visit(&inst);

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ class SILPerformanceInlinerPass : public SILFunctionTransform {
10081008
DominanceAnalysis *DA = PM->getAnalysis<DominanceAnalysis>();
10091009
SILLoopAnalysis *LA = PM->getAnalysis<SILLoopAnalysis>();
10101010
SideEffectAnalysis *SEA = PM->getAnalysis<SideEffectAnalysis>();
1011-
OptRemark::Emitter ORE(DEBUG_TYPE, getFunction()->getModule());
1011+
OptRemark::Emitter ORE(DEBUG_TYPE, *getFunction());
10121012

10131013
if (getOptions().InlineThreshold == 0) {
10141014
return;

lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ namespace {
616616
}
617617
}
618618

619-
OptRemark::Emitter ORE(DEBUG_TYPE, CurFn.getModule());
619+
OptRemark::Emitter ORE(DEBUG_TYPE, CurFn);
620620
// Go over the collected calls and try to insert speculative calls.
621621
for (auto AI : ToSpecialize)
622622
Changed |= tryToSpeculateTarget(AI, CHA, ORE);

0 commit comments

Comments
 (0)