llvm.org GIT mirror llvm / d16404a
Add support for missed and analysis optimization remarks. Summary: This adds two new diagnostics: -pass-remarks-missed and -pass-remarks-analysis. They take the same values as -pass-remarks but are intended to be triggered in different contexts. -pass-remarks-missed is used by LLVMContext::emitOptimizationRemarkMissed, which passes call when they tried to apply a transformation but couldn't. -pass-remarks-analysis is used by LLVMContext::emitOptimizationRemarkAnalysis, which passes call when they want to inform the user about analysis results. The patch also: 1- Adds support in the inliner for the two new remarks and a test case. 2- Moves emitOptimizationRemark* functions to the llvm namespace. 3- Adds an LLVMContext argument instead of making them member functions of LLVMContext. Reviewers: qcolombet Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D3682 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209442 91177308-0d34-0410-b5e6-96231b3b80d8 Diego Novillo 6 years ago
12 changed file(s) with 417 addition(s) and 122 deletion(s). Raw diff Collapse all Expand all
2525 class DiagnosticPrinter;
2626 class Function;
2727 class Instruction;
28 class LLVMContextImpl;
2829 class Twine;
2930 class Value;
3031 class DebugLoc;
4748 DK_DebugMetadataVersion,
4849 DK_SampleProfile,
4950 DK_OptimizationRemark,
51 DK_OptimizationRemarkMissed,
52 DK_OptimizationRemarkAnalysis,
5053 DK_FirstPluginKind
5154 };
5255
238241 const Twine &Msg;
239242 };
240243
241 /// Diagnostic information for optimization remarks.
242 class DiagnosticInfoOptimizationRemark : public DiagnosticInfo {
244 /// Common features for diagnostics dealing with optimization remarks.
245 class DiagnosticInfoOptimizationRemarkBase : public DiagnosticInfo {
246 public:
247 /// \p PassName is the name of the pass emitting this diagnostic.
248 /// \p Fn is the function where the diagnostic is being emitted. \p DLoc is
249 /// the location information to use in the diagnostic. If line table
250 /// information is available, the diagnostic will include the source code
251 /// location. \p Msg is the message to show. Note that this class does not
252 /// copy this message, so this reference must be valid for the whole life time
253 /// of the diagnostic.
254 DiagnosticInfoOptimizationRemarkBase(enum DiagnosticKind Kind,
255 const char *PassName, const Function &Fn,
256 const DebugLoc &DLoc, const Twine &Msg)
257 : DiagnosticInfo(Kind, DS_Remark), PassName(PassName), Fn(Fn), DLoc(DLoc),
258 Msg(Msg) {}
259
260 /// \see DiagnosticInfo::print.
261 void print(DiagnosticPrinter &DP) const override;
262
263 /// Hand rolled RTTI.
264 static bool classof(const DiagnosticInfo *DI) {
265 return DI->getKind() == DK_OptimizationRemark;
266 }
267
268 /// Return true if this optimization remark is enabled by one of
269 /// of the LLVM command line flags (-pass-remarks, -pass-remarks-missed,
270 /// or -pass-remarks-analysis). Note that this only handles the LLVM
271 /// flags. We cannot access Clang flags from here (they are handled
272 /// in BackendConsumer::OptimizationRemarkHandler).
273 ///
274 /// \p pImpl points to the current LLVM context. It is needed to query the
275 /// value of the command line flag associated with this remark.
276 virtual bool isEnabled(LLVMContextImpl *pImpl) const = 0;
277
278 /// Return true if location information is available for this diagnostic.
279 bool isLocationAvailable() const;
280
281 /// Return a string with the location information for this diagnostic
282 /// in the format "file:line:col". If location information is not available,
283 /// it returns ":0:0".
284 const std::string getLocationStr() const;
285
286 /// Return location information for this diagnostic in three parts:
287 /// the source file name, line number and column.
288 void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const;
289
290 const char *getPassName() const { return PassName; }
291 const Function &getFunction() const { return Fn; }
292 const DebugLoc &getDebugLoc() const { return DLoc; }
293 const Twine &getMsg() const { return Msg; }
294
295 private:
296 /// Name of the pass that triggers this report. If this matches the
297 /// regular expression given in -Rpass=regexp, then the remark will
298 /// be emitted.
299 const char *PassName;
300
301 /// Function where this diagnostic is triggered.
302 const Function &Fn;
303
304 /// Debug location where this diagnostic is triggered.
305 DebugLoc DLoc;
306
307 /// Message to report.
308 const Twine &Msg;
309 };
310
311 /// Diagnostic information for applied optimization remarks.
312 class DiagnosticInfoOptimizationRemark
313 : public DiagnosticInfoOptimizationRemarkBase {
243314 public:
244315 /// \p PassName is the name of the pass emitting this diagnostic. If
245316 /// this name matches the regular expression given in -Rpass=, then the
251322 /// must be valid for the whole life time of the diagnostic.
252323 DiagnosticInfoOptimizationRemark(const char *PassName, const Function &Fn,
253324 const DebugLoc &DLoc, const Twine &Msg)
254 : DiagnosticInfo(DK_OptimizationRemark, DS_Remark), PassName(PassName),
255 Fn(Fn), DLoc(DLoc), Msg(Msg) {}
256
257 /// \see DiagnosticInfo::print.
258 void print(DiagnosticPrinter &DP) const override;
259
260 /// Hand rolled RTTI.
325 : DiagnosticInfoOptimizationRemarkBase(DK_OptimizationRemark, PassName,
326 Fn, DLoc, Msg) {}
327
328 /// Hand rolled RTTI
261329 static bool classof(const DiagnosticInfo *DI) {
262330 return DI->getKind() == DK_OptimizationRemark;
263331 }
264332
265 /// Return true if location information is available for this diagnostic.
266 bool isLocationAvailable() const;
267
268 /// Return a string with the location information for this diagnostic
269 /// in the format "file:line:col". If location information is not available,
270 /// it returns ":0:0".
271 const std::string getLocationStr() const;
272
273 /// Return location information for this diagnostic in three parts:
274 /// the source file name, line number and column.
275 void getLocation(StringRef *Filename, unsigned *Line, unsigned *Column) const;
276
277 const char *getPassName() const { return PassName; }
278 const Function &getFunction() const { return Fn; }
279 const DebugLoc &getDebugLoc() const { return DLoc; }
280 const Twine &getMsg() const { return Msg; }
281
282 private:
283 /// Name of the pass that triggers this report. If this matches the
284 /// regular expression given in -Rpass=regexp, then the remark will
285 /// be emitted.
286 const char *PassName;
287
288 /// Function where this diagnostic is triggered.
289 const Function &Fn;
290
291 /// Debug location where this diagnostic is triggered.
292 DebugLoc DLoc;
293
294 /// Message to report.
295 const Twine &Msg;
333 /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
334 virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
335 };
336
337 /// Diagnostic information for missed-optimization remarks.
338 class DiagnosticInfoOptimizationRemarkMissed
339 : public DiagnosticInfoOptimizationRemarkBase {
340 public:
341 /// \p PassName is the name of the pass emitting this diagnostic. If
342 /// this name matches the regular expression given in -Rpass-missed=, then the
343 /// diagnostic will be emitted. \p Fn is the function where the diagnostic
344 /// is being emitted. \p DLoc is the location information to use in the
345 /// diagnostic. If line table information is available, the diagnostic
346 /// will include the source code location. \p Msg is the message to show.
347 /// Note that this class does not copy this message, so this reference
348 /// must be valid for the whole life time of the diagnostic.
349 DiagnosticInfoOptimizationRemarkMissed(const char *PassName,
350 const Function &Fn,
351 const DebugLoc &DLoc, const Twine &Msg)
352 : DiagnosticInfoOptimizationRemarkBase(DK_OptimizationRemarkMissed,
353 PassName, Fn, DLoc, Msg) {}
354
355 /// Hand rolled RTTI
356 static bool classof(const DiagnosticInfo *DI) {
357 return DI->getKind() == DK_OptimizationRemarkMissed;
358 }
359
360 /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
361 virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
362 };
363
364 /// Diagnostic information for optimization analysis remarks.
365 class DiagnosticInfoOptimizationRemarkAnalysis
366 : public DiagnosticInfoOptimizationRemarkBase {
367 public:
368 /// \p PassName is the name of the pass emitting this diagnostic. If
369 /// this name matches the regular expression given in -Rpass-analysis=, then
370 /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
371 /// is being emitted. \p DLoc is the location information to use in the
372 /// diagnostic. If line table information is available, the diagnostic will
373 /// include the source code location. \p Msg is the message to show. Note that
374 /// this class does not copy this message, so this reference must be valid for
375 /// the whole life time of the diagnostic.
376 DiagnosticInfoOptimizationRemarkAnalysis(const char *PassName,
377 const Function &Fn,
378 const DebugLoc &DLoc,
379 const Twine &Msg)
380 : DiagnosticInfoOptimizationRemarkBase(DK_OptimizationRemarkAnalysis,
381 PassName, Fn, DLoc, Msg) {}
382
383 /// Hand rolled RTTI
384 static bool classof(const DiagnosticInfo *DI) {
385 return DI->getKind() == DK_OptimizationRemarkAnalysis;
386 }
387
388 /// \see DiagnosticInfoOptimizationRemarkBase::isEnabled.
389 virtual bool isEnabled(LLVMContextImpl *pImpl) const override;
296390 };
297391
298392 // Create wrappers for C Binding types (see CBindingWrapping.h).
299393 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef)
300394
395 /// Emit an optimization-applied message. \p PassName is the name of the pass
396 /// emitting the message. If -Rpass= is given and \p PassName matches the
397 /// regular expression in -Rpass, then the remark will be emitted. \p Fn is
398 /// the function triggering the remark, \p DLoc is the debug location where
399 /// the diagnostic is generated. \p Msg is the message string to use.
400 void emitOptimizationRemark(LLVMContext &Ctx, const char *PassName,
401 const Function &Fn, const DebugLoc &DLoc,
402 const Twine &Msg);
403
404 /// Emit an optimization-missed message. \p PassName is the name of the
405 /// pass emitting the message. If -Rpass-missed= is given and \p PassName
406 /// matches the regular expression in -Rpass, then the remark will be
407 /// emitted. \p Fn is the function triggering the remark, \p DLoc is the
408 /// debug location where the diagnostic is generated. \p Msg is the
409 /// message string to use.
410 void emitOptimizationRemarkMissed(LLVMContext &Ctx, const char *PassName,
411 const Function &Fn, const DebugLoc &DLoc,
412 const Twine &Msg);
413
414 /// Emit an optimization analysis remark message. \p PassName is the name of
415 /// the pass emitting the message. If -Rpass-analysis= is given and \p
416 /// PassName matches the regular expression in -Rpass, then the remark will be
417 /// emitted. \p Fn is the function triggering the remark, \p DLoc is the debug
418 /// location where the diagnostic is generated. \p Msg is the message string
419 /// to use.
420 void emitOptimizationRemarkAnalysis(LLVMContext &Ctx, const char *PassName,
421 const Function &Fn, const DebugLoc &DLoc,
422 const Twine &Msg);
423
301424 } // End namespace llvm
302425
303426 #endif
156156 void emitError(const Instruction *I, const Twine &ErrorStr);
157157 void emitError(const Twine &ErrorStr);
158158
159 /// emitOptimizationRemark - Emit an optimization remark message. \p PassName
160 /// is the name of the pass emitting the message. If -Rpass= is given
161 /// and \p PassName matches the regular expression in -Rpass, then the
162 /// remark will be emitted. \p Fn is the function triggering the remark,
163 /// \p DLoc is the debug location where the diagnostic is generated.
164 /// \p Msg is the message string to use.
165 void emitOptimizationRemark(const char *PassName, const Function &Fn,
166 const DebugLoc &DLoc, const Twine &Msg);
167
168159 private:
169160 LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
170161 void operator=(LLVMContext&) LLVM_DELETED_FUNCTION;
1111 // Diagnostics reporting is still done as part of the LLVMContext.
1212 //===----------------------------------------------------------------------===//
1313
14 #include "LLVMContextImpl.h"
1415 #include "llvm/ADT/Twine.h"
1516 #include "llvm/IR/Constants.h"
1617 #include "llvm/IR/DebugInfo.h"
6667 DP << getMsg();
6768 }
6869
69 bool DiagnosticInfoOptimizationRemark::isLocationAvailable() const {
70 bool DiagnosticInfoOptimizationRemarkBase::isLocationAvailable() const {
7071 return getFunction().getParent()->getNamedMetadata("llvm.dbg.cu") != nullptr;
7172 }
7273
73 void DiagnosticInfoOptimizationRemark::getLocation(StringRef *Filename,
74 unsigned *Line,
75 unsigned *Column) const {
74 void DiagnosticInfoOptimizationRemarkBase::getLocation(StringRef *Filename,
75 unsigned *Line,
76 unsigned *Column) const {
7677 DILocation DIL(getDebugLoc().getAsMDNode(getFunction().getContext()));
7778 *Filename = DIL.getFilename();
7879 *Line = DIL.getLineNumber();
7980 *Column = DIL.getColumnNumber();
8081 }
8182
82 const std::string DiagnosticInfoOptimizationRemark::getLocationStr() const {
83 const std::string DiagnosticInfoOptimizationRemarkBase::getLocationStr() const {
8384 StringRef Filename("");
8485 unsigned Line = 0;
8586 unsigned Column = 0;
8889 return Twine(Filename + ":" + Twine(Line) + ":" + Twine(Column)).str();
8990 }
9091
91 void DiagnosticInfoOptimizationRemark::print(DiagnosticPrinter &DP) const {
92 void DiagnosticInfoOptimizationRemarkBase::print(DiagnosticPrinter &DP) const {
9293 DP << getLocationStr() << ": " << getMsg();
9394 }
95
96 bool
97 DiagnosticInfoOptimizationRemark::isEnabled(LLVMContextImpl *pImpl) const {
98 return pImpl->optimizationRemarkEnabledFor(this);
99 }
100
101 bool DiagnosticInfoOptimizationRemarkMissed::isEnabled(
102 LLVMContextImpl *pImpl) const {
103 return pImpl->optimizationRemarkEnabledFor(this);
104 }
105
106 bool DiagnosticInfoOptimizationRemarkAnalysis::isEnabled(
107 LLVMContextImpl *pImpl) const {
108 return pImpl->optimizationRemarkEnabledFor(this);
109 }
110
111 void llvm::emitOptimizationRemark(LLVMContext &Ctx, const char *PassName,
112 const Function &Fn, const DebugLoc &DLoc,
113 const Twine &Msg) {
114 Ctx.diagnose(DiagnosticInfoOptimizationRemark(PassName, Fn, DLoc, Msg));
115 }
116
117 void llvm::emitOptimizationRemarkMissed(LLVMContext &Ctx, const char *PassName,
118 const Function &Fn,
119 const DebugLoc &DLoc,
120 const Twine &Msg) {
121 Ctx.diagnose(DiagnosticInfoOptimizationRemarkMissed(PassName, Fn, DLoc, Msg));
122 }
123
124 void llvm::emitOptimizationRemarkAnalysis(LLVMContext &Ctx,
125 const char *PassName,
126 const Function &Fn,
127 const DebugLoc &DLoc,
128 const Twine &Msg) {
129 Ctx.diagnose(
130 DiagnosticInfoOptimizationRemarkAnalysis(PassName, Fn, DLoc, Msg));
131 }
141141 return;
142142 }
143143
144 // Optimization remarks are selective. They need to check whether
145 // the regexp pattern, passed via -pass-remarks, matches the name
146 // of the pass that is emitting the diagnostic. If there is no match,
147 // ignore the diagnostic and return.
148 if (DI.getKind() == llvm::DK_OptimizationRemark &&
149 !pImpl->optimizationRemarksEnabledFor(
150 cast(DI).getPassName()))
151 return;
144 // Optimization remarks are selective. They need to check whether the regexp
145 // pattern, passed via one of the -pass-remarks* flags, matches the name of
146 // the pass that is emitting the diagnostic. If there is no match, ignore the
147 // diagnostic and return.
148 switch (DI.getKind()) {
149 case llvm::DK_OptimizationRemark:
150 if (!cast(DI).isEnabled(pImpl))
151 return;
152 break;
153 case llvm::DK_OptimizationRemarkMissed:
154 if (!cast(DI).isEnabled(pImpl))
155 return;
156 break;
157 case llvm::DK_OptimizationRemarkAnalysis:
158 if (!cast(DI).isEnabled(pImpl))
159 return;
160 break;
161 default:
162 break;
163 }
152164
153165 // Otherwise, print the message with a prefix based on the severity.
154166 std::string MsgStorage;
176188 diagnose(DiagnosticInfoInlineAsm(LocCookie, ErrorStr));
177189 }
178190
179 void LLVMContext::emitOptimizationRemark(const char *PassName,
180 const Function &Fn,
181 const DebugLoc &DLoc,
182 const Twine &Msg) {
183 diagnose(DiagnosticInfoOptimizationRemark(PassName, Fn, DLoc, Msg));
184 }
185
186191 //===----------------------------------------------------------------------===//
187192 // Metadata Kind Uniquing
188193 //===----------------------------------------------------------------------===//
1313 #include "LLVMContextImpl.h"
1414 #include "llvm/ADT/STLExtras.h"
1515 #include "llvm/IR/Attributes.h"
16 #include "llvm/IR/DiagnosticInfo.h"
1617 #include "llvm/IR/Module.h"
1718 #include "llvm/Support/CommandLine.h"
1819 #include "llvm/Support/Regex.h"
4748
4849 namespace {
4950
50 /// \brief Regular expression corresponding to the value given in the
51 /// command line flag -pass-remarks. Passes whose name matches this
52 /// regexp will emit a diagnostic when calling
53 /// LLVMContext::emitOptimizationRemark.
54 static Regex *OptimizationRemarkPattern = nullptr;
55
51 /// \brief Regular expression corresponding to the value given in one of the
52 /// -pass-remarks* command line flags. Passes whose name matches this regexp
53 /// will emit a diagnostic when calling the associated diagnostic function
54 /// (emitOptimizationRemark, emitOptimizationRemarkMissed or
55 /// emitOptimizationRemarkAnalysis).
5656 struct PassRemarksOpt {
57 void operator=(const std::string &Val) const {
57 std::shared_ptr Pattern;
58
59 void operator=(const std::string &Val) {
5860 // Create a regexp object to match pass names for emitOptimizationRemark.
5961 if (!Val.empty()) {
60 delete OptimizationRemarkPattern;
61 OptimizationRemarkPattern = new Regex(Val);
62 Pattern = std::make_shared(Val);
6263 std::string RegexError;
63 if (!OptimizationRemarkPattern->isValid(RegexError))
64 if (!Pattern->isValid(RegexError))
6465 report_fatal_error("Invalid regular expression '" + Val +
6566 "' in -pass-remarks: " + RegexError,
6667 false);
6970 };
7071
7172 static PassRemarksOpt PassRemarksOptLoc;
73 static PassRemarksOpt PassRemarksMissedOptLoc;
74 static PassRemarksOpt PassRemarksAnalysisOptLoc;
7275
7376 // -pass-remarks
74 // Command line flag to enable LLVMContext::emitOptimizationRemark()
75 // and LLVMContext::emitOptimizationNote() calls.
77 // Command line flag to enable emitOptimizationRemark()
7678 static cl::opt>
7779 PassRemarks("pass-remarks", cl::value_desc("pattern"),
7880 cl::desc("Enable optimization remarks from passes whose name match "
7981 "the given regular expression"),
8082 cl::Hidden, cl::location(PassRemarksOptLoc), cl::ValueRequired,
8183 cl::ZeroOrMore);
82 }
83
84 bool
85 LLVMContextImpl::optimizationRemarksEnabledFor(const char *PassName) const {
86 return OptimizationRemarkPattern &&
87 OptimizationRemarkPattern->match(PassName);
88 }
89
84
85 // -pass-remarks-missed
86 // Command line flag to enable emitOptimizationRemarkMissed()
87 static cl::opt> PassRemarksMissed(
88 "pass-remarks-missed", cl::value_desc("pattern"),
89 cl::desc("Enable missed optimization remarks from passes whose name match "
90 "the given regular expression"),
91 cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired,
92 cl::ZeroOrMore);
93
94 // -pass-remarks-analysis
95 // Command line flag to enable emitOptimizationRemarkAnalysis()
96 static cl::opt>
97 PassRemarksAnalysis(
98 "pass-remarks-analysis", cl::value_desc("pattern"),
99 cl::desc(
100 "Enable optimization analysis remarks from passes whose name match "
101 "the given regular expression"),
102 cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
103 cl::ZeroOrMore);
104 }
105
106 bool LLVMContextImpl::optimizationRemarkEnabledFor(
107 const DiagnosticInfoOptimizationRemark *DI) const {
108 return PassRemarksOptLoc.Pattern &&
109 PassRemarksOptLoc.Pattern->match(DI->getPassName());
110 }
111
112 bool LLVMContextImpl::optimizationRemarkEnabledFor(
113 const DiagnosticInfoOptimizationRemarkMissed *DI) const {
114 return PassRemarksMissedOptLoc.Pattern &&
115 PassRemarksMissedOptLoc.Pattern->match(DI->getPassName());
116 }
117
118 bool LLVMContextImpl::optimizationRemarkEnabledFor(
119 const DiagnosticInfoOptimizationRemarkAnalysis *DI) const {
120 return PassRemarksAnalysisOptLoc.Pattern &&
121 PassRemarksAnalysisOptLoc.Pattern->match(DI->getPassName());
122 }
90123
91124 namespace {
92125 struct DropReferences {
93126 // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
94127 // is a Constant*.
95 template
96 void operator()(const PairT &P) {
128 template void operator()(const PairT &P) {
97129 P.second->dropAllReferences();
98130 }
99131 };
3636
3737 class ConstantInt;
3838 class ConstantFP;
39 class DiagnosticInfoOptimizationRemark;
40 class DiagnosticInfoOptimizationRemarkMissed;
41 class DiagnosticInfoOptimizationRemarkAnalysis;
3942 class LLVMContext;
4043 class Type;
4144 class Value;
372375
373376 /// \brief Return true if the given pass name should emit optimization
374377 /// remarks.
375 bool optimizationRemarksEnabledFor(const char *PassName) const;
378 bool optimizationRemarkEnabledFor(
379 const DiagnosticInfoOptimizationRemark *DI) const;
380 bool optimizationRemarkEnabledFor(
381 const DiagnosticInfoOptimizationRemarkMissed *DI) const;
382 bool optimizationRemarkEnabledFor(
383 const DiagnosticInfoOptimizationRemarkAnalysis *DI) const;
376384
377385 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
378386 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
300300 return thres;
301301 }
302302
303 static void emitAnalysis(CallSite CS, const Twine &Msg) {
304 Function *Caller = CS.getCaller();
305 LLVMContext &Ctx = Caller->getContext();
306 DebugLoc DLoc = CS.getInstruction()->getDebugLoc();
307 emitOptimizationRemarkAnalysis(Ctx, DEBUG_TYPE, *Caller, DLoc, Msg);
308 }
309
303310 /// shouldInline - Return true if the inliner should attempt to inline
304311 /// at the given CallSite.
305312 bool Inliner::shouldInline(CallSite CS) {
308315 if (IC.isAlways()) {
309316 DEBUG(dbgs() << " Inlining: cost=always"
310317 << ", Call: " << *CS.getInstruction() << "\n");
318 emitAnalysis(CS, Twine(CS.getCalledFunction()->getName()) +
319 " should always be inlined (cost=always)");
311320 return true;
312321 }
313322
314323 if (IC.isNever()) {
315324 DEBUG(dbgs() << " NOT Inlining: cost=never"
316325 << ", Call: " << *CS.getInstruction() << "\n");
326 emitAnalysis(CS, Twine(CS.getCalledFunction()->getName() +
327 " should never be inlined (cost=never)"));
317328 return false;
318329 }
319330
322333 DEBUG(dbgs() << " NOT Inlining: cost=" << IC.getCost()
323334 << ", thres=" << (IC.getCostDelta() + IC.getCost())
324335 << ", Call: " << *CS.getInstruction() << "\n");
336 emitAnalysis(CS, Twine(CS.getCalledFunction()->getName() +
337 " too costly to inline (cost=") +
338 Twine(IC.getCost()) + ", threshold=" +
339 Twine(IC.getCostDelta() + IC.getCost()) + ")");
325340 return false;
326341 }
327342
389404 DEBUG(dbgs() << " NOT Inlining: " << *CS.getInstruction() <<
390405 " Cost = " << IC.getCost() <<
391406 ", outer Cost = " << TotalSecondaryCost << '\n');
407 emitAnalysis(
408 CS, Twine("Not inlining. Cost of inlining " +
409 CS.getCalledFunction()->getName() +
410 " increases the cost of inlining " +
411 CS.getCaller()->getName() + " in other contexts"));
392412 return false;
393413 }
394414 }
396416 DEBUG(dbgs() << " Inlining: cost=" << IC.getCost()
397417 << ", thres=" << (IC.getCostDelta() + IC.getCost())
398418 << ", Call: " << *CS.getInstruction() << '\n');
419 emitAnalysis(
420 CS, CS.getCalledFunction()->getName() + Twine(" can be inlined into ") +
421 CS.getCaller()->getName() + " with cost=" + Twine(IC.getCost()) +
422 " (threshold=" + Twine(IC.getCostDelta() + IC.getCost()) + ")");
399423 return true;
400424 }
401425
517541 InlineHistoryIncludes(Callee, InlineHistoryID, InlineHistory))
518542 continue;
519543
520
544 LLVMContext &CallerCtx = Caller->getContext();
545
546 // Get DebugLoc to report. CS will be invalid after Inliner.
547 DebugLoc DLoc = CS.getInstruction()->getDebugLoc();
548
521549 // If the policy determines that we should inline this function,
522550 // try to do so.
523 if (!shouldInline(CS))
551 if (!shouldInline(CS)) {
552 emitOptimizationRemarkMissed(CallerCtx, DEBUG_TYPE, *Caller, DLoc,
553 Twine(Callee->getName() +
554 " will not be inlined into " +
555 Caller->getName()));
524556 continue;
525
526 // Get DebugLoc to report. CS will be invalid after Inliner.
527 DebugLoc DLoc = CS.getInstruction()->getDebugLoc();
557 }
528558
529559 // Attempt to inline the function.
530560 if (!InlineCallIfPossible(CS, InlineInfo, InlinedArrayAllocas,
531 InlineHistoryID, InsertLifetime, DL))
561 InlineHistoryID, InsertLifetime, DL)) {
562 emitOptimizationRemarkMissed(CallerCtx, DEBUG_TYPE, *Caller, DLoc,
563 Twine(Callee->getName() +
564 " will not be inlined into " +
565 Caller->getName()));
532566 continue;
567 }
533568 ++NumInlined;
534569
535570 // Report the inline decision.
536 Caller->getContext().emitOptimizationRemark(
537 DEBUG_TYPE, *Caller, DLoc,
571 emitOptimizationRemark(
572 CallerCtx, DEBUG_TYPE, *Caller, DLoc,
538573 Twine(Callee->getName() + " inlined into " + Caller->getName()));
539574
540575 // If inlining this function gave us any new call sites, throw them
6363 #include "llvm/IR/CallSite.h"
6464 #include "llvm/IR/Constants.h"
6565 #include "llvm/IR/DerivedTypes.h"
66 #include "llvm/IR/DiagnosticInfo.h"
6667 #include "llvm/IR/Function.h"
6768 #include "llvm/IR/Instructions.h"
6869 #include "llvm/IR/IntrinsicInst.h"
317318 break;
318319 }
319320 if (SafeToTail) {
320 F.getContext().emitOptimizationRemark(
321 "tailcallelim", F, CI->getDebugLoc(),
321 emitOptimizationRemark(
322 F.getContext(), "tailcallelim", F, CI->getDebugLoc(),
322323 "marked this readnone call a tail call candidate");
323324 CI->setTailCall();
324325 Modified = true;
364365 if (Visited[CI->getParent()] != ESCAPED) {
365366 // If the escape point was part way through the block, calls after the
366367 // escape point wouldn't have been put into DeferredTails.
367 F.getContext().emitOptimizationRemark(
368 "tailcallelim", F, CI->getDebugLoc(),
369 "marked this call a tail call candidate");
368 emitOptimizationRemark(F.getContext(), "tailcallelim", F,
369 CI->getDebugLoc(),
370 "marked this call a tail call candidate");
370371 CI->setTailCall();
371372 Modified = true;
372373 } else {
677678 BasicBlock *BB = Ret->getParent();
678679 Function *F = BB->getParent();
679680
680 F->getContext().emitOptimizationRemark(
681 "tailcallelim", *F, CI->getDebugLoc(),
682 "transforming tail recursion to loop");
681 emitOptimizationRemark(F->getContext(), "tailcallelim", *F, CI->getDebugLoc(),
682 "transforming tail recursion to loop");
683683
684684 // OK! We can transform this tail call. If this is the first one found,
685685 // create the new entry block, allowing us to branch back to the old entry.
2323 #include "llvm/Analysis/ScalarEvolution.h"
2424 #include "llvm/IR/BasicBlock.h"
2525 #include "llvm/IR/Dominators.h"
26 #include "llvm/IR/DiagnosticInfo.h"
2627 #include "llvm/IR/LLVMContext.h"
2728 #include "llvm/Support/Debug.h"
2829 #include "llvm/Support/raw_ostream.h"
236237 if (CompletelyUnroll) {
237238 DEBUG(dbgs() << "COMPLETELY UNROLLING loop %" << Header->getName()
238239 << " with trip count " << TripCount << "!\n");
239 Ctx.emitOptimizationRemark(DEBUG_TYPE, *F, LoopLoc,
240 Twine("completely unrolled loop with ") +
241 Twine(TripCount) + " iterations");
240 emitOptimizationRemark(Ctx, DEBUG_TYPE, *F, LoopLoc,
241 Twine("completely unrolled loop with ") +
242 Twine(TripCount) + " iterations");
242243 } else {
243244 DEBUG(dbgs() << "UNROLLING loop %" << Header->getName()
244245 << " by " << Count);
254255 DiagMsg.concat(" with run-time trip count");
255256 }
256257 DEBUG(dbgs() << "!\n");
257 Ctx.emitOptimizationRemark(DEBUG_TYPE, *F, LoopLoc, DiagMsg);
258 emitOptimizationRemark(Ctx, DEBUG_TYPE, *F, LoopLoc, DiagMsg);
258259 }
259260
260261 bool ContinueOnTrue = L->contains(BI->getSuccessor(0));
1919 #include "llvm/ADT/Triple.h"
2020 #include "llvm/Analysis/ValueTracking.h"
2121 #include "llvm/IR/DataLayout.h"
22 #include "llvm/IR/DiagnosticInfo.h"
2223 #include "llvm/IR/Function.h"
2324 #include "llvm/IR/IRBuilder.h"
2425 #include "llvm/IR/IntrinsicInst.h"
788789 uint64_t LenTrue = GetStringLength(SI->getTrueValue());
789790 uint64_t LenFalse = GetStringLength(SI->getFalseValue());
790791 if (LenTrue && LenFalse) {
791 Context->emitOptimizationRemark(
792 "simplify-libcalls", *Caller, SI->getDebugLoc(),
793 "folded strlen(select) to select of constants");
792 emitOptimizationRemark(*Context, "simplify-libcalls", *Caller,
793 SI->getDebugLoc(),
794 "folded strlen(select) to select of constants");
794795 return B.CreateSelect(SI->getCondition(),
795796 ConstantInt::get(CI->getType(), LenTrue-1),
796797 ConstantInt::get(CI->getType(), LenFalse-1));
6666 #include "llvm/IR/DataLayout.h"
6767 #include "llvm/IR/DebugInfo.h"
6868 #include "llvm/IR/DerivedTypes.h"
69 #include "llvm/IR/DiagnosticInfo.h"
6970 #include "llvm/IR/Dominators.h"
7071 #include "llvm/IR/Function.h"
7172 #include "llvm/IR/IRBuilder.h"
12121213 DEBUG(dbgs() << "LV: Trying to at least unroll the loops.\n");
12131214
12141215 // Report the unrolling decision.
1215 F->getContext().emitOptimizationRemark(
1216 DEBUG_TYPE, *F, L->getStartLoc(),
1217 Twine("unrolled with interleaving factor " + Twine(UF) +
1218 " (vectorization not beneficial)"));
1216 emitOptimizationRemark(F->getContext(), DEBUG_TYPE, *F, L->getStartLoc(),
1217 Twine("unrolled with interleaving factor " +
1218 Twine(UF) +
1219 " (vectorization not beneficial)"));
12191220
12201221 // We decided not to vectorize, but we may want to unroll.
12211222 InnerLoopUnroller Unroller(L, SE, LI, DT, DL, TLI, UF);
12271228 ++LoopsVectorized;
12281229
12291230 // Report the vectorization decision.
1230 F->getContext().emitOptimizationRemark(
1231 DEBUG_TYPE, *F, L->getStartLoc(),
1231 emitOptimizationRemark(
1232 F->getContext(), DEBUG_TYPE, *F, L->getStartLoc(),
12321233 Twine("vectorized loop (vectorization factor: ") + Twine(VF.Width) +
12331234 ", unrolling interleave factor: " + Twine(UF) + ")");
12341235 }
0 ; RUN: opt < %s -inline -pass-remarks=inline -pass-remarks-missed=inline -pass-remarks-analysis=inline -S 2>&1 | FileCheck %s
1
2 ; CHECK: foo should always be inlined (cost=always)
3 ; CHECK: foo inlined into bar
4 ; CHECK: foz should never be inlined (cost=never)
5 ; CHECK: foz will not be inlined into bar
6
7 ; Function Attrs: alwaysinline nounwind uwtable
8 define i32 @foo(i32 %x, i32 %y) #0 {
9 entry:
10 %x.addr = alloca i32, align 4
11 %y.addr = alloca i32, align 4
12 store i32 %x, i32* %x.addr, align 4
13 store i32 %y, i32* %y.addr, align 4
14 %0 = load i32* %x.addr, align 4
15 %1 = load i32* %y.addr, align 4
16 %add = add nsw i32 %0, %1
17 ret i32 %add
18 }
19
20 ; Function Attrs: noinline nounwind uwtable
21 define float @foz(i32 %x, i32 %y) #1 {
22 entry:
23 %x.addr = alloca i32, align 4
24 %y.addr = alloca i32, align 4
25 store i32 %x, i32* %x.addr, align 4
26 store i32 %y, i32* %y.addr, align 4
27 %0 = load i32* %x.addr, align 4
28 %1 = load i32* %y.addr, align 4
29 %mul = mul nsw i32 %0, %1
30 %conv = sitofp i32 %mul to float
31 ret float %conv
32 }
33
34 ; Function Attrs: nounwind uwtable
35 define i32 @bar(i32 %j) #2 {
36 entry:
37 %j.addr = alloca i32, align 4
38 store i32 %j, i32* %j.addr, align 4
39 %0 = load i32* %j.addr, align 4
40 %1 = load i32* %j.addr, align 4
41 %sub = sub nsw i32 %1, 2
42 %call = call i32 @foo(i32 %0, i32 %sub)
43 %conv = sitofp i32 %call to float
44 %2 = load i32* %j.addr, align 4
45 %sub1 = sub nsw i32 %2, 2
46 %3 = load i32* %j.addr, align 4
47 %call2 = call float @foz(i32 %sub1, i32 %3)
48 %mul = fmul float %conv, %call2
49 %conv3 = fptosi float %mul to i32
50 ret i32 %conv3
51 }
52
53 attributes #0 = { alwaysinline nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
54 attributes #1 = { noinline nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
55 attributes #2 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
56
57 !llvm.ident = !{!0}
58
59 !0 = metadata !{metadata !"clang version 3.5.0 "}