Skip to content

Commit 8158f0c

Browse files
committed
[X86] Use X86_MC::ParseX86Triple to add mode features to feature string in X86Subtarget::initSubtargetFeatures.
Remove mode flags from constructor and remove calls to ToggleFeature for the mode bits. By adding them to the feature string we handle initializing the mode member variables in X86Subtarget and the feature bits in MCSubtargetInfo in one shot.
1 parent db37937 commit 8158f0c

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

llvm/lib/Target/X86/X86Subtarget.cpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,16 @@ void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
231231
if (CPU.empty())
232232
CPU = "generic";
233233

234-
std::string FullFS = std::string(FS);
235-
if (In64BitMode) {
236-
// SSE2 should default to enabled in 64-bit mode, but can be turned off
237-
// explicitly.
238-
if (!FullFS.empty())
239-
FullFS = "+sse2," + FullFS;
240-
else
241-
FullFS = "+sse2";
242-
}
234+
std::string FullFS = X86_MC::ParseX86Triple(TargetTriple);
235+
assert(!FullFS.empty() && "Failed to parse X86 triple");
236+
237+
// SSE2 should default to enabled in 64-bit mode, but can be turned off
238+
// explicitly.
239+
if (TargetTriple.isArch64Bit())
240+
FullFS += ",+sse2";
241+
242+
if (!FS.empty())
243+
FullFS = (Twine(FullFS) + "," + FS).str();
243244

244245
// Parse features string and set the CPU.
245246
ParseSubtargetFeatures(CPU, FullFS);
@@ -251,17 +252,6 @@ void X86Subtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
251252
if (hasSSE42() || hasSSE4A())
252253
IsUAMem16Slow = false;
253254

254-
// It's important to keep the MCSubtargetInfo feature bits in sync with
255-
// target data structure which is shared with MC code emitter, etc.
256-
if (In64BitMode)
257-
ToggleFeature(X86::Mode64Bit);
258-
else if (In32BitMode)
259-
ToggleFeature(X86::Mode32Bit);
260-
else if (In16BitMode)
261-
ToggleFeature(X86::Mode16Bit);
262-
else
263-
llvm_unreachable("Not 16-bit, 32-bit or 64-bit mode!");
264-
265255
LLVM_DEBUG(dbgs() << "Subtarget features: SSELevel " << X86SSELevel
266256
<< ", 3DNowLevel " << X863DNowLevel << ", 64bit "
267257
<< HasX86_64 << "\n");
@@ -312,11 +302,6 @@ X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
312302
TM(TM), TargetTriple(TT), StackAlignOverride(StackAlignOverride),
313303
PreferVectorWidthOverride(PreferVectorWidthOverride),
314304
RequiredVectorWidth(RequiredVectorWidth),
315-
In64BitMode(TargetTriple.getArch() == Triple::x86_64),
316-
In32BitMode(TargetTriple.getArch() == Triple::x86 &&
317-
TargetTriple.getEnvironment() != Triple::CODE16),
318-
In16BitMode(TargetTriple.getArch() == Triple::x86 &&
319-
TargetTriple.getEnvironment() == Triple::CODE16),
320305
InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this),
321306
FrameLowering(*this, getStackAlignment()) {
322307
// Determine the PICStyle based on the target selected.

llvm/lib/Target/X86/X86Subtarget.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,13 @@ class X86Subtarget final : public X86GenSubtargetInfo {
498498
unsigned RequiredVectorWidth;
499499

500500
/// True if compiling for 64-bit, false for 16-bit or 32-bit.
501-
bool In64BitMode;
501+
bool In64BitMode = false;
502502

503503
/// True if compiling for 32-bit, false for 16-bit or 64-bit.
504-
bool In32BitMode;
504+
bool In32BitMode = false;
505505

506506
/// True if compiling for 16-bit, false for 32-bit or 64-bit.
507-
bool In16BitMode;
507+
bool In16BitMode = false;
508508

509509
/// Contains the Overhead of gather\scatter instructions
510510
int GatherOverhead = 1024;

0 commit comments

Comments
 (0)