[llvm] r368327 - [llvm-mc] Add reportWarning() to MCContext
Brian Cain via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 8 12:13:24 PDT 2019
Author: bcain
Date: Thu Aug 8 12:13:23 2019
New Revision: 368327
URL: http://llvm.org/viewvc/llvm-project?rev=368327&view=rev
Log:
[llvm-mc] Add reportWarning() to MCContext
Adding reportWarning() to MCContext, so that it can be used from
the Hexagon assembler backend.
Added:
llvm/trunk/test/MC/Hexagon/nowarn.s
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp
llvm/trunk/tools/llvm-mc/llvm-mc.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=368327&r1=368326&r2=368327&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Thu Aug 8 12:13:23 2019
@@ -22,6 +22,7 @@
#include "llvm/MC/MCAsmMacro.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCSubtargetInfo.h"
+#include "llvm/MC/MCTargetOptions.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
@@ -275,6 +276,8 @@ namespace llvm {
/// Do automatic reset in destructor
bool AutoReset;
+ MCTargetOptions const *TargetOptions;
+
bool HadError = false;
MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
@@ -298,7 +301,9 @@ namespace llvm {
public:
explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI,
const MCObjectFileInfo *MOFI,
- const SourceMgr *Mgr = nullptr, bool DoAutoReset = true);
+ const SourceMgr *Mgr = nullptr,
+ MCTargetOptions const *TargetOpts = nullptr,
+ bool DoAutoReset = true);
MCContext(const MCContext &) = delete;
MCContext &operator=(const MCContext &) = delete;
~MCContext();
@@ -659,6 +664,7 @@ namespace llvm {
bool hadError() { return HadError; }
void reportError(SMLoc L, const Twine &Msg);
+ void reportWarning(SMLoc L, const Twine &Msg);
// Unrecoverable error has occurred. Display the best diagnostic we can
// and bail via exit(1). For now, most MC backend errors are unrecoverable.
// FIXME: We should really do something about that.
Modified: llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp?rev=368327&r1=368326&r2=368327&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineModuleInfo.cpp Thu Aug 8 12:13:23 2019
@@ -194,9 +194,9 @@ void MMIAddrLabelMapCallbackPtr::allUses
}
MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM)
- : ImmutablePass(ID), TM(*TM),
- Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
- TM->getObjFileLowering(), nullptr, false) {
+ : ImmutablePass(ID), TM(*TM),
+ Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
+ TM->getObjFileLowering(), nullptr, nullptr, false) {
initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry());
}
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=368327&r1=368326&r2=368327&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Thu Aug 8 12:13:23 2019
@@ -58,11 +58,11 @@ AsSecureLogFileName("as-secure-log-file-
MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
const MCObjectFileInfo *mofi, const SourceMgr *mgr,
- bool DoAutoReset)
+ MCTargetOptions const *TargetOpts, bool DoAutoReset)
: SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai), MRI(mri), MOFI(mofi),
Symbols(Allocator), UsedNames(Allocator),
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
- AutoReset(DoAutoReset) {
+ AutoReset(DoAutoReset), TargetOptions(TargetOpts) {
SecureLogFile = AsSecureLogFileName;
if (SrcMgr && SrcMgr->getNumBuffers())
@@ -691,6 +691,21 @@ void MCContext::reportError(SMLoc Loc, c
report_fatal_error(Msg, false);
}
+void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
+ if (TargetOptions && TargetOptions->MCNoWarn)
+ return;
+ if (TargetOptions && TargetOptions->MCFatalWarnings)
+ reportError(Loc, Msg);
+ else {
+ // If we have a source manager use it. Otherwise, try using the inline
+ // source manager.
+ if (SrcMgr)
+ SrcMgr->PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
+ else if (InlineSrcMgr)
+ InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
+ }
+}
+
void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) {
reportError(Loc, Msg);
Modified: llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp?rev=368327&r1=368326&r2=368327&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp Thu Aug 8 12:13:23 2019
@@ -726,9 +726,6 @@ void HexagonMCChecker::reportNote(SMLoc
}
void HexagonMCChecker::reportWarning(Twine const &Msg) {
- if (ReportErrors) {
- auto SM = Context.getSourceManager();
- if (SM)
- SM->PrintMessage(MCB.getLoc(), SourceMgr::DK_Warning, Msg);
- }
+ if (ReportErrors)
+ Context.reportWarning(MCB.getLoc(), Msg);
}
Added: llvm/trunk/test/MC/Hexagon/nowarn.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Hexagon/nowarn.s?rev=368327&view=auto
==============================================================================
--- llvm/trunk/test/MC/Hexagon/nowarn.s (added)
+++ llvm/trunk/test/MC/Hexagon/nowarn.s Thu Aug 8 12:13:23 2019
@@ -0,0 +1,19 @@
+# RUN: llvm-mc -arch=hexagon -mhvx --filetype=asm %s -o - 2>&1 | FileCheck %s
+# RUN: llvm-mc --no-warn -arch=hexagon -mhvx --filetype=obj %s -o - | llvm-objdump -d - | FileCheck --check-prefix=CHECK-NOWARN %s
+# RUN: not llvm-mc --fatal-warnings -arch=hexagon -mhvx --filetype=asm %s 2>&1 | FileCheck --check-prefix=CHECK-FATAL-WARN %s
+
+ .text
+ .warning
+
+{
+ v7.tmp = vmem(r28 + #3)
+ v7:6.w = vadd(v17:16.w, v17:16.w)
+ v17:16.uw = vunpack(v8.uh)
+}
+
+# CHECK-NOWARN-NOT: warning
+# CHECK-FATAL-WARN-NOT: warning
+# CHECK-FATAL-WARN: error
+# CHECK-FATAL-WARN: error
+# CHECK: warning:
+# CHECK: warning:
Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=368327&r1=368326&r2=368327&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Thu Aug 8 12:13:23 2019
@@ -279,7 +279,7 @@ static int fillCommandLineSymbols(MCAsmP
static int AssembleInput(const char *ProgName, const Target *TheTarget,
SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str,
MCAsmInfo &MAI, MCSubtargetInfo &STI,
- MCInstrInfo &MCII, MCTargetOptions &MCOptions) {
+ MCInstrInfo &MCII, MCTargetOptions const &MCOptions) {
std::unique_ptr<MCAsmParser> Parser(
createMCAsmParser(SrcMgr, Ctx, Str, MAI));
std::unique_ptr<MCTargetAsmParser> TAP(
@@ -316,7 +316,7 @@ int main(int argc, char **argv) {
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
- MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
+ const MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
setDwarfDebugFlags(argc, argv);
setDwarfDebugProducer();
@@ -368,7 +368,7 @@ int main(int argc, char **argv) {
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
MCObjectFileInfo MOFI;
- MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr);
+ MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr, &MCOptions);
MOFI.InitMCObjectFileInfo(TheTriple, PIC, Ctx, LargeCodeModel);
if (SaveTempLabels)
More information about the llvm-commits
mailing list