|
| 1 | +//===--- OptRemarkGenerator.cpp -------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#define DEBUG_TYPE "sil-opt-remark-gen" |
| 14 | + |
| 15 | +#include "swift/SIL/OptimizationRemark.h" |
| 16 | +#include "swift/SIL/SILFunction.h" |
| 17 | +#include "swift/SIL/SILInstruction.h" |
| 18 | +#include "swift/SIL/SILModule.h" |
| 19 | +#include "swift/SIL/SILVisitor.h" |
| 20 | +#include "swift/SILOptimizer/PassManager/Passes.h" |
| 21 | +#include "swift/SILOptimizer/PassManager/Transforms.h" |
| 22 | + |
| 23 | +using namespace swift; |
| 24 | + |
| 25 | +//===----------------------------------------------------------------------===// |
| 26 | +// Opt Remark Generator Visitor |
| 27 | +//===----------------------------------------------------------------------===// |
| 28 | + |
| 29 | +namespace { |
| 30 | + |
| 31 | +struct OptRemarkGeneratorInstructionVisitor |
| 32 | + : public SILInstructionVisitor<OptRemarkGeneratorInstructionVisitor> { |
| 33 | + SILModule &mod; |
| 34 | + OptRemark::Emitter ORE; |
| 35 | + |
| 36 | + OptRemarkGeneratorInstructionVisitor(SILModule &mod) |
| 37 | + : mod(mod), ORE(DEBUG_TYPE, mod) {} |
| 38 | + |
| 39 | + void visitStrongRetainInst(StrongRetainInst *sri); |
| 40 | + void visitStrongReleaseInst(StrongReleaseInst *sri); |
| 41 | + void visitRetainValueInst(RetainValueInst *rvi); |
| 42 | + void visitReleaseValueInst(ReleaseValueInst *rvi); |
| 43 | + void visitSILInstruction(SILInstruction *) {} |
| 44 | +}; |
| 45 | + |
| 46 | +} // anonymous namespace |
| 47 | + |
| 48 | +void OptRemarkGeneratorInstructionVisitor::visitStrongRetainInst( |
| 49 | + StrongRetainInst *sri) { |
| 50 | + ORE.emit([&]() { |
| 51 | + using namespace OptRemark; |
| 52 | + return RemarkMissed("memory-management", *sri) |
| 53 | + << "Unable to remove ARC operation"; |
| 54 | + }); |
| 55 | +} |
| 56 | + |
| 57 | +void OptRemarkGeneratorInstructionVisitor::visitStrongReleaseInst( |
| 58 | + StrongReleaseInst *sri) { |
| 59 | + ORE.emit([&]() { |
| 60 | + using namespace OptRemark; |
| 61 | + return RemarkMissed("memory-management", *sri) |
| 62 | + << "Unable to remove ARC operation"; |
| 63 | + }); |
| 64 | +} |
| 65 | + |
| 66 | +void OptRemarkGeneratorInstructionVisitor::visitRetainValueInst( |
| 67 | + RetainValueInst *rvi) { |
| 68 | + ORE.emit([&]() { |
| 69 | + using namespace OptRemark; |
| 70 | + return RemarkMissed("memory-management", *rvi) |
| 71 | + << "Unable to remove ARC operation"; |
| 72 | + }); |
| 73 | +} |
| 74 | + |
| 75 | +void OptRemarkGeneratorInstructionVisitor::visitReleaseValueInst( |
| 76 | + ReleaseValueInst *rvi) { |
| 77 | + ORE.emit([&]() { |
| 78 | + using namespace OptRemark; |
| 79 | + return RemarkMissed("memory-management", *rvi) |
| 80 | + << "Unable to remove ARC operation"; |
| 81 | + }); |
| 82 | +} |
| 83 | + |
| 84 | +//===----------------------------------------------------------------------===// |
| 85 | +// Top Level Entrypoint |
| 86 | +//===----------------------------------------------------------------------===// |
| 87 | + |
| 88 | +namespace { |
| 89 | + |
| 90 | +class OptRemarkGenerator : public SILFunctionTransform { |
| 91 | + ~OptRemarkGenerator() override {} |
| 92 | + |
| 93 | + /// The entry point to the transformation. |
| 94 | + void run() override { |
| 95 | + OptRemarkGeneratorInstructionVisitor visitor(getFunction()->getModule()); |
| 96 | + for (auto &block : *getFunction()) { |
| 97 | + for (auto &inst : block) { |
| 98 | + visitor.visit(&inst); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | +}; |
| 103 | + |
| 104 | +} // end anonymous namespace |
| 105 | + |
| 106 | +SILTransform *swift::createOptRemarkGenerator() { |
| 107 | + return new OptRemarkGenerator(); |
| 108 | +} |
0 commit comments