Index: clang/include/clang/Basic/BuiltinsX86.def =================================================================== --- clang/include/clang/Basic/BuiltinsX86.def +++ clang/include/clang/Basic/BuiltinsX86.def @@ -33,6 +33,8 @@ BUILTIN(__builtin_cpu_supports, "bcC*", "nc") BUILTIN(__builtin_cpu_is, "bcC*", "nc") +TARGET_BUILTIN(__SSC_MARK, "vIi", "n", "") + // Undefined Values // TARGET_BUILTIN(__builtin_ia32_undef128, "V2d", "ncV:128:", "") Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -12545,6 +12545,24 @@ case X86::BI__rdtsc: { return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_rdtsc)); } + case X86::BI__SSC_MARK: { + llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, {Int32Ty}, false); + std::string Constraints = "i,~{ebx}"; + std::string MachineClobbers = this->getTarget().getClobbers(); + if (!MachineClobbers.empty()) { + Constraints += ','; + Constraints += MachineClobbers; + } + llvm::InlineAsm *IA = + llvm::InlineAsm::get(FTy, "movl $0, %ebx; .byte 0x64, 0x67, 0x90", + Constraints, /*hasSideEffects=*/true); + llvm::AttributeList NoReturnAttr = llvm::AttributeList::get( + getLLVMContext(), llvm::AttributeList::FunctionIndex, + llvm::Attribute::NoReturn); + llvm::CallInst *CI = Builder.CreateCall(IA, Ops[0]); + CI->setAttributes(NoReturnAttr); + return CI; + } case X86::BI__builtin_ia32_rdtscp: { Value *Call = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_rdtscp)); Builder.CreateDefaultAlignedStore(Builder.CreateExtractValue(Call, 1), Index: clang/test/CodeGen/X86/ssc-mark.c =================================================================== --- /dev/null +++ clang/test/CodeGen/X86/ssc-mark.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -ffreestanding %s -triple=i386-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s +// RUN: %clang_cc1 -ffreestanding %s -triple x86_64-unknown-unknown -emit-llvm -o - -Wall -Werror | FileCheck %s + +void test_ssc_mark() { + // CHECK-LABEL: test_ssc_mark() + // CHECK: call void asm sideeffect "movl $0, %ebx; .byte 0x64, 0x67, 0x90", "i,~{ebx},~{dirflag},~{fpsr},~{flags}"(i32 7) + // CHECK: ret void + return __SSC_MARK(7); +}