blob: 9b9f562f855d1dd86d93ee4e4b25c7e268d53640 [file] [log] [blame]
Daniel Dunbarcea0c702010-02-25 04:37:45 +00001//===--- CodeGenAction.cpp - LLVM Code Generation Frontend Action ---------===//
Daniel Dunbarc13935e2008-10-21 23:49:24 +00002//
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
Justin Lebarb080b632017-01-25 21:29:48 +000010#include "clang/CodeGen/CodeGenAction.h"
11#include "CodeGenModule.h"
Alex Lorenzee024992014-08-04 18:41:51 +000012#include "CoverageMappingGen.h"
Amjad Aboud546bc112017-02-09 22:07:24 +000013#include "MacroPPCallbacks.h"
Chris Lattner5bbb3c82009-03-29 16:50:03 +000014#include "clang/AST/ASTConsumer.h"
Daniel Dunbarb9bbd542009-11-15 06:48:46 +000015#include "clang/AST/ASTContext.h"
Hans Wennborga926d842014-05-23 20:37:38 +000016#include "clang/AST/DeclCXX.h"
Chandler Carruth0d9593d2015-01-14 11:29:14 +000017#include "clang/AST/DeclGroup.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/Basic/FileManager.h"
19#include "clang/Basic/SourceManager.h"
20#include "clang/Basic/TargetInfo.h"
Daniel Dunbarc1b17292010-06-15 17:48:49 +000021#include "clang/CodeGen/BackendUtil.h"
Daniel Dunbarb9bbd542009-11-15 06:48:46 +000022#include "clang/CodeGen/ModuleBuilder.h"
Daniel Dunbarcea0c702010-02-25 04:37:45 +000023#include "clang/Frontend/CompilerInstance.h"
Daniel Dunbaracadc552009-12-03 09:12:54 +000024#include "clang/Frontend/FrontendDiagnostic.h"
Chandler Carruth0d9593d2015-01-14 11:29:14 +000025#include "clang/Lex/Preprocessor.h"
Teresa Johnsonffc4e242016-11-11 05:35:12 +000026#include "llvm/Bitcode/BitcodeReader.h"
Adam Nemet7b796f82017-01-26 04:07:11 +000027#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
Diego Novillo829b1702014-04-16 16:54:24 +000028#include "llvm/IR/DebugInfo.h"
Quentin Colombet728c5542014-02-06 18:30:43 +000029#include "llvm/IR/DiagnosticInfo.h"
30#include "llvm/IR/DiagnosticPrinter.h"
Jonas Devlieghere5eb9c812017-03-13 18:08:11 +000031#include "llvm/IR/GlobalValue.h"
Chandler Carruthffd55512013-01-02 11:45:17 +000032#include "llvm/IR/LLVMContext.h"
33#include "llvm/IR/Module.h"
Chandler Carruthb45836a2013-03-26 02:25:54 +000034#include "llvm/IRReader/IRReader.h"
Chandler Carruth00fa3f72014-03-06 03:46:44 +000035#include "llvm/Linker/Linker.h"
Daniel Dunbar3e111522010-06-07 23:21:04 +000036#include "llvm/Pass.h"
Chris Lattner5ec32e72010-04-06 18:38:50 +000037#include "llvm/Support/MemoryBuffer.h"
38#include "llvm/Support/SourceMgr.h"
Chris Lattner263d64c2009-02-18 01:37:30 +000039#include "llvm/Support/Timer.h"
Hal Finkel8f96e822016-10-11 00:26:09 +000040#include "llvm/Support/ToolOutputFile.h"
41#include "llvm/Support/YAMLTraits.h"
Jonas Devlieghere5eb9c812017-03-13 18:08:11 +000042#include "llvm/Transforms/IPO/Internalize.h"
43
Ahmed Charlesdfca6f92014-03-09 11:36:40 +000044#include <memory>
Daniel Dunbarc13935e2008-10-21 23:49:24 +000045using namespace clang;
46using namespace llvm;
47
Nico Weber2992efa2011-01-25 20:34:14 +000048namespace clang {
Vivek Pandya1dee3be2017-09-15 20:09:55 +000049 class BackendConsumer;
50 class ClangDiagnosticHandler final : public DiagnosticHandler {
51 public:
52 ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon)
53 : CodeGenOpts(CGOpts), BackendCon(BCon) {}
Nico Weberade321e2018-04-10 18:53:28 +000054
Vivek Pandya1dee3be2017-09-15 20:09:55 +000055 bool handleDiagnostics(const DiagnosticInfo &DI) override;
Adam Nemet5d2eb162017-09-19 17:59:40 +000056
57 bool isAnalysisRemarkEnabled(StringRef PassName) const override {
Vivek Pandya1dee3be2017-09-15 20:09:55 +000058 return (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
59 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName));
60 }
Adam Nemet5d2eb162017-09-19 17:59:40 +000061 bool isMissedOptRemarkEnabled(StringRef PassName) const override {
Vivek Pandya1dee3be2017-09-15 20:09:55 +000062 return (CodeGenOpts.OptimizationRemarkMissedPattern &&
63 CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName));
64 }
Adam Nemet5d2eb162017-09-19 17:59:40 +000065 bool isPassedOptRemarkEnabled(StringRef PassName) const override {
Vivek Pandya1dee3be2017-09-15 20:09:55 +000066 return (CodeGenOpts.OptimizationRemarkPattern &&
67 CodeGenOpts.OptimizationRemarkPattern->match(PassName));
68 }
Adam Nemet5d2eb162017-09-19 17:59:40 +000069
Adam Nemet3ac802a2017-09-19 23:00:59 +000070 bool isAnyRemarkEnabled() const override {
71 return (CodeGenOpts.OptimizationRemarkAnalysisPattern ||
72 CodeGenOpts.OptimizationRemarkMissedPattern ||
73 CodeGenOpts.OptimizationRemarkPattern);
74 }
75
Vivek Pandya1dee3be2017-09-15 20:09:55 +000076 private:
77 const CodeGenOptions &CodeGenOpts;
78 BackendConsumer *BackendCon;
79 };
80
Benjamin Kramer16634c22009-11-28 10:07:24 +000081 class BackendConsumer : public ASTConsumer {
Justin Lebarb080b632017-01-25 21:29:48 +000082 using LinkModule = CodeGenAction::LinkModule;
83
David Blaikie68e081d2011-12-20 02:48:34 +000084 virtual void anchor();
David Blaikie9c902b52011-09-25 23:23:43 +000085 DiagnosticsEngine &Diags;
Daniel Dunbarc13935e2008-10-21 23:49:24 +000086 BackendAction Action;
Saleem Abdulrasool888e2892017-01-05 16:02:32 +000087 const HeaderSearchOptions &HeaderSearchOpts;
Daniel Dunbarde182242009-11-30 08:39:32 +000088 const CodeGenOptions &CodeGenOpts;
Daniel Dunbarde182242009-11-30 08:39:32 +000089 const TargetOptions &TargetOpts;
Dan Gohmanfec0ff82011-07-05 22:02:36 +000090 const LangOptions &LangOpts;
Peter Collingbourne03f89072016-07-15 00:55:40 +000091 std::unique_ptr<raw_pwrite_stream> AsmOutStream;
Chris Lattnereae6cb62009-03-05 08:00:35 +000092 ASTContext *Context;
Nico Weberade321e2018-04-10 18:53:28 +000093
94 Timer LLVMIRGeneration;
95 unsigned LLVMIRGenerationRefCount;
Mike Stump11289f42009-09-09 15:08:12 +000096
Reid Kleckner15241ba2016-11-30 00:25:36 +000097 /// True if we've finished generating IR. This prevents us from generating
98 /// additional LLVM IR after emitting output in HandleTranslationUnit. This
99 /// can happen when Clang plugins trigger additional AST deserialization.
100 bool IRGenFinished = false;
101
Ahmed Charlesb8984322014-03-07 20:03:18 +0000102 std::unique_ptr<CodeGenerator> Gen;
Mike Stump11289f42009-09-09 15:08:12 +0000103
Justin Lebarb080b632017-01-25 21:29:48 +0000104 SmallVector<LinkModule, 4> LinkModules;
Daniel Dunbarc13935e2008-10-21 23:49:24 +0000105
Rafael Espindola8ce88a52015-12-14 23:17:07 +0000106 // This is here so that the diagnostic printer knows the module a diagnostic
107 // refers to.
108 llvm::Module *CurLinkModule = nullptr;
109
Mike Stump11289f42009-09-09 15:08:12 +0000110 public:
Justin Lebarb080b632017-01-25 21:29:48 +0000111 BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags,
112 const HeaderSearchOptions &HeaderSearchOpts,
113 const PreprocessorOptions &PPOpts,
114 const CodeGenOptions &CodeGenOpts,
115 const TargetOptions &TargetOpts,
116 const LangOptions &LangOpts, bool TimePasses,
117 const std::string &InFile,
118 SmallVector<LinkModule, 4> LinkModules,
119 std::unique_ptr<raw_pwrite_stream> OS, LLVMContext &C,
120 CoverageSourceInfo *CoverageInfo = nullptr)
Saleem Abdulrasool888e2892017-01-05 16:02:32 +0000121 : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
122 CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
Peter Collingbourne03f89072016-07-15 00:55:40 +0000123 AsmOutStream(std::move(OS)), Context(nullptr),
Nico Weberade321e2018-04-10 18:53:28 +0000124 LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
125 LLVMIRGenerationRefCount(0),
Adrian Prantle74f5252015-06-30 02:26:03 +0000126 Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts,
Justin Lebarb080b632017-01-25 21:29:48 +0000127 CodeGenOpts, C, CoverageInfo)),
128 LinkModules(std::move(LinkModules)) {
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000129 FrontendTimesIsEnabled = TimePasses;
Chris Lattnerdeffa132009-02-18 01:23:44 +0000130 }
Serge Pavlov41c1f792016-02-18 16:42:09 +0000131 llvm::Module *getModule() const { return Gen->GetModule(); }
132 std::unique_ptr<llvm::Module> takeModule() {
133 return std::unique_ptr<llvm::Module>(Gen->ReleaseModule());
134 }
Daniel Dunbar400a6932010-02-25 04:37:50 +0000135
Amjad Aboud546bc112017-02-09 22:07:24 +0000136 CodeGenerator *getCodeGenerator() { return Gen.get(); }
137
Craig Topper4f12f102014-03-12 06:41:41 +0000138 void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override {
Rafael Espindoladf88f6f2012-03-08 15:51:03 +0000139 Gen->HandleCXXStaticMemberVarInstantiation(VD);
Rafael Espindola189fa742012-03-05 10:54:55 +0000140 }
141
Craig Topper4f12f102014-03-12 06:41:41 +0000142 void Initialize(ASTContext &Ctx) override {
Richard Smith293534b2015-08-18 20:39:29 +0000143 assert(!Context && "initialized multiple times");
Nico Weberade321e2018-04-10 18:53:28 +0000144
Chris Lattner5cf49fe2009-03-28 02:18:25 +0000145 Context = &Ctx;
Nico Weberade321e2018-04-10 18:53:28 +0000146
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000147 if (FrontendTimesIsEnabled)
Nico Weberade321e2018-04-10 18:53:28 +0000148 LLVMIRGeneration.startTimer();
149
Chris Lattner5cf49fe2009-03-28 02:18:25 +0000150 Gen->Initialize(Ctx);
Nico Weberade321e2018-04-10 18:53:28 +0000151
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000152 if (FrontendTimesIsEnabled)
Nico Weberade321e2018-04-10 18:53:28 +0000153 LLVMIRGeneration.stopTimer();
Daniel Dunbarc13935e2008-10-21 23:49:24 +0000154 }
Mike Stump11289f42009-09-09 15:08:12 +0000155
Craig Topper4f12f102014-03-12 06:41:41 +0000156 bool HandleTopLevelDecl(DeclGroupRef D) override {
Chris Lattner5bbb3c82009-03-29 16:50:03 +0000157 PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(),
Chris Lattnereae6cb62009-03-05 08:00:35 +0000158 Context->getSourceManager(),
159 "LLVM IR generation of declaration");
Nico Weberade321e2018-04-10 18:53:28 +0000160
161 // Recurse.
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000162 if (FrontendTimesIsEnabled) {
Nico Weberade321e2018-04-10 18:53:28 +0000163 LLVMIRGenerationRefCount += 1;
164 if (LLVMIRGenerationRefCount == 1)
165 LLVMIRGeneration.startTimer();
166 }
Chris Lattner5bbb3c82009-03-29 16:50:03 +0000167
Daniel Dunbarc13935e2008-10-21 23:49:24 +0000168 Gen->HandleTopLevelDecl(D);
Nico Weberade321e2018-04-10 18:53:28 +0000169
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000170 if (FrontendTimesIsEnabled) {
Nico Weberade321e2018-04-10 18:53:28 +0000171 LLVMIRGenerationRefCount -= 1;
172 if (LLVMIRGenerationRefCount == 0)
173 LLVMIRGeneration.stopTimer();
174 }
175
Argyrios Kyrtzidis841dd882011-11-18 00:26:59 +0000176 return true;
Daniel Dunbarc13935e2008-10-21 23:49:24 +0000177 }
Mike Stump11289f42009-09-09 15:08:12 +0000178
Stephan Bergmann17d7d142016-03-30 06:27:31 +0000179 void HandleInlineFunctionDefinition(FunctionDecl *D) override {
Hans Wennborga926d842014-05-23 20:37:38 +0000180 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
181 Context->getSourceManager(),
Stephan Bergmann17d7d142016-03-30 06:27:31 +0000182 "LLVM IR generation of inline function");
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000183 if (FrontendTimesIsEnabled)
Nico Weberade321e2018-04-10 18:53:28 +0000184 LLVMIRGeneration.startTimer();
Hans Wennborga926d842014-05-23 20:37:38 +0000185
Stephan Bergmann17d7d142016-03-30 06:27:31 +0000186 Gen->HandleInlineFunctionDefinition(D);
Nico Weberade321e2018-04-10 18:53:28 +0000187
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000188 if (FrontendTimesIsEnabled)
Nico Weberade321e2018-04-10 18:53:28 +0000189 LLVMIRGeneration.stopTimer();
Hans Wennborga926d842014-05-23 20:37:38 +0000190 }
191
Reid Kleckner68c4bb52016-11-30 01:32:53 +0000192 void HandleInterestingDecl(DeclGroupRef D) override {
Reid Kleckner15241ba2016-11-30 00:25:36 +0000193 // Ignore interesting decls from the AST reader after IRGen is finished.
194 if (!IRGenFinished)
195 HandleTopLevelDecl(D);
196 }
197
Justin Lebarb080b632017-01-25 21:29:48 +0000198 // Links each entry in LinkModules into our module. Returns true on error.
199 bool LinkInModules() {
200 for (auto &LM : LinkModules) {
201 if (LM.PropagateAttrs)
202 for (Function &F : *LM.Module)
203 Gen->CGM().AddDefaultFnAttrs(F);
204
205 CurLinkModule = LM.Module.get();
Jonas Devlieghere5eb9c812017-03-13 18:08:11 +0000206
207 bool Err;
208 if (LM.Internalize) {
209 Err = Linker::linkModules(
210 *getModule(), std::move(LM.Module), LM.LinkFlags,
211 [](llvm::Module &M, const llvm::StringSet<> &GVS) {
Reid Kleckner987a2812017-03-13 22:33:07 +0000212 internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) {
Jonas Devlieghere5eb9c812017-03-13 18:08:11 +0000213 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
214 });
215 });
216 } else {
217 Err = Linker::linkModules(*getModule(), std::move(LM.Module),
218 LM.LinkFlags);
219 }
220
221 if (Err)
Justin Lebarb080b632017-01-25 21:29:48 +0000222 return true;
223 }
224 return false; // success
225 }
226
Craig Topper4f12f102014-03-12 06:41:41 +0000227 void HandleTranslationUnit(ASTContext &C) override {
Chris Lattnereae6cb62009-03-05 08:00:35 +0000228 {
Chris Lattnere46de752009-03-06 06:46:31 +0000229 PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000230 if (FrontendTimesIsEnabled) {
Nico Weberade321e2018-04-10 18:53:28 +0000231 LLVMIRGenerationRefCount += 1;
232 if (LLVMIRGenerationRefCount == 1)
233 LLVMIRGeneration.startTimer();
234 }
Chris Lattner263d64c2009-02-18 01:37:30 +0000235
Chris Lattnercf169832009-03-28 04:11:33 +0000236 Gen->HandleTranslationUnit(C);
Nico Weberade321e2018-04-10 18:53:28 +0000237
Andrew V. Tischenko8ab2c9c2018-04-23 09:22:30 +0000238 if (FrontendTimesIsEnabled) {
Nico Weberade321e2018-04-10 18:53:28 +0000239 LLVMIRGenerationRefCount -= 1;
240 if (LLVMIRGenerationRefCount == 0)
241 LLVMIRGeneration.stopTimer();
242 }
243
244 IRGenFinished = true;
Chris Lattnereae6cb62009-03-05 08:00:35 +0000245 }
Chris Lattner263d64c2009-02-18 01:37:30 +0000246
Daniel Dunbarf976d1b2010-06-07 23:20:08 +0000247 // Silently ignore if we weren't initialized for some reason.
Serge Pavlov41c1f792016-02-18 16:42:09 +0000248 if (!getModule())
Daniel Dunbarf976d1b2010-06-07 23:20:08 +0000249 return;
Mike Stump11289f42009-09-09 15:08:12 +0000250
Daniel Dunbarf976d1b2010-06-07 23:20:08 +0000251 // Install an inline asm handler so that diagnostics get printed through
252 // our diagnostics hooks.
Serge Pavlov41c1f792016-02-18 16:42:09 +0000253 LLVMContext &Ctx = getModule()->getContext();
Chris Lattner068f2ab2010-11-17 08:13:04 +0000254 LLVMContext::InlineAsmDiagHandlerTy OldHandler =
255 Ctx.getInlineAsmDiagnosticHandler();
Daniel Dunbarf976d1b2010-06-07 23:20:08 +0000256 void *OldContext = Ctx.getInlineAsmDiagnosticContext();
Chris Lattner068f2ab2010-11-17 08:13:04 +0000257 Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
Daniel Dunbarf976d1b2010-06-07 23:20:08 +0000258
Vivek Pandya1dee3be2017-09-15 20:09:55 +0000259 std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler =
Quentin Colombet728c5542014-02-06 18:30:43 +0000260 Ctx.getDiagnosticHandler();
Vivek Pandya1dee3be2017-09-15 20:09:55 +0000261 Ctx.setDiagnosticHandler(llvm::make_unique<ClangDiagnosticHandler>(
262 CodeGenOpts, this));
Brian Gesiak9f59da82017-06-30 19:37:11 +0000263 Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
Brian Gesiak562eab92017-07-01 05:45:26 +0000264 if (CodeGenOpts.DiagnosticsHotnessThreshold != 0)
265 Ctx.setDiagnosticsHotnessThreshold(
266 CodeGenOpts.DiagnosticsHotnessThreshold);
Quentin Colombet728c5542014-02-06 18:30:43 +0000267
Reid Kleckner3fc649c2017-09-23 01:03:17 +0000268 std::unique_ptr<llvm::ToolOutputFile> OptRecordFile;
Hal Finkel8f96e822016-10-11 00:26:09 +0000269 if (!CodeGenOpts.OptRecordFile.empty()) {
270 std::error_code EC;
Reid Kleckner3fc649c2017-09-23 01:03:17 +0000271 OptRecordFile = llvm::make_unique<llvm::ToolOutputFile>(
272 CodeGenOpts.OptRecordFile, EC, sys::fs::F_None);
Hal Finkel8f96e822016-10-11 00:26:09 +0000273 if (EC) {
274 Diags.Report(diag::err_cannot_open_file) <<
275 CodeGenOpts.OptRecordFile << EC.message();
276 return;
277 }
278
Mehdi Amini6f408362016-11-19 18:19:41 +0000279 Ctx.setDiagnosticsOutputFile(
280 llvm::make_unique<yaml::Output>(OptRecordFile->os()));
Hal Finkel8f96e822016-10-11 00:26:09 +0000281
282 if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone)
Brian Gesiak9f59da82017-06-30 19:37:11 +0000283 Ctx.setDiagnosticsHotnessRequested(true);
Hal Finkel8f96e822016-10-11 00:26:09 +0000284 }
285
Justin Lebarb080b632017-01-25 21:29:48 +0000286 // Link each LinkModule into our module.
287 if (LinkInModules())
288 return;
Rafael Espindola8ce88a52015-12-14 23:17:07 +0000289
Steven Wu27fb5222016-05-11 16:26:03 +0000290 EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef());
291
Saleem Abdulrasool888e2892017-01-05 16:02:32 +0000292 EmitBackendOutput(Diags, HeaderSearchOpts, CodeGenOpts, TargetOpts,
293 LangOpts, C.getTargetInfo().getDataLayout(),
Peter Collingbourne03f89072016-07-15 00:55:40 +0000294 getModule(), Action, std::move(AsmOutStream));
Rafael Espindola666a2ab2013-12-18 16:38:48 +0000295
Daniel Dunbarf976d1b2010-06-07 23:20:08 +0000296 Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
Quentin Colombet728c5542014-02-06 18:30:43 +0000297
Vivek Pandya1dee3be2017-09-15 20:09:55 +0000298 Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler));
Hal Finkel8f96e822016-10-11 00:26:09 +0000299
300 if (OptRecordFile)
301 OptRecordFile->keep();
Daniel Dunbarc13935e2008-10-21 23:49:24 +0000302 }
Mike Stump11289f42009-09-09 15:08:12 +0000303
Craig Topper4f12f102014-03-12 06:41:41 +0000304 void HandleTagDeclDefinition(TagDecl *D) override {
Chris Lattnereae6cb62009-03-05 08:00:35 +0000305 PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
306 Context->getSourceManager(),
307 "LLVM IR generation of declaration");
Daniel Dunbarc13935e2008-10-21 23:49:24 +0000308 Gen->HandleTagDeclDefinition(D);
309 }
Douglas Gregorbeecd582009-04-21 17:11:58 +0000310
Craig Topper4f12f102014-03-12 06:41:41 +0000311 void HandleTagDeclRequiredDefinition(const TagDecl *D) override {
David Blaikie48ad6dc2013-07-13 21:08:14 +0000312 Gen->HandleTagDeclRequiredDefinition(D);
313 }
314
Craig Topper4f12f102014-03-12 06:41:41 +0000315 void CompleteTentativeDefinition(VarDecl *D) override {
Douglas Gregorbeecd582009-04-21 17:11:58 +0000316 Gen->CompleteTentativeDefinition(D);
317 }
Daniel Dunbar50aa0a52010-04-29 16:29:09 +0000318
David Majnemer929025d2016-01-26 19:30:26 +0000319 void AssignInheritanceModel(CXXRecordDecl *RD) override {
320 Gen->AssignInheritanceModel(RD);
321 }
322
Nico Weberb6a5d052015-01-15 04:07:35 +0000323 void HandleVTable(CXXRecordDecl *RD) override {
324 Gen->HandleVTable(RD);
Douglas Gregor88d292c2010-05-13 16:44:06 +0000325 }
326
Chris Lattner5ec32e72010-04-06 18:38:50 +0000327 static void InlineAsmDiagHandler(const llvm::SMDiagnostic &SM,void *Context,
328 unsigned LocCookie) {
329 SourceLocation Loc = SourceLocation::getFromRawEncoding(LocCookie);
330 ((BackendConsumer*)Context)->InlineAsmDiagHandler2(SM, Loc);
331 }
Daniel Dunbar50aa0a52010-04-29 16:29:09 +0000332
Oliver Stannard91817852016-02-02 13:52:52 +0000333 /// Get the best possible source location to represent a diagnostic that
334 /// may have associated debug info.
335 const FullSourceLoc
Justin Bognere91e9dd2017-02-17 17:34:49 +0000336 getBestLocationFromDebugLoc(const llvm::DiagnosticInfoWithLocationBase &D,
Oliver Stannard91817852016-02-02 13:52:52 +0000337 bool &BadDebugInfo, StringRef &Filename,
338 unsigned &Line, unsigned &Column) const;
339
Chris Lattner5ec32e72010-04-06 18:38:50 +0000340 void InlineAsmDiagHandler2(const llvm::SMDiagnostic &,
341 SourceLocation LocCookie);
Quentin Colombet728c5542014-02-06 18:30:43 +0000342
343 void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI);
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000344 /// Specialized handler for InlineAsm diagnostic.
Quentin Colombet728c5542014-02-06 18:30:43 +0000345 /// \return True if the diagnostic has been successfully reported, false
346 /// otherwise.
347 bool InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D);
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000348 /// Specialized handler for StackSize diagnostic.
Quentin Colombet728c5542014-02-06 18:30:43 +0000349 /// \return True if the diagnostic has been successfully reported, false
350 /// otherwise.
351 bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D);
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000352 /// Specialized handler for unsupported backend feature diagnostic.
Oliver Stannard91817852016-02-02 13:52:52 +0000353 void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D);
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000354 /// Specialized handlers for optimization remarks.
Diego Novillod23ec942014-05-29 19:55:06 +0000355 /// Note that these handlers only accept remarks and they always handle
Diego Novillo829b1702014-04-16 16:54:24 +0000356 /// them.
Tyler Nowickif8a767d2014-07-18 19:40:19 +0000357 void EmitOptimizationMessage(const llvm::DiagnosticInfoOptimizationBase &D,
358 unsigned DiagID);
Adam Nemet7b796f82017-01-26 04:07:11 +0000359 void
360 OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &D);
Diego Novillod23ec942014-05-29 19:55:06 +0000361 void OptimizationRemarkHandler(
Adam Nemetb4e64a72016-09-27 22:19:29 +0000362 const llvm::OptimizationRemarkAnalysisFPCommute &D);
Diego Novillod23ec942014-05-29 19:55:06 +0000363 void OptimizationRemarkHandler(
Adam Nemetb4e64a72016-09-27 22:19:29 +0000364 const llvm::OptimizationRemarkAnalysisAliasing &D);
Tyler Nowickif8a767d2014-07-18 19:40:19 +0000365 void OptimizationFailureHandler(
366 const llvm::DiagnosticInfoOptimizationFailure &D);
Mike Stump11289f42009-09-09 15:08:12 +0000367 };
Jonas Devlieghere5eb9c812017-03-13 18:08:11 +0000368
David Blaikie68e081d2011-12-20 02:48:34 +0000369 void BackendConsumer::anchor() {}
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000370}
Daniel Dunbarc13935e2008-10-21 23:49:24 +0000371
Vivek Pandya1dee3be2017-09-15 20:09:55 +0000372bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo &DI) {
373 BackendCon->DiagnosticHandlerImpl(DI);
374 return true;
375}
376
Chris Lattner79f67a72010-04-08 00:23:06 +0000377/// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr
378/// buffer to be a valid FullSourceLoc.
379static FullSourceLoc ConvertBackendLocation(const llvm::SMDiagnostic &D,
380 SourceManager &CSM) {
381 // Get both the clang and llvm source managers. The location is relative to
382 // a memory buffer that the LLVM Source Manager is handling, we need to add
Daniel Dunbar50aa0a52010-04-29 16:29:09 +0000383 // a copy to the Clang source manager.
Chris Lattner79f67a72010-04-08 00:23:06 +0000384 const llvm::SourceMgr &LSM = *D.getSourceMgr();
Daniel Dunbar50aa0a52010-04-29 16:29:09 +0000385
Chris Lattner79f67a72010-04-08 00:23:06 +0000386 // We need to copy the underlying LLVM memory buffer because llvm::SourceMgr
387 // already owns its one and clang::SourceManager wants to own its one.
388 const MemoryBuffer *LBuf =
389 LSM.getMemoryBuffer(LSM.FindBufferContainingLoc(D.getLoc()));
Daniel Dunbar50aa0a52010-04-29 16:29:09 +0000390
Chris Lattner79f67a72010-04-08 00:23:06 +0000391 // Create the copy and transfer ownership to clang::SourceManager.
Alp Tokeraa0dd5a2014-06-27 06:02:00 +0000392 // TODO: Avoid copying files into memory.
Rafael Espindolad87f8d72014-08-27 20:03:29 +0000393 std::unique_ptr<llvm::MemoryBuffer> CBuf =
394 llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(),
395 LBuf->getBufferIdentifier());
Alp Tokeraa0dd5a2014-06-27 06:02:00 +0000396 // FIXME: Keep a file ID map instead of creating new IDs for each location.
David Blaikie50a5f972014-08-29 07:59:55 +0000397 FileID FID = CSM.createFileID(std::move(CBuf));
Daniel Dunbar50aa0a52010-04-29 16:29:09 +0000398
Chris Lattner79f67a72010-04-08 00:23:06 +0000399 // Translate the offset into the file.
Alp Tokeraa0dd5a2014-06-27 06:02:00 +0000400 unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart();
Daniel Dunbar50aa0a52010-04-29 16:29:09 +0000401 SourceLocation NewLoc =
Argyrios Kyrtzidise6e67de2011-09-19 20:40:19 +0000402 CSM.getLocForStartOfFile(FID).getLocWithOffset(Offset);
Chris Lattner79f67a72010-04-08 00:23:06 +0000403 return FullSourceLoc(NewLoc, CSM);
404}
405
Chris Lattner6d672132010-04-06 17:52:14 +0000406
Chris Lattner5ec32e72010-04-06 18:38:50 +0000407/// InlineAsmDiagHandler2 - This function is invoked when the backend hits an
408/// error parsing inline asm. The SMDiagnostic indicates the error relative to
Daniel Dunbar50aa0a52010-04-29 16:29:09 +0000409/// the temporary memory buffer that the inline asm parser has set up.
Chris Lattner5ec32e72010-04-06 18:38:50 +0000410void BackendConsumer::InlineAsmDiagHandler2(const llvm::SMDiagnostic &D,
411 SourceLocation LocCookie) {
412 // There are a couple of different kinds of errors we could get here. First,
413 // we re-format the SMDiagnostic in terms of a clang diagnostic.
Argyrios Kyrtzidisa11b35a2012-02-01 06:36:49 +0000414
415 // Strip "error: " off the start of the message string.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000416 StringRef Message = D.getMessage();
Argyrios Kyrtzidisa11b35a2012-02-01 06:36:49 +0000417 if (Message.startswith("error: "))
418 Message = Message.substr(7);
Chris Lattner5ec32e72010-04-06 18:38:50 +0000419
Chris Lattnerc7ed7ea2010-06-15 00:03:12 +0000420 // If the SMDiagnostic has an inline asm source location, translate it.
Chris Lattner5ec32e72010-04-06 18:38:50 +0000421 FullSourceLoc Loc;
Chris Lattner79f67a72010-04-08 00:23:06 +0000422 if (D.getLoc() != SMLoc())
423 Loc = ConvertBackendLocation(D, Context->getSourceManager());
Argyrios Kyrtzidisa11b35a2012-02-01 06:36:49 +0000424
Joey Gouly5798b262014-06-05 21:23:42 +0000425 unsigned DiagID;
426 switch (D.getKind()) {
427 case llvm::SourceMgr::DK_Error:
428 DiagID = diag::err_fe_inline_asm;
429 break;
430 case llvm::SourceMgr::DK_Warning:
431 DiagID = diag::warn_fe_inline_asm;
432 break;
433 case llvm::SourceMgr::DK_Note:
434 DiagID = diag::note_fe_inline_asm;
435 break;
Adam Nemet7b1faaa2017-10-12 23:56:54 +0000436 case llvm::SourceMgr::DK_Remark:
437 llvm_unreachable("remarks unexpected");
Joey Gouly5798b262014-06-05 21:23:42 +0000438 }
Chris Lattnerc7ed7ea2010-06-15 00:03:12 +0000439 // If this problem has clang-level source location information, report the
Joey Gouly5798b262014-06-05 21:23:42 +0000440 // issue in the source with a note showing the instantiated
Chris Lattnerc7ed7ea2010-06-15 00:03:12 +0000441 // code.
442 if (LocCookie.isValid()) {
Joey Gouly5798b262014-06-05 21:23:42 +0000443 Diags.Report(LocCookie, DiagID).AddString(Message);
Jonas Devlieghere5eb9c812017-03-13 18:08:11 +0000444
Benjamin Kramere06b2b72011-10-16 10:48:28 +0000445 if (D.getLoc().isValid()) {
446 DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here);
447 // Convert the SMDiagnostic ranges into SourceRange and attach them
448 // to the diagnostic.
Yaron Kerenede60302015-08-01 19:11:36 +0000449 for (const std::pair<unsigned, unsigned> &Range : D.getRanges()) {
Benjamin Kramere06b2b72011-10-16 10:48:28 +0000450 unsigned Column = D.getColumnNo();
451 B << SourceRange(Loc.getLocWithOffset(Range.first - Column),
452 Loc.getLocWithOffset(Range.second - Column));
453 }
454 }
Chris Lattnerc7ed7ea2010-06-15 00:03:12 +0000455 return;
456 }
Jonas Devlieghere5eb9c812017-03-13 18:08:11 +0000457
Joey Gouly5798b262014-06-05 21:23:42 +0000458 // Otherwise, report the backend issue as occurring in the generated .s file.
459 // If Loc is invalid, we still need to report the issue, it just gets no
Chris Lattnerc7ed7ea2010-06-15 00:03:12 +0000460 // location info.
Joey Gouly5798b262014-06-05 21:23:42 +0000461 Diags.Report(Loc, DiagID).AddString(Message);
Chris Lattner5ec32e72010-04-06 18:38:50 +0000462}
463
Quentin Colombet728c5542014-02-06 18:30:43 +0000464#define ComputeDiagID(Severity, GroupName, DiagID) \
465 do { \
466 switch (Severity) { \
467 case llvm::DS_Error: \
468 DiagID = diag::err_fe_##GroupName; \
469 break; \
470 case llvm::DS_Warning: \
471 DiagID = diag::warn_fe_##GroupName; \
472 break; \
Tobias Grosser74160242014-02-28 09:11:08 +0000473 case llvm::DS_Remark: \
474 llvm_unreachable("'remark' severity not expected"); \
475 break; \
476 case llvm::DS_Note: \
477 DiagID = diag::note_fe_##GroupName; \
478 break; \
479 } \
480 } while (false)
481
482#define ComputeDiagRemarkID(Severity, GroupName, DiagID) \
483 do { \
484 switch (Severity) { \
485 case llvm::DS_Error: \
486 DiagID = diag::err_fe_##GroupName; \
487 break; \
488 case llvm::DS_Warning: \
489 DiagID = diag::warn_fe_##GroupName; \
490 break; \
491 case llvm::DS_Remark: \
492 DiagID = diag::remark_fe_##GroupName; \
493 break; \
Quentin Colombet728c5542014-02-06 18:30:43 +0000494 case llvm::DS_Note: \
495 DiagID = diag::note_fe_##GroupName; \
496 break; \
497 } \
498 } while (false)
499
500bool
501BackendConsumer::InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D) {
502 unsigned DiagID;
503 ComputeDiagID(D.getSeverity(), inline_asm, DiagID);
504 std::string Message = D.getMsgStr().str();
505
506 // If this problem has clang-level source location information, report the
Tobias Grosserbd25beb2014-02-26 10:21:56 +0000507 // issue as being a problem in the source with a note showing the instantiated
Quentin Colombet728c5542014-02-06 18:30:43 +0000508 // code.
509 SourceLocation LocCookie =
510 SourceLocation::getFromRawEncoding(D.getLocCookie());
511 if (LocCookie.isValid())
512 Diags.Report(LocCookie, DiagID).AddString(Message);
513 else {
514 // Otherwise, report the backend diagnostic as occurring in the generated
515 // .s file.
516 // If Loc is invalid, we still need to report the diagnostic, it just gets
517 // no location info.
518 FullSourceLoc Loc;
519 Diags.Report(Loc, DiagID).AddString(Message);
520 }
521 // We handled all the possible severities.
522 return true;
523}
524
525bool
526BackendConsumer::StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D) {
527 if (D.getSeverity() != llvm::DS_Warning)
528 // For now, the only support we have for StackSize diagnostic is warning.
529 // We do not know how to format other severities.
530 return false;
531
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000532 if (const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) {
Matt Arsenault4deb4ed22016-06-20 18:13:09 +0000533 // FIXME: Shouldn't need to truncate to uint32_t
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000534 Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()),
535 diag::warn_fe_frame_larger_than)
Matt Arsenault4deb4ed22016-06-20 18:13:09 +0000536 << static_cast<uint32_t>(D.getStackSize()) << Decl::castToDeclContext(ND);
Alp Tokerfb8d02b2014-06-05 22:10:59 +0000537 return true;
538 }
539
540 return false;
Quentin Colombet728c5542014-02-06 18:30:43 +0000541}
542
Oliver Stannard91817852016-02-02 13:52:52 +0000543const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc(
Justin Bognere91e9dd2017-02-17 17:34:49 +0000544 const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo,
545 StringRef &Filename, unsigned &Line, unsigned &Column) const {
Diego Novillod23ec942014-05-29 19:55:06 +0000546 SourceManager &SourceMgr = Context->getSourceManager();
547 FileManager &FileMgr = SourceMgr.getFileManager();
Alp Toker27506272014-06-05 22:11:12 +0000548 SourceLocation DILoc;
Diego Novillo86f884e2015-05-08 20:59:56 +0000549
550 if (D.isLocationAvailable()) {
551 D.getLocation(&Filename, &Line, &Column);
552 const FileEntry *FE = FileMgr.getFile(Filename);
553 if (FE && Line > 0) {
554 // If -gcolumn-info was not used, Column will be 0. This upsets the
555 // source manager, so pass 1 if Column is not set.
556 DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1);
557 }
Oliver Stannard91817852016-02-02 13:52:52 +0000558 BadDebugInfo = DILoc.isInvalid();
Diego Novillo829b1702014-04-16 16:54:24 +0000559 }
Alp Toker27506272014-06-05 22:11:12 +0000560
561 // If a location isn't available, try to approximate it using the associated
562 // function definition. We use the definition's right brace to differentiate
563 // from diagnostics that genuinely relate to the function itself.
564 FullSourceLoc Loc(DILoc, SourceMgr);
565 if (Loc.isInvalid())
566 if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName()))
Oliver Stannard91817852016-02-02 13:52:52 +0000567 Loc = FD->getASTContext().getFullLoc(FD->getLocation());
Diego Novillod23ec942014-05-29 19:55:06 +0000568
Diego Novillo86f884e2015-05-08 20:59:56 +0000569 if (DILoc.isInvalid() && D.isLocationAvailable())
Diego Novillod23ec942014-05-29 19:55:06 +0000570 // If we were not able to translate the file:line:col information
571 // back to a SourceLocation, at least emit a note stating that
572 // we could not translate this location. This can happen in the
573 // case of #line directives.
Oliver Stannard91817852016-02-02 13:52:52 +0000574 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
Ben Craig6e4695a2016-05-06 13:29:46 +0000575 << Filename << Line << Column;
Oliver Stannard91817852016-02-02 13:52:52 +0000576
577 return Loc;
578}
579
580void BackendConsumer::UnsupportedDiagHandler(
581 const llvm::DiagnosticInfoUnsupported &D) {
582 // We only support errors.
583 assert(D.getSeverity() == llvm::DS_Error);
584
585 StringRef Filename;
586 unsigned Line, Column;
Reid Klecknerf70ee602017-05-12 00:10:49 +0000587 bool BadDebugInfo = false;
588 FullSourceLoc Loc =
589 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
Oliver Stannard91817852016-02-02 13:52:52 +0000590
Zachary Turner41a9ee92017-10-11 23:54:34 +0000591 Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
Oliver Stannard91817852016-02-02 13:52:52 +0000592
593 if (BadDebugInfo)
594 // If we were not able to translate the file:line:col information
595 // back to a SourceLocation, at least emit a note stating that
596 // we could not translate this location. This can happen in the
597 // case of #line directives.
598 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
599 << Filename << Line << Column;
600}
601
602void BackendConsumer::EmitOptimizationMessage(
603 const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) {
604 // We only support warnings and remarks.
605 assert(D.getSeverity() == llvm::DS_Remark ||
606 D.getSeverity() == llvm::DS_Warning);
607
608 StringRef Filename;
609 unsigned Line, Column;
610 bool BadDebugInfo = false;
Reid Klecknerf70ee602017-05-12 00:10:49 +0000611 FullSourceLoc Loc =
612 getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
Oliver Stannard91817852016-02-02 13:52:52 +0000613
Adam Nemet1eea3e52016-09-13 04:32:40 +0000614 std::string Msg;
615 raw_string_ostream MsgStream(Msg);
Adam Nemet699fc5b2016-09-27 20:55:12 +0000616 MsgStream << D.getMsg();
Adam Nemet1eea3e52016-09-13 04:32:40 +0000617
618 if (D.getHotness())
619 MsgStream << " (hotness: " << *D.getHotness() << ")";
620
Oliver Stannard91817852016-02-02 13:52:52 +0000621 Diags.Report(Loc, DiagID)
Mehdi Amini117296c2016-10-01 02:56:57 +0000622 << AddFlagValue(D.getPassName())
Adam Nemet1eea3e52016-09-13 04:32:40 +0000623 << MsgStream.str();
Oliver Stannard91817852016-02-02 13:52:52 +0000624
625 if (BadDebugInfo)
626 // If we were not able to translate the file:line:col information
627 // back to a SourceLocation, at least emit a note stating that
628 // we could not translate this location. This can happen in the
629 // case of #line directives.
630 Diags.Report(Loc, diag::note_fe_backend_invalid_loc)
Diego Novillod23ec942014-05-29 19:55:06 +0000631 << Filename << Line << Column;
632}
633
634void BackendConsumer::OptimizationRemarkHandler(
Adam Nemet7b796f82017-01-26 04:07:11 +0000635 const llvm::DiagnosticInfoOptimizationBase &D) {
Adam Nemet28c2c222017-10-04 04:25:31 +0000636 // Without hotness information, don't show noisy remarks.
637 if (D.isVerbose() && !D.getHotness())
638 return;
639
Adam Nemet7b796f82017-01-26 04:07:11 +0000640 if (D.isPassed()) {
641 // Optimization remarks are active only if the -Rpass flag has a regular
642 // expression that matches the name of the pass name in \p D.
643 if (CodeGenOpts.OptimizationRemarkPattern &&
644 CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName()))
645 EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark);
646 } else if (D.isMissed()) {
647 // Missed optimization remarks are active only if the -Rpass-missed
648 // flag has a regular expression that matches the name of the pass
649 // name in \p D.
650 if (CodeGenOpts.OptimizationRemarkMissedPattern &&
651 CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName()))
652 EmitOptimizationMessage(
653 D, diag::remark_fe_backend_optimization_remark_missed);
654 } else {
655 assert(D.isAnalysis() && "Unknown remark type");
Diego Novillod23ec942014-05-29 19:55:06 +0000656
Adam Nemet7b796f82017-01-26 04:07:11 +0000657 bool ShouldAlwaysPrint = false;
658 if (auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D))
659 ShouldAlwaysPrint = ORA->shouldAlwaysPrint();
Diego Novillod23ec942014-05-29 19:55:06 +0000660
Adam Nemet7b796f82017-01-26 04:07:11 +0000661 if (ShouldAlwaysPrint ||
662 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
663 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
664 EmitOptimizationMessage(
665 D, diag::remark_fe_backend_optimization_remark_analysis);
666 }
Diego Novillo829b1702014-04-16 16:54:24 +0000667}
668
Tyler Nowicki8a0925c2015-08-10 19:56:40 +0000669void BackendConsumer::OptimizationRemarkHandler(
Adam Nemetb4e64a72016-09-27 22:19:29 +0000670 const llvm::OptimizationRemarkAnalysisFPCommute &D) {
Tyler Nowicki65061a22015-08-11 01:10:08 +0000671 // Optimization analysis remarks are active if the pass name is set to
672 // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a
673 // regular expression that matches the name of the pass name in \p D.
674
Adam Nemetb5beb972016-06-29 04:55:31 +0000675 if (D.shouldAlwaysPrint() ||
Tyler Nowicki65061a22015-08-11 01:10:08 +0000676 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
677 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
Tyler Nowicki8a0925c2015-08-10 19:56:40 +0000678 EmitOptimizationMessage(
679 D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute);
680}
681
Tyler Nowicki034baf62015-08-10 23:05:16 +0000682void BackendConsumer::OptimizationRemarkHandler(
Adam Nemetb4e64a72016-09-27 22:19:29 +0000683 const llvm::OptimizationRemarkAnalysisAliasing &D) {
Tyler Nowicki65061a22015-08-11 01:10:08 +0000684 // Optimization analysis remarks are active if the pass name is set to
685 // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a
686 // regular expression that matches the name of the pass name in \p D.
687
Adam Nemetb5beb972016-06-29 04:55:31 +0000688 if (D.shouldAlwaysPrint() ||
Tyler Nowicki65061a22015-08-11 01:10:08 +0000689 (CodeGenOpts.OptimizationRemarkAnalysisPattern &&
690 CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName())))
Tyler Nowicki034baf62015-08-10 23:05:16 +0000691 EmitOptimizationMessage(
692 D, diag::remark_fe_backend_optimization_remark_analysis_aliasing);
693}
694
Tyler Nowickif8a767d2014-07-18 19:40:19 +0000695void BackendConsumer::OptimizationFailureHandler(
696 const llvm::DiagnosticInfoOptimizationFailure &D) {
697 EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure);
698}
699
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000700/// This function is invoked when the backend needs
Quentin Colombet728c5542014-02-06 18:30:43 +0000701/// to report something to the user.
702void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) {
703 unsigned DiagID = diag::err_fe_inline_asm;
704 llvm::DiagnosticSeverity Severity = DI.getSeverity();
705 // Get the diagnostic ID based.
706 switch (DI.getKind()) {
707 case llvm::DK_InlineAsm:
708 if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI)))
709 return;
710 ComputeDiagID(Severity, inline_asm, DiagID);
711 break;
712 case llvm::DK_StackSize:
713 if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI)))
714 return;
715 ComputeDiagID(Severity, backend_frame_larger_than, DiagID);
716 break;
Rafael Espindola8ce88a52015-12-14 23:17:07 +0000717 case DK_Linker:
718 assert(CurLinkModule);
719 // FIXME: stop eating the warnings and notes.
720 if (Severity != DS_Error)
721 return;
722 DiagID = diag::err_fe_cannot_link_module;
723 break;
Diego Novillo829b1702014-04-16 16:54:24 +0000724 case llvm::DK_OptimizationRemark:
725 // Optimization remarks are always handled completely by this
726 // handler. There is no generic way of emitting them.
Adam Nemetb4e64a72016-09-27 22:19:29 +0000727 OptimizationRemarkHandler(cast<OptimizationRemark>(DI));
Diego Novillo829b1702014-04-16 16:54:24 +0000728 return;
Diego Novillo9c89ff12014-05-29 16:19:27 +0000729 case llvm::DK_OptimizationRemarkMissed:
Diego Novillod23ec942014-05-29 19:55:06 +0000730 // Optimization remarks are always handled completely by this
731 // handler. There is no generic way of emitting them.
Adam Nemetb4e64a72016-09-27 22:19:29 +0000732 OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI));
Diego Novillod23ec942014-05-29 19:55:06 +0000733 return;
Diego Novillo9c89ff12014-05-29 16:19:27 +0000734 case llvm::DK_OptimizationRemarkAnalysis:
Diego Novillod23ec942014-05-29 19:55:06 +0000735 // Optimization remarks are always handled completely by this
736 // handler. There is no generic way of emitting them.
Adam Nemetb4e64a72016-09-27 22:19:29 +0000737 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI));
Diego Novillo9c89ff12014-05-29 16:19:27 +0000738 return;
Tyler Nowicki8a0925c2015-08-10 19:56:40 +0000739 case llvm::DK_OptimizationRemarkAnalysisFPCommute:
740 // Optimization remarks are always handled completely by this
741 // handler. There is no generic way of emitting them.
Adam Nemetb4e64a72016-09-27 22:19:29 +0000742 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI));
Tyler Nowicki8a0925c2015-08-10 19:56:40 +0000743 return;
Tyler Nowicki034baf62015-08-10 23:05:16 +0000744 case llvm::DK_OptimizationRemarkAnalysisAliasing:
745 // Optimization remarks are always handled completely by this
746 // handler. There is no generic way of emitting them.
Adam Nemetb4e64a72016-09-27 22:19:29 +0000747 OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI));
Tyler Nowicki034baf62015-08-10 23:05:16 +0000748 return;
Adam Nemet7b796f82017-01-26 04:07:11 +0000749 case llvm::DK_MachineOptimizationRemark:
750 // Optimization remarks are always handled completely by this
751 // handler. There is no generic way of emitting them.
752 OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI));
753 return;
754 case llvm::DK_MachineOptimizationRemarkMissed:
755 // Optimization remarks are always handled completely by this
756 // handler. There is no generic way of emitting them.
757 OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI));
758 return;
759 case llvm::DK_MachineOptimizationRemarkAnalysis:
760 // Optimization remarks are always handled completely by this
761 // handler. There is no generic way of emitting them.
762 OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI));
763 return;
Tyler Nowickif8a767d2014-07-18 19:40:19 +0000764 case llvm::DK_OptimizationFailure:
765 // Optimization failures are always handled completely by this
766 // handler.
767 OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI));
768 return;
Oliver Stannard91817852016-02-02 13:52:52 +0000769 case llvm::DK_Unsupported:
770 UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI));
771 return;
Quentin Colombet728c5542014-02-06 18:30:43 +0000772 default:
773 // Plugin IDs are not bound to any value as they are set dynamically.
Tobias Grosser74160242014-02-28 09:11:08 +0000774 ComputeDiagRemarkID(Severity, backend_plugin, DiagID);
Quentin Colombet728c5542014-02-06 18:30:43 +0000775 break;
776 }
777 std::string MsgStorage;
778 {
779 raw_string_ostream Stream(MsgStorage);
780 DiagnosticPrinterRawOStream DP(Stream);
781 DI.print(DP);
782 }
783
Rafael Espindola8ce88a52015-12-14 23:17:07 +0000784 if (DiagID == diag::err_fe_cannot_link_module) {
785 Diags.Report(diag::err_fe_cannot_link_module)
786 << CurLinkModule->getModuleIdentifier() << MsgStorage;
787 return;
788 }
789
Quentin Colombet728c5542014-02-06 18:30:43 +0000790 // Report the backend message using the usual diagnostic mechanism.
791 FullSourceLoc Loc;
792 Diags.Report(Loc, DiagID).AddString(MsgStorage);
793}
794#undef ComputeDiagID
Daniel Dunbarcea0c702010-02-25 04:37:45 +0000795
Peter Collingbourne8f5cf742011-02-19 23:03:58 +0000796CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext)
Artem Belevich5d40ae32015-10-27 17:56:59 +0000797 : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext),
Eric Christopher02e3dd42016-03-12 01:47:11 +0000798 OwnsVMContext(!_VMContext) {}
Daniel Dunbarcea0c702010-02-25 04:37:45 +0000799
Peter Collingbourne8f5cf742011-02-19 23:03:58 +0000800CodeGenAction::~CodeGenAction() {
801 TheModule.reset();
802 if (OwnsVMContext)
803 delete VMContext;
804}
Daniel Dunbare8ecf9a2010-02-25 20:37:44 +0000805
Daniel Dunbar6f8362c2010-06-07 23:27:59 +0000806bool CodeGenAction::hasIRSupport() const { return true; }
807
Daniel Dunbar400a6932010-02-25 04:37:50 +0000808void CodeGenAction::EndSourceFileAction() {
809 // If the consumer creation failed, do nothing.
810 if (!getCompilerInstance().hasASTConsumer())
811 return;
812
813 // Steal the module from the consumer.
David Blaikie780dd3b2014-08-29 05:08:19 +0000814 TheModule = BEConsumer->takeModule();
Daniel Dunbar400a6932010-02-25 04:37:50 +0000815}
816
Rafael Espindolae8337302014-08-19 14:36:35 +0000817std::unique_ptr<llvm::Module> CodeGenAction::takeModule() {
818 return std::move(TheModule);
819}
820
Peter Collingbourne8f5cf742011-02-19 23:03:58 +0000821llvm::LLVMContext *CodeGenAction::takeLLVMContext() {
822 OwnsVMContext = false;
823 return VMContext;
824}
825
Peter Collingbourne03f89072016-07-15 00:55:40 +0000826static std::unique_ptr<raw_pwrite_stream>
Rafael Espindola2f16bc12015-04-14 15:15:49 +0000827GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) {
Daniel Dunbar6f8362c2010-06-07 23:27:59 +0000828 switch (Action) {
829 case Backend_EmitAssembly:
830 return CI.createDefaultOutputFile(false, InFile, "s");
831 case Backend_EmitLL:
832 return CI.createDefaultOutputFile(false, InFile, "ll");
833 case Backend_EmitBC:
834 return CI.createDefaultOutputFile(true, InFile, "bc");
835 case Backend_EmitNothing:
Craig Topper8a13c412014-05-21 05:09:00 +0000836 return nullptr;
Daniel Dunbar6f8362c2010-06-07 23:27:59 +0000837 case Backend_EmitMCNull:
Alp Tokerea046722014-06-03 17:23:34 +0000838 return CI.createNullOutputFile();
Daniel Dunbar6f8362c2010-06-07 23:27:59 +0000839 case Backend_EmitObj:
840 return CI.createDefaultOutputFile(true, InFile, "o");
841 }
842
David Blaikie83d382b2011-09-23 05:06:16 +0000843 llvm_unreachable("Invalid action!");
Daniel Dunbar6f8362c2010-06-07 23:27:59 +0000844}
845
David Blaikie6beb6aa2014-08-10 19:56:51 +0000846std::unique_ptr<ASTConsumer>
847CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
Daniel Dunbarcea0c702010-02-25 04:37:45 +0000848 BackendAction BA = static_cast<BackendAction>(Act);
Alexey Sotkinaba98fc2018-03-02 12:11:40 +0000849 std::unique_ptr<raw_pwrite_stream> OS = CI.takeOutputStream();
850 if (!OS)
851 OS = GetOutputStream(CI, InFile, BA);
852
Daniel Dunbarcea0c702010-02-25 04:37:45 +0000853 if (BA != Backend_EmitNothing && !OS)
Craig Topper8a13c412014-05-21 05:09:00 +0000854 return nullptr;
Daniel Dunbarcea0c702010-02-25 04:37:45 +0000855
Artem Belevich5d40ae32015-10-27 17:56:59 +0000856 // Load bitcode modules to link with, if we need to.
857 if (LinkModules.empty())
Justin Lebarb080b632017-01-25 21:29:48 +0000858 for (const CodeGenOptions::BitcodeFileToLink &F :
859 CI.getCodeGenOpts().LinkBitcodeFiles) {
860 auto BCBuf = CI.getFileManager().getBufferForFile(F.Filename);
Artem Belevich5d40ae32015-10-27 17:56:59 +0000861 if (!BCBuf) {
862 CI.getDiagnostics().Report(diag::err_cannot_open_file)
Justin Lebarb080b632017-01-25 21:29:48 +0000863 << F.Filename << BCBuf.getError().message();
Artem Belevich5d40ae32015-10-27 17:56:59 +0000864 LinkModules.clear();
865 return nullptr;
866 }
Peter Collingbournef1d76db2011-10-30 17:30:44 +0000867
Peter Collingbourned9445c42016-11-13 07:00:17 +0000868 Expected<std::unique_ptr<llvm::Module>> ModuleOrErr =
Peter Collingbournee2dcf7c2016-11-08 06:03:43 +0000869 getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext);
Peter Collingbourned9445c42016-11-13 07:00:17 +0000870 if (!ModuleOrErr) {
871 handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) {
872 CI.getDiagnostics().Report(diag::err_cannot_open_file)
Justin Lebarb080b632017-01-25 21:29:48 +0000873 << F.Filename << EIB.message();
Peter Collingbourned9445c42016-11-13 07:00:17 +0000874 });
Artem Belevich5d40ae32015-10-27 17:56:59 +0000875 LinkModules.clear();
876 return nullptr;
877 }
Jonas Devlieghere5eb9c812017-03-13 18:08:11 +0000878 LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs,
879 F.Internalize, F.LinkFlags});
Peter Collingbournef1d76db2011-10-30 17:30:44 +0000880 }
Peter Collingbournef1d76db2011-10-30 17:30:44 +0000881
Alex Lorenzee024992014-08-04 18:41:51 +0000882 CoverageSourceInfo *CoverageInfo = nullptr;
883 // Add the preprocessor callback only when the coverage mapping is generated.
884 if (CI.getCodeGenOpts().CoverageMapping) {
885 CoverageInfo = new CoverageSourceInfo;
Craig Topperb8a70532014-09-10 04:53:53 +0000886 CI.getPreprocessor().addPPCallbacks(
887 std::unique_ptr<PPCallbacks>(CoverageInfo));
Alex Lorenzee024992014-08-04 18:41:51 +0000888 }
Artem Belevich5d40ae32015-10-27 17:56:59 +0000889
David Blaikie037e75b2014-08-10 21:06:17 +0000890 std::unique_ptr<BackendConsumer> Result(new BackendConsumer(
Adrian Prantle74f5252015-06-30 02:26:03 +0000891 BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(),
892 CI.getPreprocessorOpts(), CI.getCodeGenOpts(), CI.getTargetOpts(),
Justin Lebarb080b632017-01-25 21:29:48 +0000893 CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile,
894 std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo));
David Blaikie6beb6aa2014-08-10 19:56:51 +0000895 BEConsumer = Result.get();
Amjad Aboud546bc112017-02-09 22:07:24 +0000896
897 // Enable generating macro debug info only when debug info is not disabled and
898 // also macro debug info is enabled.
899 if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo &&
900 CI.getCodeGenOpts().MacroDebugInfo) {
901 std::unique_ptr<PPCallbacks> Callbacks =
902 llvm::make_unique<MacroPPCallbacks>(BEConsumer->getCodeGenerator(),
903 CI.getPreprocessor());
904 CI.getPreprocessor().addPPCallbacks(std::move(Callbacks));
905 }
906
David Blaikie6beb6aa2014-08-10 19:56:51 +0000907 return std::move(Result);
Daniel Dunbarc13935e2008-10-21 23:49:24 +0000908}
Daniel Dunbarcea0c702010-02-25 04:37:45 +0000909
Tim Northover1390b442016-04-06 19:58:07 +0000910static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM,
911 void *Context,
912 unsigned LocCookie) {
913 SM.print(nullptr, llvm::errs());
914
915 auto Diags = static_cast<DiagnosticsEngine *>(Context);
916 unsigned DiagID;
917 switch (SM.getKind()) {
918 case llvm::SourceMgr::DK_Error:
919 DiagID = diag::err_fe_inline_asm;
920 break;
921 case llvm::SourceMgr::DK_Warning:
922 DiagID = diag::warn_fe_inline_asm;
923 break;
924 case llvm::SourceMgr::DK_Note:
925 DiagID = diag::note_fe_inline_asm;
926 break;
Adam Nemet7b1faaa2017-10-12 23:56:54 +0000927 case llvm::SourceMgr::DK_Remark:
928 llvm_unreachable("remarks unexpected");
Tim Northover1390b442016-04-06 19:58:07 +0000929 }
930
931 Diags->Report(DiagID).AddString("cannot compile inline asm");
932}
933
Peter Collingbourne65cb42c2017-01-24 19:55:38 +0000934std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) {
935 CompilerInstance &CI = getCompilerInstance();
936 SourceManager &SM = CI.getSourceManager();
937
938 // For ThinLTO backend invocations, ensure that the context
Peter Collingbournef5d17122017-01-26 21:09:48 +0000939 // merges types based on ODR identifiers. We also need to read
940 // the correct module out of a multi-module bitcode file.
941 if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) {
Peter Collingbourne65cb42c2017-01-24 19:55:38 +0000942 VMContext->enableDebugTypeODRUniquing();
943
Peter Collingbournef5d17122017-01-26 21:09:48 +0000944 auto DiagErrors = [&](Error E) -> std::unique_ptr<llvm::Module> {
945 unsigned DiagID =
946 CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
947 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
948 CI.getDiagnostics().Report(DiagID) << EIB.message();
949 });
950 return {};
951 };
952
Vitaly Bukac35ff822018-02-16 23:34:16 +0000953 Expected<std::vector<BitcodeModule>> BMsOrErr = getBitcodeModuleList(MBRef);
954 if (!BMsOrErr)
955 return DiagErrors(BMsOrErr.takeError());
956 BitcodeModule *Bm = FindThinLTOModule(*BMsOrErr);
957 // We have nothing to do if the file contains no ThinLTO module. This is
958 // possible if ThinLTO compilation was not able to split module. Content of
959 // the file was already processed by indexing and will be passed to the
960 // linker using merged object file.
961 if (!Bm) {
962 auto M = llvm::make_unique<llvm::Module>("empty", *VMContext);
963 M->setTargetTriple(CI.getTargetOpts().Triple);
964 return M;
965 }
Peter Collingbournef5d17122017-01-26 21:09:48 +0000966 Expected<std::unique_ptr<llvm::Module>> MOrErr =
Vitaly Bukac35ff822018-02-16 23:34:16 +0000967 Bm->parseModule(*VMContext);
Peter Collingbournef5d17122017-01-26 21:09:48 +0000968 if (!MOrErr)
969 return DiagErrors(MOrErr.takeError());
970 return std::move(*MOrErr);
971 }
972
Peter Collingbourne65cb42c2017-01-24 19:55:38 +0000973 llvm::SMDiagnostic Err;
974 if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext))
975 return M;
976
977 // Translate from the diagnostic info to the SourceManager location if
978 // available.
979 // TODO: Unify this with ConvertBackendLocation()
980 SourceLocation Loc;
981 if (Err.getLineNo() > 0) {
982 assert(Err.getColumnNo() >= 0);
983 Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()),
984 Err.getLineNo(), Err.getColumnNo() + 1);
985 }
986
987 // Strip off a leading diagnostic code if there is one.
988 StringRef Msg = Err.getMessage();
989 if (Msg.startswith("error: "))
990 Msg = Msg.substr(7);
991
992 unsigned DiagID =
993 CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");
994
995 CI.getDiagnostics().Report(Loc, DiagID) << Msg;
996 return {};
997}
998
Daniel Dunbar6f8362c2010-06-07 23:27:59 +0000999void CodeGenAction::ExecuteAction() {
1000 // If this is an IR file, we have to treat it specially.
Richard Smith40c0efa2017-04-26 18:57:40 +00001001 if (getCurrentFileKind().getLanguage() == InputKind::LLVM_IR) {
Daniel Dunbar6f8362c2010-06-07 23:27:59 +00001002 BackendAction BA = static_cast<BackendAction>(Act);
1003 CompilerInstance &CI = getCompilerInstance();
Peter Collingbourne03f89072016-07-15 00:55:40 +00001004 std::unique_ptr<raw_pwrite_stream> OS =
1005 GetOutputStream(CI, getCurrentFile(), BA);
Daniel Dunbar6f8362c2010-06-07 23:27:59 +00001006 if (BA != Backend_EmitNothing && !OS)
1007 return;
1008
1009 bool Invalid;
1010 SourceManager &SM = CI.getSourceManager();
Alp Toker7b463d52014-06-30 01:33:59 +00001011 FileID FID = SM.getMainFileID();
1012 llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid);
Daniel Dunbar6f8362c2010-06-07 23:27:59 +00001013 if (Invalid)
1014 return;
1015
Peter Collingbourne65cb42c2017-01-24 19:55:38 +00001016 TheModule = loadModule(*MainFile);
1017 if (!TheModule)
Daniel Dunbar6f8362c2010-06-07 23:27:59 +00001018 return;
Peter Collingbourne65cb42c2017-01-24 19:55:38 +00001019
Rafael Espindolad5e81e52013-12-20 22:01:25 +00001020 const TargetOptions &TargetOpts = CI.getTargetOpts();
1021 if (TheModule->getTargetTriple() != TargetOpts.Triple) {
Nico Weber6cf2df22015-01-29 06:25:59 +00001022 CI.getDiagnostics().Report(SourceLocation(),
1023 diag::warn_fe_override_module)
1024 << TargetOpts.Triple;
Rafael Espindolad5e81e52013-12-20 22:01:25 +00001025 TheModule->setTargetTriple(TargetOpts.Triple);
1026 }
Daniel Dunbar6f8362c2010-06-07 23:27:59 +00001027
Steven Wu27fb5222016-05-11 16:26:03 +00001028 EmbedBitcode(TheModule.get(), CI.getCodeGenOpts(),
1029 MainFile->getMemBufferRef());
1030
Tim Northover1390b442016-04-06 19:58:07 +00001031 LLVMContext &Ctx = TheModule->getContext();
1032 Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler,
1033 &CI.getDiagnostics());
Steven Wu27fb5222016-05-11 16:26:03 +00001034
Saleem Abdulrasool888e2892017-01-05 16:02:32 +00001035 EmitBackendOutput(CI.getDiagnostics(), CI.getHeaderSearchOpts(),
1036 CI.getCodeGenOpts(), TargetOpts, CI.getLangOpts(),
1037 CI.getTarget().getDataLayout(), TheModule.get(), BA,
1038 std::move(OS));
Daniel Dunbar6f8362c2010-06-07 23:27:59 +00001039 return;
1040 }
1041
1042 // Otherwise follow the normal AST path.
1043 this->ASTFrontendAction::ExecuteAction();
1044}
1045
1046//
1047
David Blaikie68e081d2011-12-20 02:48:34 +00001048void EmitAssemblyAction::anchor() { }
Peter Collingbourne8f5cf742011-02-19 23:03:58 +00001049EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext)
1050 : CodeGenAction(Backend_EmitAssembly, _VMContext) {}
Daniel Dunbarcea0c702010-02-25 04:37:45 +00001051
David Blaikie68e081d2011-12-20 02:48:34 +00001052void EmitBCAction::anchor() { }
Peter Collingbourne8f5cf742011-02-19 23:03:58 +00001053EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext)
1054 : CodeGenAction(Backend_EmitBC, _VMContext) {}
Daniel Dunbarcea0c702010-02-25 04:37:45 +00001055
David Blaikie68e081d2011-12-20 02:48:34 +00001056void EmitLLVMAction::anchor() { }
Peter Collingbourne8f5cf742011-02-19 23:03:58 +00001057EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext)
1058 : CodeGenAction(Backend_EmitLL, _VMContext) {}
Daniel Dunbarcea0c702010-02-25 04:37:45 +00001059
David Blaikie68e081d2011-12-20 02:48:34 +00001060void EmitLLVMOnlyAction::anchor() { }
Peter Collingbourne8f5cf742011-02-19 23:03:58 +00001061EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext)
1062 : CodeGenAction(Backend_EmitNothing, _VMContext) {}
Daniel Dunbarcea0c702010-02-25 04:37:45 +00001063
David Blaikie68e081d2011-12-20 02:48:34 +00001064void EmitCodeGenOnlyAction::anchor() { }
Peter Collingbourne8f5cf742011-02-19 23:03:58 +00001065EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext)
1066 : CodeGenAction(Backend_EmitMCNull, _VMContext) {}
Daniel Dunbar4c77a642010-05-25 18:41:01 +00001067
David Blaikie68e081d2011-12-20 02:48:34 +00001068void EmitObjAction::anchor() { }
Peter Collingbourne8f5cf742011-02-19 23:03:58 +00001069EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext)
1070 : CodeGenAction(Backend_EmitObj, _VMContext) {}