Skip to content

Commit d6d12a1

Browse files
committed
Replace string GNU Triples with llvm::Triple in InitMCObjectFileInfo. NFC.
Summary: This affects other tools so the previous C++ API has been retained as a deprecated function for the moment. Clang has been updated with a trivial patch (not covered by the pre-commit review) to avoid breaking -Werror builds. Other in-tree tools will be fixed with similar trivial patches. This continues the patch series to eliminate StringRef forms of GNU triples from the internals of LLVM that began in r239036. Reviewers: rengolin Reviewed By: rengolin Subscribers: llvm-commits, rengolin Differential Revision: http://reviews.llvm.org/D10366 llvm-svn: 239721
1 parent d8673ed commit d6d12a1

File tree

8 files changed

+32
-20
lines changed

8 files changed

+32
-20
lines changed

clang/lib/Parse/ParseStmtAsm.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ StmtResult Parser::ParseMicrosoftAsmStatement(SourceLocation AsmLoc) {
512512

513513
llvm::SourceMgr TempSrcMgr;
514514
llvm::MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &TempSrcMgr);
515-
MOFI->InitMCObjectFileInfo(TT, llvm::Reloc::Default, llvm::CodeModel::Default,
516-
Ctx);
515+
MOFI->InitMCObjectFileInfo(TheTriple, llvm::Reloc::Default,
516+
llvm::CodeModel::Default, Ctx);
517517
std::unique_ptr<llvm::MemoryBuffer> Buffer =
518518
llvm::MemoryBuffer::getMemBuffer(AsmString, "<MS inline asm>");
519519

clang/tools/driver/cc1as_main.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
323323

324324
MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr);
325325
// FIXME: Assembler behavior can change with -static.
326-
MOFI->InitMCObjectFileInfo(Opts.Triple,
327-
Reloc::Default, CodeModel::Default, Ctx);
326+
MOFI->InitMCObjectFileInfo(Triple(Opts.Triple), Reloc::Default,
327+
CodeModel::Default, Ctx);
328328
if (Opts.SaveTemporaryLabels)
329329
Ctx.setAllowTemporaryLabels(false);
330330
if (Opts.GenDwarfForAssembly)

llvm/include/llvm/MC/MCObjectFileInfo.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
namespace llvm {
2121
class MCContext;
2222
class MCSection;
23-
class StringRef;
2423

2524
class MCObjectFileInfo {
2625
protected:
@@ -185,8 +184,12 @@ class MCObjectFileInfo {
185184
MCSection *SXDataSection;
186185

187186
public:
188-
void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
189-
MCContext &ctx);
187+
void InitMCObjectFileInfo(const Triple &TT, Reloc::Model RM,
188+
CodeModel::Model CM, MCContext &ctx);
189+
LLVM_ATTRIBUTE_DEPRECATED(
190+
void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM,
191+
CodeModel::Model CM, MCContext &ctx),
192+
"StringRef GNU Triple argument replaced by a llvm::Triple object");
190193

191194
bool getSupportsWeakOmittedEHFrame() const {
192195
return SupportsWeakOmittedEHFrame;

llvm/lib/MC/MCObjectFileInfo.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,8 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
729729
SectionKind::getDataRel());
730730
}
731731

732-
void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
732+
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple,
733+
Reloc::Model relocm,
733734
CodeModel::Model cm,
734735
MCContext &ctx) {
735736
RelocM = relocm;
@@ -753,7 +754,7 @@ void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
753754
DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.
754755
DwarfAccelTypesSection = nullptr; // Used only by selected targets.
755756

756-
TT = Triple(T);
757+
TT = TheTriple;
757758

758759
Triple::ArchType Arch = TT.getArch();
759760
// FIXME: Checking for Arch here to filter out bogus triples such as
@@ -777,6 +778,12 @@ void MCObjectFileInfo::InitMCObjectFileInfo(StringRef T, Reloc::Model relocm,
777778
}
778779
}
779780

781+
void MCObjectFileInfo::InitMCObjectFileInfo(StringRef TT, Reloc::Model RM,
782+
CodeModel::Model CM,
783+
MCContext &ctx) {
784+
InitMCObjectFileInfo(Triple(TT), RM, CM, ctx);
785+
}
786+
780787
MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
781788
return Ctx->getELFSection(".debug_types", ELF::SHT_PROGBITS, ELF::SHF_GROUP,
782789
0, utostr(Hash));

