CodeGenAction.cpp 41 KB

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