CodeGenAction.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. //===--- CodeGenAction.cpp - LLVM Code Generation Frontend Action ---------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "clang/CodeGen/CodeGenAction.h"
  9. #include "CodeGenModule.h"
  10. #include "CoverageMappingGen.h"
  11. #include "MacroPPCallbacks.h"
  12. #include "clang/AST/ASTConsumer.h"
  13. #include "clang/AST/ASTContext.h"
  14. #include "clang/AST/DeclCXX.h"
  15. #include "clang/AST/DeclGroup.h"
  16. #include "clang/Basic/FileManager.h"
  17. #include "clang/Basic/SourceManager.h"
  18. #include "clang/Basic/TargetInfo.h"
  19. #include "clang/CodeGen/BackendUtil.h"
  20. #include "clang/CodeGen/ModuleBuilder.h"
  21. #include "clang/Frontend/CompilerInstance.h"
  22. #include "clang/Frontend/FrontendDiagnostic.h"
  23. #include "clang/Lex/Preprocessor.h"
  24. #include "llvm/Bitcode/BitcodeReader.h"
  25. #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
  26. #include "llvm/IR/DebugInfo.h"
  27. #include "llvm/IR/DiagnosticInfo.h"
  28. #include "llvm/IR/DiagnosticPrinter.h"
  29. #include "llvm/IR/GlobalValue.h"
  30. #include "llvm/IR/LLVMContext.h"
  31. #include "llvm/IR/Module.h"
  32. #include "llvm/IR/RemarkStreamer.h"
  33. #include "llvm/IRReader/IRReader.h"
  34. #include "llvm/Linker/Linker.h"
  35. #include "llvm/Pass.h"
  36. #include "llvm/Support/MemoryBuffer.h"
  37. #include "llvm/Support/SourceMgr.h"
  38. #include "llvm/Support/Timer.h"
  39. #include "llvm/Support/ToolOutputFile.h"
  40. #include "llvm/Support/YAMLTraits.h"
  41. #include "llvm/Transforms/IPO/Internalize.h"
  42. #include <memory>
  43. using namespace clang;
  44. using namespace llvm;
  45. namespace clang {
  46. class BackendConsumer;
  47. class ClangDiagnosticHandler final : public DiagnosticHandler {
  48. public:
  49. ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
  50. : CodeGenOpts(CGOpts), BackendCon(BCon) {}
  51. bool handleDiagnostics(const DiagnosticInfo &DI) override;
  52. bool isAnalysisRemarkEnabled(StringRef PassName) const override {
  53. return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
  54. CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
  55. }
  56. bool isMissedOptRemarkEnabled(StringRef PassName) const override {
  57. return (CodeGenOpts.OptimizationRemarkMissedPattern &&
  58. CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
  59. }
  60. bool isPassedOptRemarkEnabled(StringRef PassName) const override {
  61. return (CodeGenOpts.OptimizationRemarkPattern &&
  62. CodeGenOpts.OptimizationRemarkPattern->match(PassName));
  63. }
  64. bool isAnyRemarkEnabled() const override {
  65. return (CodeGenOpts.OptimizationRemarkAnalysisPattern ||
  66. CodeGenOpts.OptimizationRemarkMissedPattern ||
  67. CodeGenOpts.OptimizationRemarkPattern);
  68. }
  69. private:
  70. const CodeGenOptions &CodeGenOpts;
  71. BackendConsumer *BackendCon;
  72. };
  73. class BackendConsumer : public ASTConsumer {
  74. using LinkModule = CodeGenAction::LinkModule;
  75. virtual void anchor();
  76. DiagnosticsEngine &Diags;
  77. BackendAction Action;
  78. const HeaderSearchOptions &HeaderSearchOpts;
  79. const CodeGenOptions &CodeGenOpts;
  80. const TargetOptions &TargetOpts;
  81. const LangOptions &LangOpts;
  82. std::unique_ptr<raw_pwrite_stream> AsmOutStream;
  83. ASTContext *Context;
  84. Timer LLVMIRGeneration;
  85. unsigned LLVMIRGenerationRefCount;
  86. /// True if we've finished generating IR. This prevents us from generating
  87. /// additional LLVM IR after emitting output in HandleTranslationUnit. This
  88. /// can happen when Clang plugins trigger additional AST deserialization.
  89. bool IRGenFinished = false;
  90. std::unique_ptr<CodeGenerator> Gen;
  91. SmallVector<LinkModule, 4> LinkModules;
  92. // This is here so that the diagnostic printer knows the module a diagnostic
  93. // refers to.
  94. llvm::Module *CurLinkModule = nullptr;
  95. public:
  96. BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags,
  97. const HeaderSearchOptions &HeaderSearchOpts,
  98. const PreprocessorOptions &PPOpts,
  99. const CodeGenOptions &CodeGenOpts,
  100. const TargetOptions &TargetOpts,
  101. const LangOptions &LangOpts, bool TimePasses,
  102. const std::string &InFile,
  103. SmallVector<LinkModule, 4> LinkModules,
  104. std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &C,
  105. CoverageSourceInfo *CoverageInfo = nullptr)
  106. : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
  107. CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
  108. AsmOutStream(std::move(OS)), Context(nullptr),
  109. LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
  110. LLVMIRGenerationRefCount(0),
  111. Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts,
  112. CodeGenOpts, C, CoverageInfo)),
  113. LinkModules(std::move(LinkModules)) {
  114. FrontendTimesIsEnabled = TimePasses;
  115. llvm::TimePassesIsEnabled = TimePasses;
  116. }
  117. llvm::Module *getModule() const { return Gen->GetModule(); }
  118. std::unique_ptr<llvm::Module> takeModule() {
  119. return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
  120. }
  121. CodeGenerator *getCodeGenerator() { return Gen.get(); }
  122. void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override {
  123. Gen->HandleCXXStaticMemberVarInstantiation(VD);
  124. }
  125. void Initialize(ASTContext &Ctx) override {
  126. assert(!Context && "initialized multiple times");
  127. Context = &Ctx;
  128. if (FrontendTimesIsEnabled)
  129. LLVMIRGeneration.startTimer();
  130. Gen->Initialize(Ctx);
  131. if (FrontendTimesIsEnabled)
  132. LLVMIRGeneration.stopTimer();
  133. }
  134. bool HandleTopLevelDecl(DeclGroupRef D) override {
  135. PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(),
  136. Context->getSourceManager(),
  137. "LLVM IR generation of declaration");
  138. // Recurse.
  139. if (FrontendTimesIsEnabled) {
  140. LLVMIRGenerationRefCount += 1;
  141. if (LLVMIRGenerationRefCount == 1)
  142. LLVMIRGeneration.startTimer();
  143. }
  144. Gen->HandleTopLevelDecl(D);
  145. if (FrontendTimesIsEnabled) {
  146. LLVMIRGenerationRefCount -= 1;
  147. if (LLVMIRGenerationRefCount == 0)
  148. LLVMIRGeneration.stopTimer();
  149. }
  150. return true;
  151. }
  152. void HandleInlineFunctionDefinition(FunctionDecl *D) override {
  153. PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
  154. Context->getSourceManager(),
  155. "LLVM IR generation of inline function");
  156. if (FrontendTimesIsEnabled)
  157. LLVMIRGeneration.startTimer();
  158. Gen->HandleInlineFunctionDefinition(D);
  159. if (FrontendTimesIsEnabled)
  160. LLVMIRGeneration.stopTimer();
  161. }
  162. void HandleInterestingDecl(DeclGroupRef D) override {
  163. // Ignore interesting decls from the AST reader after IRGen is finished.
  164. if (!IRGenFinished)
  165. HandleTopLevelDecl(D);
  166. }
  167. // Links each entry in LinkModules into our module. Returns true on error.
  168. bool LinkInModules() {
  169. for (auto &LM : LinkModules) {
  170. if (LM.PropagateAttrs)
  171. for (Function &F : *LM.Module)
  172. Gen->CGM().AddDefaultFnAttrs(F);
  173. CurLinkModule = LM.Module.get();
  174. bool Err;
  175. if (LM.Internalize) {
  176. Err = Linker::linkModules(
  177. *getModule(), std::move(LM.Module), LM.LinkFlags,
  178. [](llvm::Module &M, const llvm::StringSet<> &GVS) {
  179. internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
  180. return !GV.hasName() || (GVS.count(GV.getName()) == 0);
  181. });
  182. });
  183. } else {
  184. Err = Linker::linkModules(*getModule(), std::move(LM.Module),
  185. LM.LinkFlags);
  186. }
  187. if (Err)
  188. return true;
  189. }
  190. return false; // success
  191. }
  192. void HandleTranslationUnit(ASTContext &C) override {
  193. {
  194. PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
  195. if (FrontendTimesIsEnabled) {
  196. LLVMIRGenerationRefCount += 1;
  197. if (LLVMIRGenerationRefCount == 1)
  198. LLVMIRGeneration.startTimer();
  199. }
  200. Gen->HandleTranslationUnit(C);
  201. if (FrontendTimesIsEnabled) {
  202. LLVMIRGenerationRefCount -= 1;
  203. if (LLVMIRGenerationRefCount == 0)
  204. LLVMIRGeneration.stopTimer();
  205. }
  206. IRGenFinished = true;
  207. }
  208. // Silently ignore if we weren't initialized for some reason.
  209. if (!getModule())
  210. return;
  211. // Install an inline asm handler so that diagnostics get printed through
  212. // our diagnostics hooks.
  213. LLVMContext &Ctx = getModule()->getContext();
  214. LLVMContext::InlineAsmDiagHandlerTy OldHandler =
  215. Ctx.getInlineAsmDiagnosticHandler();
  216. void *OldContext = Ctx.getInlineAsmDiagnosticContext();
  217. Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
  218. std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler =
  219. Ctx.getDiagnosticHandler();
  220. Ctx.setDiagnosticHandler(llvm::make_unique<ClangDiagnosticHandler>(
  221. CodeGenOpts, this));
  222. Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
  223. if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
  224. Ctx.setDiagnosticsHotnessThreshold(
  225. CodeGenOpts.DiagnosticsHotnessThreshold);
  226. std::unique_ptr<llvm::ToolOutputFile> OptRecordFile;
  227. if (!CodeGenOpts.OptRecordFile.empty()) {
  228. std::error_code EC;
  229. OptRecordFile = llvm::make_unique<llvm::ToolOutputFile>(
  230. CodeGenOpts.OptRecordFile, EC, sys::fs::F_None);
  231. if (EC) {
  232. Diags.Report(diag::err_cannot_open_file) <<
  233. CodeGenOpts.OptRecordFile << EC.message();
  234. return;
  235. }
  236. Ctx.setRemarkStreamer(llvm::make_unique<RemarkStreamer>(
  237. CodeGenOpts.OptRecordFile, OptRecordFile->os()));
  238. if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone)
  239. Ctx.setDiagnosticsHotnessRequested(true);
  240. }
  241. // Link each LinkModule into our module.
  242. if (LinkInModules())
  243. return;
  244. EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
  245. EmitBackendOutput(Diags, HeaderSearchOpts, CodeGenOpts, TargetOpts,
  246. LangOpts, C.getTargetInfo().getDataLayout(),
  247. getModule(), Action, std::move(AsmOutStream));
  248. Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
  249. Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
  250. if (OptRecordFile)
  251. OptRecordFile->keep();
  252. }
  253. void HandleTagDeclDefinition(TagDecl *D) override {
  254. PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
  255. Context->getSourceManager(),
  256. "LLVM IR generation of declaration");
  257. Gen->HandleTagDeclDefinition(D);
  258. }
  259. void HandleTagDeclRequiredDefinition(const TagDecl *D) override {
  260. Gen->HandleTagDeclRequiredDefinition(D);
  261. }
  262. void CompleteTentativeDefinition(VarDecl *D) override {
  263. Gen->CompleteTentativeDefinition(D);
  264. }
  265. void AssignInheritanceModel(CXXRecordDecl *RD) override {
  266. Gen->AssignInheritanceModel(RD);
  267. }
  268. void HandleVTable(CXXRecordDecl *RD) override {
  269. Gen->HandleVTable(RD);
  270. }
  271. static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context,
  272. unsigned LocCookie) {
  273. SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie);
  274. ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc);
  275. }
  276. /// Get the best possible source location to represent a diagnostic that
  277. /// may have associated debug info.
  278. const FullSourceLoc
  279. getBestLocationFromDebugLoc(const llvm::DiagnosticInfoWithLocationBase &D,
  280. bool &BadDebugInfo, StringRef &Filename,
  281. unsigned &Line, unsigned &Column) const;
  282. void InlineAsmDiagHandler2(const llvm::SMDiagnostic &,
  283. SourceLocation LocCookie);
  284. void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI);
  285. /// Specialized handler for InlineAsm diagnostic.
  286. /// \return True if the diagnostic has been successfully reported, false
  287. /// otherwise.
  288. bool InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D);
  289. /// Specialized handler for StackSize diagnostic.
  290. /// \return True if the diagnostic has been successfully reported, false
  291. /// otherwise.
  292. bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D);
  293. /// Specialized handler for unsupported backend feature diagnostic.
  294. void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D);
  295. /// Specialized handlers for optimization remarks.
  296. /// Note that these handlers only accept remarks and they always handle
  297. /// them.
  298. void EmitOptimizationMessage(const llvm::DiagnosticInfoOptimizationBase &D,
  299. unsigned DiagID);
  300. void
  301. OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &D);
  302. void OptimizationRemarkHandler(
  303. const llvm::OptimizationRemarkAnalysisFPCommute &D);
  304. void OptimizationRemarkHandler(
  305. const llvm::OptimizationRemarkAnalysisAliasing &D);
  306. void OptimizationFailureHandler(
  307. const llvm::DiagnosticInfoOptimizationFailure &D);
  308. };
  309. void BackendConsumer::anchor() {}
  310. }
  311. bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo &DI) {
  312. BackendCon->DiagnosticHandlerImpl(DI);
  313. return true;
  314. }
  315. /// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr
  316. /// buffer to be a valid FullSourceLoc.
  317. static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D,
  318. SourceManager &CSM) {
  319. // Get both the clang and llvm source managers. The location is relative to
  320. // a memory buffer that the LLVM Source Manager is handling, we need to add
  321. // a copy to the Clang source manager.
  322. const llvm::SourceMgr &LSM = *D.getSourceMgr();
  323. // We need to copy the underlying LLVM memory buffer because llvm::SourceMgr
  324. // already owns its one and clang::SourceManager wants to own its one.
  325. const MemoryBuffer *LBuf =
  326. LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
  327. // Create the copy and transfer ownership to clang::SourceManager.
  328. // TODO: Avoid copying files into memory.
  329. std::unique_ptr<llvm::MemoryBuffer> CBuf =
  330. llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
  331. LBuf->getBufferIdentifier());
  332. // FIXME: Keep a file ID map instead of creating new IDs for each location.
  333. FileID FID = CSM.createFileID(std::move(CBuf));
  334. // Translate the offset into the file.
  335. unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
  336. SourceLocation NewLoc =
  337. CSM.getLocForStartOfFile(FID).getLocWithOffset(Offset);
  338. return FullSourceLoc(NewLoc, CSM);
  339. }
  340. /// InlineAsmDiagHandler2 - This function is invoked when the backend hits an
  341. /// error parsing inline asm. The SMDiagnostic indicates the error relative to
  342. /// the temporary memory buffer that the inline asm parser has set up.
  343. void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
  344. SourceLocation LocCookie) {
  345. // There are a couple of different kinds of errors we could get here. First,
  346. // we re-format the SMDiagnostic in terms of a clang diagnostic.
  347. // Strip "error: " off the start of the message string.
  348. StringRef Message = D.getMessage();
  349. if (Message.startswith("error: "))
  350. Message = Message.substr(7);
  351. // If the SMDiagnostic has an inline asm source location, translate it.
  352. FullSourceLoc Loc;
  353. if (D.getLoc() != SMLoc())
  354. Loc = ConvertBackendLocation(D, Context->getSourceManager());
  355. unsigned DiagID;
  356. switch (D.getKind()) {
  357. case llvm::SourceMgr::DK_Error:
  358. DiagID = diag::err_fe_inline_asm;
  359. break;
  360. case llvm::SourceMgr::DK_Warning:
  361. DiagID = diag::warn_fe_inline_asm;
  362. break;
  363. case llvm::SourceMgr::DK_Note:
  364. DiagID = diag::note_fe_inline_asm;
  365. break;
  366. case llvm::SourceMgr::DK_Remark:
  367. llvm_unreachable("remarks unexpected");
  368. }
  369. // If this problem has clang-level source location information, report the
  370. // issue in the source with a note showing the instantiated
  371. // code.
  372. if (LocCookie.isValid()) {
  373. Diags.Report(LocCookie, DiagID).AddString(Message);
  374. if (D.getLoc().isValid()) {
  375. DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here);
  376. // Convert the SMDiagnostic ranges into SourceRange and attach them
  377. // to the diagnostic.
  378. for (const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
  379. unsigned Column = D.getColumnNo();
  380. B << SourceRange(Loc.getLocWithOffset(Range.first - Column),
  381. Loc.getLocWithOffset(Range.second - Column));
  382. }
  383. }
  384. return;
  385. }
  386. // Otherwise, report the backend issue as occurring in the generated .s file.
  387. // If Loc is invalid, we still need to report the issue, it just gets no
  388. // location info.
  389. Diags.Report(Loc, DiagID).AddString(Message);
  390. }
  391. #define ComputeDiagID(Severity, GroupName, DiagID) \
  392. do { \
  393. switch (Severity) { \
  394. case llvm::DS_Error: \
  395. DiagID = diag::err_fe_##GroupName; \
  396. break; \
  397. case llvm::DS_Warning: \
  398. DiagID = diag::warn_fe_##GroupName; \
  399. break; \
  400. case llvm::DS_Remark: \
  401. llvm_unreachable("'remark' severity not expected"); \
  402. break; \
  403. case llvm::DS_Note: \
  404. DiagID = diag::note_fe_##GroupName; \
  405. break; \
  406. } \
  407. } while (false)
  408. #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \
  409. do { \
  410. switch (Severity) { \
  411. case llvm::DS_Error: \
  412. DiagID = diag::err_fe_##GroupName; \
  413. break; \
  414. case llvm::DS_Warning: \
  415. DiagID = diag::warn_fe_##GroupName; \
  416. break; \
  417. case llvm::DS_Remark: \
  418. DiagID = diag::remark_fe_##GroupName; \
  419. break; \
  420. case llvm::DS_Note: \
  421. DiagID = diag::note_fe_##GroupName; \
  422. break; \
  423. } \
  424. } while (false)
  425. bool
  426. BackendConsumer::InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D) {
  427. unsigned DiagID;
  428. ComputeDiagID(D.getSeverity(), inline_asm, DiagID);
  429. std::string Message = D.getMsgStr().str();
  430. // If this problem has clang-level source location information, report the
  431. // issue as being a problem in the source with a note showing the instantiated
  432. // code.
  433. SourceLocation LocCookie =
  434. SourceLocation::getFromRawEncoding(D.getLocCookie());
  435. if (LocCookie.isValid())
  436. Diags.Report(LocCookie, DiagID).AddString(Message);
  437. else {
  438. // Otherwise, report the backend diagnostic as occurring in the generated
  439. // .s file.
  440. // If Loc is invalid, we still need to report the diagnostic, it just gets
  441. // no location info.
  442. FullSourceLoc Loc;
  443. Diags.Report(Loc, DiagID).AddString(Message);
  444. }
  445. // We handled all the possible severities.
  446. return true;
  447. }
  448. bool
  449. BackendConsumer::StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D) {
  450. if (D.getSeverity() != llvm::DS_Warning)
  451. // For now, the only support we have for StackSize diagnostic is warning.
  452. // We do not know how to format other severities.
  453. return false;
  454. if (const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
  455. // FIXME: Shouldn't need to truncate to uint32_t
  456. Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
  457. diag::warn_fe_frame_larger_than)
  458. << static_cast<uint32_t>(D.getStackSize()) << Decl::castToDeclContext(ND);
  459. return true;
  460. }
  461. return false;
  462. }
  463. const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc(
  464. const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo,
  465. StringRef &Filename, unsigned &Line, unsigned &Column) const {
  466. SourceManager &SourceMgr = Context->getSourceManager();
  467. FileManager &FileMgr = SourceMgr.getFileManager();
  468. SourceLocation DILoc;
  469. if (D.isLocationAvailable()) {
  470. D.getLocation(Filename, Line, Column);
  471. if (Line > 0) {
  472. const FileEntry *FE = FileMgr.getFile(Filename);
  473. if (!FE)
  474. FE = FileMgr.getFile(D.getAbsolutePath());
  475. if (FE) {
  476. // If -gcolumn-info was not used, Column will be 0. This upsets the
  477. // source manager, so pass 1 if Column is not set.
  478. DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1);
  479. }
  480. }
  481. BadDebugInfo = DILoc.isInvalid();
  482. }
  483. // If a location isn't available, try to approximate it using the associated
  484. // function definition. We use the definition's right brace to differentiate
  485. // from diagnostics that genuinely relate to the function itself.
  486. FullSourceLoc Loc(DILoc, SourceMgr);
  487. if (Loc.isInvalid())
  488. if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
  489. Loc = FD->getASTContext().getFullLoc(FD->getLocation());
  490. if (DILoc.isInvalid() && D.isLocationAvailable())
  491. // If we were not able to translate the file:line:col information
  492. // back to a SourceLocation, at least emit a note stating that
  493. // we could not translate this location. This can happen in the
  494. // case of #line directives.
  495. Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
  496. << Filename << Line << Column;
  497. return Loc;
  498. }
  499. void BackendConsumer::UnsupportedDiagHandler(
  500. const llvm::DiagnosticInfoUnsupported &D) {
  501. // We only support errors.
  502. assert(D.getSeverity() == llvm::DS_Error);
  503. StringRef Filename;
  504. unsigned Line, Column;
  505. bool BadDebugInfo = false;
  506. FullSourceLoc Loc =
  507. getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
  508. Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
  509. if (BadDebugInfo)
  510. // If we were not able to translate the file:line:col information
  511. // back to a SourceLocation, at least emit a note stating that
  512. // we could not translate this location. This can happen in the
  513. // case of #line directives.
  514. Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
  515. << Filename << Line << Column;
  516. }
  517. void BackendConsumer::EmitOptimizationMessage(
  518. const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) {
  519. // We only support warnings and remarks.
  520. assert(D.getSeverity() == llvm::DS_Remark ||
  521. D.getSeverity() == llvm::DS_Warning);
  522. StringRef Filename;
  523. unsigned Line, Column;
  524. bool BadDebugInfo = false;
  525. FullSourceLoc Loc =
  526. getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
  527. std::string Msg;
  528. raw_string_ostream MsgStream(Msg);
  529. MsgStream << D.getMsg();
  530. if (D.getHotness())
  531. MsgStream << " (hotness: " << *D.getHotness() << ")";
  532. Diags.Report(Loc, DiagID)
  533. << AddFlagValue(D.getPassName())
  534. << MsgStream.str();
  535. if (BadDebugInfo)
  536. // If we were not able to translate the file:line:col information
  537. // back to a SourceLocation, at least emit a note stating that
  538. // we could not translate this location. This can happen in the
  539. // case of #line directives.
  540. Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
  541. << Filename << Line << Column;
  542. }
  543. void BackendConsumer::OptimizationRemarkHandler(
  544. const llvm::DiagnosticInfoOptimizationBase &D) {
  545. // Without hotness information, don't show noisy remarks.
  546. if (D.isVerbose() && !D.getHotness())
  547. return;
  548. if (D.isPassed()) {
  549. // Optimization remarks are active only if the -Rpass flag has a regular
  550. // expression that matches the name of the pass name in \p D.
  551. if (CodeGenOpts.OptimizationRemarkPattern &&
  552. CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
  553. EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
  554. } else if (D.isMissed()) {
  555. // Missed optimization remarks are active only if the -Rpass-missed
  556. // flag has a regular expression that matches the name of the pass
  557. // name in \p D.
  558. if (CodeGenOpts.OptimizationRemarkMissedPattern &&
  559. CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
  560. EmitOptimizationMessage(
  561. D, diag::remark_fe_backend_optimization_remark_missed);
  562. } else {
  563. assert(D.isAnalysis() && "Unknown remark type");
  564. bool ShouldAlwaysPrint = false;
  565. if (auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
  566. ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
  567. if (ShouldAlwaysPrint ||
  568. (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
  569. CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
  570. EmitOptimizationMessage(
  571. D, diag::remark_fe_backend_optimization_remark_analysis);
  572. }
  573. }
  574. void BackendConsumer::OptimizationRemarkHandler(
  575. const llvm::OptimizationRemarkAnalysisFPCommute &D) {
  576. // Optimization analysis remarks are active if the pass name is set to
  577. // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a
  578. // regular expression that matches the name of the pass name in \p D.
  579. if (D.shouldAlwaysPrint() ||
  580. (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
  581. CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
  582. EmitOptimizationMessage(
  583. D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
  584. }
  585. void BackendConsumer::OptimizationRemarkHandler(
  586. const llvm::OptimizationRemarkAnalysisAliasing &D) {
  587. // Optimization analysis remarks are active if the pass name is set to
  588. // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a
  589. // regular expression that matches the name of the pass name in \p D.
  590. if (D.shouldAlwaysPrint() ||
  591. (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
  592. CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
  593. EmitOptimizationMessage(
  594. D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
  595. }
  596. void BackendConsumer::OptimizationFailureHandler(
  597. const llvm::DiagnosticInfoOptimizationFailure &D) {
  598. EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
  599. }
  600. /// This function is invoked when the backend needs
  601. /// to report something to the user.
  602. void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
  603. unsigned DiagID = diag::err_fe_inline_asm;
  604. llvm::DiagnosticSeverity Severity = DI.getSeverity();
  605. // Get the diagnostic ID based.
  606. switch (DI.getKind()) {
  607. case llvm::DK_InlineAsm:
  608. if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
  609. return;
  610. ComputeDiagID(Severity, inline_asm, DiagID);
  611. break;
  612. case llvm::DK_StackSize:
  613. if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
  614. return;
  615. ComputeDiagID(Severity, backend_frame_larger_than, DiagID);
  616. break;
  617. case DK_Linker:
  618. assert(CurLinkModule);
  619. // FIXME: stop eating the warnings and notes.
  620. if (Severity != DS_Error)
  621. return;
  622. DiagID = diag::err_fe_cannot_link_module;
  623. break;
  624. case llvm::DK_OptimizationRemark:
  625. // Optimization remarks are always handled completely by this
  626. // handler. There is no generic way of emitting them.
  627. OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
  628. return;
  629. case llvm::DK_OptimizationRemarkMissed:
  630. // Optimization remarks are always handled completely by this
  631. // handler. There is no generic way of emitting them.
  632. OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
  633. return;
  634. case llvm::DK_OptimizationRemarkAnalysis:
  635. // Optimization remarks are always handled completely by this
  636. // handler. There is no generic way of emitting them.
  637. OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
  638. return;
  639. case llvm::DK_OptimizationRemarkAnalysisFPCommute:
  640. // Optimization remarks are always handled completely by this
  641. // handler. There is no generic way of emitting them.
  642. OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
  643. return;
  644. case llvm::DK_OptimizationRemarkAnalysisAliasing:
  645. // Optimization remarks are always handled completely by this
  646. // handler. There is no generic way of emitting them.
  647. OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
  648. return;
  649. case llvm::DK_MachineOptimizationRemark:
  650. // Optimization remarks are always handled completely by this
  651. // handler. There is no generic way of emitting them.
  652. OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
  653. return;
  654. case llvm::DK_MachineOptimizationRemarkMissed:
  655. // Optimization remarks are always handled completely by this
  656. // handler. There is no generic way of emitting them.
  657. OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
  658. return;
  659. case llvm::DK_MachineOptimizationRemarkAnalysis:
  660. // Optimization remarks are always handled completely by this
  661. // handler. There is no generic way of emitting them.
  662. OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
  663. return;
  664. case llvm::DK_OptimizationFailure:
  665. // Optimization failures are always handled completely by this
  666. // handler.
  667. OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
  668. return;
  669. case llvm::DK_Unsupported:
  670. UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
  671. return;
  672. default:
  673. // Plugin IDs are not bound to any value as they are set dynamically.
  674. ComputeDiagRemarkID(Severity, backend_plugin, DiagID);
  675. break;
  676. }
  677. std::string MsgStorage;
  678. {
  679. raw_string_ostream Stream(MsgStorage);
  680. DiagnosticPrinterRawOStream DP(Stream);
  681. DI.print(DP);
  682. }
  683. if (DiagID == diag::err_fe_cannot_link_module) {
  684. Diags.Report(diag::err_fe_cannot_link_module)
  685. << CurLinkModule->getModuleIdentifier() << MsgStorage;
  686. return;
  687. }
  688. // Report the backend message using the usual diagnostic mechanism.
  689. FullSourceLoc Loc;
  690. Diags.Report(Loc, DiagID).AddString(MsgStorage);
  691. }
  692. #undef ComputeDiagID
  693. CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
  694. : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
  695. OwnsVMContext(!_VMContext) {}
  696. CodeGenAction::~CodeGenAction() {
  697. TheModule.reset();
  698. if (OwnsVMContext)
  699. delete VMContext;
  700. }
  701. bool CodeGenAction::hasIRSupport() const { return true; }
  702. void CodeGenAction::EndSourceFileAction() {
  703. // If the consumer creation failed, do nothing.
  704. if (!getCompilerInstance().hasASTConsumer())
  705. return;
  706. // Steal the module from the consumer.
  707. TheModule = BEConsumer->takeModule();
  708. }
  709. std::unique_ptr<llvm::Module> CodeGenAction::takeModule() {
  710. return std::move(TheModule);
  711. }
  712. llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
  713. OwnsVMContext = false;
  714. return VMContext;
  715. }
  716. static std::unique_ptr<raw_pwrite_stream>
  717. GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) {
  718. switch (Action) {
  719. case Backend_EmitAssembly:
  720. return CI.createDefaultOutputFile(false, InFile, "s");
  721. case Backend_EmitLL:
  722. return CI.createDefaultOutputFile(false, InFile, "ll");
  723. case Backend_EmitBC:
  724. return CI.createDefaultOutputFile(true, InFile, "bc");
  725. case Backend_EmitNothing:
  726. return nullptr;
  727. case Backend_EmitMCNull:
  728. return CI.createNullOutputFile();
  729. case Backend_EmitObj:
  730. return CI.createDefaultOutputFile(true, InFile, "o");
  731. }
  732. llvm_unreachable("Invalid action!");
  733. }
  734. std::unique_ptr<ASTConsumer>
  735. CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
  736. BackendAction BA = static_cast<BackendAction>(Act);
  737. std::unique_ptr<raw_pwrite_stream> OS = CI.takeOutputStream();
  738. if (!OS)
  739. OS = GetOutputStream(CI, InFile, BA);
  740. if (BA != Backend_EmitNothing && !OS)
  741. return nullptr;
  742. // Load bitcode modules to link with, if we need to.
  743. if (LinkModules.empty())
  744. for (const CodeGenOptions::BitcodeFileToLink &F :
  745. CI.getCodeGenOpts().LinkBitcodeFiles) {
  746. auto BCBuf = CI.getFileManager().getBufferForFile(F.Filename);
  747. if (!BCBuf) {
  748. CI.getDiagnostics().Report(diag::err_cannot_open_file)
  749. << F.Filename << BCBuf.getError().message();
  750. LinkModules.clear();
  751. return nullptr;
  752. }
  753. Expected<std::unique_ptr<llvm::Module>> ModuleOrErr =
  754. getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
  755. if (!ModuleOrErr) {
  756. handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
  757. CI.getDiagnostics().Report(diag::err_cannot_open_file)
  758. << F.Filename << EIB.message();
  759. });
  760. LinkModules.clear();
  761. return nullptr;
  762. }
  763. LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
  764. F.Internalize, F.LinkFlags});
  765. }
  766. CoverageSourceInfo *CoverageInfo = nullptr;
  767. // Add the preprocessor callback only when the coverage mapping is generated.
  768. if (CI.getCodeGenOpts().CoverageMapping) {
  769. CoverageInfo = new CoverageSourceInfo;
  770. CI.getPreprocessor().addPPCallbacks(
  771. std::unique_ptr<PPCallbacks>(CoverageInfo));
  772. }
  773. std::unique_ptr<BackendConsumer> Result(new BackendConsumer(
  774. BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(),
  775. CI.getPreprocessorOpts(), CI.getCodeGenOpts(), CI.getTargetOpts(),
  776. CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
  777. std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
  778. BEConsumer = Result.get();
  779. // Enable generating macro debug info only when debug info is not disabled and
  780. // also macro debug info is enabled.
  781. if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo &&
  782. CI.getCodeGenOpts().MacroDebugInfo) {
  783. std::unique_ptr<PPCallbacks> Callbacks =
  784. llvm::make_unique<MacroPPCallbacks>(BEConsumer->getCodeGenerator(),
  785. CI.getPreprocessor());
  786. CI.getPreprocessor().addPPCallbacks(std::move(Callbacks));
  787. }
  788. return std::move(Result);
  789. }
  790. static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM,
  791. void *Context,
  792. unsigned LocCookie) {
  793. SM.print(nullptr, llvm::errs());
  794. auto Diags = static_cast<DiagnosticsEngine *>(Context);
  795. unsigned DiagID;
  796. switch (SM.getKind()) {
  797. case llvm::SourceMgr::DK_Error:
  798. DiagID = diag::err_fe_inline_asm;
  799. break;
  800. case llvm::SourceMgr::DK_Warning:
  801. DiagID = diag::warn_fe_inline_asm;
  802. break;
  803. case llvm::SourceMgr::DK_Note:
  804. DiagID = diag::note_fe_inline_asm;
  805. break;
  806. case llvm::SourceMgr::DK_Remark:
  807. llvm_unreachable("remarks unexpected");
  808. }
  809. Diags->Report(DiagID).AddString("cannot compile inline asm");
  810. }
  811. std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
  812. CompilerInstance &CI = getCompilerInstance();
  813. SourceManager &SM = CI.getSourceManager();
  814. // For ThinLTO backend invocations, ensure that the context
  815. // merges types based on ODR identifiers. We also need to read
  816. // the correct module out of a multi-module bitcode file.
  817. if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) {
  818. VMContext->enableDebugTypeODRUniquing();
  819. auto DiagErrors = [&](Error E) -> std::unique_ptr<llvm::Module> {
  820. unsigned DiagID =
  821. CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
  822. handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
  823. CI.getDiagnostics().Report(DiagID) << EIB.message();
  824. });
  825. return {};
  826. };
  827. Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef);
  828. if (!BMsOrErr)
  829. return DiagErrors(BMsOrErr.takeError());
  830. BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
  831. // We have nothing to do if the file contains no ThinLTO module. This is
  832. // possible if ThinLTO compilation was not able to split module. Content of
  833. // the file was already processed by indexing and will be passed to the
  834. // linker using merged object file.
  835. if (!Bm) {
  836. auto M = llvm::make_unique<llvm::Module>("empty", *VMContext);
  837. M->setTargetTriple(CI.getTargetOpts().Triple);
  838. return M;
  839. }
  840. Expected<std::unique_ptr<llvm::Module>> MOrErr =
  841. Bm->parseModule(*VMContext);
  842. if (!MOrErr)
  843. return DiagErrors(MOrErr.takeError());
  844. return std::move(*MOrErr);
  845. }
  846. llvm::SMDiagnostic Err;
  847. if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
  848. return M;
  849. // Translate from the diagnostic info to the SourceManager location if
  850. // available.
  851. // TODO: Unify this with ConvertBackendLocation()
  852. SourceLocation Loc;
  853. if (Err.getLineNo() > 0) {
  854. assert(Err.getColumnNo() >= 0);
  855. Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()),
  856. Err.getLineNo(), Err.getColumnNo() + 1);
  857. }
  858. // Strip off a leading diagnostic code if there is one.
  859. StringRef Msg = Err.getMessage();
  860. if (Msg.startswith("error: "))
  861. Msg = Msg.substr(7);
  862. unsigned DiagID =
  863. CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
  864. CI.getDiagnostics().Report(Loc, DiagID) << Msg;
  865. return {};
  866. }
  867. void CodeGenAction::ExecuteAction() {
  868. // If this is an IR file, we have to treat it specially.
  869. if (getCurrentFileKind().getLanguage() == InputKind::LLVM_IR) {
  870. BackendAction BA = static_cast<BackendAction>(Act);
  871. CompilerInstance &CI = getCompilerInstance();
  872. std::unique_ptr<raw_pwrite_stream> OS =
  873. GetOutputStream(CI, getCurrentFile(), BA);
  874. if (BA != Backend_EmitNothing && !OS)
  875. return;
  876. bool Invalid;
  877. SourceManager &SM = CI.getSourceManager();
  878. FileID FID = SM.getMainFileID();
  879. llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid);
  880. if (Invalid)
  881. return;
  882. TheModule = loadModule(*MainFile);
  883. if (!TheModule)
  884. return;
  885. const TargetOptions &TargetOpts = CI.getTargetOpts();
  886. if (TheModule->getTargetTriple() != TargetOpts.Triple) {
  887. CI.getDiagnostics().Report(SourceLocation(),
  888. diag::warn_fe_override_module)
  889. << TargetOpts.Triple;
  890. TheModule->setTargetTriple(TargetOpts.Triple);
  891. }
  892. EmbedBitcode(TheModule.get(), CI.getCodeGenOpts(),
  893. MainFile->getMemBufferRef());
  894. LLVMContext &Ctx = TheModule->getContext();
  895. Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,
  896. &CI.getDiagnostics());
  897. EmitBackendOutput(CI.getDiagnostics(), CI.getHeaderSearchOpts(),
  898. CI.getCodeGenOpts(), TargetOpts, CI.getLangOpts(),
  899. CI.getTarget().getDataLayout(), TheModule.get(), BA,
  900. std::move(OS));
  901. return;
  902. }
  903. // Otherwise follow the normal AST path.
  904. this->ASTFrontendAction::ExecuteAction();
  905. }
  906. //
  907. void EmitAssemblyAction::anchor() { }
  908. EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext)
  909. : CodeGenAction(Backend_EmitAssembly, _VMContext) {}
  910. void EmitBCAction::anchor() { }
  911. EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext)
  912. : CodeGenAction(Backend_EmitBC, _VMContext) {}
  913. void EmitLLVMAction::anchor() { }
  914. EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext)
  915. : CodeGenAction(Backend_EmitLL, _VMContext) {}
  916. void EmitLLVMOnlyAction::anchor() { }
  917. EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext)
  918. : CodeGenAction(Backend_EmitNothing, _VMContext) {}
  919. void EmitCodeGenOnlyAction::anchor() { }
  920. EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext)
  921. : CodeGenAction(Backend_EmitMCNull, _VMContext) {}
  922. void EmitObjAction::anchor() { }
  923. EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext)
  924. : CodeGenAction(Backend_EmitObj, _VMContext) {}