llvm/lib/Object/IRObjectFile.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
4545
if (InlineAsm.empty())
4646
return;
4747

48-
StringRef Triple = M->getTargetTriple();
48+
Triple TT(M->getTargetTriple());
4949
std::string Err;
50-
const Target *T = TargetRegistry::lookupTarget(Triple, Err);
50+
const Target *T = TargetRegistry::lookupTarget(TT.str(), Err);
5151
if (!T)
5252
return;
5353

54-
std::unique_ptr<MCRegisterInfo> MRI(T->createMCRegInfo(Triple));
54+
std::unique_ptr<MCRegisterInfo> MRI(T->createMCRegInfo(TT.str()));
5555
if (!MRI)
5656
return;
5757

58-
std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, Triple));
58+
std::unique_ptr<MCAsmInfo> MAI(T->createMCAsmInfo(*MRI, TT.str()));
5959
if (!MAI)
6060
return;
6161

6262
std::unique_ptr<MCSubtargetInfo> STI(
63-
T->createMCSubtargetInfo(Triple, "", ""));
63+
T->createMCSubtargetInfo(TT.str(), "", ""));
6464
if (!STI)
6565
return;
6666

@@ -70,7 +70,7 @@ IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
7070

7171
MCObjectFileInfo MOFI;
7272
MCContext MCCtx(MAI.get(), MRI.get(), &MOFI);
73-
MOFI.InitMCObjectFileInfo(Triple, Reloc::Default, CodeModel::Default, MCCtx);
73+
MOFI.InitMCObjectFileInfo(TT, Reloc::Default, CodeModel::Default, MCCtx);
7474
std::unique_ptr<RecordStreamer> Streamer(new RecordStreamer(MCCtx));
7575
T->createNullTargetStreamer(*Streamer);
7676

llvm/lib/Target/TargetLoweringObjectFile.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ void TargetLoweringObjectFile::Initialize(MCContext &ctx,
4444
const TargetMachine &TM) {
4545
Ctx = &ctx;
4646
DL = TM.getDataLayout();
47-
InitMCObjectFileInfo(TM.getTargetTriple(),
48-
TM.getRelocationModel(), TM.getCodeModel(), *Ctx);
47+
InitMCObjectFileInfo(Triple(TM.getTargetTriple()), TM.getRelocationModel(),
48+
TM.getCodeModel(), *Ctx);
4949
}
5050

5151
TargetLoweringObjectFile::~TargetLoweringObjectFile() {

llvm/tools/dsymutil/DwarfLinker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ bool DwarfStreamer::init(Triple TheTriple, StringRef OutputFilename) {
527527

528528
MOFI.reset(new MCObjectFileInfo);
529529
MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
530-
MOFI->InitMCObjectFileInfo(TripleName, Reloc::Default, CodeModel::Default,
530+
MOFI->InitMCObjectFileInfo(TheTriple, Reloc::Default, CodeModel::Default,
531531
*MC);
532532

533533
MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "");

llvm/tools/llvm-mc/llvm-mc.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ int main(int argc, char **argv) {
383383
cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
384384
MCTargetOptions MCOptions = InitMCTargetOptionsFromFlags();
385385
TripleName = Triple::normalize(TripleName);
386-
Triple TheTriple(TripleName);
387386
setDwarfDebugFlags(argc, argv);
388387

389388
setDwarfDebugProducer();
@@ -392,6 +391,9 @@ int main(int argc, char **argv) {
392391
const Target *TheTarget = GetTarget(ProgName);
393392
if (!TheTarget)
394393
return 1;
394+
// Now that GetTarget() has (potentially) replaced TripleName, it's safe to
395+
// construct the Triple object.
396+
Triple TheTriple(TripleName);
395397

396398
ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
397399
MemoryBuffer::getFileOrSTDIN(InputFilename);
@@ -429,7 +431,7 @@ int main(int argc, char **argv) {
429431
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
430432
MCObjectFileInfo MOFI;
431433
MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr);
432-
MOFI.InitMCObjectFileInfo(TripleName, RelocModel, CMModel, Ctx);
434+
MOFI.InitMCObjectFileInfo(TheTriple, RelocModel, CMModel, Ctx);
433435

434436
if (SaveTempLabels)
435437
Ctx.setAllowTemporaryLabels(false);

0 commit comments

Comments
 (0)