CodeGenAction.cpp 40 KB

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