Skip to content

Commit 3baaf95

Browse files
jyknightyuxuanchen1997
authored andcommitted
Remove the x86_mmx IR type. (#98505)
Summary: It is now translated to `<1 x i64>`, which allows the removal of a bunch of special casing. This _incompatibly_ changes the ABI of any LLVM IR function with `x86_mmx` arguments or returns: instead of passing in mmx registers, they will now be passed via integer registers. However, the real-world incompatibility caused by this is expected to be minimal, because Clang never uses the x86_mmx type -- it lowers `__m64` to either `<1 x i64>` or `double`, depending on ABI. This change does _not_ eliminate the SelectionDAG `MVT::x86mmx` type. That type simply no longer corresponds to an IR type, and is used only by MMX intrinsics and inline-asm operands. Because SelectionDAGBuilder only knows how to generate the operands/results of intrinsics based on the IR type, it thus now generates the intrinsics with the type MVT::v1i64, instead of MVT::x86mmx. We need to fix this before the DAG LegalizeTypes, and thus have the X86 backend fix them up in DAGCombine. (This may be a short-lived hack, if all the MMX intrinsics can be removed in upcoming changes.) Works towards issue #98272. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250667
1 parent d32b5ca commit 3baaf95

File tree

84 files changed

+1881
-1933
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1881
-1933
lines changed

llvm/bindings/ocaml/llvm/llvm.mli

-4
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,6 @@ val void_type : llcontext -> lltype
760760
[llvm::Type::LabelTy]. *)
761761
val label_type : llcontext -> lltype
762762

763-
(** [x86_mmx_type c] returns the x86 64-bit MMX register type in the
764-
context [c]. See [llvm::Type::X86_MMXTy]. *)
765-
val x86_mmx_type : llcontext -> lltype
766-
767763
(** [type_by_name m name] returns the specified type from the current module
768764
if it exists.
769765
See the method [llvm::Module::getTypeByName] *)

llvm/bindings/ocaml/llvm/llvm_ocaml.c

-5
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,6 @@ value llvm_label_type(value Context) {
686686
return to_val(LLVMLabelTypeInContext(Context_val(Context)));
687687
}
688688

