[PATCH] D29411: [Assembler] Move SourceMgr and DiagInfo into AsmPrinter.
Sanne Wouda via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 11:41:06 PST 2017
sanwou01 created this revision.
This ensures these objects are still around during finalization.
https://reviews.llvm.org/D29411
Files:
include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
Index: lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -40,19 +40,12 @@
#define DEBUG_TYPE "asm-printer"
-namespace {
- struct SrcMgrDiagInfo {
- const MDNode *LocInfo;
- LLVMContext::InlineAsmDiagHandlerTy DiagHandler;
- void *DiagContext;
- };
-}
-
/// srcMgrDiagHandler - This callback is invoked when the SourceMgr for an
/// inline asm has an error in it. diagInfo is a pointer to the SrcMgrDiagInfo
/// struct above.
static void srcMgrDiagHandler(const SMDiagnostic &Diag, void *diagInfo) {
- SrcMgrDiagInfo *DiagInfo = static_cast<SrcMgrDiagInfo *>(diagInfo);
+ AsmPrinter::SrcMgrDiagInfo *DiagInfo =
+ static_cast<AsmPrinter::SrcMgrDiagInfo *>(diagInfo);
assert(DiagInfo && "Diagnostic context not passed down?");
// If the inline asm had metadata associated with it, pull out a location
@@ -99,15 +92,15 @@
return;
}
- SourceMgr SrcMgr;
+ SourceMgr &SrcMgr = *getInlineSourceManager();
SrcMgr.setIncludeDirs(MCOptions.IASSearchPaths);
- SrcMgrDiagInfo DiagInfo;
// If the current LLVMContext has an inline asm handler, set it in SourceMgr.
LLVMContext &LLVMCtx = MMI->getModule()->getContext();
bool HasDiagHandler = false;
if (LLVMCtx.getInlineAsmDiagnosticHandler() != nullptr) {
+ SrcMgrDiagInfo &DiagInfo = getNewDiagInfo();
// If the source manager has an issue, we arrange for srcMgrDiagHandler
// to be invoked, getting DiagInfo passed into it.
DiagInfo.LocInfo = LocMDNode;
Index: include/llvm/CodeGen/AsmPrinter.h
===================================================================
--- include/llvm/CodeGen/AsmPrinter.h
+++ include/llvm/CodeGen/AsmPrinter.h
@@ -23,6 +23,7 @@
#include "llvm/IR/InlineAsm.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/SourceMgr.h"
namespace llvm {
class AsmPrinterHandler;
@@ -109,6 +110,9 @@
MCSymbol *CurrentFnEnd;
MCSymbol *CurExceptionSym;
+ /// A SourceMgr for inline assembly.
+ mutable std::unique_ptr<SourceMgr> InlineSrcMgr;
+
// The garbage collection metadata printer table.
void *GCMetadataPrinters; // Really a DenseMap.
@@ -137,6 +141,27 @@
/// maintains ownership of the emitters.
SmallVector<HandlerInfo, 1> Handlers;
+public:
+ struct SrcMgrDiagInfo {
+ const MDNode *LocInfo;
+ LLVMContext::InlineAsmDiagHandlerTy DiagHandler;
+ void *DiagContext;
+ };
+
+private:
+ mutable std::vector<std::unique_ptr<SrcMgrDiagInfo>> DiagInfos;
+
+ SourceMgr *getInlineSourceManager() const {
+ if (!InlineSrcMgr)
+ InlineSrcMgr = make_unique<SourceMgr>();
+
+ return InlineSrcMgr.get();
+ }
+
+ SrcMgrDiagInfo &getNewDiagInfo() const {
+ DiagInfos.push_back(make_unique<SrcMgrDiagInfo>());
+ return *DiagInfos.back();
+ }
/// If the target supports dwarf debug info, this pointer is non-null.
DwarfDebug *DD;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29411.86689.patch
Type: text/x-patch
Size: 3053 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170201/fab58980/attachment.bin>
More information about the llvm-commits
mailing list