Skip to content

Commit 4f6b171

Browse files
committed
[llvm-mc] Add reportWarning() to MCContext
Adding reportWarning() to MCContext, so that it can be used from the Hexagon assembler backend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368327 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3d3e1b8 commit 4f6b171

File tree

6 files changed

+51
-14
lines changed

6 files changed

+51
-14
lines changed

include/llvm/MC/MCContext.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/MC/MCAsmMacro.h"
2323
#include "llvm/MC/MCDwarf.h"
2424
#include "llvm/MC/MCSubtargetInfo.h"
25+
#include "llvm/MC/MCTargetOptions.h"
2526
#include "llvm/MC/SectionKind.h"
2627
#include "llvm/Support/Allocator.h"
2728
#include "llvm/Support/Compiler.h"
@@ -275,6 +276,8 @@ namespace llvm {
275276
/// Do automatic reset in destructor
276277
bool AutoReset;
277278

279+
MCTargetOptions const *TargetOptions;
280+
278281
bool HadError = false;
279282

280283
MCSymbol *createSymbolImpl(const StringMapEntry<bool> *Name,
@@ -298,7 +301,9 @@ namespace llvm {
298301
public:
299302
explicit MCContext(const MCAsmInfo *MAI, const MCRegisterInfo *MRI,
300303
const MCObjectFileInfo *MOFI,
301-
const SourceMgr *Mgr = nullptr, bool DoAutoReset = true);
304+
const SourceMgr *Mgr = nullptr,
305+
MCTargetOptions const *TargetOpts = nullptr,
306+
bool DoAutoReset = true);
302307
MCContext(const MCContext &) = delete;
303308
MCContext &operator=(const MCContext &) = delete;
304309
~MCContext();
@@ -659,6 +664,7 @@ namespace llvm {
659664

660665
bool hadError() { return HadError; }
661666
void reportError(SMLoc L, const Twine &Msg);
667+
void reportWarning(SMLoc L, const Twine &Msg);
662668
// Unrecoverable error has occurred. Display the best diagnostic we can
663669
// and bail via exit(1). For now, most MC backend errors are unrecoverable.
664670
// FIXME: We should really do something about that.

lib/CodeGen/MachineModuleInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ void MMIAddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) {
194194
}
195195

196196
MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM)
197-
: ImmutablePass(ID), TM(*TM),
198-
Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
199-
TM->getObjFileLowering(), nullptr, false) {
197+
: ImmutablePass(ID), TM(*TM),
198+
Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
199+
TM->getObjFileLowering(), nullptr, nullptr, false) {
200200
initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry());
201201
}
202202

