Skip to content

Commit 1695f88

Browse files
committed
fixup: Fix target specific diags that were missed
1 parent 7327ce4 commit 1695f88

15 files changed

+76
-72
lines changed

llvm/include/llvm/IR/DiagnosticPrinter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class Module;
2424
class raw_ostream;
2525
class SMDiagnostic;
2626
class StringRef;
27-
class Twine;
2827
class Value;
2928

3029
/// Interface for custom diagnostic printing.
@@ -47,7 +46,6 @@ class DiagnosticPrinter {
4746
virtual DiagnosticPrinter &operator<<(unsigned int N) = 0;
4847
virtual DiagnosticPrinter &operator<<(int N) = 0;
4948
virtual DiagnosticPrinter &operator<<(double N) = 0;
50-
virtual DiagnosticPrinter &operator<<(const Twine &Str) = 0;
5149

5250
// IR related types.
5351
virtual DiagnosticPrinter &operator<<(const Value &V) = 0;
@@ -80,7 +78,6 @@ class DiagnosticPrinterRawOStream : public DiagnosticPrinter {
8078
DiagnosticPrinter &operator<<(unsigned int N) override;
8179
DiagnosticPrinter &operator<<(int N) override;
8280
DiagnosticPrinter &operator<<(double N) override;
83-
DiagnosticPrinter &operator<<(const Twine &Str) override;
8481

8582
// IR related types.
8683
DiagnosticPrinter &operator<<(const Value &V) override;

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "llvm/Support/CodeGen.h"
6565
#include "llvm/Support/ErrorHandling.h"
6666
#include "llvm/Support/Format.h"
67+
#include "llvm/Support/FormatVariadic.h"
6768
#include "llvm/Support/raw_ostream.h"
6869
#include "llvm/Target/TargetMachine.h"
6970
#include "llvm/TargetParser/Triple.h"
@@ -706,10 +707,10 @@ getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
706707

707708
namespace {
708709
class LoweringDiagnosticInfo : public DiagnosticInfo {
709-
const Twine &Msg;
710+
StringRef Msg;
710711

711712
public:
712-
LoweringDiagnosticInfo(const Twine &DiagMsg,
713+
LoweringDiagnosticInfo(StringRef DiagMsg,
713714
DiagnosticSeverity Severity = DS_Error)
714715
: DiagnosticInfo(DK_Lowering, Severity), Msg(DiagMsg) {}
715716
void print(DiagnosticPrinter &DP) const override { DP << Msg; }
@@ -869,15 +870,17 @@ static MCSection *selectExplicitSectionGlobal(const GlobalObject *GO,
869870
// been placed in an incompatible mergeable section. Emit an error if this
870871
// is the case to avoid creating broken output.
871872
if ((Section->getFlags() & ELF::SHF_MERGE) &&
872-
(Section->getEntrySize() != getEntrySizeForKind(Kind)))
873-
GO->getContext().diagnose(LoweringDiagnosticInfo(
874-
"Symbol '" + GO->getName() + "' from module '" +
875-
(GO->getParent() ? GO->getParent()->getSourceFileName() : "unknown") +
876-
"' required a section with entry-size=" +
877-
Twine(getEntrySizeForKind(Kind)) + " but was placed in section '" +
878-
SectionName + "' with entry-size=" + Twine(Section->getEntrySize()) +
879-
": Explicit assignment by pragma or attribute of an incompatible "
880-
"symbol to this section?"));
873+
(Section->getEntrySize() != getEntrySizeForKind(Kind))) {
874+
SmallString<128> Msg = formatv(
875+
"Symbol '{0}' from module '{1}' required a section with "
876+
"entry-size={2} but was placed in section '{3}' with entry-size={4}: "
877+
"Explicit assignment by pragma or attribute of an incompatible "
878+
"symbol to this section?",
879+
GO->getName(),
880+
GO->getParent() ? GO->getParent()->getSourceFileName() : "unknown",
881+
getEntrySizeForKind(Kind), SectionName, Section->getEntrySize());
882+
GO->getContext().diagnose(LoweringDiagnosticInfo(Msg));
883+
}
881884
}
882885

883886
return Section;

llvm/lib/IR/DiagnosticPrinter.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(double N) {
9090
return *this;
9191
}
9292

93-
DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Twine &Str) {
94-
Str.print(Stream);
95-
return *this;
96-
}
97-
9893
// IR related types.
9994
DiagnosticPrinter &DiagnosticPrinterRawOStream::operator<<(const Value &V) {
10095
// Avoid printing '@' prefix for named functions.

llvm/lib/LTO/LTOCodeGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,9 +744,9 @@ LTOCodeGenerator::setDiagnosticHandler(lto_diagnostic_handler_t DiagHandler,
744744

745745
namespace {
746746
class LTODiagnosticInfo : public DiagnosticInfo {
747-
const Twine &Msg;
747+
StringRef Msg;
748748
public:
749-
LTODiagnosticInfo(const Twine &DiagMsg, DiagnosticSeverity Severity=DS_Error)
749+
LTODiagnosticInfo(StringRef DiagMsg, DiagnosticSeverity Severity=DS_Error)
750750
: DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
751751
void print(DiagnosticPrinter &DP) const override { DP << Msg; }
752752
};

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ static void promoteModule(Module &TheModule, const ModuleSummaryIndex &Index,
165165

166166
namespace {
167167
class ThinLTODiagnosticInfo : public DiagnosticInfo {
168-
const Twine &Msg;
168+
StringRef Msg;
169169
public:
170-
ThinLTODiagnosticInfo(const Twine &DiagMsg,
170+
ThinLTODiagnosticInfo(StringRef DiagMsg,
171171
DiagnosticSeverity Severity = DS_Error)
172172
: DiagnosticInfo(DK_Linker, Severity), Msg(DiagMsg) {}
173173
void print(DiagnosticPrinter &DP) const override { DP << Msg; }

llvm/lib/Linker/IRMover.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ Type *TypeMapTy::get(Type *Ty, SmallPtrSet<StructType *, 8> &Visited) {
340340
}
341341

342342
LinkDiagnosticInfo::LinkDiagnosticInfo(DiagnosticSeverity Severity,
343-
const Twine &Msg)
343+
StringRef Msg)
344344
: DiagnosticInfo(DK_Linker, Severity), Msg(Msg) {}
345345
void LinkDiagnosticInfo::print(DiagnosticPrinter &DP) const { DP << Msg; }
346346

@@ -438,7 +438,9 @@ class IRLinker {
438438
GlobalValue *copyGlobalValueProto(const GlobalValue *SGV, bool ForDefinition);
439439

440440
void emitWarning(const Twine &Message) {
441-
SrcM->getContext().diagnose(LinkDiagnosticInfo(DS_Warning, Message));
441+
SmallString<128> Storage;
442+
SrcM->getContext().diagnose(
443+
LinkDiagnosticInfo(DS_Warning, Message.toStringRef(Storage)));
442444
}
443445

444446
/// Given a global in the source module, return the global in the

llvm/lib/Linker/LinkDiagnosticInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
namespace llvm {
1515
class LinkDiagnosticInfo : public DiagnosticInfo {
16-
const Twine &Msg;
16+
StringRef Msg;
1717

1818
public:
19-
LinkDiagnosticInfo(DiagnosticSeverity Severity, const Twine &Msg);
19+
LinkDiagnosticInfo(DiagnosticSeverity Severity, StringRef Msg);
2020
void print(DiagnosticPrinter &DP) const override;
2121
};
2222
}

llvm/lib/Linker/LinkModules.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "LinkDiagnosticInfo.h"
1414
#include "llvm-c/Linker.h"
1515
#include "llvm/ADT/SetVector.h"
16+
#include "llvm/ADT/SmallString.h"
1617
#include "llvm/IR/Comdat.h"
1718
#include "llvm/IR/GlobalValue.h"
1819
#include "llvm/IR/LLVMContext.h"
@@ -58,7 +59,9 @@ class ModuleLinker {
5859

5960
/// Should we have mover and linker error diag info?
6061
bool emitError(const Twine &Message) {
61-
SrcM->getContext().diagnose(LinkDiagnosticInfo(DS_Error, Message));
62+
SmallString<128> Storage;
63+
SrcM->getContext().diagnose(
64+
LinkDiagnosticInfo(DS_Error, Message.toStringRef(Storage)));
6265
return true;
6366
}
6467

llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "Utils/AMDGPUBaseInfo.h"
3232
#include "Utils/AMDKernelCodeTUtils.h"
3333
#include "Utils/SIDefinesUtils.h"
34+
#include "llvm/ADT/SmallString.h"
3435
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
3536
#include "llvm/BinaryFormat/ELF.h"
3637
#include "llvm/CodeGen/MachineFrameInfo.h"
@@ -43,6 +44,7 @@
4344
#include "llvm/MC/MCStreamer.h"
4445
#include "llvm/MC/TargetRegistry.h"
4546
#include "llvm/Support/AMDHSAKernelDescriptor.h"
47+
#include "llvm/Support/FormatVariadic.h"
4648
#include "llvm/Target/TargetLoweringObjectFile.h"
4749
#include "llvm/Target/TargetMachine.h"
4850
#include "llvm/TargetParser/TargetParser.h"
@@ -466,12 +468,11 @@ void AMDGPUAsmPrinter::validateMCResourceInfo(Function &F) {
466468
F, "amdgpu-waves-per-eu", {0, 0}, true);
467469

468470
if (TryGetMCExprValue(OccupancyExpr, Occupancy) && Occupancy < MinWEU) {
469-
DiagnosticInfoOptimizationFailure Diag(
470-
F, F.getSubprogram(),
471+
SmallString<256> Msg = formatv(
471472
"failed to meet occupancy target given by 'amdgpu-waves-per-eu' in "
472-
"'" +
473-
F.getName() + "': desired occupancy was " + Twine(MinWEU) +
474-
", final occupancy is " + Twine(Occupancy));
473+
"'{0}': desired occupancy was {1}, final occupancy is {2}",
474+
F.getName(), MinWEU, Occupancy);
475+
DiagnosticInfoOptimizationFailure Diag(F, F.getSubprogram(), Msg);
475476
F.getContext().diagnose(Diag);
476477
return;
477478
}
@@ -1261,13 +1262,12 @@ void AMDGPUAsmPrinter::getSIProgramInfo(SIProgramInfo &ProgInfo,
12611262
AMDGPU::getIntegerPairAttribute(F, "amdgpu-waves-per-eu", {0, 0}, true);
12621263
uint64_t Occupancy;
12631264
if (TryGetMCExprValue(ProgInfo.Occupancy, Occupancy) && Occupancy < MinWEU) {
1264-
DiagnosticInfoOptimizationFailure Diag(
1265-
F, F.getSubprogram(),
1265+
SmallString<256> Msg = formatv(
12661266
"failed to meet occupancy target given by 'amdgpu-waves-per-eu' in "
1267-
"'" +
1268-
F.getName() + "': desired occupancy was " + Twine(MinWEU) +
1269-
", final occupancy is " + Twine(Occupancy));
1270-
F.getContext().diagnose(Diag);
1267+
"'{0}'': desired occupancy was {1}, final occupancy is {2}",
1268+
F.getName(), MinWEU, Occupancy);
1269+
F.getContext().diagnose(
1270+
DiagnosticInfoOptimizationFailure(F, F.getSubprogram(), Msg));
12711271
}
12721272

12731273
if (isGFX11Plus(STM)) {

llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,15 +1376,15 @@ SDValue AMDGPUTargetLowering::lowerUnhandledCall(CallLoweringInfo &CLI,
13761376

13771377
const Function &Fn = DAG.getMachineFunction().getFunction();
13781378

1379-
StringRef FuncName("<unknown>");
1380-
1379+
SmallString<128> Msg = Reason;
13811380
if (const ExternalSymbolSDNode *G = dyn_cast<ExternalSymbolSDNode>(Callee))
1382-
FuncName = G->getSymbol();
1381+
Msg.append(G->getSymbol());
13831382
else if (const GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
1384-
FuncName = G->getGlobal()->getName();
1383+
Msg.append(G->getGlobal()->getName());
1384+
else
1385+
Msg.append("<unknown>");
13851386

1386-
DiagnosticInfoUnsupported NoCalls(
1387-
Fn, Reason + FuncName, CLI.DL.getDebugLoc());
1387+
DiagnosticInfoUnsupported NoCalls(Fn, Msg, CLI.DL.getDebugLoc());
13881388
DAG.getContext()->diagnose(NoCalls);
13891389

13901390
if (!CLI.IsTailCall) {

0 commit comments

Comments
 (0)