Skip to content

Commit a5ba4ee

Browse files
committedAug 12, 2017
[Triple] Add isThumb and isARM functions.
Summary: isThumb returns true for Thumb triples (little and big endian), isARM returns true for ARM triples (little and big endian). There are a few more checks using arm/thumb that are not covered by those functions, e.g. that the architecture is either ARM or Thumb (little endian) or ARM/Thumb little endian only. Reviewers: javed.absar, rengolin, kristof.beyls, t.p.northover Reviewed By: rengolin Subscribers: llvm-commits, aemerson Differential Revision: https://reviews.llvm.org/D34682 llvm-svn: 310781
1 parent 32546d1 commit a5ba4ee

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed
 

‎llvm/include/llvm/ADT/Triple.h

+10
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,16 @@ class Triple {
630630
return getArch() == Triple::nvptx || getArch() == Triple::nvptx64;
631631
}
632632

633+
/// Tests whether the target is Thumb (little and big endian).
634+
bool isThumb() const {
635+
return getArch() == Triple::thumb || getArch() == Triple::thumbeb;
636+
}
637+
638+
/// Tests whether the target is ARM (little and big endian).
639+
bool isARM() const {
640+
return getArch() == Triple::arm || getArch() == Triple::armeb;
641+
}
642+
633643
/// Tests wether the target supports comdat
634644
bool supportsCOMDAT() const { return !isOSBinFormatMachO(); }
635645

‎llvm/lib/MC/MCSectionELF.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
113113
OS << 'c';
114114
if (Flags & ELF::XCORE_SHF_DP_SECTION)
115115
OS << 'd';
116-
} else if (Arch == Triple::arm || Arch == Triple::armeb ||
117-
Arch == Triple::thumb || Arch == Triple::thumbeb) {
116+
} else if (T.isARM() || T.isThumb()) {
118117
if (Flags & ELF::SHF_ARM_PURECODE)
119118
OS << 'y';
120119
}

‎llvm/lib/Object/ELFObjectFile.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ void ELFObjectFileBase::setARMSubArch(Triple &TheTriple) const {
260260

261261
std::string Triple;
262262
// Default to ARM, but use the triple if it's been set.
263-
if (TheTriple.getArch() == Triple::thumb ||
264-
TheTriple.getArch() == Triple::thumbeb)
263+
if (TheTriple.isThumb())
265264
Triple = "thumb";
266265
else
267266
Triple = "arm";

‎llvm/lib/Target/ARM/ARMAsmPrinter.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,7 @@ void ARMAsmPrinter::EmitStartOfAsmFile(Module &M) {
476476
// Use the triple's architecture and subarchitecture to determine
477477
// if we're thumb for the purposes of the top level code16 assembler
478478
// flag.
479-
bool isThumb = TT.getArch() == Triple::thumb ||
480-
TT.getArch() == Triple::thumbeb ||
481-
TT.getSubArch() == Triple::ARMSubArch_v7m ||
482-
TT.getSubArch() == Triple::ARMSubArch_v6m;
483-
if (!M.getModuleInlineAsm().empty() && isThumb)
479+
if (!M.getModuleInlineAsm().empty() && TT.isThumb())
484480
OutStreamer->EmitAssemblerFlag(MCAF_Code16);
485481
}
486482

‎llvm/lib/Target/ARM/ARMAsmPrinter.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ class LLVM_LIBRARY_VISIBILITY ARMAsmPrinter : public AsmPrinter {
135135
const Triple &TT = TM.getTargetTriple();
136136
if (!TT.isOSBinFormatMachO())
137137
return 0;
138-
bool isThumb = TT.getArch() == Triple::thumb ||
139-
TT.getArch() == Triple::thumbeb ||
138+
bool isThumb = TT.isThumb() ||
140139
TT.getSubArch() == Triple::ARMSubArch_v7m ||
141140
TT.getSubArch() == Triple::ARMSubArch_v6m;
142141
return isThumb ? ARM::DW_ISA_ARM_thumb : ARM::DW_ISA_ARM_arm;

‎llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,13 @@ static bool getARMLoadDeprecationInfo(MCInst &MI, const MCSubtargetInfo &STI,
131131
#include "ARMGenSubtargetInfo.inc"
132132

133133
std::string ARM_MC::ParseARMTriple(const Triple &TT, StringRef CPU) {
134-
bool isThumb =
135-
TT.getArch() == Triple::thumb || TT.getArch() == Triple::thumbeb;
136-
137134
std::string ARMArchFeature;
138135

139136
ARM::ArchKind ArchID = ARM::parseArch(TT.getArchName());
140137
if (ArchID != ARM::ArchKind::INVALID && (CPU.empty() || CPU == "generic"))
141138
ARMArchFeature = (ARMArchFeature + "+" + ARM::getArchName(ArchID)).str();
142139

143-
if (isThumb) {
140+
if (TT.isThumb()) {
144141
if (ARMArchFeature.empty())
145142
ARMArchFeature = "+thumb-mode";
146143
else

0 commit comments

Comments
 (0)