lib/MC/MCContext.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ AsSecureLogFileName("as-secure-log-file-name",
5858

5959
MCContext::MCContext(const MCAsmInfo *mai, const MCRegisterInfo *mri,
6060
const MCObjectFileInfo *mofi, const SourceMgr *mgr,
61-
bool DoAutoReset)
61+
MCTargetOptions const *TargetOpts, bool DoAutoReset)
6262
: SrcMgr(mgr), InlineSrcMgr(nullptr), MAI(mai), MRI(mri), MOFI(mofi),
6363
Symbols(Allocator), UsedNames(Allocator),
6464
CurrentDwarfLoc(0, 0, 0, DWARF2_FLAG_IS_STMT, 0, 0),
65-
AutoReset(DoAutoReset) {
65+
AutoReset(DoAutoReset), TargetOptions(TargetOpts) {
6666
SecureLogFile = AsSecureLogFileName;
6767

6868
if (SrcMgr && SrcMgr->getNumBuffers())
@@ -691,6 +691,21 @@ void MCContext::reportError(SMLoc Loc, const Twine &Msg) {
691691
report_fatal_error(Msg, false);
692692
}
693693

694+
void MCContext::reportWarning(SMLoc Loc, const Twine &Msg) {
695+
if (TargetOptions && TargetOptions->MCNoWarn)
696+
return;
697+
if (TargetOptions && TargetOptions->MCFatalWarnings)
698+
reportError(Loc, Msg);
699+
else {
700+
// If we have a source manager use it. Otherwise, try using the inline
701+
// source manager.
702+
if (SrcMgr)
703+
SrcMgr->PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
704+
else if (InlineSrcMgr)
705+
InlineSrcMgr->PrintMessage(Loc, SourceMgr::DK_Warning, Msg);
706+
}
707+
}
708+
694709
void MCContext::reportFatalError(SMLoc Loc, const Twine &Msg) {
695710
reportError(Loc, Msg);
696711

lib/Target/Hexagon/MCTargetDesc/HexagonMCChecker.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,9 +726,6 @@ void HexagonMCChecker::reportNote(SMLoc Loc, llvm::Twine const &Msg) {
726726
}
727727

728728
void HexagonMCChecker::reportWarning(Twine const &Msg) {
729-
if (ReportErrors) {
730-
auto SM = Context.getSourceManager();
731-
if (SM)
732-
SM->PrintMessage(MCB.getLoc(), SourceMgr::DK_Warning, Msg);
733-
}
729+
if (ReportErrors)
730+
Context.reportWarning(MCB.getLoc(), Msg);
734731
}

test/MC/Hexagon/nowarn.s

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# RUN: llvm-mc -arch=hexagon -mhvx --filetype=asm %s -o - 2>&1 | FileCheck %s
2+
# RUN: llvm-mc --no-warn -arch=hexagon -mhvx --filetype=obj %s -o - | llvm-objdump -d - | FileCheck --check-prefix=CHECK-NOWARN %s
3+
# RUN: not llvm-mc --fatal-warnings -arch=hexagon -mhvx --filetype=asm %s 2>&1 | FileCheck --check-prefix=CHECK-FATAL-WARN %s
4+
5+
.text
6+
.warning
7+
8+
{
9+
v7.tmp = vmem(r28 + #3)
10+
v7:6.w = vadd(v17:16.w, v17:16.w)
11+
v17:16.uw = vunpack(v8.uh)
12+
}
13+
14+
# CHECK-NOWARN-NOT: warning
15+
# CHECK-FATAL-WARN-NOT: warning
16+
# CHECK-FATAL-WARN: error
17+
# CHECK-FATAL-WARN: error
18+
# CHECK: warning:
19+
# CHECK: warning:

tools/llvm-mc/llvm-mc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static int fillCommandLineSymbols(MCAsmParser &Parser) {
279279
static int AssembleInput(const char *ProgName, const Target *TheTarget,
280280
SourceMgr &SrcMgr, MCContext &Ctx, MCStreamer &Str,
281281
MCAsmInfo &MAI, MCSubtargetInfo &STI,
282-
MCInstrInfo &MCII, MCTargetOptions &MCOptions) {
282+
MCInstrInfo &MCII, MCTargetOptions const &MCOptions) {
283283
std::unique_ptr<MCAsmParser> Parser(
284284
createMCAsmParser(SrcMgr, Ctx, Str, MAI));
285285
std::unique_ptr<MCTargetAsmParser> TAP(
@@ -316,7 +316,7 @@ int main(int argc, char **argv) {
316316
cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
317317

318318
cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
319-
MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
319+
const MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
320320
setDwarfDebugFlags(argc, argv);
321321

322322
setDwarfDebugProducer();
@@ -368,7 +368,7 @@ int main(int argc, char **argv) {
368368
// FIXME: This is not pretty. MCContext has a ptr to MCObjectFileInfo and
369369
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
370370
MCObjectFileInfo MOFI;
371-
MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr);
371+
MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr, &MCOptions);
372372
MOFI.InitMCObjectFileInfo(TheTriple, PIC, Ctx, LargeCodeModel);
373373

374374
if (SaveTempLabels)

0 commit comments

Comments
 (0)