689-
/* llcontext -> lltype */
690-
value llvm_x86_mmx_type(value Context) {
691-
return to_val(LLVMX86MMXTypeInContext(Context_val(Context)));
692-
}
693-
694689
/* llmodule -> string -> lltype option */
695690
value llvm_type_by_name(value M, value Name) {
696691
return ptr_to_option(LLVMGetTypeByName(Module_val(M), String_val(Name)));

llvm/docs/BitCodeFormat.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ TYPE_CODE_X86_MMX Record
12911291

12921292
``[X86_MMX]``
12931293

1294-
The ``X86_MMX`` record (code 17) adds an ``x86_mmx`` type to the type table.
1294+
The ``X86_MMX`` record (code 17) is deprecated, and imported as a <1 x i64> vector.
12951295

12961296
TYPE_CODE_STRUCT_ANON Record
12971297
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

llvm/docs/LangRef.rst

+1-19
Original file line numberDiff line numberDiff line change
@@ -3945,24 +3945,6 @@ or constants of this type.
39453945
x86_amx
39463946

39473947

3948-
X86_mmx Type
3949-
""""""""""""
3950-
3951-
:Overview:
3952-
3953-
The x86_mmx type represents a value held in an MMX register on an x86
3954-
machine. The operations allowed on it are quite limited: parameters and
3955-
return values, load and store, and bitcast. User-specified MMX
3956-
instructions are represented as intrinsic or asm calls with arguments
3957-
and/or results of this type. There are no arrays, vectors or constants
3958-
of this type.
3959-
3960-
:Syntax:
3961-
3962-
::
3963-
3964-
x86_mmx
3965-
39663948

39673949
.. _t_pointer:
39683950

@@ -4396,7 +4378,7 @@ represented by ``0xH`` followed by 4 hexadecimal digits. The bfloat 16-bit
43964378
format is represented by ``0xR`` followed by 4 hexadecimal digits. All
43974379
hexadecimal formats are big-endian (sign bit at the left).
43984380

4399-
There are no constants of type x86_mmx and x86_amx.
4381+
There are no constants of type x86_amx.
44004382

44014383
.. _complexconstants:
44024384

llvm/docs/ReleaseNotes.rst

+15
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ Update on required toolchains to build LLVM
5050
Changes to the LLVM IR
5151
----------------------
5252

53+
* The ``x86_mmx`` IR type has been removed. It will be translated to
54+
the standard vector type ``<1 x i64>`` in bitcode upgrade.
55+
5356
Changes to LLVM infrastructure
5457
------------------------------
5558

@@ -120,6 +123,12 @@ Changes to the X86 Backend
120123
encoding. To use optimised NOP filling in a code section, leave off the
121124
"fillval" argument, i.e. `.balign N`, `.p2align N` or `.align N` respectively.
122125

126+
* Due to the removal of the ``x86_mmx`` IR type, functions with
127+
``x86_mmx`` arguments or return values will use a different,
128+
incompatible, calling convention ABI. Such functions are not
129+
generally seen in the wild (Clang never generates them!), so this is
130+
not expected to result in real-world compatibility problems.
131+
123132
Changes to the OCaml bindings
124133
-----------------------------
125134

@@ -129,6 +138,12 @@ Changes to the Python bindings
129138
Changes to the C API
130139
--------------------
131140

141+
* The following symbols are deleted due to the removal of the ``x86_mmx`` IR type:
142+
143+
* ``LLVMX86_MMXTypeKind``
144+
* ``LLVMX86MMXTypeInContext``
145+
* ``LLVMX86MMXType``
146+
132147
Changes to the CodeGen infrastructure
133148
-------------------------------------
134149

llvm/include/llvm-c/Core.h

+21-27
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,27 @@ typedef enum {
146146
} LLVMOpcode;
147147

148148
typedef enum {
149-
LLVMVoidTypeKind, /**< type with no size */
150-
LLVMHalfTypeKind, /**< 16 bit floating point type */
151-
LLVMFloatTypeKind, /**< 32 bit floating point type */
152-
LLVMDoubleTypeKind, /**< 64 bit floating point type */
153-
LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
154-
LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
155-
LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
156-
LLVMLabelTypeKind, /**< Labels */
157-
LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
158-
LLVMFunctionTypeKind, /**< Functions */
159-
LLVMStructTypeKind, /**< Structures */
160-
LLVMArrayTypeKind, /**< Arrays */
161-
LLVMPointerTypeKind, /**< Pointers */
162-
LLVMVectorTypeKind, /**< Fixed width SIMD vector type */
163-
LLVMMetadataTypeKind, /**< Metadata */
164-
LLVMX86_MMXTypeKind, /**< X86 MMX */
165-
LLVMTokenTypeKind, /**< Tokens */
166-
LLVMScalableVectorTypeKind, /**< Scalable SIMD vector type */
167-
LLVMBFloatTypeKind, /**< 16 bit brain floating point type */
168-
LLVMX86_AMXTypeKind, /**< X86 AMX */
169-
LLVMTargetExtTypeKind, /**< Target extension type */
149+
LLVMVoidTypeKind = 0, /**< type with no size */
150+
LLVMHalfTypeKind = 1, /**< 16 bit floating point type */
151+
LLVMFloatTypeKind = 2, /**< 32 bit floating point type */
152+
LLVMDoubleTypeKind = 3, /**< 64 bit floating point type */
153+
LLVMX86_FP80TypeKind = 4, /**< 80 bit floating point type (X87) */
154+
LLVMFP128TypeKind = 5, /**< 128 bit floating point type (112-bit mantissa)*/
155+
LLVMPPC_FP128TypeKind = 6, /**< 128 bit floating point type (two 64-bits) */
156+
LLVMLabelTypeKind = 7, /**< Labels */
157+
LLVMIntegerTypeKind = 8, /**< Arbitrary bit width integers */
158+
LLVMFunctionTypeKind = 9, /**< Functions */
159+
LLVMStructTypeKind = 10, /**< Structures */
160+
LLVMArrayTypeKind = 11, /**< Arrays */
161+
LLVMPointerTypeKind = 12, /**< Pointers */
162+
LLVMVectorTypeKind = 13, /**< Fixed width SIMD vector type */
163+
LLVMMetadataTypeKind = 14, /**< Metadata */
164+
/* 15 previously used by LLVMX86_MMXTypeKind */
165+
LLVMTokenTypeKind = 16, /**< Tokens */
166+
LLVMScalableVectorTypeKind = 17, /**< Scalable SIMD vector type */
167+
LLVMBFloatTypeKind = 18, /**< 16 bit brain floating point type */
168+
LLVMX86_AMXTypeKind = 19, /**< X86 AMX */
169+
LLVMTargetExtTypeKind = 20, /**< Target extension type */
170170
} LLVMTypeKind;
171171

172172
typedef enum {
@@ -1716,11 +1716,6 @@ LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
17161716
*/
17171717
LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
17181718

1719-
/**
1720-
* Create a X86 MMX type in a context.
1721-
*/
1722-
LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
1723-
17241719
/**
17251720
* Create a X86 AMX type in a context.
17261721
*/
@@ -1742,7 +1737,6 @@ LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C);
17421737
*/
17431738
LLVMTypeRef LLVMVoidType(void);
17441739
LLVMTypeRef LLVMLabelType(void);
1745-
LLVMTypeRef LLVMX86MMXType(void);
17461740
LLVMTypeRef LLVMX86AMXType(void);
17471741

17481742
/**

llvm/include/llvm/IR/DataLayout.h

-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@ inline TypeSize DataLayout::getTypeSizeInBits(Type *Ty) const {
693693
case Type::FloatTyID:
694694
return TypeSize::getFixed(32);
695695
case Type::DoubleTyID:
696-
case Type::X86_MMXTyID:
697696
return TypeSize::getFixed(64);
698697
case Type::PPC_FP128TyID:
699698
case Type::FP128TyID:

llvm/include/llvm/IR/Type.h

+3-9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class Type {
6363
VoidTyID, ///< type with no size
6464
LabelTyID, ///< Labels
6565
MetadataTyID, ///< Metadata
66-
X86_MMXTyID, ///< MMX vectors (64 bits, X86 specific)
6766
X86_AMXTyID, ///< AMX vectors (8192 bits, X86 specific)
6867
TokenTyID, ///< Tokens
6968

@@ -197,9 +196,6 @@ class Type {
197196

198197
const fltSemantics &getFltSemantics() const;
199198

200-
/// Return true if this is X86 MMX.
201-
bool isX86_MMXTy() const { return getTypeID() == X86_MMXTyID; }
202-
203199
/// Return true if this is X86 AMX.
204200
bool isX86_AMXTy() const { return getTypeID() == X86_AMXTyID; }
205201

@@ -285,8 +281,8 @@ class Type {
285281
/// Return true if the type is a valid type for a register in codegen. This
286282
/// includes all first-class types except struct and array types.
287283
bool isSingleValueType() const {
288-
return isFloatingPointTy() || isX86_MMXTy() || isIntegerTy() ||
289-
isPointerTy() || isVectorTy() || isX86_AMXTy() || isTargetExtTy();
284+
return isFloatingPointTy() || isIntegerTy() || isPointerTy() ||
285+
isVectorTy() || isX86_AMXTy() || isTargetExtTy();
290286
}
291287

292288
/// Return true if the type is an aggregate type. This means it is valid as
@@ -302,8 +298,7 @@ class Type {
302298
bool isSized(SmallPtrSetImpl<Type*> *Visited = nullptr) const {
303299
// If it's a primitive, it is always sized.
304300
if (getTypeID() == IntegerTyID || isFloatingPointTy() ||
305-
getTypeID() == PointerTyID || getTypeID() == X86_MMXTyID ||
306-
getTypeID() == X86_AMXTyID)
301+
getTypeID() == PointerTyID || getTypeID() == X86_AMXTyID)
307302
return true;
308303
// If it is not something that can have a size (e.g. a function or label),
309304
// it doesn't have a size.
@@ -453,7 +448,6 @@ class Type {
453448
static Type *getX86_FP80Ty(LLVMContext &C);
454449
static Type *getFP128Ty(LLVMContext &C);
455450
static Type *getPPC_FP128Ty(LLVMContext &C);
456-
static Type *getX86_MMXTy(LLVMContext &C);
457451
static Type *getX86_AMXTy(LLVMContext &C);
458452
static Type *getTokenTy(LLVMContext &C);
459453
static IntegerType *getIntNTy(LLVMContext &C, unsigned N);

llvm/lib/Analysis/ConstantFolding.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,14 @@ Constant *FoldReinterpretLoadFromConst(Constant *C, Type *LoadTy,
564564
Type *MapTy = Type::getIntNTy(C->getContext(),
565565
DL.getTypeSizeInBits(LoadTy).getFixedValue());
566566
if (Constant *Res = FoldReinterpretLoadFromConst(C, MapTy, Offset, DL)) {
567-
if (Res->isNullValue() && !LoadTy->isX86_MMXTy() &&
568-
!LoadTy->isX86_AMXTy())
567+
if (Res->isNullValue() && !LoadTy->isX86_AMXTy())
569568
// Materializing a zero can be done trivially without a bitcast
570569
return Constant::getNullValue(LoadTy);
571570
Type *CastTy = LoadTy->isPtrOrPtrVectorTy() ? DL.getIntPtrType(LoadTy) : LoadTy;
572571
Res = FoldBitCast(Res, CastTy, DL);
573572
if (LoadTy->isPtrOrPtrVectorTy()) {
574573
// For vector of pointer, we needed to first convert to a vector of integer, then do vector inttoptr
575-
if (Res->isNullValue() && !LoadTy->isX86_MMXTy() &&
576-
!LoadTy->isX86_AMXTy())
574+
if (Res->isNullValue() && !LoadTy->isX86_AMXTy())
577575
return Constant::getNullValue(LoadTy);
578576
if (DL.isNonIntegralPointerType(LoadTy->getScalarType()))
579577
// Be careful not to replace a load of an addrspace value with an inttoptr here
@@ -764,7 +762,7 @@ Constant *llvm::ConstantFoldLoadFromUniformValue(Constant *C, Type *Ty,
764762
// uniform.
765763
if (!DL.typeSizeEqualsStoreSize(C->getType()))
766764
return nullptr;
767-
if (C->isNullValue() && !Ty->isX86_MMXTy() && !Ty->isX86_AMXTy())
765+
if (C->isNullValue() && !Ty->isX86_AMXTy())
768766
return Constant::getNullValue(Ty);
769767
if (C->isAllOnesValue() &&
770768
(Ty->isIntOrIntVectorTy() || Ty->isFPOrFPVectorTy()))

llvm/lib/AsmParser/LLLexer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,8 @@ lltok::Kind LLLexer::LexIdentifier() {
838838
TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
839839
TYPEKEYWORD("label", Type::getLabelTy(Context));
840840
TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
841-
TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context));
841+
TYPEKEYWORD("x86_mmx", llvm::FixedVectorType::get(
842+
llvm::IntegerType::get(Context, 64), 1));
842843
TYPEKEYWORD("x86_amx", Type::getX86_AMXTy(Context));
843844
TYPEKEYWORD("token", Type::getTokenTy(Context));
844845
TYPEKEYWORD("ptr", PointerType::getUnqual(Context));

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2496,7 +2496,9 @@ Error BitcodeReader::parseTypeTableBody() {
24962496
ResultTy = Type::getMetadataTy(Context);
24972497
break;
24982498
case bitc::TYPE_CODE_X86_MMX: // X86_MMX
2499-
ResultTy = Type::getX86_MMXTy(Context);
2499+
// Deprecated: decodes as <1 x i64>
2500+
ResultTy =
2501+
llvm::FixedVectorType::get(llvm::IntegerType::get(Context, 64), 1);
25002502
break;
25012503
case bitc::TYPE_CODE_X86_AMX: // X86_AMX
25022504
ResultTy = Type::getX86_AMXTy(Context);

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1088,8 +1088,9 @@ void ModuleBitcodeWriter::writeTypeTable() {
10881088
case Type::FP128TyID: Code = bitc::TYPE_CODE_FP128; break;
10891089
case Type::PPC_FP128TyID: Code = bitc::TYPE_CODE_PPC_FP128; break;
10901090
case Type::LabelTyID: Code = bitc::TYPE_CODE_LABEL; break;
1091-
case Type::MetadataTyID: Code = bitc::TYPE_CODE_METADATA; break;
1092-
case Type::X86_MMXTyID: Code = bitc::TYPE_CODE_X86_MMX; break;
1091+
case Type::MetadataTyID:
1092+
Code = bitc::TYPE_CODE_METADATA;
1093+
break;
10931094
case Type::X86_AMXTyID: Code = bitc::TYPE_CODE_X86_AMX; break;
10941095
case Type::TokenTyID: Code = bitc::TYPE_CODE_TOKEN; break;
10951096
case Type::IntegerTyID:

llvm/lib/CodeGen/ValueTypes.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Type *EVT::getTypeForEVT(LLVMContext &Context) const {
207207
assert(isExtended() && "Type is not extended!");
208208
return LLVMTy;
209209
case MVT::isVoid: return Type::getVoidTy(Context);
210-
case MVT::x86mmx: return Type::getX86_MMXTy(Context);
210+
case MVT::x86mmx: return llvm::FixedVectorType::get(llvm::IntegerType::get(Context, 64), 1);
211211
case MVT::aarch64svcount:
212212
return TargetExtType::get(Context, "aarch64.svcount");
213213
case MVT::x86amx: return Type::getX86_AMXTy(Context);
@@ -241,8 +241,8 @@ MVT MVT::getVT(Type *Ty, bool HandleUnknown){
241241
case Type::BFloatTyID: return MVT(MVT::bf16);
242242
case Type::FloatTyID: return MVT(MVT::f32);
243243
case Type::DoubleTyID: return MVT(MVT::f64);
244-
case Type::X86_FP80TyID: return MVT(MVT::f80);
245-
case Type::X86_MMXTyID: return MVT(MVT::x86mmx);
244+
case Type::X86_FP80TyID:
245+
return MVT(MVT::f80);
246246
case Type::TargetExtTyID: {
247247
TargetExtType *TargetExtTy = cast<TargetExtType>(Ty);
248248
if (TargetExtTy->getName() == "aarch64.svcount")
@@ -302,4 +302,3 @@ void MVT::print(raw_ostream &OS) const {
302302
else
303303
OS << EVT(*this).getEVTString();
304304
}
305-

llvm/lib/IR/AsmWriter.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,9 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
573573
case Type::FP128TyID: OS << "fp128"; return;
574574
case Type::PPC_FP128TyID: OS << "ppc_fp128"; return;
575575
case Type::LabelTyID: OS << "label"; return;
576-
case Type::MetadataTyID: OS << "metadata"; return;
577-
case Type::X86_MMXTyID: OS << "x86_mmx"; return;
576+
case Type::MetadataTyID:
577+
OS << "metadata";
578+
return;
578579
case Type::X86_AMXTyID: OS << "x86_amx"; return;
579580
case Type::TokenTyID: OS << "token"; return;
580581
case Type::IntegerTyID:

llvm/lib/IR/ConstantFold.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
142142
return UndefValue::get(DestTy);
143143
}
144144

145-
if (V->isNullValue() && !DestTy->isX86_MMXTy() && !DestTy->isX86_AMXTy() &&
145+
if (V->isNullValue() && !DestTy->isX86_AMXTy() &&
146146
opc != Instruction::AddrSpaceCast)
147147
return Constant::getNullValue(DestTy);
148148

llvm/lib/IR/Core.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,6 @@ LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) {
609609
return LLVMPointerTypeKind;
610610
case Type::FixedVectorTyID:
611611
return LLVMVectorTypeKind;
612-
case Type::X86_MMXTyID:
613-
return LLVMX86_MMXTypeKind;
614612
case Type::X86_AMXTyID:
615613
return LLVMX86_AMXTypeKind;
616614
case Type::TokenTyID:
@@ -725,9 +723,6 @@ LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) {
725723
LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) {
726724
return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C));
727725
}
728-
LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) {
729-
return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
730-
}
731726
LLVMTypeRef LLVMX86AMXTypeInContext(LLVMContextRef C) {
732727
return (LLVMTypeRef) Type::getX86_AMXTy(*unwrap(C));
733728
}
@@ -753,9 +748,6 @@ LLVMTypeRef LLVMFP128Type(void) {
753748
LLVMTypeRef LLVMPPCFP128Type(void) {
754749
return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
755750
}
756-
LLVMTypeRef LLVMX86MMXType(void) {
757-
return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
758-
}
759751
LLVMTypeRef LLVMX86AMXType(void) {
760752
return LLVMX86AMXTypeInContext(LLVMGetGlobalContext());
761753
}

llvm/lib/IR/DataLayout.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,6 @@ Align DataLayout::getAlignment(Type *Ty, bool abi_or_pref) const {
835835
// layout.
836836
return Align(PowerOf2Ceil(BitWidth / 8));
837837
}
838-
case Type::X86_MMXTyID:
839838
case Type::FixedVectorTyID:
840839
case Type::ScalableVectorTyID: {
841840
unsigned BitWidth = getTypeSizeInBits(Ty).getKnownMinValue();

0 commit comments

Comments
 (0)