DiagnosticInfo.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/IR/DiagnosticInfo.h - Diagnostic Declaration --------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the different classes involved in low level diagnostics.
  15. //
  16. // Diagnostics reporting is still done as part of the LLVMContext.
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_IR_DIAGNOSTICINFO_H
  19. #define LLVM_IR_DIAGNOSTICINFO_H
  20. #include "llvm-c/Types.h"
  21. #include "llvm/ADT/ArrayRef.h"
  22. #include "llvm/ADT/SmallVector.h"
  23. #include "llvm/ADT/StringRef.h"
  24. #include "llvm/ADT/Twine.h"
  25. #include "llvm/IR/DebugLoc.h"
  26. #include "llvm/Support/CBindingWrapping.h"
  27. #include "llvm/Support/ErrorHandling.h"
  28. #include "llvm/Support/SourceMgr.h"
  29. #include "llvm/Support/TypeSize.h"
  30. #include <algorithm>
  31. #include <cstdint>
  32. #include <functional>
  33. #include <iterator>
  34. #include <optional>
  35. #include <string>
  36. namespace llvm {
  37. // Forward declarations.
  38. class DiagnosticPrinter;
  39. class DIFile;
  40. class DISubprogram;
  41. class CallInst;
  42. class Function;
  43. class Instruction;
  44. class InstructionCost;
  45. class Module;
  46. class Type;
  47. class Value;
  48. /// Defines the different supported severity of a diagnostic.
  49. enum DiagnosticSeverity : char {
  50. DS_Error,
  51. DS_Warning,
  52. DS_Remark,
  53. // A note attaches additional information to one of the previous diagnostic
  54. // types.
  55. DS_Note
  56. };
  57. /// Defines the different supported kind of a diagnostic.
  58. /// This enum should be extended with a new ID for each added concrete subclass.
  59. enum DiagnosticKind {
  60. DK_InlineAsm,
  61. DK_ResourceLimit,
  62. DK_StackSize,
  63. DK_Linker,
  64. DK_Lowering,
  65. DK_DebugMetadataVersion,
  66. DK_DebugMetadataInvalid,
  67. DK_ISelFallback,
  68. DK_SampleProfile,
  69. DK_OptimizationRemark,
  70. DK_OptimizationRemarkMissed,
  71. DK_OptimizationRemarkAnalysis,
  72. DK_OptimizationRemarkAnalysisFPCommute,
  73. DK_OptimizationRemarkAnalysisAliasing,
  74. DK_OptimizationFailure,
  75. DK_FirstRemark = DK_OptimizationRemark,
  76. DK_LastRemark = DK_OptimizationFailure,
  77. DK_MachineOptimizationRemark,
  78. DK_MachineOptimizationRemarkMissed,
  79. DK_MachineOptimizationRemarkAnalysis,
  80. DK_FirstMachineRemark = DK_MachineOptimizationRemark,
  81. DK_LastMachineRemark = DK_MachineOptimizationRemarkAnalysis,
  82. DK_MIRParser,
  83. DK_PGOProfile,
  84. DK_Unsupported,
  85. DK_SrcMgr,
  86. DK_DontCall,
  87. DK_MisExpect,
  88. DK_FirstPluginKind // Must be last value to work with
  89. // getNextAvailablePluginDiagnosticKind
  90. };
  91. /// Get the next available kind ID for a plugin diagnostic.
  92. /// Each time this function is called, it returns a different number.
  93. /// Therefore, a plugin that wants to "identify" its own classes
  94. /// with a dynamic identifier, just have to use this method to get a new ID
  95. /// and assign it to each of its classes.
  96. /// The returned ID will be greater than or equal to DK_FirstPluginKind.
  97. /// Thus, the plugin identifiers will not conflict with the
  98. /// DiagnosticKind values.
  99. int getNextAvailablePluginDiagnosticKind();
  100. /// This is the base abstract class for diagnostic reporting in
  101. /// the backend.
  102. /// The print method must be overloaded by the subclasses to print a
  103. /// user-friendly message in the client of the backend (let us call it a
  104. /// frontend).
  105. class DiagnosticInfo {
  106. private:
  107. /// Kind defines the kind of report this is about.
  108. const /* DiagnosticKind */ int Kind;
  109. /// Severity gives the severity of the diagnostic.
  110. const DiagnosticSeverity Severity;
  111. virtual void anchor();
  112. public:
  113. DiagnosticInfo(/* DiagnosticKind */ int Kind, DiagnosticSeverity Severity)
  114. : Kind(Kind), Severity(Severity) {}
  115. virtual ~DiagnosticInfo() = default;
  116. /* DiagnosticKind */ int getKind() const { return Kind; }
  117. DiagnosticSeverity getSeverity() const { return Severity; }
  118. /// Print using the given \p DP a user-friendly message.
  119. /// This is the default message that will be printed to the user.
  120. /// It is used when the frontend does not directly take advantage
  121. /// of the information contained in fields of the subclasses.
  122. /// The printed message must not end with '.' nor start with a severity
  123. /// keyword.
  124. virtual void print(DiagnosticPrinter &DP) const = 0;
  125. };
  126. using DiagnosticHandlerFunction = std::function<void(const DiagnosticInfo &)>;
  127. /// Diagnostic information for inline asm reporting.
  128. /// This is basically a message and an optional location.
  129. class DiagnosticInfoInlineAsm : public DiagnosticInfo {
  130. private:
  131. /// Optional line information. 0 if not set.
  132. uint64_t LocCookie = 0;
  133. /// Message to be reported.
  134. const Twine &MsgStr;
  135. /// Optional origin of the problem.
  136. const Instruction *Instr = nullptr;
  137. public:
  138. /// \p MsgStr is the message to be reported to the frontend.
  139. /// This class does not copy \p MsgStr, therefore the reference must be valid
  140. /// for the whole life time of the Diagnostic.
  141. DiagnosticInfoInlineAsm(const Twine &MsgStr,
  142. DiagnosticSeverity Severity = DS_Error)
  143. : DiagnosticInfo(DK_InlineAsm, Severity), MsgStr(MsgStr) {}
  144. /// \p LocCookie if non-zero gives the line number for this report.
  145. /// \p MsgStr gives the message.
  146. /// This class does not copy \p MsgStr, therefore the reference must be valid
  147. /// for the whole life time of the Diagnostic.
  148. DiagnosticInfoInlineAsm(uint64_t LocCookie, const Twine &MsgStr,
  149. DiagnosticSeverity Severity = DS_Error)
  150. : DiagnosticInfo(DK_InlineAsm, Severity), LocCookie(LocCookie),
  151. MsgStr(MsgStr) {}
  152. /// \p Instr gives the original instruction that triggered the diagnostic.
  153. /// \p MsgStr gives the message.
  154. /// This class does not copy \p MsgStr, therefore the reference must be valid
  155. /// for the whole life time of the Diagnostic.
  156. /// Same for \p I.
  157. DiagnosticInfoInlineAsm(const Instruction &I, const Twine &MsgStr,
  158. DiagnosticSeverity Severity = DS_Error);
  159. uint64_t getLocCookie() const { return LocCookie; }
  160. const Twine &getMsgStr() const { return MsgStr; }
  161. const Instruction *getInstruction() const { return Instr; }
  162. /// \see DiagnosticInfo::print.
  163. void print(DiagnosticPrinter &DP) const override;
  164. static bool classof(const DiagnosticInfo *DI) {
  165. return DI->getKind() == DK_InlineAsm;
  166. }
  167. };
  168. /// Diagnostic information for debug metadata version reporting.
  169. /// This is basically a module and a version.
  170. class DiagnosticInfoDebugMetadataVersion : public DiagnosticInfo {
  171. private:
  172. /// The module that is concerned by this debug metadata version diagnostic.
  173. const Module &M;
  174. /// The actual metadata version.
  175. unsigned MetadataVersion;
  176. public:
  177. /// \p The module that is concerned by this debug metadata version diagnostic.
  178. /// \p The actual metadata version.
  179. DiagnosticInfoDebugMetadataVersion(const Module &M, unsigned MetadataVersion,
  180. DiagnosticSeverity Severity = DS_Warning)
  181. : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M),
  182. MetadataVersion(MetadataVersion) {}
  183. const Module &getModule() const { return M; }
  184. unsigned getMetadataVersion() const { return MetadataVersion; }
  185. /// \see DiagnosticInfo::print.
  186. void print(DiagnosticPrinter &DP) const override;
  187. static bool classof(const DiagnosticInfo *DI) {
  188. return DI->getKind() == DK_DebugMetadataVersion;
  189. }
  190. };
  191. /// Diagnostic information for stripping invalid debug metadata.
  192. class DiagnosticInfoIgnoringInvalidDebugMetadata : public DiagnosticInfo {
  193. private:
  194. /// The module that is concerned by this debug metadata version diagnostic.
  195. const Module &M;
  196. public:
  197. /// \p The module that is concerned by this debug metadata version diagnostic.
  198. DiagnosticInfoIgnoringInvalidDebugMetadata(
  199. const Module &M, DiagnosticSeverity Severity = DS_Warning)
  200. : DiagnosticInfo(DK_DebugMetadataVersion, Severity), M(M) {}
  201. const Module &getModule() const { return M; }
  202. /// \see DiagnosticInfo::print.
  203. void print(DiagnosticPrinter &DP) const override;
  204. static bool classof(const DiagnosticInfo *DI) {
  205. return DI->getKind() == DK_DebugMetadataInvalid;
  206. }
  207. };
  208. /// Diagnostic information for the sample profiler.
  209. class DiagnosticInfoSampleProfile : public DiagnosticInfo {
  210. public:
  211. DiagnosticInfoSampleProfile(StringRef FileName, unsigned LineNum,
  212. const Twine &Msg,
  213. DiagnosticSeverity Severity = DS_Error)
  214. : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
  215. LineNum(LineNum), Msg(Msg) {}
  216. DiagnosticInfoSampleProfile(StringRef FileName, const Twine &Msg,
  217. DiagnosticSeverity Severity = DS_Error)
  218. : DiagnosticInfo(DK_SampleProfile, Severity), FileName(FileName),
  219. Msg(Msg) {}
  220. DiagnosticInfoSampleProfile(const Twine &Msg,
  221. DiagnosticSeverity Severity = DS_Error)
  222. : DiagnosticInfo(DK_SampleProfile, Severity), Msg(Msg) {}
  223. /// \see DiagnosticInfo::print.
  224. void print(DiagnosticPrinter &DP) const override;
  225. static bool classof(const DiagnosticInfo *DI) {
  226. return DI->getKind() == DK_SampleProfile;
  227. }
  228. StringRef getFileName() const { return FileName; }
  229. unsigned getLineNum() const { return LineNum; }
  230. const Twine &getMsg() const { return Msg; }
  231. private:
  232. /// Name of the input file associated with this diagnostic.
  233. StringRef FileName;
  234. /// Line number where the diagnostic occurred. If 0, no line number will
  235. /// be emitted in the message.
  236. unsigned LineNum = 0;
  237. /// Message to report.
  238. const Twine &Msg;
  239. };
  240. /// Diagnostic information for the PGO profiler.
  241. class DiagnosticInfoPGOProfile : public DiagnosticInfo {
  242. public:
  243. DiagnosticInfoPGOProfile(const char *FileName, const Twine &Msg,
  244. DiagnosticSeverity Severity = DS_Error)
  245. : DiagnosticInfo(DK_PGOProfile, Severity), FileName(FileName), Msg(Msg) {}
  246. /// \see DiagnosticInfo::print.
  247. void print(DiagnosticPrinter &DP) const override;
  248. static bool classof(const DiagnosticInfo *DI) {
  249. return DI->getKind() == DK_PGOProfile;
  250. }
  251. const char *getFileName() const { return FileName; }
  252. const Twine &getMsg() const { return Msg; }
  253. private:
  254. /// Name of the input file associated with this diagnostic.
  255. const char *FileName;
  256. /// Message to report.
  257. const Twine &Msg;
  258. };
  259. class DiagnosticLocation {
  260. DIFile *File = nullptr;
  261. unsigned Line = 0;
  262. unsigned Column = 0;
  263. public:
  264. DiagnosticLocation() = default;
  265. DiagnosticLocation(const DebugLoc &DL);
  266. DiagnosticLocation(const DISubprogram *SP);
  267. bool isValid() const { return File; }
  268. /// Return the full path to the file.
  269. std::string getAbsolutePath() const;
  270. /// Return the file name relative to the compilation directory.
  271. StringRef getRelativePath() const;
  272. unsigned getLine() const { return Line; }
  273. unsigned getColumn() const { return Column; }
  274. };
  275. /// Common features for diagnostics with an associated location.
  276. class DiagnosticInfoWithLocationBase : public DiagnosticInfo {
  277. void anchor() override;
  278. public:
  279. /// \p Fn is the function where the diagnostic is being emitted. \p Loc is
  280. /// the location information to use in the diagnostic.
  281. DiagnosticInfoWithLocationBase(enum DiagnosticKind Kind,
  282. enum DiagnosticSeverity Severity,
  283. const Function &Fn,
  284. const DiagnosticLocation &Loc)
  285. : DiagnosticInfo(Kind, Severity), Fn(Fn), Loc(Loc) {}
  286. /// Return true if location information is available for this diagnostic.
  287. bool isLocationAvailable() const { return Loc.isValid(); }
  288. /// Return a string with the location information for this diagnostic
  289. /// in the format "file:line:col". If location information is not available,
  290. /// it returns "<unknown>:0:0".
  291. std::string getLocationStr() const;
  292. /// Return location information for this diagnostic in three parts:
  293. /// the relative source file path, line number and column.
  294. void getLocation(StringRef &RelativePath, unsigned &Line,
  295. unsigned &Column) const;
  296. /// Return the absolute path tot the file.
  297. std::string getAbsolutePath() const;
  298. const Function &getFunction() const { return Fn; }
  299. DiagnosticLocation getLocation() const { return Loc; }
  300. private:
  301. /// Function where this diagnostic is triggered.
  302. const Function &Fn;
  303. /// Debug location where this diagnostic is triggered.
  304. DiagnosticLocation Loc;
  305. };
  306. /// Diagnostic information for stack size etc. reporting.
  307. /// This is basically a function and a size.
  308. class DiagnosticInfoResourceLimit : public DiagnosticInfoWithLocationBase {
  309. private:
  310. /// The function that is concerned by this resource limit diagnostic.
  311. const Function &Fn;
  312. /// Description of the resource type (e.g. stack size)
  313. const char *ResourceName;
  314. /// The computed size usage
  315. uint64_t ResourceSize;
  316. // Threshould passed
  317. uint64_t ResourceLimit;
  318. public:
  319. /// \p The function that is concerned by this stack size diagnostic.
  320. /// \p The computed stack size.
  321. DiagnosticInfoResourceLimit(const Function &Fn, const char *ResourceName,
  322. uint64_t ResourceSize, uint64_t ResourceLimit,
  323. DiagnosticSeverity Severity = DS_Warning,
  324. DiagnosticKind Kind = DK_ResourceLimit);
  325. const Function &getFunction() const { return Fn; }
  326. const char *getResourceName() const { return ResourceName; }
  327. uint64_t getResourceSize() const { return ResourceSize; }
  328. uint64_t getResourceLimit() const { return ResourceLimit; }
  329. /// \see DiagnosticInfo::print.
  330. void print(DiagnosticPrinter &DP) const override;
  331. static bool classof(const DiagnosticInfo *DI) {
  332. return DI->getKind() == DK_ResourceLimit || DI->getKind() == DK_StackSize;
  333. }
  334. };
  335. class DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit {
  336. void anchor() override;
  337. public:
  338. DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize,
  339. uint64_t StackLimit,
  340. DiagnosticSeverity Severity = DS_Warning)
  341. : DiagnosticInfoResourceLimit(Fn, "stack frame size", StackSize,
  342. StackLimit, Severity, DK_StackSize) {}
  343. uint64_t getStackSize() const { return getResourceSize(); }
  344. uint64_t getStackLimit() const { return getResourceLimit(); }
  345. static bool classof(const DiagnosticInfo *DI) {
  346. return DI->getKind() == DK_StackSize;
  347. }
  348. };
  349. /// Common features for diagnostics dealing with optimization remarks
  350. /// that are used by both IR and MIR passes.
  351. class DiagnosticInfoOptimizationBase : public DiagnosticInfoWithLocationBase {
  352. public:
  353. /// Used to set IsVerbose via the stream interface.
  354. struct setIsVerbose {};
  355. /// When an instance of this is inserted into the stream, the arguments
  356. /// following will not appear in the remark printed in the compiler output
  357. /// (-Rpass) but only in the optimization record file
  358. /// (-fsave-optimization-record).
  359. struct setExtraArgs {};
  360. /// Used in the streaming interface as the general argument type. It
  361. /// internally converts everything into a key-value pair.
  362. struct Argument {
  363. std::string Key;
  364. std::string Val;
  365. // If set, the debug location corresponding to the value.
  366. DiagnosticLocation Loc;
  367. explicit Argument(StringRef Str = "") : Key("String"), Val(Str) {}
  368. Argument(StringRef Key, const Value *V);
  369. Argument(StringRef Key, const Type *T);
  370. Argument(StringRef Key, StringRef S);
  371. Argument(StringRef Key, const char *S) : Argument(Key, StringRef(S)) {};
  372. Argument(StringRef Key, int N);
  373. Argument(StringRef Key, float N);
  374. Argument(StringRef Key, long N);
  375. Argument(StringRef Key, long long N);
  376. Argument(StringRef Key, unsigned N);
  377. Argument(StringRef Key, unsigned long N);
  378. Argument(StringRef Key, unsigned long long N);
  379. Argument(StringRef Key, ElementCount EC);
  380. Argument(StringRef Key, bool B) : Key(Key), Val(B ? "true" : "false") {}
  381. Argument(StringRef Key, DebugLoc dl);
  382. Argument(StringRef Key, InstructionCost C);
  383. };
  384. /// \p PassName is the name of the pass emitting this diagnostic. \p
  385. /// RemarkName is a textual identifier for the remark (single-word,
  386. /// camel-case). \p Fn is the function where the diagnostic is being emitted.
  387. /// \p Loc is the location information to use in the diagnostic. If line table
  388. /// information is available, the diagnostic will include the source code
  389. /// location.
  390. DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind,
  391. enum DiagnosticSeverity Severity,
  392. const char *PassName, StringRef RemarkName,
  393. const Function &Fn,
  394. const DiagnosticLocation &Loc)
  395. : DiagnosticInfoWithLocationBase(Kind, Severity, Fn, Loc),
  396. PassName(PassName), RemarkName(RemarkName) {}
  397. void insert(StringRef S);
  398. void insert(Argument A);
  399. void insert(setIsVerbose V);
  400. void insert(setExtraArgs EA);
  401. /// \see DiagnosticInfo::print.
  402. void print(DiagnosticPrinter &DP) const override;
  403. /// Return true if this optimization remark is enabled by one of
  404. /// of the LLVM command line flags (-pass-remarks, -pass-remarks-missed,
  405. /// or -pass-remarks-analysis). Note that this only handles the LLVM
  406. /// flags. We cannot access Clang flags from here (they are handled
  407. /// in BackendConsumer::OptimizationRemarkHandler).
  408. virtual bool isEnabled() const = 0;
  409. StringRef getPassName() const { return PassName; }
  410. StringRef getRemarkName() const { return RemarkName; }
  411. std::string getMsg() const;
  412. std::optional<uint64_t> getHotness() const { return Hotness; }
  413. void setHotness(std::optional<uint64_t> H) { Hotness = H; }
  414. bool isVerbose() const { return IsVerbose; }
  415. ArrayRef<Argument> getArgs() const { return Args; }
  416. static bool classof(const DiagnosticInfo *DI) {
  417. return (DI->getKind() >= DK_FirstRemark &&
  418. DI->getKind() <= DK_LastRemark) ||
  419. (DI->getKind() >= DK_FirstMachineRemark &&
  420. DI->getKind() <= DK_LastMachineRemark);
  421. }
  422. bool isPassed() const {
  423. return (getKind() == DK_OptimizationRemark ||
  424. getKind() == DK_MachineOptimizationRemark);
  425. }
  426. bool isMissed() const {
  427. return (getKind() == DK_OptimizationRemarkMissed ||
  428. getKind() == DK_MachineOptimizationRemarkMissed);
  429. }
  430. bool isAnalysis() const {
  431. return (getKind() == DK_OptimizationRemarkAnalysis ||
  432. getKind() == DK_MachineOptimizationRemarkAnalysis);
  433. }
  434. protected:
  435. /// Name of the pass that triggers this report. If this matches the
  436. /// regular expression given in -Rpass=regexp, then the remark will
  437. /// be emitted.
  438. const char *PassName;
  439. /// Textual identifier for the remark (single-word, camel-case). Can be used
  440. /// by external tools reading the output file for optimization remarks to
  441. /// identify the remark.
  442. StringRef RemarkName;
  443. /// If profile information is available, this is the number of times the
  444. /// corresponding code was executed in a profile instrumentation run.
  445. std::optional<uint64_t> Hotness;
  446. /// Arguments collected via the streaming interface.
  447. SmallVector<Argument, 4> Args;
  448. /// The remark is expected to be noisy.
  449. bool IsVerbose = false;
  450. /// If positive, the index of the first argument that only appear in
  451. /// the optimization records and not in the remark printed in the compiler
  452. /// output.
  453. int FirstExtraArgIndex = -1;
  454. };
  455. /// Allow the insertion operator to return the actual remark type rather than a
  456. /// common base class. This allows returning the result of the insertion
  457. /// directly by value, e.g. return OptimizationRemarkAnalysis(...) << "blah".
  458. template <class RemarkT>
  459. RemarkT &
  460. operator<<(RemarkT &R,
  461. std::enable_if_t<
  462. std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
  463. StringRef>
  464. S) {
  465. R.insert(S);
  466. return R;
  467. }
  468. /// Also allow r-value for the remark to allow insertion into a
  469. /// temporarily-constructed remark.
  470. template <class RemarkT>
  471. RemarkT &
  472. operator<<(RemarkT &&R,
  473. std::enable_if_t<
  474. std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
  475. StringRef>
  476. S) {
  477. R.insert(S);
  478. return R;
  479. }
  480. template <class RemarkT>
  481. RemarkT &
  482. operator<<(RemarkT &R,
  483. std::enable_if_t<
  484. std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
  485. DiagnosticInfoOptimizationBase::Argument>
  486. A) {
  487. R.insert(A);
  488. return R;
  489. }
  490. template <class RemarkT>
  491. RemarkT &
  492. operator<<(RemarkT &&R,
  493. std::enable_if_t<
  494. std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
  495. DiagnosticInfoOptimizationBase::Argument>
  496. A) {
  497. R.insert(A);
  498. return R;
  499. }
  500. template <class RemarkT>
  501. RemarkT &
  502. operator<<(RemarkT &R,
  503. std::enable_if_t<
  504. std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
  505. DiagnosticInfoOptimizationBase::setIsVerbose>
  506. V) {
  507. R.insert(V);
  508. return R;
  509. }
  510. template <class RemarkT>
  511. RemarkT &
  512. operator<<(RemarkT &&R,
  513. std::enable_if_t<
  514. std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
  515. DiagnosticInfoOptimizationBase::setIsVerbose>
  516. V) {
  517. R.insert(V);
  518. return R;
  519. }
  520. template <class RemarkT>
  521. RemarkT &
  522. operator<<(RemarkT &R,
  523. std::enable_if_t<
  524. std::is_base_of<DiagnosticInfoOptimizationBase, RemarkT>::value,
  525. DiagnosticInfoOptimizationBase::setExtraArgs>
  526. EA) {
  527. R.insert(EA);
  528. return R;
  529. }
  530. /// Common features for diagnostics dealing with optimization remarks
  531. /// that are used by IR passes.
  532. class DiagnosticInfoIROptimization : public DiagnosticInfoOptimizationBase {
  533. void anchor() override;
  534. public:
  535. /// \p PassName is the name of the pass emitting this diagnostic. \p
  536. /// RemarkName is a textual identifier for the remark (single-word,
  537. /// camel-case). \p Fn is the function where the diagnostic is being emitted.
  538. /// \p Loc is the location information to use in the diagnostic. If line table
  539. /// information is available, the diagnostic will include the source code
  540. /// location. \p CodeRegion is IR value (currently basic block) that the
  541. /// optimization operates on. This is currently used to provide run-time
  542. /// hotness information with PGO.
  543. DiagnosticInfoIROptimization(enum DiagnosticKind Kind,
  544. enum DiagnosticSeverity Severity,
  545. const char *PassName, StringRef RemarkName,
  546. const Function &Fn,
  547. const DiagnosticLocation &Loc,
  548. const Value *CodeRegion = nullptr)
  549. : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn,
  550. Loc),
  551. CodeRegion(CodeRegion) {}
  552. /// This is ctor variant allows a pass to build an optimization remark
  553. /// from an existing remark.
  554. ///
  555. /// This is useful when a transformation pass (e.g LV) wants to emit a remark
  556. /// (\p Orig) generated by one of its analyses (e.g. LAA) as its own analysis
  557. /// remark. The string \p Prepend will be emitted before the original
  558. /// message.
  559. DiagnosticInfoIROptimization(const char *PassName, StringRef Prepend,
  560. const DiagnosticInfoIROptimization &Orig)
  561. : DiagnosticInfoOptimizationBase(
  562. (DiagnosticKind)Orig.getKind(), Orig.getSeverity(), PassName,
  563. Orig.RemarkName, Orig.getFunction(), Orig.getLocation()),
  564. CodeRegion(Orig.getCodeRegion()) {
  565. *this << Prepend;
  566. std::copy(Orig.Args.begin(), Orig.Args.end(), std::back_inserter(Args));
  567. }
  568. /// Legacy interface.
  569. /// \p PassName is the name of the pass emitting this diagnostic.
  570. /// \p Fn is the function where the diagnostic is being emitted. \p Loc is
  571. /// the location information to use in the diagnostic. If line table
  572. /// information is available, the diagnostic will include the source code
  573. /// location. \p Msg is the message to show. Note that this class does not
  574. /// copy this message, so this reference must be valid for the whole life time
  575. /// of the diagnostic.
  576. DiagnosticInfoIROptimization(enum DiagnosticKind Kind,
  577. enum DiagnosticSeverity Severity,
  578. const char *PassName, const Function &Fn,
  579. const DiagnosticLocation &Loc, const Twine &Msg)
  580. : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, "", Fn, Loc) {
  581. *this << Msg.str();
  582. }
  583. const Value *getCodeRegion() const { return CodeRegion; }
  584. static bool classof(const DiagnosticInfo *DI) {
  585. return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark;
  586. }
  587. private:
  588. /// The IR value (currently basic block) that the optimization operates on.
  589. /// This is currently used to provide run-time hotness information with PGO.
  590. const Value *CodeRegion = nullptr;
  591. };
  592. /// Diagnostic information for applied optimization remarks.
  593. class OptimizationRemark : public DiagnosticInfoIROptimization {
  594. public:
  595. /// \p PassName is the name of the pass emitting this diagnostic. If this name
  596. /// matches the regular expression given in -Rpass=, then the diagnostic will
  597. /// be emitted. \p RemarkName is a textual identifier for the remark (single-
  598. /// word, camel-case). \p Loc is the debug location and \p CodeRegion is the
  599. /// region that the optimization operates on (currently only block is
  600. /// supported).
  601. OptimizationRemark(const char *PassName, StringRef RemarkName,
  602. const DiagnosticLocation &Loc, const Value *CodeRegion);
  603. /// Same as above, but the debug location and code region are derived from \p
  604. /// Instr.
  605. OptimizationRemark(const char *PassName, StringRef RemarkName,
  606. const Instruction *Inst);
  607. /// Same as above, but the debug location and code region are derived from \p
  608. /// Func.
  609. OptimizationRemark(const char *PassName, StringRef RemarkName,
  610. const Function *Func);
  611. static bool classof(const DiagnosticInfo *DI) {
  612. return DI->getKind() == DK_OptimizationRemark;
  613. }
  614. /// \see DiagnosticInfoOptimizationBase::isEnabled.
  615. bool isEnabled() const override;
  616. private:
  617. /// This is deprecated now and only used by the function API below.
  618. /// \p PassName is the name of the pass emitting this diagnostic. If
  619. /// this name matches the regular expression given in -Rpass=, then the
  620. /// diagnostic will be emitted. \p Fn is the function where the diagnostic
  621. /// is being emitted. \p Loc is the location information to use in the
  622. /// diagnostic. If line table information is available, the diagnostic
  623. /// will include the source code location. \p Msg is the message to show.
  624. /// Note that this class does not copy this message, so this reference
  625. /// must be valid for the whole life time of the diagnostic.
  626. OptimizationRemark(const char *PassName, const Function &Fn,
  627. const DiagnosticLocation &Loc, const Twine &Msg)
  628. : DiagnosticInfoIROptimization(DK_OptimizationRemark, DS_Remark, PassName,
  629. Fn, Loc, Msg) {}
  630. };
  631. /// Diagnostic information for missed-optimization remarks.
  632. class OptimizationRemarkMissed : public DiagnosticInfoIROptimization {
  633. public:
  634. /// \p PassName is the name of the pass emitting this diagnostic. If this name
  635. /// matches the regular expression given in -Rpass-missed=, then the
  636. /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
  637. /// remark (single-word, camel-case). \p Loc is the debug location and \p
  638. /// CodeRegion is the region that the optimization operates on (currently only
  639. /// block is supported).
  640. OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
  641. const DiagnosticLocation &Loc,
  642. const Value *CodeRegion);
  643. /// Same as above but \p Inst is used to derive code region and debug
  644. /// location.
  645. OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
  646. const Instruction *Inst);
  647. /// Same as above but \p F is used to derive code region and debug
  648. /// location.
  649. OptimizationRemarkMissed(const char *PassName, StringRef RemarkName,
  650. const Function *F);
  651. static bool classof(const DiagnosticInfo *DI) {
  652. return DI->getKind() == DK_OptimizationRemarkMissed;
  653. }
  654. /// \see DiagnosticInfoOptimizationBase::isEnabled.
  655. bool isEnabled() const override;
  656. private:
  657. /// This is deprecated now and only used by the function API below.
  658. /// \p PassName is the name of the pass emitting this diagnostic. If
  659. /// this name matches the regular expression given in -Rpass-missed=, then the
  660. /// diagnostic will be emitted. \p Fn is the function where the diagnostic
  661. /// is being emitted. \p Loc is the location information to use in the
  662. /// diagnostic. If line table information is available, the diagnostic
  663. /// will include the source code location. \p Msg is the message to show.
  664. /// Note that this class does not copy this message, so this reference
  665. /// must be valid for the whole life time of the diagnostic.
  666. OptimizationRemarkMissed(const char *PassName, const Function &Fn,
  667. const DiagnosticLocation &Loc, const Twine &Msg)
  668. : DiagnosticInfoIROptimization(DK_OptimizationRemarkMissed, DS_Remark,
  669. PassName, Fn, Loc, Msg) {}
  670. };
  671. /// Diagnostic information for optimization analysis remarks.
  672. class OptimizationRemarkAnalysis : public DiagnosticInfoIROptimization {
  673. public:
  674. /// \p PassName is the name of the pass emitting this diagnostic. If this name
  675. /// matches the regular expression given in -Rpass-analysis=, then the
  676. /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
  677. /// remark (single-word, camel-case). \p Loc is the debug location and \p
  678. /// CodeRegion is the region that the optimization operates on (currently only
  679. /// block is supported).
  680. OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
  681. const DiagnosticLocation &Loc,
  682. const Value *CodeRegion);
  683. /// This is ctor variant allows a pass to build an optimization remark
  684. /// from an existing remark.
  685. ///
  686. /// This is useful when a transformation pass (e.g LV) wants to emit a remark
  687. /// (\p Orig) generated by one of its analyses (e.g. LAA) as its own analysis
  688. /// remark. The string \p Prepend will be emitted before the original
  689. /// message.
  690. OptimizationRemarkAnalysis(const char *PassName, StringRef Prepend,
  691. const OptimizationRemarkAnalysis &Orig)
  692. : DiagnosticInfoIROptimization(PassName, Prepend, Orig) {}
  693. /// Same as above but \p Inst is used to derive code region and debug
  694. /// location.
  695. OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
  696. const Instruction *Inst);
  697. /// Same as above but \p F is used to derive code region and debug
  698. /// location.
  699. OptimizationRemarkAnalysis(const char *PassName, StringRef RemarkName,
  700. const Function *F);
  701. static bool classof(const DiagnosticInfo *DI) {
  702. return DI->getKind() == DK_OptimizationRemarkAnalysis;
  703. }
  704. /// \see DiagnosticInfoOptimizationBase::isEnabled.
  705. bool isEnabled() const override;
  706. static const char *AlwaysPrint;
  707. bool shouldAlwaysPrint() const { return getPassName() == AlwaysPrint; }
  708. protected:
  709. OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
  710. const Function &Fn, const DiagnosticLocation &Loc,
  711. const Twine &Msg)
  712. : DiagnosticInfoIROptimization(Kind, DS_Remark, PassName, Fn, Loc, Msg) {}
  713. OptimizationRemarkAnalysis(enum DiagnosticKind Kind, const char *PassName,
  714. StringRef RemarkName,
  715. const DiagnosticLocation &Loc,
  716. const Value *CodeRegion);
  717. private:
  718. /// This is deprecated now and only used by the function API below.
  719. /// \p PassName is the name of the pass emitting this diagnostic. If
  720. /// this name matches the regular expression given in -Rpass-analysis=, then
  721. /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
  722. /// is being emitted. \p Loc is the location information to use in the
  723. /// diagnostic. If line table information is available, the diagnostic will
  724. /// include the source code location. \p Msg is the message to show. Note that
  725. /// this class does not copy this message, so this reference must be valid for
  726. /// the whole life time of the diagnostic.
  727. OptimizationRemarkAnalysis(const char *PassName, const Function &Fn,
  728. const DiagnosticLocation &Loc, const Twine &Msg)
  729. : DiagnosticInfoIROptimization(DK_OptimizationRemarkAnalysis, DS_Remark,
  730. PassName, Fn, Loc, Msg) {}
  731. };
  732. /// Diagnostic information for optimization analysis remarks related to
  733. /// floating-point non-commutativity.
  734. class OptimizationRemarkAnalysisFPCommute : public OptimizationRemarkAnalysis {
  735. void anchor() override;
  736. public:
  737. /// \p PassName is the name of the pass emitting this diagnostic. If this name
  738. /// matches the regular expression given in -Rpass-analysis=, then the
  739. /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
  740. /// remark (single-word, camel-case). \p Loc is the debug location and \p
  741. /// CodeRegion is the region that the optimization operates on (currently only
  742. /// block is supported). The front-end will append its own message related to
  743. /// options that address floating-point non-commutativity.
  744. OptimizationRemarkAnalysisFPCommute(const char *PassName,
  745. StringRef RemarkName,
  746. const DiagnosticLocation &Loc,
  747. const Value *CodeRegion)
  748. : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
  749. PassName, RemarkName, Loc, CodeRegion) {}
  750. static bool classof(const DiagnosticInfo *DI) {
  751. return DI->getKind() == DK_OptimizationRemarkAnalysisFPCommute;
  752. }
  753. private:
  754. /// This is deprecated now and only used by the function API below.
  755. /// \p PassName is the name of the pass emitting this diagnostic. If
  756. /// this name matches the regular expression given in -Rpass-analysis=, then
  757. /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
  758. /// is being emitted. \p Loc is the location information to use in the
  759. /// diagnostic. If line table information is available, the diagnostic will
  760. /// include the source code location. \p Msg is the message to show. The
  761. /// front-end will append its own message related to options that address
  762. /// floating-point non-commutativity. Note that this class does not copy this
  763. /// message, so this reference must be valid for the whole life time of the
  764. /// diagnostic.
  765. OptimizationRemarkAnalysisFPCommute(const char *PassName, const Function &Fn,
  766. const DiagnosticLocation &Loc,
  767. const Twine &Msg)
  768. : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisFPCommute,
  769. PassName, Fn, Loc, Msg) {}
  770. };
  771. /// Diagnostic information for optimization analysis remarks related to
  772. /// pointer aliasing.
  773. class OptimizationRemarkAnalysisAliasing : public OptimizationRemarkAnalysis {
  774. void anchor() override;
  775. public:
  776. /// \p PassName is the name of the pass emitting this diagnostic. If this name
  777. /// matches the regular expression given in -Rpass-analysis=, then the
  778. /// diagnostic will be emitted. \p RemarkName is a textual identifier for the
  779. /// remark (single-word, camel-case). \p Loc is the debug location and \p
  780. /// CodeRegion is the region that the optimization operates on (currently only
  781. /// block is supported). The front-end will append its own message related to
  782. /// options that address pointer aliasing legality.
  783. OptimizationRemarkAnalysisAliasing(const char *PassName, StringRef RemarkName,
  784. const DiagnosticLocation &Loc,
  785. const Value *CodeRegion)
  786. : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
  787. PassName, RemarkName, Loc, CodeRegion) {}
  788. static bool classof(const DiagnosticInfo *DI) {
  789. return DI->getKind() == DK_OptimizationRemarkAnalysisAliasing;
  790. }
  791. private:
  792. /// This is deprecated now and only used by the function API below.
  793. /// \p PassName is the name of the pass emitting this diagnostic. If
  794. /// this name matches the regular expression given in -Rpass-analysis=, then
  795. /// the diagnostic will be emitted. \p Fn is the function where the diagnostic
  796. /// is being emitted. \p Loc is the location information to use in the
  797. /// diagnostic. If line table information is available, the diagnostic will
  798. /// include the source code location. \p Msg is the message to show. The
  799. /// front-end will append its own message related to options that address
  800. /// pointer aliasing legality. Note that this class does not copy this
  801. /// message, so this reference must be valid for the whole life time of the
  802. /// diagnostic.
  803. OptimizationRemarkAnalysisAliasing(const char *PassName, const Function &Fn,
  804. const DiagnosticLocation &Loc,
  805. const Twine &Msg)
  806. : OptimizationRemarkAnalysis(DK_OptimizationRemarkAnalysisAliasing,
  807. PassName, Fn, Loc, Msg) {}
  808. };
  809. /// Diagnostic information for machine IR parser.
  810. // FIXME: Remove this, use DiagnosticInfoSrcMgr instead.
  811. class DiagnosticInfoMIRParser : public DiagnosticInfo {
  812. const SMDiagnostic &Diagnostic;
  813. public:
  814. DiagnosticInfoMIRParser(DiagnosticSeverity Severity,
  815. const SMDiagnostic &Diagnostic)
  816. : DiagnosticInfo(DK_MIRParser, Severity), Diagnostic(Diagnostic) {}
  817. const SMDiagnostic &getDiagnostic() const { return Diagnostic; }
  818. void print(DiagnosticPrinter &DP) const override;
  819. static bool classof(const DiagnosticInfo *DI) {
  820. return DI->getKind() == DK_MIRParser;
  821. }
  822. };
  823. /// Diagnostic information for ISel fallback path.
  824. class DiagnosticInfoISelFallback : public DiagnosticInfo {
  825. /// The function that is concerned by this diagnostic.
  826. const Function &Fn;
  827. public:
  828. DiagnosticInfoISelFallback(const Function &Fn,
  829. DiagnosticSeverity Severity = DS_Warning)
  830. : DiagnosticInfo(DK_ISelFallback, Severity), Fn(Fn) {}
  831. const Function &getFunction() const { return Fn; }
  832. void print(DiagnosticPrinter &DP) const override;
  833. static bool classof(const DiagnosticInfo *DI) {
  834. return DI->getKind() == DK_ISelFallback;
  835. }
  836. };
  837. // Create wrappers for C Binding types (see CBindingWrapping.h).
  838. DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DiagnosticInfo, LLVMDiagnosticInfoRef)
  839. /// Diagnostic information for optimization failures.
  840. class DiagnosticInfoOptimizationFailure : public DiagnosticInfoIROptimization {
  841. public:
  842. /// \p Fn is the function where the diagnostic is being emitted. \p Loc is
  843. /// the location information to use in the diagnostic. If line table
  844. /// information is available, the diagnostic will include the source code
  845. /// location. \p Msg is the message to show. Note that this class does not
  846. /// copy this message, so this reference must be valid for the whole life time
  847. /// of the diagnostic.
  848. DiagnosticInfoOptimizationFailure(const Function &Fn,
  849. const DiagnosticLocation &Loc,
  850. const Twine &Msg)
  851. : DiagnosticInfoIROptimization(DK_OptimizationFailure, DS_Warning,
  852. nullptr, Fn, Loc, Msg) {}
  853. /// \p PassName is the name of the pass emitting this diagnostic. \p
  854. /// RemarkName is a textual identifier for the remark (single-word,
  855. /// camel-case). \p Loc is the debug location and \p CodeRegion is the
  856. /// region that the optimization operates on (currently basic block is
  857. /// supported).
  858. DiagnosticInfoOptimizationFailure(const char *PassName, StringRef RemarkName,
  859. const DiagnosticLocation &Loc,
  860. const Value *CodeRegion);
  861. static bool classof(const DiagnosticInfo *DI) {
  862. return DI->getKind() == DK_OptimizationFailure;
  863. }
  864. /// \see DiagnosticInfoOptimizationBase::isEnabled.
  865. bool isEnabled() const override;
  866. };
  867. /// Diagnostic information for unsupported feature in backend.
  868. class DiagnosticInfoUnsupported : public DiagnosticInfoWithLocationBase {
  869. private:
  870. Twine Msg;
  871. public:
  872. /// \p Fn is the function where the diagnostic is being emitted. \p Loc is
  873. /// the location information to use in the diagnostic. If line table
  874. /// information is available, the diagnostic will include the source code
  875. /// location. \p Msg is the message to show. Note that this class does not
  876. /// copy this message, so this reference must be valid for the whole life time
  877. /// of the diagnostic.
  878. DiagnosticInfoUnsupported(
  879. const Function &Fn, const Twine &Msg,
  880. const DiagnosticLocation &Loc = DiagnosticLocation(),
  881. DiagnosticSeverity Severity = DS_Error)
  882. : DiagnosticInfoWithLocationBase(DK_Unsupported, Severity, Fn, Loc),
  883. Msg(Msg) {}
  884. static bool classof(const DiagnosticInfo *DI) {
  885. return DI->getKind() == DK_Unsupported;
  886. }
  887. const Twine &getMessage() const { return Msg; }
  888. void print(DiagnosticPrinter &DP) const override;
  889. };
  890. /// Diagnostic information for MisExpect analysis.
  891. class DiagnosticInfoMisExpect : public DiagnosticInfoWithLocationBase {
  892. public:
  893. DiagnosticInfoMisExpect(const Instruction *Inst, Twine &Msg);
  894. /// \see DiagnosticInfo::print.
  895. void print(DiagnosticPrinter &DP) const override;
  896. static bool classof(const DiagnosticInfo *DI) {
  897. return DI->getKind() == DK_MisExpect;
  898. }
  899. const Twine &getMsg() const { return Msg; }
  900. private:
  901. /// Message to report.
  902. const Twine &Msg;
  903. };
  904. static DiagnosticSeverity getDiagnosticSeverity(SourceMgr::DiagKind DK) {
  905. switch (DK) {
  906. case llvm::SourceMgr::DK_Error:
  907. return DS_Error;
  908. break;
  909. case llvm::SourceMgr::DK_Warning:
  910. return DS_Warning;
  911. break;
  912. case llvm::SourceMgr::DK_Note:
  913. return DS_Note;
  914. break;
  915. case llvm::SourceMgr::DK_Remark:
  916. return DS_Remark;
  917. break;
  918. }
  919. llvm_unreachable("unknown SourceMgr::DiagKind");
  920. }
  921. /// Diagnostic information for SMDiagnostic reporting.
  922. class DiagnosticInfoSrcMgr : public DiagnosticInfo {
  923. const SMDiagnostic &Diagnostic;
  924. StringRef ModName;
  925. // For inlineasm !srcloc translation.
  926. bool InlineAsmDiag;
  927. unsigned LocCookie;
  928. public:
  929. DiagnosticInfoSrcMgr(const SMDiagnostic &Diagnostic, StringRef ModName,
  930. bool InlineAsmDiag = true, unsigned LocCookie = 0)
  931. : DiagnosticInfo(DK_SrcMgr, getDiagnosticSeverity(Diagnostic.getKind())),
  932. Diagnostic(Diagnostic), ModName(ModName), InlineAsmDiag(InlineAsmDiag),
  933. LocCookie(LocCookie) {}
  934. StringRef getModuleName() const { return ModName; }
  935. bool isInlineAsmDiag() const { return InlineAsmDiag; }
  936. const SMDiagnostic &getSMDiag() const { return Diagnostic; }
  937. unsigned getLocCookie() const { return LocCookie; }
  938. void print(DiagnosticPrinter &DP) const override;
  939. static bool classof(const DiagnosticInfo *DI) {
  940. return DI->getKind() == DK_SrcMgr;
  941. }
  942. };
  943. void diagnoseDontCall(const CallInst &CI);
  944. class DiagnosticInfoDontCall : public DiagnosticInfo {
  945. StringRef CalleeName;
  946. StringRef Note;
  947. unsigned LocCookie;
  948. public:
  949. DiagnosticInfoDontCall(StringRef CalleeName, StringRef Note,
  950. DiagnosticSeverity DS, unsigned LocCookie)
  951. : DiagnosticInfo(DK_DontCall, DS), CalleeName(CalleeName), Note(Note),
  952. LocCookie(LocCookie) {}
  953. StringRef getFunctionName() const { return CalleeName; }
  954. StringRef getNote() const { return Note; }
  955. unsigned getLocCookie() const { return LocCookie; }
  956. void print(DiagnosticPrinter &DP) const override;
  957. static bool classof(const DiagnosticInfo *DI) {
  958. return DI->getKind() == DK_DontCall;
  959. }
  960. };
  961. } // end namespace llvm
  962. #endif // LLVM_IR_DIAGNOSTICINFO_H
  963. #ifdef __GNUC__
  964. #pragma GCC diagnostic pop
  965. #endif