Index: lib/Target/X86/X86.td =================================================================== --- lib/Target/X86/X86.td +++ lib/Target/X86/X86.td @@ -220,6 +220,8 @@ def FeaturePadShortFunctions : SubtargetFeature<"pad-short-functions", "PadShortFunctions", "true", "Pad short functions">; +def FeatureSMAP : SubtargetFeature<"smap", "HasSMAP", "true", + "Supervisor Mode Access Protection">; def FeatureSGX : SubtargetFeature<"sgx", "HasSGX", "true", "Enable Software Guard Extensions">; def FeatureCLFLUSHOPT : SubtargetFeature<"clflushopt", "HasCLFLUSHOPT", "true", Index: lib/Target/X86/X86InstrInfo.td =================================================================== --- lib/Target/X86/X86InstrInfo.td +++ lib/Target/X86/X86InstrInfo.td @@ -832,6 +832,8 @@ def NoVLX_Or_NoDQI : Predicate<"!Subtarget->hasVLX() || !Subtarget->hasDQI()">; def PKU : Predicate<"Subtarget->hasPKU()">; +def hasSMAP : Predicate<"Subtarget->hasSMAP()">, + AssemblerPredicate<"FeatureSMAP","smap">; def HasPOPCNT : Predicate<"Subtarget->hasPOPCNT()">; def HasAES : Predicate<"Subtarget->hasAES()">; def HasFXSR : Predicate<"Subtarget->hasFXSR()">; Index: lib/Target/X86/X86InstrSystem.td =================================================================== --- lib/Target/X86/X86InstrSystem.td +++ lib/Target/X86/X86InstrSystem.td @@ -625,9 +625,11 @@ //===----------------------------------------------------------------------===// // SMAP Instruction -let Defs = [EFLAGS] in { - def CLAC : I<0x01, MRM_CA, (outs), (ins), "clac", []>, TB; - def STAC : I<0x01, MRM_CB, (outs), (ins), "stac", []>, TB; +let Predicates = [hasSMAP] in { + let Defs = [EFLAGS] in { + def CLAC : I<0x01, MRM_CA, (outs), (ins), "clac", []>, TB; + def STAC : I<0x01, MRM_CB, (outs), (ins), "stac", []>, TB; + } } //===----------------------------------------------------------------------===// Index: lib/Target/X86/X86Subtarget.h =================================================================== --- lib/Target/X86/X86Subtarget.h +++ lib/Target/X86/X86Subtarget.h @@ -288,6 +288,9 @@ /// Processor supports MPX - Memory Protection Extensions bool HasMPX; + /// Processor has Supervisor Mode Access Protection + bool HasSMAP; + /// Processor has Software Guard Extensions bool HasSGX; @@ -504,6 +507,7 @@ bool hasBWI() const { return HasBWI; } bool hasVLX() const { return HasVLX; } bool hasPKU() const { return HasPKU; } + bool hasSMAP() const {return HasSMAP; } bool hasMPX() const { return HasMPX; } bool hasCLFLUSHOPT() const { return HasCLFLUSHOPT; } Index: test/MC/X86/X86_64-smap.s =================================================================== --- /dev/null +++ test/MC/X86/X86_64-smap.s @@ -0,0 +1,14 @@ +// RUN: llvm-mc -triple x86_64-unknown-unknown -mattr=+smap --show-encoding < %s | FileCheck --check-prefix=SMAP-ON %s +// RUN: not llvm-mc -triple x86_64-unknown-unknown -mattr=-smap --show-encoding %s 2> %t +// RUN: FileCheck --check-prefix=SMAP-OFF < %t %s + + // SMAP-ON: clac + // SMAP-ON: encoding: [0x0f,0x01,0xca] + // SMAP-OFF: instruction requires: smap + clac + + // SMAP-ON: stac + // SMAP-ON: encoding: [0x0f,0x01,0xcb] + // SMAP-OFF: instruction requires: smap + stac + Index: test/MC/X86/x86-64.s =================================================================== --- test/MC/X86/x86-64.s +++ test/MC/X86/x86-64.s @@ -1366,14 +1366,6 @@ // CHECK: encoding: [0x48,0x0f,0x35] sysexitq -// CHECK: clac -// CHECK: encoding: [0x0f,0x01,0xca] -clac - -// CHECK: stac -// CHECK: encoding: [0x0f,0x01,0xcb] -stac - // CHECK: faddp %st(1) // CHECK: fmulp %st(1) // CHECK: fsubp %st(1)