CodeGenAction.cpp 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. //===--- CodeGenAction.cpp - LLVM Code Generation Frontend Action ---------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "clang/CodeGen/CodeGenAction.h"
  10. #include "CodeGenModule.h"
  11. #include "CoverageMappingGen.h"
  12. #include "MacroPPCallbacks.h"
  13. #include "clang/AST/ASTConsumer.h"
  14. #include "clang/AST/ASTContext.h"
  15. #include "clang/AST/DeclCXX.h"
  16. #include "clang/AST/DeclGroup.h"
  17. #include "clang/Basic/FileManager.h"
  18. #include "clang/Basic/SourceManager.h"
  19. #include "clang/Basic/TargetInfo.h"
  20. #include "clang/CodeGen/BackendUtil.h"
  21. #include "clang/CodeGen/ModuleBuilder.h"
  22. #include "clang/Frontend/CompilerInstance.h"
  23. #include "clang/Frontend/FrontendDiagnostic.h"
  24. #include "clang/Lex/Preprocessor.h"
  25. #include "llvm/Bitcode/BitcodeReader.h"
  26. #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
  27. #include "llvm/IR/DebugInfo.h"
  28. #include "llvm/IR/DiagnosticInfo.h"
  29. #include "llvm/IR/DiagnosticPrinter.h"
  30. #include "llvm/IR/GlobalValue.h"
  31. #include "llvm/IR/LLVMContext.h"
  32. #include "llvm/IR/Module.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.setDiagnosticsOutputFile(
  237. llvm::make_unique<yaml::Output>(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. const FileEntry *FE = FileMgr.getFile(Filename);
  472. if (FE && Line > 0) {
  473. // If -gcolumn-info was not used, Column will be 0. This upsets the
  474. // source manager, so pass 1 if Column is not set.
  475. DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1);
  476. }
  477. BadDebugInfo = DILoc.isInvalid();
  478. }
  479. // If a location isn't available, try to approximate it using the associated
  480. // function definition. We use the definition's right brace to differentiate
  481. // from diagnostics that genuinely relate to the function itself.
  482. FullSourceLoc Loc(DILoc, SourceMgr);
  483. if (Loc.isInvalid())
  484. if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
  485. Loc = FD->getASTContext().getFullLoc(FD->getLocation());
  486. if (DILoc.isInvalid() && D.isLocationAvailable())
  487. // If we were not able to translate the file:line:col information
  488. // back to a SourceLocation, at least emit a note stating that
  489. // we could not translate this location. This can happen in the
  490. // case of #line directives.
  491. Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
  492. << Filename << Line << Column;
  493. return Loc;
  494. }
  495. void BackendConsumer::UnsupportedDiagHandler(
  496. const llvm::DiagnosticInfoUnsupported &D) {
  497. // We only support errors.
  498. assert(D.getSeverity() == llvm::DS_Error);
  499. StringRef Filename;
  500. unsigned Line, Column;
  501. bool BadDebugInfo = false;
  502. FullSourceLoc Loc =
  503. getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
  504. Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
  505. if (BadDebugInfo)
  506. // If we were not able to translate the file:line:col information
  507. // back to a SourceLocation, at least emit a note stating that
  508. // we could not translate this location. This can happen in the
  509. // case of #line directives.
  510. Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
  511. << Filename << Line << Column;
  512. }
  513. void BackendConsumer::EmitOptimizationMessage(
  514. const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) {
  515. // We only support warnings and remarks.
  516. assert(D.getSeverity() == llvm::DS_Remark ||
  517. D.getSeverity() == llvm::DS_Warning);
  518. StringRef Filename;
  519. unsigned Line, Column;
  520. bool BadDebugInfo = false;
  521. FullSourceLoc Loc =
  522. getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
  523. std::string Msg;
  524. raw_string_ostream MsgStream(Msg);
  525. MsgStream << D.getMsg();
  526. if (D.getHotness())
  527. MsgStream << " (hotness: " << *D.getHotness() << ")";
  528. Diags.Report(Loc, DiagID)
  529. << AddFlagValue(D.getPassName())
  530. << MsgStream.str();
  531. if (BadDebugInfo)
  532. // If we were not able to translate the file:line:col information
  533. // back to a SourceLocation, at least emit a note stating that
  534. // we could not translate this location. This can happen in the
  535. // case of #line directives.
  536. Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
  537. << Filename << Line << Column;
  538. }
  539. void BackendConsumer::OptimizationRemarkHandler(
  540. const llvm::DiagnosticInfoOptimizationBase &D) {
  541. // Without hotness information, don't show noisy remarks.
  542. if (D.isVerbose() && !D.getHotness())
  543. return;
  544. if (D.isPassed()) {
  545. // Optimization remarks are active only if the -Rpass flag has a regular
  546. // expression that matches the name of the pass name in \p D.
  547. if (CodeGenOpts.OptimizationRemarkPattern &&
  548. CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
  549. EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
  550. } else if (D.isMissed()) {
  551. // Missed optimization remarks are active only if the -Rpass-missed
  552. // flag has a regular expression that matches the name of the pass
  553. // name in \p D.
  554. if (CodeGenOpts.OptimizationRemarkMissedPattern &&
  555. CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
  556. EmitOptimizationMessage(
  557. D, diag::remark_fe_backend_optimization_remark_missed);
  558. } else {
  559. assert(D.isAnalysis() && "Unknown remark type");
  560. bool ShouldAlwaysPrint = false;
  561. if (auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
  562. ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
  563. if (ShouldAlwaysPrint ||
  564. (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
  565. CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
  566. EmitOptimizationMessage(
  567. D, diag::remark_fe_backend_optimization_remark_analysis);
  568. }
  569. }
  570. void BackendConsumer::OptimizationRemarkHandler(
  571. const llvm::OptimizationRemarkAnalysisFPCommute &D) {
  572. // Optimization analysis remarks are active if the pass name is set to
  573. // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a
  574. // regular expression that matches the name of the pass name in \p D.
  575. if (D.shouldAlwaysPrint() ||
  576. (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
  577. CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
  578. EmitOptimizationMessage(
  579. D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
  580. }
  581. void BackendConsumer::OptimizationRemarkHandler(
  582. const llvm::OptimizationRemarkAnalysisAliasing &D) {
  583. // Optimization analysis remarks are active if the pass name is set to
  584. // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a
  585. // regular expression that matches the name of the pass name in \p D.
  586. if (D.shouldAlwaysPrint() ||
  587. (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
  588. CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
  589. EmitOptimizationMessage(
  590. D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
  591. }
  592. void BackendConsumer::OptimizationFailureHandler(
  593. const llvm::DiagnosticInfoOptimizationFailure &D) {
  594. EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
  595. }
  596. /// This function is invoked when the backend needs
  597. /// to report something to the user.
  598. void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
  599. unsigned DiagID = diag::err_fe_inline_asm;
  600. llvm::DiagnosticSeverity Severity = DI.getSeverity();
  601. // Get the diagnostic ID based.
  602. switch (DI.getKind()) {
  603. case llvm::DK_InlineAsm:
  604. if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
  605. return;
  606. ComputeDiagID(Severity, inline_asm, DiagID);
  607. break;
  608. case llvm::DK_StackSize:
  609. if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
  610. return;
  611. ComputeDiagID(Severity, backend_frame_larger_than, DiagID);
  612. break;
  613. case DK_Linker:
  614. assert(CurLinkModule);
  615. // FIXME: stop eating the warnings and notes.
  616. if (Severity != DS_Error)
  617. return;
  618. DiagID = diag::err_fe_cannot_link_module;
  619. break;
  620. case llvm::DK_OptimizationRemark:
  621. // Optimization remarks are always handled completely by this
  622. // handler. There is no generic way of emitting them.
  623. OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
  624. return;
  625. case llvm::DK_OptimizationRemarkMissed:
  626. // Optimization remarks are always handled completely by this
  627. // handler. There is no generic way of emitting them.
  628. OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
  629. return;
  630. case llvm::DK_OptimizationRemarkAnalysis:
  631. // Optimization remarks are always handled completely by this
  632. // handler. There is no generic way of emitting them.
  633. OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
  634. return;
  635. case llvm::DK_OptimizationRemarkAnalysisFPCommute:
  636. // Optimization remarks are always handled completely by this
  637. // handler. There is no generic way of emitting them.
  638. OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
  639. return;
  640. case llvm::DK_OptimizationRemarkAnalysisAliasing:
  641. // Optimization remarks are always handled completely by this
  642. // handler. There is no generic way of emitting them.
  643. OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
  644. return;
  645. case llvm::DK_MachineOptimizationRemark:
  646. // Optimization remarks are always handled completely by this
  647. // handler. There is no generic way of emitting them.
  648. OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
  649. return;
  650. case llvm::DK_MachineOptimizationRemarkMissed:
  651. // Optimization remarks are always handled completely by this
  652. // handler. There is no generic way of emitting them.
  653. OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
  654. return;
  655. case llvm::DK_MachineOptimizationRemarkAnalysis:
  656. // Optimization remarks are always handled completely by this
  657. // handler. There is no generic way of emitting them.
  658. OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
  659. return;
  660. case llvm::DK_OptimizationFailure:
  661. // Optimization failures are always handled completely by this
  662. // handler.
  663. OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
  664. return;
  665. case llvm::DK_Unsupported:
  666. UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
  667. return;
  668. default:
  669. // Plugin IDs are not bound to any value as they are set dynamically.
  670. ComputeDiagRemarkID(Severity, backend_plugin, DiagID);
  671. break;
  672. }
  673. std::string MsgStorage;
  674. {
  675. raw_string_ostream Stream(MsgStorage);
  676. DiagnosticPrinterRawOStream DP(Stream);
  677. DI.print(DP);
  678. }
  679. if (DiagID == diag::err_fe_cannot_link_module) {
  680. Diags.Report(diag::err_fe_cannot_link_module)
  681. << CurLinkModule->getModuleIdentifier() << MsgStorage;
  682. return;
  683. }
  684. // Report the backend message using the usual diagnostic mechanism.
  685. FullSourceLoc Loc;
  686. Diags.Report(Loc, DiagID).AddString(MsgStorage);
  687. }
  688. #undef ComputeDiagID
  689. CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
  690. : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
  691. OwnsVMContext(!_VMContext) {}
  692. CodeGenAction::~CodeGenAction() {
  693. TheModule.reset();
  694. if (OwnsVMContext)
  695. delete VMContext;
  696. }
  697. bool CodeGenAction::hasIRSupport() const { return true; }
  698. void CodeGenAction::EndSourceFileAction() {
  699. // If the consumer creation failed, do nothing.
  700. if (!getCompilerInstance().hasASTConsumer())
  701. return;
  702. // Steal the module from the consumer.
  703. TheModule = BEConsumer->takeModule();
  704. }
  705. std::unique_ptr<llvm::Module> CodeGenAction::takeModule() {
  706. return std::move(TheModule);
  707. }
  708. llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
  709. OwnsVMContext = false;
  710. return VMContext;
  711. }
  712. static std::unique_ptr<raw_pwrite_stream>
  713. GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) {
  714. switch (Action) {
  715. case Backend_EmitAssembly:
  716. return CI.createDefaultOutputFile(false, InFile, "s");
  717. case Backend_EmitLL:
  718. return CI.createDefaultOutputFile(false, InFile, "ll");
  719. case Backend_EmitBC:
  720. return CI.createDefaultOutputFile(true, InFile, "bc");
  721. case Backend_EmitNothing:
  722. return nullptr;
  723. case Backend_EmitMCNull:
  724. return CI.createNullOutputFile();
  725. case Backend_EmitObj:
  726. return CI.createDefaultOutputFile(true, InFile, "o");
  727. }
  728. llvm_unreachable("Invalid action!");
  729. }
  730. std::unique_ptr<ASTConsumer>
  731. CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
  732. BackendAction BA = static_cast<BackendAction>(Act);
  733. std::unique_ptr<raw_pwrite_stream> OS = CI.takeOutputStream();
  734. if (!OS)
  735. OS = GetOutputStream(CI, InFile, BA);
  736. if (BA != Backend_EmitNothing && !OS)
  737. return nullptr;
  738. // Load bitcode modules to link with, if we need to.
  739. if (LinkModules.empty())
  740. for (const CodeGenOptions::BitcodeFileToLink &F :
  741. CI.getCodeGenOpts().LinkBitcodeFiles) {
  742. auto BCBuf = CI.getFileManager().getBufferForFile(F.Filename);
  743. if (!BCBuf) {
  744. CI.getDiagnostics().Report(diag::err_cannot_open_file)
  745. << F.Filename << BCBuf.getError().message();
  746. LinkModules.clear();
  747. return nullptr;
  748. }
  749. Expected<std::unique_ptr<llvm::Module>> ModuleOrErr =
  750. getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
  751. if (!ModuleOrErr) {
  752. handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
  753. CI.getDiagnostics().Report(diag::err_cannot_open_file)
  754. << F.Filename << EIB.message();
  755. });
  756. LinkModules.clear();
  757. return nullptr;
  758. }
  759. LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
  760. F.Internalize, F.LinkFlags});
  761. }
  762. CoverageSourceInfo *CoverageInfo = nullptr;
  763. // Add the preprocessor callback only when the coverage mapping is generated.
  764. if (CI.getCodeGenOpts().CoverageMapping) {
  765. CoverageInfo = new CoverageSourceInfo;
  766. CI.getPreprocessor().addPPCallbacks(
  767. std::unique_ptr<PPCallbacks>(CoverageInfo));
  768. }
  769. std::unique_ptr<BackendConsumer> Result(new BackendConsumer(
  770. BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(),
  771. CI.getPreprocessorOpts(), CI.getCodeGenOpts(), CI.getTargetOpts(),
  772. CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
  773. std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
  774. BEConsumer = Result.get();
  775. // Enable generating macro debug info only when debug info is not disabled and
  776. // also macro debug info is enabled.
  777. if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo &&
  778. CI.getCodeGenOpts().MacroDebugInfo) {
  779. std::unique_ptr<PPCallbacks> Callbacks =
  780. llvm::make_unique<MacroPPCallbacks>(BEConsumer->getCodeGenerator(),
  781. CI.getPreprocessor());
  782. CI.getPreprocessor().addPPCallbacks(std::move(Callbacks));
  783. }
  784. return std::move(Result);
  785. }
  786. static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM,
  787. void *Context,
  788. unsigned LocCookie) {
  789. SM.print(nullptr, llvm::errs());
  790. auto Diags = static_cast<DiagnosticsEngine *>(Context);
  791. unsigned DiagID;
  792. switch (SM.getKind()) {
  793. case llvm::SourceMgr::DK_Error:
  794. DiagID = diag::err_fe_inline_asm;
  795. break;
  796. case llvm::SourceMgr::DK_Warning:
  797. DiagID = diag::warn_fe_inline_asm;
  798. break;
  799. case llvm::SourceMgr::DK_Note:
  800. DiagID = diag::note_fe_inline_asm;
  801. break;
  802. case llvm::SourceMgr::DK_Remark:
  803. llvm_unreachable("remarks unexpected");
  804. }
  805. Diags->Report(DiagID).AddString("cannot compile inline asm");
  806. }
  807. std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
  808. CompilerInstance &CI = getCompilerInstance();
  809. SourceManager &SM = CI.getSourceManager();
  810. // For ThinLTO backend invocations, ensure that the context
  811. // merges types based on ODR identifiers. We also need to read
  812. // the correct module out of a multi-module bitcode file.
  813. if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) {
  814. VMContext->enableDebugTypeODRUniquing();
  815. auto DiagErrors = [&](Error E) -> std::unique_ptr<llvm::Module> {
  816. unsigned DiagID =
  817. CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
  818. handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
  819. CI.getDiagnostics().Report(DiagID) << EIB.message();
  820. });
  821. return {};
  822. };
  823. Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef);
  824. if (!BMsOrErr)
  825. return DiagErrors(BMsOrErr.takeError());
  826. BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
  827. // We have nothing to do if the file contains no ThinLTO module. This is
  828. // possible if ThinLTO compilation was not able to split module. Content of
  829. // the file was already processed by indexing and will be passed to the
  830. // linker using merged object file.
  831. if (!Bm) {
  832. auto M = llvm::make_unique<llvm::Module>("empty", *VMContext);
  833. M->setTargetTriple(CI.getTargetOpts().Triple);
  834. return M;
  835. }
  836. Expected<std::unique_ptr<llvm::Module>> MOrErr =
  837. Bm->parseModule(*VMContext);
  838. if (!MOrErr)
  839. return DiagErrors(MOrErr.takeError());
  840. return std::move(*MOrErr);
  841. }
  842. llvm::SMDiagnostic Err;
  843. if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
  844. return M;
  845. // Translate from the diagnostic info to the SourceManager location if
  846. // available.
  847. // TODO: Unify this with ConvertBackendLocation()
  848. SourceLocation Loc;
  849. if (Err.getLineNo() > 0) {
  850. assert(Err.getColumnNo() >= 0);
  851. Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()),
  852. Err.getLineNo(), Err.getColumnNo() + 1);
  853. }
  854. // Strip off a leading diagnostic code if there is one.
  855. StringRef Msg = Err.getMessage();
  856. if (Msg.startswith("error: "))
  857. Msg = Msg.substr(7);
  858. unsigned DiagID =
  859. CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
  860. CI.getDiagnostics().Report(Loc, DiagID) << Msg;
  861. return {};
  862. }
  863. void CodeGenAction::ExecuteAction() {
  864. // If this is an IR file, we have to treat it specially.
  865. if (getCurrentFileKind().getLanguage() == InputKind::LLVM_IR) {
  866. BackendAction BA = static_cast<BackendAction>(Act);
  867. CompilerInstance &CI = getCompilerInstance();
  868. std::unique_ptr<raw_pwrite_stream> OS =
  869. GetOutputStream(CI, getCurrentFile(), BA);
  870. if (BA != Backend_EmitNothing && !OS)
  871. return;
  872. bool Invalid;
  873. SourceManager &SM = CI.getSourceManager();
  874. FileID FID = SM.getMainFileID();
  875. llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid);
  876. if (Invalid)
  877. return;
  878. TheModule = loadModule(*MainFile);
  879. if (!TheModule)
  880. return;
  881. const TargetOptions &TargetOpts = CI.getTargetOpts();
  882. if (TheModule->getTargetTriple() != TargetOpts.Triple) {
  883. CI.getDiagnostics().Report(SourceLocation(),
  884. diag::warn_fe_override_module)
  885. << TargetOpts.Triple;
  886. TheModule->setTargetTriple(TargetOpts.Triple);
  887. }
  888. EmbedBitcode(TheModule.get(), CI.getCodeGenOpts(),
  889. MainFile->getMemBufferRef());
  890. LLVMContext &Ctx = TheModule->getContext();
  891. Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,
  892. &CI.getDiagnostics());
  893. EmitBackendOutput(CI.getDiagnostics(), CI.getHeaderSearchOpts(),
  894. CI.getCodeGenOpts(), TargetOpts, CI.getLangOpts(),
  895. CI.getTarget().getDataLayout(), TheModule.get(), BA,
  896. std::move(OS));
  897. return;
  898. }
  899. // Otherwise follow the normal AST path.
  900. this->ASTFrontendAction::ExecuteAction();
  901. }
  902. //
  903. void EmitAssemblyAction::anchor() { }
  904. EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext)
  905. : CodeGenAction(Backend_EmitAssembly, _VMContext) {}
  906. void EmitBCAction::anchor() { }
  907. EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext)
  908. : CodeGenAction(Backend_EmitBC, _VMContext) {}
  909. void EmitLLVMAction::anchor() { }
  910. EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext)
  911. : CodeGenAction(Backend_EmitLL, _VMContext) {}
  912. void EmitLLVMOnlyAction::anchor() { }
  913. EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext)
  914. : CodeGenAction(Backend_EmitNothing, _VMContext) {}
  915. void EmitCodeGenOnlyAction::anchor() { }
  916. EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext)
  917. : CodeGenAction(Backend_EmitMCNull, _VMContext) {}
  918. void EmitObjAction::anchor() { }
  919. EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext)
  920. : CodeGenAction(Backend_EmitObj, _VMContext) {}