Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 1 | //===--- CodeGenAction.cpp - LLVM Code Generation Frontend Action ---------===// |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 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 | |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 10 | #include "clang/CodeGen/CodeGenAction.h" |
| 11 | #include "CodeGenModule.h" |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 12 | #include "CoverageMappingGen.h" |
Amjad Aboud | 546bc11 | 2017-02-09 22:07:24 +0000 | [diff] [blame] | 13 | #include "MacroPPCallbacks.h" |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTConsumer.h" |
Daniel Dunbar | b9bbd54 | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Hans Wennborg | a926d84 | 2014-05-23 20:37:38 +0000 | [diff] [blame] | 16 | #include "clang/AST/DeclCXX.h" |
Chandler Carruth | 0d9593d | 2015-01-14 11:29:14 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclGroup.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 18 | #include "clang/Basic/FileManager.h" |
| 19 | #include "clang/Basic/SourceManager.h" |
| 20 | #include "clang/Basic/TargetInfo.h" |
Daniel Dunbar | c1b1729 | 2010-06-15 17:48:49 +0000 | [diff] [blame] | 21 | #include "clang/CodeGen/BackendUtil.h" |
Daniel Dunbar | b9bbd54 | 2009-11-15 06:48:46 +0000 | [diff] [blame] | 22 | #include "clang/CodeGen/ModuleBuilder.h" |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 23 | #include "clang/Frontend/CompilerInstance.h" |
Daniel Dunbar | acadc55 | 2009-12-03 09:12:54 +0000 | [diff] [blame] | 24 | #include "clang/Frontend/FrontendDiagnostic.h" |
Chandler Carruth | 0d9593d | 2015-01-14 11:29:14 +0000 | [diff] [blame] | 25 | #include "clang/Lex/Preprocessor.h" |
Teresa Johnson | ffc4e24 | 2016-11-11 05:35:12 +0000 | [diff] [blame] | 26 | #include "llvm/Bitcode/BitcodeReader.h" |
Adam Nemet | 7b796f8 | 2017-01-26 04:07:11 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" |
Diego Novillo | 829b170 | 2014-04-16 16:54:24 +0000 | [diff] [blame] | 28 | #include "llvm/IR/DebugInfo.h" |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 29 | #include "llvm/IR/DiagnosticInfo.h" |
| 30 | #include "llvm/IR/DiagnosticPrinter.h" |
Jonas Devlieghere | 5eb9c81 | 2017-03-13 18:08:11 +0000 | [diff] [blame] | 31 | #include "llvm/IR/GlobalValue.h" |
Chandler Carruth | ffd5551 | 2013-01-02 11:45:17 +0000 | [diff] [blame] | 32 | #include "llvm/IR/LLVMContext.h" |
| 33 | #include "llvm/IR/Module.h" |
Chandler Carruth | b45836a | 2013-03-26 02:25:54 +0000 | [diff] [blame] | 34 | #include "llvm/IRReader/IRReader.h" |
Chandler Carruth | 00fa3f7 | 2014-03-06 03:46:44 +0000 | [diff] [blame] | 35 | #include "llvm/Linker/Linker.h" |
Daniel Dunbar | 3e11152 | 2010-06-07 23:21:04 +0000 | [diff] [blame] | 36 | #include "llvm/Pass.h" |
Chris Lattner | 5ec32e7 | 2010-04-06 18:38:50 +0000 | [diff] [blame] | 37 | #include "llvm/Support/MemoryBuffer.h" |
| 38 | #include "llvm/Support/SourceMgr.h" |
Chris Lattner | 263d64c | 2009-02-18 01:37:30 +0000 | [diff] [blame] | 39 | #include "llvm/Support/Timer.h" |
Hal Finkel | 8f96e82 | 2016-10-11 00:26:09 +0000 | [diff] [blame] | 40 | #include "llvm/Support/ToolOutputFile.h" |
| 41 | #include "llvm/Support/YAMLTraits.h" |
Jonas Devlieghere | 5eb9c81 | 2017-03-13 18:08:11 +0000 | [diff] [blame] | 42 | #include "llvm/Transforms/IPO/Internalize.h" |
| 43 | |
Ahmed Charles | dfca6f9 | 2014-03-09 11:36:40 +0000 | [diff] [blame] | 44 | #include <memory> |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 45 | using namespace clang; |
| 46 | using namespace llvm; |
| 47 | |
Nico Weber | 2992efa | 2011-01-25 20:34:14 +0000 | [diff] [blame] | 48 | namespace clang { |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 49 | class BackendConsumer; |
| 50 | class ClangDiagnosticHandler final : public DiagnosticHandler { |
| 51 | public: |
| 52 | ClangDiagnosticHandler(const CodeGenOptions &CGOpts, BackendConsumer *BCon) |
| 53 | : CodeGenOpts(CGOpts), BackendCon(BCon) {} |
| 54 | |
| 55 | bool handleDiagnostics(const DiagnosticInfo &DI) override; |
Adam Nemet | 5d2eb16 | 2017-09-19 17:59:40 +0000 | [diff] [blame] | 56 | |
| 57 | bool isAnalysisRemarkEnabled(StringRef PassName) const override { |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 58 | return (CodeGenOpts.OptimizationRemarkAnalysisPattern && |
| 59 | CodeGenOpts.OptimizationRemarkAnalysisPattern->match(PassName)); |
| 60 | } |
Adam Nemet | 5d2eb16 | 2017-09-19 17:59:40 +0000 | [diff] [blame] | 61 | bool isMissedOptRemarkEnabled(StringRef PassName) const override { |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 62 | return (CodeGenOpts.OptimizationRemarkMissedPattern && |
| 63 | CodeGenOpts.OptimizationRemarkMissedPattern->match(PassName)); |
| 64 | } |
Adam Nemet | 5d2eb16 | 2017-09-19 17:59:40 +0000 | [diff] [blame] | 65 | bool isPassedOptRemarkEnabled(StringRef PassName) const override { |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 66 | return (CodeGenOpts.OptimizationRemarkPattern && |
| 67 | CodeGenOpts.OptimizationRemarkPattern->match(PassName)); |
| 68 | } |
Adam Nemet | 5d2eb16 | 2017-09-19 17:59:40 +0000 | [diff] [blame] | 69 | |
Adam Nemet | 3ac802a | 2017-09-19 23:00:59 +0000 | [diff] [blame] | 70 | bool isAnyRemarkEnabled() const override { |
| 71 | return (CodeGenOpts.OptimizationRemarkAnalysisPattern || |
| 72 | CodeGenOpts.OptimizationRemarkMissedPattern || |
| 73 | CodeGenOpts.OptimizationRemarkPattern); |
| 74 | } |
| 75 | |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 76 | private: |
| 77 | const CodeGenOptions &CodeGenOpts; |
| 78 | BackendConsumer *BackendCon; |
| 79 | }; |
| 80 | |
Benjamin Kramer | 16634c2 | 2009-11-28 10:07:24 +0000 | [diff] [blame] | 81 | class BackendConsumer : public ASTConsumer { |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 82 | using LinkModule = CodeGenAction::LinkModule; |
| 83 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 84 | virtual void anchor(); |
David Blaikie | 9c902b5 | 2011-09-25 23:23:43 +0000 | [diff] [blame] | 85 | DiagnosticsEngine &Diags; |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 86 | BackendAction Action; |
Saleem Abdulrasool | 888e289 | 2017-01-05 16:02:32 +0000 | [diff] [blame] | 87 | const HeaderSearchOptions &HeaderSearchOpts; |
Daniel Dunbar | de18224 | 2009-11-30 08:39:32 +0000 | [diff] [blame] | 88 | const CodeGenOptions &CodeGenOpts; |
Daniel Dunbar | de18224 | 2009-11-30 08:39:32 +0000 | [diff] [blame] | 89 | const TargetOptions &TargetOpts; |
Dan Gohman | fec0ff8 | 2011-07-05 22:02:36 +0000 | [diff] [blame] | 90 | const LangOptions &LangOpts; |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 91 | std::unique_ptr<raw_pwrite_stream> AsmOutStream; |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 92 | ASTContext *Context; |
Daniel Dunbar | b3a36cf | 2008-10-29 08:50:02 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 263d64c | 2009-02-18 01:37:30 +0000 | [diff] [blame] | 94 | Timer LLVMIRGeneration; |
Davide Italiano | b99fabd | 2016-07-21 06:28:48 +0000 | [diff] [blame] | 95 | unsigned LLVMIRGenerationRefCount; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 96 | |
Reid Kleckner | 15241ba | 2016-11-30 00:25:36 +0000 | [diff] [blame] | 97 | /// 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 Charles | b898432 | 2014-03-07 20:03:18 +0000 | [diff] [blame] | 102 | std::unique_ptr<CodeGenerator> Gen; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 104 | SmallVector<LinkModule, 4> LinkModules; |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 105 | |
Rafael Espindola | 8ce88a5 | 2015-12-14 23:17:07 +0000 | [diff] [blame] | 106 | // This is here so that the diagnostic printer knows the module a diagnostic |
| 107 | // refers to. |
| 108 | llvm::Module *CurLinkModule = nullptr; |
| 109 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 110 | public: |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 111 | 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 Abdulrasool | 888e289 | 2017-01-05 16:02:32 +0000 | [diff] [blame] | 121 | : Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts), |
| 122 | CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts), |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 123 | AsmOutStream(std::move(OS)), Context(nullptr), |
Matthias Braun | ae032b6 | 2016-11-18 19:43:25 +0000 | [diff] [blame] | 124 | LLVMIRGeneration("irgen", "LLVM IR Generation Time"), |
Davide Italiano | b99fabd | 2016-07-21 06:28:48 +0000 | [diff] [blame] | 125 | LLVMIRGenerationRefCount(0), |
Adrian Prantl | e74f525 | 2015-06-30 02:26:03 +0000 | [diff] [blame] | 126 | Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 127 | CodeGenOpts, C, CoverageInfo)), |
| 128 | LinkModules(std::move(LinkModules)) { |
Daniel Dunbar | 8e70505 | 2009-11-30 08:39:52 +0000 | [diff] [blame] | 129 | llvm::TimePassesIsEnabled = TimePasses; |
Chris Lattner | deffa13 | 2009-02-18 01:23:44 +0000 | [diff] [blame] | 130 | } |
Serge Pavlov | 41c1f79 | 2016-02-18 16:42:09 +0000 | [diff] [blame] | 131 | 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 Dunbar | 400a693 | 2010-02-25 04:37:50 +0000 | [diff] [blame] | 135 | |
Amjad Aboud | 546bc11 | 2017-02-09 22:07:24 +0000 | [diff] [blame] | 136 | CodeGenerator *getCodeGenerator() { return Gen.get(); } |
| 137 | |
Craig Topper | 4f12f10 | 2014-03-12 06:41:41 +0000 | [diff] [blame] | 138 | void HandleCXXStaticMemberVarInstantiation(VarDecl *VD) override { |
Rafael Espindola | df88f6f | 2012-03-08 15:51:03 +0000 | [diff] [blame] | 139 | Gen->HandleCXXStaticMemberVarInstantiation(VD); |
Rafael Espindola | 189fa74 | 2012-03-05 10:54:55 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Craig Topper | 4f12f10 | 2014-03-12 06:41:41 +0000 | [diff] [blame] | 142 | void Initialize(ASTContext &Ctx) override { |
Richard Smith | 293534b | 2015-08-18 20:39:29 +0000 | [diff] [blame] | 143 | assert(!Context && "initialized multiple times"); |
| 144 | |
Chris Lattner | 5cf49fe | 2009-03-28 02:18:25 +0000 | [diff] [blame] | 145 | Context = &Ctx; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 146 | |
Daniel Dunbar | 8e70505 | 2009-11-30 08:39:52 +0000 | [diff] [blame] | 147 | if (llvm::TimePassesIsEnabled) |
Chris Lattner | 263d64c | 2009-02-18 01:37:30 +0000 | [diff] [blame] | 148 | LLVMIRGeneration.startTimer(); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 149 | |
Chris Lattner | 5cf49fe | 2009-03-28 02:18:25 +0000 | [diff] [blame] | 150 | Gen->Initialize(Ctx); |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 151 | |
Daniel Dunbar | 8e70505 | 2009-11-30 08:39:52 +0000 | [diff] [blame] | 152 | if (llvm::TimePassesIsEnabled) |
Chris Lattner | 263d64c | 2009-02-18 01:37:30 +0000 | [diff] [blame] | 153 | LLVMIRGeneration.stopTimer(); |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 154 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 155 | |
Craig Topper | 4f12f10 | 2014-03-12 06:41:41 +0000 | [diff] [blame] | 156 | bool HandleTopLevelDecl(DeclGroupRef D) override { |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 157 | PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(), |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 158 | Context->getSourceManager(), |
| 159 | "LLVM IR generation of declaration"); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Davide Italiano | b99fabd | 2016-07-21 06:28:48 +0000 | [diff] [blame] | 161 | // Recurse. |
| 162 | if (llvm::TimePassesIsEnabled) { |
| 163 | LLVMIRGenerationRefCount += 1; |
| 164 | if (LLVMIRGenerationRefCount == 1) |
| 165 | LLVMIRGeneration.startTimer(); |
| 166 | } |
Chris Lattner | 5bbb3c8 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 167 | |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 168 | Gen->HandleTopLevelDecl(D); |
Chris Lattner | 263d64c | 2009-02-18 01:37:30 +0000 | [diff] [blame] | 169 | |
Davide Italiano | b99fabd | 2016-07-21 06:28:48 +0000 | [diff] [blame] | 170 | if (llvm::TimePassesIsEnabled) { |
| 171 | LLVMIRGenerationRefCount -= 1; |
| 172 | if (LLVMIRGenerationRefCount == 0) |
| 173 | LLVMIRGeneration.stopTimer(); |
| 174 | } |
Argyrios Kyrtzidis | 841dd88 | 2011-11-18 00:26:59 +0000 | [diff] [blame] | 175 | |
| 176 | return true; |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 177 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 178 | |
Stephan Bergmann | 17d7d14 | 2016-03-30 06:27:31 +0000 | [diff] [blame] | 179 | void HandleInlineFunctionDefinition(FunctionDecl *D) override { |
Hans Wennborg | a926d84 | 2014-05-23 20:37:38 +0000 | [diff] [blame] | 180 | PrettyStackTraceDecl CrashInfo(D, SourceLocation(), |
| 181 | Context->getSourceManager(), |
Stephan Bergmann | 17d7d14 | 2016-03-30 06:27:31 +0000 | [diff] [blame] | 182 | "LLVM IR generation of inline function"); |
Hans Wennborg | a926d84 | 2014-05-23 20:37:38 +0000 | [diff] [blame] | 183 | if (llvm::TimePassesIsEnabled) |
| 184 | LLVMIRGeneration.startTimer(); |
| 185 | |
Stephan Bergmann | 17d7d14 | 2016-03-30 06:27:31 +0000 | [diff] [blame] | 186 | Gen->HandleInlineFunctionDefinition(D); |
Hans Wennborg | a926d84 | 2014-05-23 20:37:38 +0000 | [diff] [blame] | 187 | |
| 188 | if (llvm::TimePassesIsEnabled) |
| 189 | LLVMIRGeneration.stopTimer(); |
| 190 | } |
| 191 | |
Reid Kleckner | 68c4bb5 | 2016-11-30 01:32:53 +0000 | [diff] [blame] | 192 | void HandleInterestingDecl(DeclGroupRef D) override { |
Reid Kleckner | 15241ba | 2016-11-30 00:25:36 +0000 | [diff] [blame] | 193 | // Ignore interesting decls from the AST reader after IRGen is finished. |
| 194 | if (!IRGenFinished) |
| 195 | HandleTopLevelDecl(D); |
| 196 | } |
| 197 | |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 198 | // 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 Devlieghere | 5eb9c81 | 2017-03-13 18:08:11 +0000 | [diff] [blame] | 206 | |
| 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 Kleckner | 987a281 | 2017-03-13 22:33:07 +0000 | [diff] [blame] | 212 | internalizeModule(M, [&GVS](const llvm::GlobalValue &GV) { |
Jonas Devlieghere | 5eb9c81 | 2017-03-13 18:08:11 +0000 | [diff] [blame] | 213 | 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 Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 222 | return true; |
| 223 | } |
| 224 | return false; // success |
| 225 | } |
| 226 | |
Craig Topper | 4f12f10 | 2014-03-12 06:41:41 +0000 | [diff] [blame] | 227 | void HandleTranslationUnit(ASTContext &C) override { |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 228 | { |
Chris Lattner | e46de75 | 2009-03-06 06:46:31 +0000 | [diff] [blame] | 229 | PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); |
Davide Italiano | b99fabd | 2016-07-21 06:28:48 +0000 | [diff] [blame] | 230 | if (llvm::TimePassesIsEnabled) { |
| 231 | LLVMIRGenerationRefCount += 1; |
| 232 | if (LLVMIRGenerationRefCount == 1) |
| 233 | LLVMIRGeneration.startTimer(); |
| 234 | } |
Chris Lattner | 263d64c | 2009-02-18 01:37:30 +0000 | [diff] [blame] | 235 | |
Chris Lattner | cf16983 | 2009-03-28 04:11:33 +0000 | [diff] [blame] | 236 | Gen->HandleTranslationUnit(C); |
Daniel Dunbar | a94d873 | 2008-11-11 06:35:39 +0000 | [diff] [blame] | 237 | |
Davide Italiano | b99fabd | 2016-07-21 06:28:48 +0000 | [diff] [blame] | 238 | if (llvm::TimePassesIsEnabled) { |
| 239 | LLVMIRGenerationRefCount -= 1; |
| 240 | if (LLVMIRGenerationRefCount == 0) |
| 241 | LLVMIRGeneration.stopTimer(); |
| 242 | } |
Reid Kleckner | 15241ba | 2016-11-30 00:25:36 +0000 | [diff] [blame] | 243 | |
| 244 | IRGenFinished = true; |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 245 | } |
Chris Lattner | 263d64c | 2009-02-18 01:37:30 +0000 | [diff] [blame] | 246 | |
Daniel Dunbar | f976d1b | 2010-06-07 23:20:08 +0000 | [diff] [blame] | 247 | // Silently ignore if we weren't initialized for some reason. |
Serge Pavlov | 41c1f79 | 2016-02-18 16:42:09 +0000 | [diff] [blame] | 248 | if (!getModule()) |
Daniel Dunbar | f976d1b | 2010-06-07 23:20:08 +0000 | [diff] [blame] | 249 | return; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 250 | |
Daniel Dunbar | f976d1b | 2010-06-07 23:20:08 +0000 | [diff] [blame] | 251 | // Install an inline asm handler so that diagnostics get printed through |
| 252 | // our diagnostics hooks. |
Serge Pavlov | 41c1f79 | 2016-02-18 16:42:09 +0000 | [diff] [blame] | 253 | LLVMContext &Ctx = getModule()->getContext(); |
Chris Lattner | 068f2ab | 2010-11-17 08:13:04 +0000 | [diff] [blame] | 254 | LLVMContext::InlineAsmDiagHandlerTy OldHandler = |
| 255 | Ctx.getInlineAsmDiagnosticHandler(); |
Daniel Dunbar | f976d1b | 2010-06-07 23:20:08 +0000 | [diff] [blame] | 256 | void *OldContext = Ctx.getInlineAsmDiagnosticContext(); |
Chris Lattner | 068f2ab | 2010-11-17 08:13:04 +0000 | [diff] [blame] | 257 | Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this); |
Daniel Dunbar | f976d1b | 2010-06-07 23:20:08 +0000 | [diff] [blame] | 258 | |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 259 | std::unique_ptr<DiagnosticHandler> OldDiagnosticHandler = |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 260 | Ctx.getDiagnosticHandler(); |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 261 | Ctx.setDiagnosticHandler(llvm::make_unique<ClangDiagnosticHandler>( |
| 262 | CodeGenOpts, this)); |
Brian Gesiak | 9f59da8 | 2017-06-30 19:37:11 +0000 | [diff] [blame] | 263 | Ctx.setDiagnosticsHotnessRequested(CodeGenOpts.DiagnosticsWithHotness); |
Brian Gesiak | 562eab9 | 2017-07-01 05:45:26 +0000 | [diff] [blame] | 264 | if (CodeGenOpts.DiagnosticsHotnessThreshold != 0) |
| 265 | Ctx.setDiagnosticsHotnessThreshold( |
| 266 | CodeGenOpts.DiagnosticsHotnessThreshold); |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 267 | |
Reid Kleckner | 3fc649c | 2017-09-23 01:03:17 +0000 | [diff] [blame] | 268 | std::unique_ptr<llvm::ToolOutputFile> OptRecordFile; |
Hal Finkel | 8f96e82 | 2016-10-11 00:26:09 +0000 | [diff] [blame] | 269 | if (!CodeGenOpts.OptRecordFile.empty()) { |
| 270 | std::error_code EC; |
Reid Kleckner | 3fc649c | 2017-09-23 01:03:17 +0000 | [diff] [blame] | 271 | OptRecordFile = llvm::make_unique<llvm::ToolOutputFile>( |
| 272 | CodeGenOpts.OptRecordFile, EC, sys::fs::F_None); |
Hal Finkel | 8f96e82 | 2016-10-11 00:26:09 +0000 | [diff] [blame] | 273 | if (EC) { |
| 274 | Diags.Report(diag::err_cannot_open_file) << |
| 275 | CodeGenOpts.OptRecordFile << EC.message(); |
| 276 | return; |
| 277 | } |
| 278 | |
Mehdi Amini | 6f40836 | 2016-11-19 18:19:41 +0000 | [diff] [blame] | 279 | Ctx.setDiagnosticsOutputFile( |
| 280 | llvm::make_unique<yaml::Output>(OptRecordFile->os())); |
Hal Finkel | 8f96e82 | 2016-10-11 00:26:09 +0000 | [diff] [blame] | 281 | |
| 282 | if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone) |
Brian Gesiak | 9f59da8 | 2017-06-30 19:37:11 +0000 | [diff] [blame] | 283 | Ctx.setDiagnosticsHotnessRequested(true); |
Hal Finkel | 8f96e82 | 2016-10-11 00:26:09 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 286 | // Link each LinkModule into our module. |
| 287 | if (LinkInModules()) |
| 288 | return; |
Rafael Espindola | 8ce88a5 | 2015-12-14 23:17:07 +0000 | [diff] [blame] | 289 | |
Steven Wu | 27fb522 | 2016-05-11 16:26:03 +0000 | [diff] [blame] | 290 | EmbedBitcode(getModule(), CodeGenOpts, llvm::MemoryBufferRef()); |
| 291 | |
Saleem Abdulrasool | 888e289 | 2017-01-05 16:02:32 +0000 | [diff] [blame] | 292 | EmitBackendOutput(Diags, HeaderSearchOpts, CodeGenOpts, TargetOpts, |
| 293 | LangOpts, C.getTargetInfo().getDataLayout(), |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 294 | getModule(), Action, std::move(AsmOutStream)); |
Rafael Espindola | 666a2ab | 2013-12-18 16:38:48 +0000 | [diff] [blame] | 295 | |
Daniel Dunbar | f976d1b | 2010-06-07 23:20:08 +0000 | [diff] [blame] | 296 | Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext); |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 297 | |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 298 | Ctx.setDiagnosticHandler(std::move(OldDiagnosticHandler)); |
Hal Finkel | 8f96e82 | 2016-10-11 00:26:09 +0000 | [diff] [blame] | 299 | |
| 300 | if (OptRecordFile) |
| 301 | OptRecordFile->keep(); |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 302 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 303 | |
Craig Topper | 4f12f10 | 2014-03-12 06:41:41 +0000 | [diff] [blame] | 304 | void HandleTagDeclDefinition(TagDecl *D) override { |
Chris Lattner | eae6cb6 | 2009-03-05 08:00:35 +0000 | [diff] [blame] | 305 | PrettyStackTraceDecl CrashInfo(D, SourceLocation(), |
| 306 | Context->getSourceManager(), |
| 307 | "LLVM IR generation of declaration"); |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 308 | Gen->HandleTagDeclDefinition(D); |
| 309 | } |
Douglas Gregor | beecd58 | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 310 | |
Craig Topper | 4f12f10 | 2014-03-12 06:41:41 +0000 | [diff] [blame] | 311 | void HandleTagDeclRequiredDefinition(const TagDecl *D) override { |
David Blaikie | 48ad6dc | 2013-07-13 21:08:14 +0000 | [diff] [blame] | 312 | Gen->HandleTagDeclRequiredDefinition(D); |
| 313 | } |
| 314 | |
Craig Topper | 4f12f10 | 2014-03-12 06:41:41 +0000 | [diff] [blame] | 315 | void CompleteTentativeDefinition(VarDecl *D) override { |
Douglas Gregor | beecd58 | 2009-04-21 17:11:58 +0000 | [diff] [blame] | 316 | Gen->CompleteTentativeDefinition(D); |
| 317 | } |
Daniel Dunbar | 50aa0a5 | 2010-04-29 16:29:09 +0000 | [diff] [blame] | 318 | |
David Majnemer | 929025d | 2016-01-26 19:30:26 +0000 | [diff] [blame] | 319 | void AssignInheritanceModel(CXXRecordDecl *RD) override { |
| 320 | Gen->AssignInheritanceModel(RD); |
| 321 | } |
| 322 | |
Nico Weber | b6a5d05 | 2015-01-15 04:07:35 +0000 | [diff] [blame] | 323 | void HandleVTable(CXXRecordDecl *RD) override { |
| 324 | Gen->HandleVTable(RD); |
Douglas Gregor | 88d292c | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Chris Lattner | 5ec32e7 | 2010-04-06 18:38:50 +0000 | [diff] [blame] | 327 | 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 Dunbar | 50aa0a5 | 2010-04-29 16:29:09 +0000 | [diff] [blame] | 332 | |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 333 | /// Get the best possible source location to represent a diagnostic that |
| 334 | /// may have associated debug info. |
| 335 | const FullSourceLoc |
Justin Bogner | e91e9dd | 2017-02-17 17:34:49 +0000 | [diff] [blame] | 336 | getBestLocationFromDebugLoc(const llvm::DiagnosticInfoWithLocationBase &D, |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 337 | bool &BadDebugInfo, StringRef &Filename, |
| 338 | unsigned &Line, unsigned &Column) const; |
| 339 | |
Chris Lattner | 5ec32e7 | 2010-04-06 18:38:50 +0000 | [diff] [blame] | 340 | void InlineAsmDiagHandler2(const llvm::SMDiagnostic &, |
| 341 | SourceLocation LocCookie); |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 342 | |
| 343 | void DiagnosticHandlerImpl(const llvm::DiagnosticInfo &DI); |
| 344 | /// \brief Specialized handler for InlineAsm diagnostic. |
| 345 | /// \return True if the diagnostic has been successfully reported, false |
| 346 | /// otherwise. |
| 347 | bool InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D); |
| 348 | /// \brief Specialized handler for StackSize diagnostic. |
| 349 | /// \return True if the diagnostic has been successfully reported, false |
| 350 | /// otherwise. |
| 351 | bool StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D); |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 352 | /// \brief Specialized handler for unsupported backend feature diagnostic. |
| 353 | void UnsupportedDiagHandler(const llvm::DiagnosticInfoUnsupported &D); |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 354 | /// \brief Specialized handlers for optimization remarks. |
| 355 | /// Note that these handlers only accept remarks and they always handle |
Diego Novillo | 829b170 | 2014-04-16 16:54:24 +0000 | [diff] [blame] | 356 | /// them. |
Tyler Nowicki | f8a767d | 2014-07-18 19:40:19 +0000 | [diff] [blame] | 357 | void EmitOptimizationMessage(const llvm::DiagnosticInfoOptimizationBase &D, |
| 358 | unsigned DiagID); |
Adam Nemet | 7b796f8 | 2017-01-26 04:07:11 +0000 | [diff] [blame] | 359 | void |
| 360 | OptimizationRemarkHandler(const llvm::DiagnosticInfoOptimizationBase &D); |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 361 | void OptimizationRemarkHandler( |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 362 | const llvm::OptimizationRemarkAnalysisFPCommute &D); |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 363 | void OptimizationRemarkHandler( |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 364 | const llvm::OptimizationRemarkAnalysisAliasing &D); |
Tyler Nowicki | f8a767d | 2014-07-18 19:40:19 +0000 | [diff] [blame] | 365 | void OptimizationFailureHandler( |
| 366 | const llvm::DiagnosticInfoOptimizationFailure &D); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 367 | }; |
Jonas Devlieghere | 5eb9c81 | 2017-03-13 18:08:11 +0000 | [diff] [blame] | 368 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 369 | void BackendConsumer::anchor() {} |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 370 | } |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 371 | |
Vivek Pandya | 1dee3be | 2017-09-15 20:09:55 +0000 | [diff] [blame] | 372 | bool ClangDiagnosticHandler::handleDiagnostics(const DiagnosticInfo &DI) { |
| 373 | BackendCon->DiagnosticHandlerImpl(DI); |
| 374 | return true; |
| 375 | } |
| 376 | |
Chris Lattner | 79f67a7 | 2010-04-08 00:23:06 +0000 | [diff] [blame] | 377 | /// ConvertBackendLocation - Convert a location in a temporary llvm::SourceMgr |
| 378 | /// buffer to be a valid FullSourceLoc. |
| 379 | static 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 Dunbar | 50aa0a5 | 2010-04-29 16:29:09 +0000 | [diff] [blame] | 383 | // a copy to the Clang source manager. |
Chris Lattner | 79f67a7 | 2010-04-08 00:23:06 +0000 | [diff] [blame] | 384 | const llvm::SourceMgr &LSM = *D.getSourceMgr(); |
Daniel Dunbar | 50aa0a5 | 2010-04-29 16:29:09 +0000 | [diff] [blame] | 385 | |
Chris Lattner | 79f67a7 | 2010-04-08 00:23:06 +0000 | [diff] [blame] | 386 | // 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 Dunbar | 50aa0a5 | 2010-04-29 16:29:09 +0000 | [diff] [blame] | 390 | |
Chris Lattner | 79f67a7 | 2010-04-08 00:23:06 +0000 | [diff] [blame] | 391 | // Create the copy and transfer ownership to clang::SourceManager. |
Alp Toker | aa0dd5a | 2014-06-27 06:02:00 +0000 | [diff] [blame] | 392 | // TODO: Avoid copying files into memory. |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 393 | std::unique_ptr<llvm::MemoryBuffer> CBuf = |
| 394 | llvm::MemoryBuffer::getMemBufferCopy(LBuf->getBuffer(), |
| 395 | LBuf->getBufferIdentifier()); |
Alp Toker | aa0dd5a | 2014-06-27 06:02:00 +0000 | [diff] [blame] | 396 | // FIXME: Keep a file ID map instead of creating new IDs for each location. |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 397 | FileID FID = CSM.createFileID(std::move(CBuf)); |
Daniel Dunbar | 50aa0a5 | 2010-04-29 16:29:09 +0000 | [diff] [blame] | 398 | |
Chris Lattner | 79f67a7 | 2010-04-08 00:23:06 +0000 | [diff] [blame] | 399 | // Translate the offset into the file. |
Alp Toker | aa0dd5a | 2014-06-27 06:02:00 +0000 | [diff] [blame] | 400 | unsigned Offset = D.getLoc().getPointer() - LBuf->getBufferStart(); |
Daniel Dunbar | 50aa0a5 | 2010-04-29 16:29:09 +0000 | [diff] [blame] | 401 | SourceLocation NewLoc = |
Argyrios Kyrtzidis | e6e67de | 2011-09-19 20:40:19 +0000 | [diff] [blame] | 402 | CSM.getLocForStartOfFile(FID).getLocWithOffset(Offset); |
Chris Lattner | 79f67a7 | 2010-04-08 00:23:06 +0000 | [diff] [blame] | 403 | return FullSourceLoc(NewLoc, CSM); |
| 404 | } |
| 405 | |
Chris Lattner | 6d67213 | 2010-04-06 17:52:14 +0000 | [diff] [blame] | 406 | |
Chris Lattner | 5ec32e7 | 2010-04-06 18:38:50 +0000 | [diff] [blame] | 407 | /// InlineAsmDiagHandler2 - This function is invoked when the backend hits an |
| 408 | /// error parsing inline asm. The SMDiagnostic indicates the error relative to |
Daniel Dunbar | 50aa0a5 | 2010-04-29 16:29:09 +0000 | [diff] [blame] | 409 | /// the temporary memory buffer that the inline asm parser has set up. |
Chris Lattner | 5ec32e7 | 2010-04-06 18:38:50 +0000 | [diff] [blame] | 410 | void 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 Kyrtzidis | a11b35a | 2012-02-01 06:36:49 +0000 | [diff] [blame] | 414 | |
| 415 | // Strip "error: " off the start of the message string. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 416 | StringRef Message = D.getMessage(); |
Argyrios Kyrtzidis | a11b35a | 2012-02-01 06:36:49 +0000 | [diff] [blame] | 417 | if (Message.startswith("error: ")) |
| 418 | Message = Message.substr(7); |
Chris Lattner | 5ec32e7 | 2010-04-06 18:38:50 +0000 | [diff] [blame] | 419 | |
Chris Lattner | c7ed7ea | 2010-06-15 00:03:12 +0000 | [diff] [blame] | 420 | // If the SMDiagnostic has an inline asm source location, translate it. |
Chris Lattner | 5ec32e7 | 2010-04-06 18:38:50 +0000 | [diff] [blame] | 421 | FullSourceLoc Loc; |
Chris Lattner | 79f67a7 | 2010-04-08 00:23:06 +0000 | [diff] [blame] | 422 | if (D.getLoc() != SMLoc()) |
| 423 | Loc = ConvertBackendLocation(D, Context->getSourceManager()); |
Argyrios Kyrtzidis | a11b35a | 2012-02-01 06:36:49 +0000 | [diff] [blame] | 424 | |
Joey Gouly | 5798b26 | 2014-06-05 21:23:42 +0000 | [diff] [blame] | 425 | 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; |
| 436 | } |
Chris Lattner | c7ed7ea | 2010-06-15 00:03:12 +0000 | [diff] [blame] | 437 | // If this problem has clang-level source location information, report the |
Joey Gouly | 5798b26 | 2014-06-05 21:23:42 +0000 | [diff] [blame] | 438 | // issue in the source with a note showing the instantiated |
Chris Lattner | c7ed7ea | 2010-06-15 00:03:12 +0000 | [diff] [blame] | 439 | // code. |
| 440 | if (LocCookie.isValid()) { |
Joey Gouly | 5798b26 | 2014-06-05 21:23:42 +0000 | [diff] [blame] | 441 | Diags.Report(LocCookie, DiagID).AddString(Message); |
Jonas Devlieghere | 5eb9c81 | 2017-03-13 18:08:11 +0000 | [diff] [blame] | 442 | |
Benjamin Kramer | e06b2b7 | 2011-10-16 10:48:28 +0000 | [diff] [blame] | 443 | if (D.getLoc().isValid()) { |
| 444 | DiagnosticBuilder B = Diags.Report(Loc, diag::note_fe_inline_asm_here); |
| 445 | // Convert the SMDiagnostic ranges into SourceRange and attach them |
| 446 | // to the diagnostic. |
Yaron Keren | ede6030 | 2015-08-01 19:11:36 +0000 | [diff] [blame] | 447 | for (const std::pair<unsigned, unsigned> &Range : D.getRanges()) { |
Benjamin Kramer | e06b2b7 | 2011-10-16 10:48:28 +0000 | [diff] [blame] | 448 | unsigned Column = D.getColumnNo(); |
| 449 | B << SourceRange(Loc.getLocWithOffset(Range.first - Column), |
| 450 | Loc.getLocWithOffset(Range.second - Column)); |
| 451 | } |
| 452 | } |
Chris Lattner | c7ed7ea | 2010-06-15 00:03:12 +0000 | [diff] [blame] | 453 | return; |
| 454 | } |
Jonas Devlieghere | 5eb9c81 | 2017-03-13 18:08:11 +0000 | [diff] [blame] | 455 | |
Joey Gouly | 5798b26 | 2014-06-05 21:23:42 +0000 | [diff] [blame] | 456 | // Otherwise, report the backend issue as occurring in the generated .s file. |
| 457 | // If Loc is invalid, we still need to report the issue, it just gets no |
Chris Lattner | c7ed7ea | 2010-06-15 00:03:12 +0000 | [diff] [blame] | 458 | // location info. |
Joey Gouly | 5798b26 | 2014-06-05 21:23:42 +0000 | [diff] [blame] | 459 | Diags.Report(Loc, DiagID).AddString(Message); |
Chris Lattner | 5ec32e7 | 2010-04-06 18:38:50 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 462 | #define ComputeDiagID(Severity, GroupName, DiagID) \ |
| 463 | do { \ |
| 464 | switch (Severity) { \ |
| 465 | case llvm::DS_Error: \ |
| 466 | DiagID = diag::err_fe_##GroupName; \ |
| 467 | break; \ |
| 468 | case llvm::DS_Warning: \ |
| 469 | DiagID = diag::warn_fe_##GroupName; \ |
| 470 | break; \ |
Tobias Grosser | 7416024 | 2014-02-28 09:11:08 +0000 | [diff] [blame] | 471 | case llvm::DS_Remark: \ |
| 472 | llvm_unreachable("'remark' severity not expected"); \ |
| 473 | break; \ |
| 474 | case llvm::DS_Note: \ |
| 475 | DiagID = diag::note_fe_##GroupName; \ |
| 476 | break; \ |
| 477 | } \ |
| 478 | } while (false) |
| 479 | |
| 480 | #define ComputeDiagRemarkID(Severity, GroupName, DiagID) \ |
| 481 | do { \ |
| 482 | switch (Severity) { \ |
| 483 | case llvm::DS_Error: \ |
| 484 | DiagID = diag::err_fe_##GroupName; \ |
| 485 | break; \ |
| 486 | case llvm::DS_Warning: \ |
| 487 | DiagID = diag::warn_fe_##GroupName; \ |
| 488 | break; \ |
| 489 | case llvm::DS_Remark: \ |
| 490 | DiagID = diag::remark_fe_##GroupName; \ |
| 491 | break; \ |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 492 | case llvm::DS_Note: \ |
| 493 | DiagID = diag::note_fe_##GroupName; \ |
| 494 | break; \ |
| 495 | } \ |
| 496 | } while (false) |
| 497 | |
| 498 | bool |
| 499 | BackendConsumer::InlineAsmDiagHandler(const llvm::DiagnosticInfoInlineAsm &D) { |
| 500 | unsigned DiagID; |
| 501 | ComputeDiagID(D.getSeverity(), inline_asm, DiagID); |
| 502 | std::string Message = D.getMsgStr().str(); |
| 503 | |
| 504 | // If this problem has clang-level source location information, report the |
Tobias Grosser | bd25beb | 2014-02-26 10:21:56 +0000 | [diff] [blame] | 505 | // issue as being a problem in the source with a note showing the instantiated |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 506 | // code. |
| 507 | SourceLocation LocCookie = |
| 508 | SourceLocation::getFromRawEncoding(D.getLocCookie()); |
| 509 | if (LocCookie.isValid()) |
| 510 | Diags.Report(LocCookie, DiagID).AddString(Message); |
| 511 | else { |
| 512 | // Otherwise, report the backend diagnostic as occurring in the generated |
| 513 | // .s file. |
| 514 | // If Loc is invalid, we still need to report the diagnostic, it just gets |
| 515 | // no location info. |
| 516 | FullSourceLoc Loc; |
| 517 | Diags.Report(Loc, DiagID).AddString(Message); |
| 518 | } |
| 519 | // We handled all the possible severities. |
| 520 | return true; |
| 521 | } |
| 522 | |
| 523 | bool |
| 524 | BackendConsumer::StackSizeDiagHandler(const llvm::DiagnosticInfoStackSize &D) { |
| 525 | if (D.getSeverity() != llvm::DS_Warning) |
| 526 | // For now, the only support we have for StackSize diagnostic is warning. |
| 527 | // We do not know how to format other severities. |
| 528 | return false; |
| 529 | |
Alp Toker | fb8d02b | 2014-06-05 22:10:59 +0000 | [diff] [blame] | 530 | if (const Decl *ND = Gen->GetDeclForMangledName(D.getFunction().getName())) { |
Matt Arsenault | 4deb4ed2 | 2016-06-20 18:13:09 +0000 | [diff] [blame] | 531 | // FIXME: Shouldn't need to truncate to uint32_t |
Alp Toker | fb8d02b | 2014-06-05 22:10:59 +0000 | [diff] [blame] | 532 | Diags.Report(ND->getASTContext().getFullLoc(ND->getLocation()), |
| 533 | diag::warn_fe_frame_larger_than) |
Matt Arsenault | 4deb4ed2 | 2016-06-20 18:13:09 +0000 | [diff] [blame] | 534 | << static_cast<uint32_t>(D.getStackSize()) << Decl::castToDeclContext(ND); |
Alp Toker | fb8d02b | 2014-06-05 22:10:59 +0000 | [diff] [blame] | 535 | return true; |
| 536 | } |
| 537 | |
| 538 | return false; |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 541 | const FullSourceLoc BackendConsumer::getBestLocationFromDebugLoc( |
Justin Bogner | e91e9dd | 2017-02-17 17:34:49 +0000 | [diff] [blame] | 542 | const llvm::DiagnosticInfoWithLocationBase &D, bool &BadDebugInfo, |
| 543 | StringRef &Filename, unsigned &Line, unsigned &Column) const { |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 544 | SourceManager &SourceMgr = Context->getSourceManager(); |
| 545 | FileManager &FileMgr = SourceMgr.getFileManager(); |
Alp Toker | 2750627 | 2014-06-05 22:11:12 +0000 | [diff] [blame] | 546 | SourceLocation DILoc; |
Diego Novillo | 86f884e | 2015-05-08 20:59:56 +0000 | [diff] [blame] | 547 | |
| 548 | if (D.isLocationAvailable()) { |
| 549 | D.getLocation(&Filename, &Line, &Column); |
| 550 | const FileEntry *FE = FileMgr.getFile(Filename); |
| 551 | if (FE && Line > 0) { |
| 552 | // If -gcolumn-info was not used, Column will be 0. This upsets the |
| 553 | // source manager, so pass 1 if Column is not set. |
| 554 | DILoc = SourceMgr.translateFileLineCol(FE, Line, Column ? Column : 1); |
| 555 | } |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 556 | BadDebugInfo = DILoc.isInvalid(); |
Diego Novillo | 829b170 | 2014-04-16 16:54:24 +0000 | [diff] [blame] | 557 | } |
Alp Toker | 2750627 | 2014-06-05 22:11:12 +0000 | [diff] [blame] | 558 | |
| 559 | // If a location isn't available, try to approximate it using the associated |
| 560 | // function definition. We use the definition's right brace to differentiate |
| 561 | // from diagnostics that genuinely relate to the function itself. |
| 562 | FullSourceLoc Loc(DILoc, SourceMgr); |
| 563 | if (Loc.isInvalid()) |
| 564 | if (const Decl *FD = Gen->GetDeclForMangledName(D.getFunction().getName())) |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 565 | Loc = FD->getASTContext().getFullLoc(FD->getLocation()); |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 566 | |
Diego Novillo | 86f884e | 2015-05-08 20:59:56 +0000 | [diff] [blame] | 567 | if (DILoc.isInvalid() && D.isLocationAvailable()) |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 568 | // If we were not able to translate the file:line:col information |
| 569 | // back to a SourceLocation, at least emit a note stating that |
| 570 | // we could not translate this location. This can happen in the |
| 571 | // case of #line directives. |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 572 | Diags.Report(Loc, diag::note_fe_backend_invalid_loc) |
Ben Craig | 6e4695a | 2016-05-06 13:29:46 +0000 | [diff] [blame] | 573 | << Filename << Line << Column; |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 574 | |
| 575 | return Loc; |
| 576 | } |
| 577 | |
| 578 | void BackendConsumer::UnsupportedDiagHandler( |
| 579 | const llvm::DiagnosticInfoUnsupported &D) { |
| 580 | // We only support errors. |
| 581 | assert(D.getSeverity() == llvm::DS_Error); |
| 582 | |
| 583 | StringRef Filename; |
| 584 | unsigned Line, Column; |
Reid Kleckner | f70ee60 | 2017-05-12 00:10:49 +0000 | [diff] [blame] | 585 | bool BadDebugInfo = false; |
| 586 | FullSourceLoc Loc = |
| 587 | getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 588 | |
| 589 | Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str(); |
| 590 | |
| 591 | if (BadDebugInfo) |
| 592 | // If we were not able to translate the file:line:col information |
| 593 | // back to a SourceLocation, at least emit a note stating that |
| 594 | // we could not translate this location. This can happen in the |
| 595 | // case of #line directives. |
| 596 | Diags.Report(Loc, diag::note_fe_backend_invalid_loc) |
| 597 | << Filename << Line << Column; |
| 598 | } |
| 599 | |
| 600 | void BackendConsumer::EmitOptimizationMessage( |
| 601 | const llvm::DiagnosticInfoOptimizationBase &D, unsigned DiagID) { |
| 602 | // We only support warnings and remarks. |
| 603 | assert(D.getSeverity() == llvm::DS_Remark || |
| 604 | D.getSeverity() == llvm::DS_Warning); |
| 605 | |
| 606 | StringRef Filename; |
| 607 | unsigned Line, Column; |
| 608 | bool BadDebugInfo = false; |
Reid Kleckner | f70ee60 | 2017-05-12 00:10:49 +0000 | [diff] [blame] | 609 | FullSourceLoc Loc = |
| 610 | getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column); |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 611 | |
Adam Nemet | 1eea3e5 | 2016-09-13 04:32:40 +0000 | [diff] [blame] | 612 | std::string Msg; |
| 613 | raw_string_ostream MsgStream(Msg); |
Adam Nemet | 699fc5b | 2016-09-27 20:55:12 +0000 | [diff] [blame] | 614 | MsgStream << D.getMsg(); |
Adam Nemet | 1eea3e5 | 2016-09-13 04:32:40 +0000 | [diff] [blame] | 615 | |
| 616 | if (D.getHotness()) |
| 617 | MsgStream << " (hotness: " << *D.getHotness() << ")"; |
| 618 | |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 619 | Diags.Report(Loc, DiagID) |
Mehdi Amini | 117296c | 2016-10-01 02:56:57 +0000 | [diff] [blame] | 620 | << AddFlagValue(D.getPassName()) |
Adam Nemet | 1eea3e5 | 2016-09-13 04:32:40 +0000 | [diff] [blame] | 621 | << MsgStream.str(); |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 622 | |
| 623 | if (BadDebugInfo) |
| 624 | // If we were not able to translate the file:line:col information |
| 625 | // back to a SourceLocation, at least emit a note stating that |
| 626 | // we could not translate this location. This can happen in the |
| 627 | // case of #line directives. |
| 628 | Diags.Report(Loc, diag::note_fe_backend_invalid_loc) |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 629 | << Filename << Line << Column; |
| 630 | } |
| 631 | |
| 632 | void BackendConsumer::OptimizationRemarkHandler( |
Adam Nemet | 7b796f8 | 2017-01-26 04:07:11 +0000 | [diff] [blame] | 633 | const llvm::DiagnosticInfoOptimizationBase &D) { |
Adam Nemet | 28c2c22 | 2017-10-04 04:25:31 +0000 | [diff] [blame^] | 634 | // Without hotness information, don't show noisy remarks. |
| 635 | if (D.isVerbose() && !D.getHotness()) |
| 636 | return; |
| 637 | |
Adam Nemet | 7b796f8 | 2017-01-26 04:07:11 +0000 | [diff] [blame] | 638 | if (D.isPassed()) { |
| 639 | // Optimization remarks are active only if the -Rpass flag has a regular |
| 640 | // expression that matches the name of the pass name in \p D. |
| 641 | if (CodeGenOpts.OptimizationRemarkPattern && |
| 642 | CodeGenOpts.OptimizationRemarkPattern->match(D.getPassName())) |
| 643 | EmitOptimizationMessage(D, diag::remark_fe_backend_optimization_remark); |
| 644 | } else if (D.isMissed()) { |
| 645 | // Missed optimization remarks are active only if the -Rpass-missed |
| 646 | // flag has a regular expression that matches the name of the pass |
| 647 | // name in \p D. |
| 648 | if (CodeGenOpts.OptimizationRemarkMissedPattern && |
| 649 | CodeGenOpts.OptimizationRemarkMissedPattern->match(D.getPassName())) |
| 650 | EmitOptimizationMessage( |
| 651 | D, diag::remark_fe_backend_optimization_remark_missed); |
| 652 | } else { |
| 653 | assert(D.isAnalysis() && "Unknown remark type"); |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 654 | |
Adam Nemet | 7b796f8 | 2017-01-26 04:07:11 +0000 | [diff] [blame] | 655 | bool ShouldAlwaysPrint = false; |
| 656 | if (auto *ORA = dyn_cast<llvm::OptimizationRemarkAnalysis>(&D)) |
| 657 | ShouldAlwaysPrint = ORA->shouldAlwaysPrint(); |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 658 | |
Adam Nemet | 7b796f8 | 2017-01-26 04:07:11 +0000 | [diff] [blame] | 659 | if (ShouldAlwaysPrint || |
| 660 | (CodeGenOpts.OptimizationRemarkAnalysisPattern && |
| 661 | CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) |
| 662 | EmitOptimizationMessage( |
| 663 | D, diag::remark_fe_backend_optimization_remark_analysis); |
| 664 | } |
Diego Novillo | 829b170 | 2014-04-16 16:54:24 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Tyler Nowicki | 8a0925c | 2015-08-10 19:56:40 +0000 | [diff] [blame] | 667 | void BackendConsumer::OptimizationRemarkHandler( |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 668 | const llvm::OptimizationRemarkAnalysisFPCommute &D) { |
Tyler Nowicki | 65061a2 | 2015-08-11 01:10:08 +0000 | [diff] [blame] | 669 | // Optimization analysis remarks are active if the pass name is set to |
| 670 | // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a |
| 671 | // regular expression that matches the name of the pass name in \p D. |
| 672 | |
Adam Nemet | b5beb97 | 2016-06-29 04:55:31 +0000 | [diff] [blame] | 673 | if (D.shouldAlwaysPrint() || |
Tyler Nowicki | 65061a2 | 2015-08-11 01:10:08 +0000 | [diff] [blame] | 674 | (CodeGenOpts.OptimizationRemarkAnalysisPattern && |
| 675 | CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) |
Tyler Nowicki | 8a0925c | 2015-08-10 19:56:40 +0000 | [diff] [blame] | 676 | EmitOptimizationMessage( |
| 677 | D, diag::remark_fe_backend_optimization_remark_analysis_fpcommute); |
| 678 | } |
| 679 | |
Tyler Nowicki | 034baf6 | 2015-08-10 23:05:16 +0000 | [diff] [blame] | 680 | void BackendConsumer::OptimizationRemarkHandler( |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 681 | const llvm::OptimizationRemarkAnalysisAliasing &D) { |
Tyler Nowicki | 65061a2 | 2015-08-11 01:10:08 +0000 | [diff] [blame] | 682 | // Optimization analysis remarks are active if the pass name is set to |
| 683 | // llvm::DiagnosticInfo::AlwasyPrint or if the -Rpass-analysis flag has a |
| 684 | // regular expression that matches the name of the pass name in \p D. |
| 685 | |
Adam Nemet | b5beb97 | 2016-06-29 04:55:31 +0000 | [diff] [blame] | 686 | if (D.shouldAlwaysPrint() || |
Tyler Nowicki | 65061a2 | 2015-08-11 01:10:08 +0000 | [diff] [blame] | 687 | (CodeGenOpts.OptimizationRemarkAnalysisPattern && |
| 688 | CodeGenOpts.OptimizationRemarkAnalysisPattern->match(D.getPassName()))) |
Tyler Nowicki | 034baf6 | 2015-08-10 23:05:16 +0000 | [diff] [blame] | 689 | EmitOptimizationMessage( |
| 690 | D, diag::remark_fe_backend_optimization_remark_analysis_aliasing); |
| 691 | } |
| 692 | |
Tyler Nowicki | f8a767d | 2014-07-18 19:40:19 +0000 | [diff] [blame] | 693 | void BackendConsumer::OptimizationFailureHandler( |
| 694 | const llvm::DiagnosticInfoOptimizationFailure &D) { |
| 695 | EmitOptimizationMessage(D, diag::warn_fe_backend_optimization_failure); |
| 696 | } |
| 697 | |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 698 | /// \brief This function is invoked when the backend needs |
| 699 | /// to report something to the user. |
| 700 | void BackendConsumer::DiagnosticHandlerImpl(const DiagnosticInfo &DI) { |
| 701 | unsigned DiagID = diag::err_fe_inline_asm; |
| 702 | llvm::DiagnosticSeverity Severity = DI.getSeverity(); |
| 703 | // Get the diagnostic ID based. |
| 704 | switch (DI.getKind()) { |
| 705 | case llvm::DK_InlineAsm: |
| 706 | if (InlineAsmDiagHandler(cast<DiagnosticInfoInlineAsm>(DI))) |
| 707 | return; |
| 708 | ComputeDiagID(Severity, inline_asm, DiagID); |
| 709 | break; |
| 710 | case llvm::DK_StackSize: |
| 711 | if (StackSizeDiagHandler(cast<DiagnosticInfoStackSize>(DI))) |
| 712 | return; |
| 713 | ComputeDiagID(Severity, backend_frame_larger_than, DiagID); |
| 714 | break; |
Rafael Espindola | 8ce88a5 | 2015-12-14 23:17:07 +0000 | [diff] [blame] | 715 | case DK_Linker: |
| 716 | assert(CurLinkModule); |
| 717 | // FIXME: stop eating the warnings and notes. |
| 718 | if (Severity != DS_Error) |
| 719 | return; |
| 720 | DiagID = diag::err_fe_cannot_link_module; |
| 721 | break; |
Diego Novillo | 829b170 | 2014-04-16 16:54:24 +0000 | [diff] [blame] | 722 | case llvm::DK_OptimizationRemark: |
| 723 | // Optimization remarks are always handled completely by this |
| 724 | // handler. There is no generic way of emitting them. |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 725 | OptimizationRemarkHandler(cast<OptimizationRemark>(DI)); |
Diego Novillo | 829b170 | 2014-04-16 16:54:24 +0000 | [diff] [blame] | 726 | return; |
Diego Novillo | 9c89ff1 | 2014-05-29 16:19:27 +0000 | [diff] [blame] | 727 | case llvm::DK_OptimizationRemarkMissed: |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 728 | // Optimization remarks are always handled completely by this |
| 729 | // handler. There is no generic way of emitting them. |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 730 | OptimizationRemarkHandler(cast<OptimizationRemarkMissed>(DI)); |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 731 | return; |
Diego Novillo | 9c89ff1 | 2014-05-29 16:19:27 +0000 | [diff] [blame] | 732 | case llvm::DK_OptimizationRemarkAnalysis: |
Diego Novillo | d23ec94 | 2014-05-29 19:55:06 +0000 | [diff] [blame] | 733 | // Optimization remarks are always handled completely by this |
| 734 | // handler. There is no generic way of emitting them. |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 735 | OptimizationRemarkHandler(cast<OptimizationRemarkAnalysis>(DI)); |
Diego Novillo | 9c89ff1 | 2014-05-29 16:19:27 +0000 | [diff] [blame] | 736 | return; |
Tyler Nowicki | 8a0925c | 2015-08-10 19:56:40 +0000 | [diff] [blame] | 737 | case llvm::DK_OptimizationRemarkAnalysisFPCommute: |
| 738 | // Optimization remarks are always handled completely by this |
| 739 | // handler. There is no generic way of emitting them. |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 740 | OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisFPCommute>(DI)); |
Tyler Nowicki | 8a0925c | 2015-08-10 19:56:40 +0000 | [diff] [blame] | 741 | return; |
Tyler Nowicki | 034baf6 | 2015-08-10 23:05:16 +0000 | [diff] [blame] | 742 | case llvm::DK_OptimizationRemarkAnalysisAliasing: |
| 743 | // Optimization remarks are always handled completely by this |
| 744 | // handler. There is no generic way of emitting them. |
Adam Nemet | b4e64a7 | 2016-09-27 22:19:29 +0000 | [diff] [blame] | 745 | OptimizationRemarkHandler(cast<OptimizationRemarkAnalysisAliasing>(DI)); |
Tyler Nowicki | 034baf6 | 2015-08-10 23:05:16 +0000 | [diff] [blame] | 746 | return; |
Adam Nemet | 7b796f8 | 2017-01-26 04:07:11 +0000 | [diff] [blame] | 747 | case llvm::DK_MachineOptimizationRemark: |
| 748 | // Optimization remarks are always handled completely by this |
| 749 | // handler. There is no generic way of emitting them. |
| 750 | OptimizationRemarkHandler(cast<MachineOptimizationRemark>(DI)); |
| 751 | return; |
| 752 | case llvm::DK_MachineOptimizationRemarkMissed: |
| 753 | // Optimization remarks are always handled completely by this |
| 754 | // handler. There is no generic way of emitting them. |
| 755 | OptimizationRemarkHandler(cast<MachineOptimizationRemarkMissed>(DI)); |
| 756 | return; |
| 757 | case llvm::DK_MachineOptimizationRemarkAnalysis: |
| 758 | // Optimization remarks are always handled completely by this |
| 759 | // handler. There is no generic way of emitting them. |
| 760 | OptimizationRemarkHandler(cast<MachineOptimizationRemarkAnalysis>(DI)); |
| 761 | return; |
Tyler Nowicki | f8a767d | 2014-07-18 19:40:19 +0000 | [diff] [blame] | 762 | case llvm::DK_OptimizationFailure: |
| 763 | // Optimization failures are always handled completely by this |
| 764 | // handler. |
| 765 | OptimizationFailureHandler(cast<DiagnosticInfoOptimizationFailure>(DI)); |
| 766 | return; |
Oliver Stannard | 9181785 | 2016-02-02 13:52:52 +0000 | [diff] [blame] | 767 | case llvm::DK_Unsupported: |
| 768 | UnsupportedDiagHandler(cast<DiagnosticInfoUnsupported>(DI)); |
| 769 | return; |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 770 | default: |
| 771 | // Plugin IDs are not bound to any value as they are set dynamically. |
Tobias Grosser | 7416024 | 2014-02-28 09:11:08 +0000 | [diff] [blame] | 772 | ComputeDiagRemarkID(Severity, backend_plugin, DiagID); |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 773 | break; |
| 774 | } |
| 775 | std::string MsgStorage; |
| 776 | { |
| 777 | raw_string_ostream Stream(MsgStorage); |
| 778 | DiagnosticPrinterRawOStream DP(Stream); |
| 779 | DI.print(DP); |
| 780 | } |
| 781 | |
Rafael Espindola | 8ce88a5 | 2015-12-14 23:17:07 +0000 | [diff] [blame] | 782 | if (DiagID == diag::err_fe_cannot_link_module) { |
| 783 | Diags.Report(diag::err_fe_cannot_link_module) |
| 784 | << CurLinkModule->getModuleIdentifier() << MsgStorage; |
| 785 | return; |
| 786 | } |
| 787 | |
Quentin Colombet | 728c554 | 2014-02-06 18:30:43 +0000 | [diff] [blame] | 788 | // Report the backend message using the usual diagnostic mechanism. |
| 789 | FullSourceLoc Loc; |
| 790 | Diags.Report(Loc, DiagID).AddString(MsgStorage); |
| 791 | } |
| 792 | #undef ComputeDiagID |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 793 | |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 794 | CodeGenAction::CodeGenAction(unsigned _Act, LLVMContext *_VMContext) |
Artem Belevich | 5d40ae3 | 2015-10-27 17:56:59 +0000 | [diff] [blame] | 795 | : Act(_Act), VMContext(_VMContext ? _VMContext : new LLVMContext), |
Eric Christopher | 02e3dd4 | 2016-03-12 01:47:11 +0000 | [diff] [blame] | 796 | OwnsVMContext(!_VMContext) {} |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 797 | |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 798 | CodeGenAction::~CodeGenAction() { |
| 799 | TheModule.reset(); |
| 800 | if (OwnsVMContext) |
| 801 | delete VMContext; |
| 802 | } |
Daniel Dunbar | e8ecf9a | 2010-02-25 20:37:44 +0000 | [diff] [blame] | 803 | |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 804 | bool CodeGenAction::hasIRSupport() const { return true; } |
| 805 | |
Daniel Dunbar | 400a693 | 2010-02-25 04:37:50 +0000 | [diff] [blame] | 806 | void CodeGenAction::EndSourceFileAction() { |
| 807 | // If the consumer creation failed, do nothing. |
| 808 | if (!getCompilerInstance().hasASTConsumer()) |
| 809 | return; |
| 810 | |
| 811 | // Steal the module from the consumer. |
David Blaikie | 780dd3b | 2014-08-29 05:08:19 +0000 | [diff] [blame] | 812 | TheModule = BEConsumer->takeModule(); |
Daniel Dunbar | 400a693 | 2010-02-25 04:37:50 +0000 | [diff] [blame] | 813 | } |
| 814 | |
Rafael Espindola | e833730 | 2014-08-19 14:36:35 +0000 | [diff] [blame] | 815 | std::unique_ptr<llvm::Module> CodeGenAction::takeModule() { |
| 816 | return std::move(TheModule); |
| 817 | } |
| 818 | |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 819 | llvm::LLVMContext *CodeGenAction::takeLLVMContext() { |
| 820 | OwnsVMContext = false; |
| 821 | return VMContext; |
| 822 | } |
| 823 | |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 824 | static std::unique_ptr<raw_pwrite_stream> |
Rafael Espindola | 2f16bc1 | 2015-04-14 15:15:49 +0000 | [diff] [blame] | 825 | GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) { |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 826 | switch (Action) { |
| 827 | case Backend_EmitAssembly: |
| 828 | return CI.createDefaultOutputFile(false, InFile, "s"); |
| 829 | case Backend_EmitLL: |
| 830 | return CI.createDefaultOutputFile(false, InFile, "ll"); |
| 831 | case Backend_EmitBC: |
| 832 | return CI.createDefaultOutputFile(true, InFile, "bc"); |
| 833 | case Backend_EmitNothing: |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 834 | return nullptr; |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 835 | case Backend_EmitMCNull: |
Alp Toker | ea04672 | 2014-06-03 17:23:34 +0000 | [diff] [blame] | 836 | return CI.createNullOutputFile(); |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 837 | case Backend_EmitObj: |
| 838 | return CI.createDefaultOutputFile(true, InFile, "o"); |
| 839 | } |
| 840 | |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 841 | llvm_unreachable("Invalid action!"); |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 842 | } |
| 843 | |
David Blaikie | 6beb6aa | 2014-08-10 19:56:51 +0000 | [diff] [blame] | 844 | std::unique_ptr<ASTConsumer> |
| 845 | CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 846 | BackendAction BA = static_cast<BackendAction>(Act); |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 847 | std::unique_ptr<raw_pwrite_stream> OS = GetOutputStream(CI, InFile, BA); |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 848 | if (BA != Backend_EmitNothing && !OS) |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 849 | return nullptr; |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 850 | |
Artem Belevich | 5d40ae3 | 2015-10-27 17:56:59 +0000 | [diff] [blame] | 851 | // Load bitcode modules to link with, if we need to. |
| 852 | if (LinkModules.empty()) |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 853 | for (const CodeGenOptions::BitcodeFileToLink &F : |
| 854 | CI.getCodeGenOpts().LinkBitcodeFiles) { |
| 855 | auto BCBuf = CI.getFileManager().getBufferForFile(F.Filename); |
Artem Belevich | 5d40ae3 | 2015-10-27 17:56:59 +0000 | [diff] [blame] | 856 | if (!BCBuf) { |
| 857 | CI.getDiagnostics().Report(diag::err_cannot_open_file) |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 858 | << F.Filename << BCBuf.getError().message(); |
Artem Belevich | 5d40ae3 | 2015-10-27 17:56:59 +0000 | [diff] [blame] | 859 | LinkModules.clear(); |
| 860 | return nullptr; |
| 861 | } |
Peter Collingbourne | f1d76db | 2011-10-30 17:30:44 +0000 | [diff] [blame] | 862 | |
Peter Collingbourne | d9445c4 | 2016-11-13 07:00:17 +0000 | [diff] [blame] | 863 | Expected<std::unique_ptr<llvm::Module>> ModuleOrErr = |
Peter Collingbourne | e2dcf7c | 2016-11-08 06:03:43 +0000 | [diff] [blame] | 864 | getOwningLazyBitcodeModule(std::move(*BCBuf), *VMContext); |
Peter Collingbourne | d9445c4 | 2016-11-13 07:00:17 +0000 | [diff] [blame] | 865 | if (!ModuleOrErr) { |
| 866 | handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) { |
| 867 | CI.getDiagnostics().Report(diag::err_cannot_open_file) |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 868 | << F.Filename << EIB.message(); |
Peter Collingbourne | d9445c4 | 2016-11-13 07:00:17 +0000 | [diff] [blame] | 869 | }); |
Artem Belevich | 5d40ae3 | 2015-10-27 17:56:59 +0000 | [diff] [blame] | 870 | LinkModules.clear(); |
| 871 | return nullptr; |
| 872 | } |
Jonas Devlieghere | 5eb9c81 | 2017-03-13 18:08:11 +0000 | [diff] [blame] | 873 | LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs, |
| 874 | F.Internalize, F.LinkFlags}); |
Peter Collingbourne | f1d76db | 2011-10-30 17:30:44 +0000 | [diff] [blame] | 875 | } |
Peter Collingbourne | f1d76db | 2011-10-30 17:30:44 +0000 | [diff] [blame] | 876 | |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 877 | CoverageSourceInfo *CoverageInfo = nullptr; |
| 878 | // Add the preprocessor callback only when the coverage mapping is generated. |
| 879 | if (CI.getCodeGenOpts().CoverageMapping) { |
| 880 | CoverageInfo = new CoverageSourceInfo; |
Craig Topper | b8a7053 | 2014-09-10 04:53:53 +0000 | [diff] [blame] | 881 | CI.getPreprocessor().addPPCallbacks( |
| 882 | std::unique_ptr<PPCallbacks>(CoverageInfo)); |
Alex Lorenz | ee02499 | 2014-08-04 18:41:51 +0000 | [diff] [blame] | 883 | } |
Artem Belevich | 5d40ae3 | 2015-10-27 17:56:59 +0000 | [diff] [blame] | 884 | |
David Blaikie | 037e75b | 2014-08-10 21:06:17 +0000 | [diff] [blame] | 885 | std::unique_ptr<BackendConsumer> Result(new BackendConsumer( |
Adrian Prantl | e74f525 | 2015-06-30 02:26:03 +0000 | [diff] [blame] | 886 | BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(), |
| 887 | CI.getPreprocessorOpts(), CI.getCodeGenOpts(), CI.getTargetOpts(), |
Justin Lebar | b080b63 | 2017-01-25 21:29:48 +0000 | [diff] [blame] | 888 | CI.getLangOpts(), CI.getFrontendOpts().ShowTimers, InFile, |
| 889 | std::move(LinkModules), std::move(OS), *VMContext, CoverageInfo)); |
David Blaikie | 6beb6aa | 2014-08-10 19:56:51 +0000 | [diff] [blame] | 890 | BEConsumer = Result.get(); |
Amjad Aboud | 546bc11 | 2017-02-09 22:07:24 +0000 | [diff] [blame] | 891 | |
| 892 | // Enable generating macro debug info only when debug info is not disabled and |
| 893 | // also macro debug info is enabled. |
| 894 | if (CI.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo && |
| 895 | CI.getCodeGenOpts().MacroDebugInfo) { |
| 896 | std::unique_ptr<PPCallbacks> Callbacks = |
| 897 | llvm::make_unique<MacroPPCallbacks>(BEConsumer->getCodeGenerator(), |
| 898 | CI.getPreprocessor()); |
| 899 | CI.getPreprocessor().addPPCallbacks(std::move(Callbacks)); |
| 900 | } |
| 901 | |
David Blaikie | 6beb6aa | 2014-08-10 19:56:51 +0000 | [diff] [blame] | 902 | return std::move(Result); |
Daniel Dunbar | c13935e | 2008-10-21 23:49:24 +0000 | [diff] [blame] | 903 | } |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 904 | |
Tim Northover | 1390b44 | 2016-04-06 19:58:07 +0000 | [diff] [blame] | 905 | static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM, |
| 906 | void *Context, |
| 907 | unsigned LocCookie) { |
| 908 | SM.print(nullptr, llvm::errs()); |
| 909 | |
| 910 | auto Diags = static_cast<DiagnosticsEngine *>(Context); |
| 911 | unsigned DiagID; |
| 912 | switch (SM.getKind()) { |
| 913 | case llvm::SourceMgr::DK_Error: |
| 914 | DiagID = diag::err_fe_inline_asm; |
| 915 | break; |
| 916 | case llvm::SourceMgr::DK_Warning: |
| 917 | DiagID = diag::warn_fe_inline_asm; |
| 918 | break; |
| 919 | case llvm::SourceMgr::DK_Note: |
| 920 | DiagID = diag::note_fe_inline_asm; |
| 921 | break; |
| 922 | } |
| 923 | |
| 924 | Diags->Report(DiagID).AddString("cannot compile inline asm"); |
| 925 | } |
| 926 | |
Peter Collingbourne | 65cb42c | 2017-01-24 19:55:38 +0000 | [diff] [blame] | 927 | std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) { |
| 928 | CompilerInstance &CI = getCompilerInstance(); |
| 929 | SourceManager &SM = CI.getSourceManager(); |
| 930 | |
| 931 | // For ThinLTO backend invocations, ensure that the context |
Peter Collingbourne | f5d1712 | 2017-01-26 21:09:48 +0000 | [diff] [blame] | 932 | // merges types based on ODR identifiers. We also need to read |
| 933 | // the correct module out of a multi-module bitcode file. |
| 934 | if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) { |
Peter Collingbourne | 65cb42c | 2017-01-24 19:55:38 +0000 | [diff] [blame] | 935 | VMContext->enableDebugTypeODRUniquing(); |
| 936 | |
Peter Collingbourne | f5d1712 | 2017-01-26 21:09:48 +0000 | [diff] [blame] | 937 | auto DiagErrors = [&](Error E) -> std::unique_ptr<llvm::Module> { |
| 938 | unsigned DiagID = |
| 939 | CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0"); |
| 940 | handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) { |
| 941 | CI.getDiagnostics().Report(DiagID) << EIB.message(); |
| 942 | }); |
| 943 | return {}; |
| 944 | }; |
| 945 | |
| 946 | Expected<llvm::BitcodeModule> BMOrErr = FindThinLTOModule(MBRef); |
| 947 | if (!BMOrErr) |
| 948 | return DiagErrors(BMOrErr.takeError()); |
| 949 | |
| 950 | Expected<std::unique_ptr<llvm::Module>> MOrErr = |
| 951 | BMOrErr->parseModule(*VMContext); |
| 952 | if (!MOrErr) |
| 953 | return DiagErrors(MOrErr.takeError()); |
| 954 | return std::move(*MOrErr); |
| 955 | } |
| 956 | |
Peter Collingbourne | 65cb42c | 2017-01-24 19:55:38 +0000 | [diff] [blame] | 957 | llvm::SMDiagnostic Err; |
| 958 | if (std::unique_ptr<llvm::Module> M = parseIR(MBRef, Err, *VMContext)) |
| 959 | return M; |
| 960 | |
| 961 | // Translate from the diagnostic info to the SourceManager location if |
| 962 | // available. |
| 963 | // TODO: Unify this with ConvertBackendLocation() |
| 964 | SourceLocation Loc; |
| 965 | if (Err.getLineNo() > 0) { |
| 966 | assert(Err.getColumnNo() >= 0); |
| 967 | Loc = SM.translateFileLineCol(SM.getFileEntryForID(SM.getMainFileID()), |
| 968 | Err.getLineNo(), Err.getColumnNo() + 1); |
| 969 | } |
| 970 | |
| 971 | // Strip off a leading diagnostic code if there is one. |
| 972 | StringRef Msg = Err.getMessage(); |
| 973 | if (Msg.startswith("error: ")) |
| 974 | Msg = Msg.substr(7); |
| 975 | |
| 976 | unsigned DiagID = |
| 977 | CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0"); |
| 978 | |
| 979 | CI.getDiagnostics().Report(Loc, DiagID) << Msg; |
| 980 | return {}; |
| 981 | } |
| 982 | |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 983 | void CodeGenAction::ExecuteAction() { |
| 984 | // If this is an IR file, we have to treat it specially. |
Richard Smith | 40c0efa | 2017-04-26 18:57:40 +0000 | [diff] [blame] | 985 | if (getCurrentFileKind().getLanguage() == InputKind::LLVM_IR) { |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 986 | BackendAction BA = static_cast<BackendAction>(Act); |
| 987 | CompilerInstance &CI = getCompilerInstance(); |
Peter Collingbourne | 03f8907 | 2016-07-15 00:55:40 +0000 | [diff] [blame] | 988 | std::unique_ptr<raw_pwrite_stream> OS = |
| 989 | GetOutputStream(CI, getCurrentFile(), BA); |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 990 | if (BA != Backend_EmitNothing && !OS) |
| 991 | return; |
| 992 | |
| 993 | bool Invalid; |
| 994 | SourceManager &SM = CI.getSourceManager(); |
Alp Toker | 7b463d5 | 2014-06-30 01:33:59 +0000 | [diff] [blame] | 995 | FileID FID = SM.getMainFileID(); |
| 996 | llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid); |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 997 | if (Invalid) |
| 998 | return; |
| 999 | |
Peter Collingbourne | 65cb42c | 2017-01-24 19:55:38 +0000 | [diff] [blame] | 1000 | TheModule = loadModule(*MainFile); |
| 1001 | if (!TheModule) |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 1002 | return; |
Peter Collingbourne | 65cb42c | 2017-01-24 19:55:38 +0000 | [diff] [blame] | 1003 | |
Rafael Espindola | d5e81e5 | 2013-12-20 22:01:25 +0000 | [diff] [blame] | 1004 | const TargetOptions &TargetOpts = CI.getTargetOpts(); |
| 1005 | if (TheModule->getTargetTriple() != TargetOpts.Triple) { |
Nico Weber | 6cf2df2 | 2015-01-29 06:25:59 +0000 | [diff] [blame] | 1006 | CI.getDiagnostics().Report(SourceLocation(), |
| 1007 | diag::warn_fe_override_module) |
| 1008 | << TargetOpts.Triple; |
Rafael Espindola | d5e81e5 | 2013-12-20 22:01:25 +0000 | [diff] [blame] | 1009 | TheModule->setTargetTriple(TargetOpts.Triple); |
| 1010 | } |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 1011 | |
Steven Wu | 27fb522 | 2016-05-11 16:26:03 +0000 | [diff] [blame] | 1012 | EmbedBitcode(TheModule.get(), CI.getCodeGenOpts(), |
| 1013 | MainFile->getMemBufferRef()); |
| 1014 | |
Tim Northover | 1390b44 | 2016-04-06 19:58:07 +0000 | [diff] [blame] | 1015 | LLVMContext &Ctx = TheModule->getContext(); |
| 1016 | Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler, |
| 1017 | &CI.getDiagnostics()); |
Steven Wu | 27fb522 | 2016-05-11 16:26:03 +0000 | [diff] [blame] | 1018 | |
Saleem Abdulrasool | 888e289 | 2017-01-05 16:02:32 +0000 | [diff] [blame] | 1019 | EmitBackendOutput(CI.getDiagnostics(), CI.getHeaderSearchOpts(), |
| 1020 | CI.getCodeGenOpts(), TargetOpts, CI.getLangOpts(), |
| 1021 | CI.getTarget().getDataLayout(), TheModule.get(), BA, |
| 1022 | std::move(OS)); |
Daniel Dunbar | 6f8362c | 2010-06-07 23:27:59 +0000 | [diff] [blame] | 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | // Otherwise follow the normal AST path. |
| 1027 | this->ASTFrontendAction::ExecuteAction(); |
| 1028 | } |
| 1029 | |
| 1030 | // |
| 1031 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1032 | void EmitAssemblyAction::anchor() { } |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 1033 | EmitAssemblyAction::EmitAssemblyAction(llvm::LLVMContext *_VMContext) |
| 1034 | : CodeGenAction(Backend_EmitAssembly, _VMContext) {} |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 1035 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1036 | void EmitBCAction::anchor() { } |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 1037 | EmitBCAction::EmitBCAction(llvm::LLVMContext *_VMContext) |
| 1038 | : CodeGenAction(Backend_EmitBC, _VMContext) {} |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 1039 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1040 | void EmitLLVMAction::anchor() { } |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 1041 | EmitLLVMAction::EmitLLVMAction(llvm::LLVMContext *_VMContext) |
| 1042 | : CodeGenAction(Backend_EmitLL, _VMContext) {} |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 1043 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1044 | void EmitLLVMOnlyAction::anchor() { } |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 1045 | EmitLLVMOnlyAction::EmitLLVMOnlyAction(llvm::LLVMContext *_VMContext) |
| 1046 | : CodeGenAction(Backend_EmitNothing, _VMContext) {} |
Daniel Dunbar | cea0c70 | 2010-02-25 04:37:45 +0000 | [diff] [blame] | 1047 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1048 | void EmitCodeGenOnlyAction::anchor() { } |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 1049 | EmitCodeGenOnlyAction::EmitCodeGenOnlyAction(llvm::LLVMContext *_VMContext) |
| 1050 | : CodeGenAction(Backend_EmitMCNull, _VMContext) {} |
Daniel Dunbar | 4c77a64 | 2010-05-25 18:41:01 +0000 | [diff] [blame] | 1051 | |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 1052 | void EmitObjAction::anchor() { } |
Peter Collingbourne | 8f5cf74 | 2011-02-19 23:03:58 +0000 | [diff] [blame] | 1053 | EmitObjAction::EmitObjAction(llvm::LLVMContext *_VMContext) |
| 1054 | : CodeGenAction(Backend_EmitObj, _VMContext) {} |