diff options
author | Mehdi Amini <joker.eph@gmail.com> | 2024-02-22 14:11:10 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-22 14:11:10 -0800 |
commit | e2f08268304dc972440391c43bf1d47e28fad93e (patch) | |
tree | a28a2ba5c0406b114f03d7831eac275cc46695da | |
parent | ae3e14276b7181ae51e9ef731f44f813a1a3f123 (diff) | |
download | llvm-e2f08268304dc972440391c43bf1d47e28fad93e.zip llvm-e2f08268304dc972440391c43bf1d47e28fad93e.tar.gz llvm-e2f08268304dc972440391c43bf1d47e28fad93e.tar.bz2 |
[MLIR] Fix LLVM dialect specification to use AnySignlessInteger instead of AnyInteger (#82694)
LLVM IR does not support signed integer, the LLVM dialect was
underspecified (likely unintentionally) and the AnyInteger constraint
was overly lax.
The arithmetic dialect is already consistently using AnySignlessInteger.
-rw-r--r-- | mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index d9b130b..3da5dee 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -49,7 +49,7 @@ class LLVM_ArithmeticOpBase<Type type, string mnemonic, } class LLVM_IntArithmeticOp<string mnemonic, string instName, list<Trait> traits = []> : - LLVM_ArithmeticOpBase<AnyInteger, mnemonic, instName, traits> { + LLVM_ArithmeticOpBase<AnySignlessInteger, mnemonic, instName, traits> { let arguments = commonArgs; string mlirBuilder = [{ $res = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs); @@ -57,7 +57,7 @@ class LLVM_IntArithmeticOp<string mnemonic, string instName, } class LLVM_IntArithmeticOpWithOverflowFlag<string mnemonic, string instName, list<Trait> traits = []> : - LLVM_ArithmeticOpBase<AnyInteger, mnemonic, instName, + LLVM_ArithmeticOpBase<AnySignlessInteger, mnemonic, instName, !listconcat([DeclareOpInterfaceMethods<IntegerOverflowFlagsInterface>], traits)> { dag iofArg = ( ins DefaultValuedAttr<LLVM_IntegerOverflowFlagsAttr, "{}">:$overflowFlags); @@ -143,9 +143,9 @@ class LLVM_ArithmeticCmpOp<string mnemonic, list<Trait> traits = []> : // Other integer operations. def LLVM_ICmpOp : LLVM_ArithmeticCmpOp<"icmp", [Pure]> { let arguments = (ins ICmpPredicate:$predicate, - AnyTypeOf<[LLVM_ScalarOrVectorOf<AnyInteger>, + AnyTypeOf<[LLVM_ScalarOrVectorOf<AnySignlessInteger>, LLVM_ScalarOrVectorOf<LLVM_AnyPointer>]>:$lhs, - AnyTypeOf<[LLVM_ScalarOrVectorOf<AnyInteger>, + AnyTypeOf<[LLVM_ScalarOrVectorOf<AnySignlessInteger>, LLVM_ScalarOrVectorOf<LLVM_AnyPointer>]>:$rhs); let hasCustomAssemblyFormat = 1; string llvmInstName = "ICmp"; @@ -204,7 +204,7 @@ def LLVM_AllocaOp : LLVM_Op<"alloca", DeclareOpInterfaceMethods<DestructurableAllocationOpInterface>, DeclareOpInterfaceMethods<GetResultPtrElementType>]>, LLVM_MemOpPatterns { - let arguments = (ins AnyInteger:$arraySize, + let arguments = (ins AnySignlessInteger:$arraySize, OptionalAttr<I64Attr>:$alignment, TypeAttr:$elem_type, UnitAttr:$inalloca); @@ -250,7 +250,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure, DeclareOpInterfaceMethods<DestructurableAccessorOpInterface>, DeclareOpInterfaceMethods<GetResultPtrElementType>]> { let arguments = (ins LLVM_ScalarOrVectorOf<LLVM_AnyPointer>:$base, - Variadic<LLVM_ScalarOrVectorOf<AnyInteger>>:$dynamicIndices, + Variadic<LLVM_ScalarOrVectorOf<AnySignlessInteger>>:$dynamicIndices, DenseI32ArrayAttr:$rawConstantIndices, TypeAttr:$elem_type, UnitAttr:$inbounds); @@ -499,37 +499,37 @@ def LLVM_AddrSpaceCastOp : LLVM_CastOp<"addrspacecast", "AddrSpaceCast", let hasFolder = 1; } def LLVM_IntToPtrOp : LLVM_CastOp<"inttoptr", "IntToPtr", - LLVM_ScalarOrVectorOf<AnyInteger>, + LLVM_ScalarOrVectorOf<AnySignlessInteger>, LLVM_ScalarOrVectorOf<LLVM_AnyPointer>>; def LLVM_PtrToIntOp : LLVM_CastOp<"ptrtoint", "PtrToInt", LLVM_ScalarOrVectorOf<LLVM_AnyPointer>, - LLVM_ScalarOrVectorOf<AnyInteger>>; + LLVM_ScalarOrVectorOf<AnySignlessInteger>>; def LLVM_SExtOp : LLVM_CastOp<"sext", "SExt", - LLVM_ScalarOrVectorOf<AnyInteger>, - LLVM_ScalarOrVectorOf<AnyInteger>> { + LLVM_ScalarOrVectorOf<AnySignlessInteger>, + LLVM_ScalarOrVectorOf<AnySignlessInteger>> { let hasVerifier = 1; } def LLVM_ZExtOp : LLVM_CastOp<"zext", "ZExt", - LLVM_ScalarOrVectorOf<AnyInteger>, - LLVM_ScalarOrVectorOf<AnyInteger>> { + LLVM_ScalarOrVectorOf<AnySignlessInteger>, + LLVM_ScalarOrVectorOf<AnySignlessInteger>> { let hasFolder = 1; let hasVerifier = 1; } def LLVM_TruncOp : LLVM_CastOp<"trunc", "Trunc", - LLVM_ScalarOrVectorOf<AnyInteger>, - LLVM_ScalarOrVectorOf<AnyInteger>>; + LLVM_ScalarOrVectorOf<AnySignlessInteger>, + LLVM_ScalarOrVectorOf<AnySignlessInteger>>; def LLVM_SIToFPOp : LLVM_CastOp<"sitofp", "SIToFP", - LLVM_ScalarOrVectorOf<AnyInteger>, + LLVM_ScalarOrVectorOf<AnySignlessInteger>, LLVM_ScalarOrVectorOf<LLVM_AnyFloat>>; def LLVM_UIToFPOp : LLVM_CastOp<"uitofp", "UIToFP", - LLVM_ScalarOrVectorOf<AnyInteger>, + LLVM_ScalarOrVectorOf<AnySignlessInteger>, LLVM_ScalarOrVectorOf<LLVM_AnyFloat>>; def LLVM_FPToSIOp : LLVM_CastOp<"fptosi", "FPToSI", LLVM_ScalarOrVectorOf<LLVM_AnyFloat>, - LLVM_ScalarOrVectorOf<AnyInteger>>; + LLVM_ScalarOrVectorOf<AnySignlessInteger>>; def LLVM_FPToUIOp : LLVM_CastOp<"fptoui", "FPToUI", LLVM_ScalarOrVectorOf<LLVM_AnyFloat>, - LLVM_ScalarOrVectorOf<AnyInteger>>; + LLVM_ScalarOrVectorOf<AnySignlessInteger>>; def LLVM_FPExtOp : LLVM_CastOp<"fpext", "FPExt", LLVM_ScalarOrVectorOf<LLVM_AnyFloat>, LLVM_ScalarOrVectorOf<LLVM_AnyFloat>>; @@ -671,7 +671,7 @@ def LLVM_ExtractElementOp : LLVM_Op<"extractelement", [Pure, "LLVM::getVectorElementType($_self)">]> { let summary = "Extract an element from an LLVM vector."; - let arguments = (ins LLVM_AnyVector:$vector, AnyInteger:$position); + let arguments = (ins LLVM_AnyVector:$vector, AnySignlessInteger:$position); let results = (outs LLVM_Type:$res); let assemblyFormat = [{ @@ -733,7 +733,7 @@ def LLVM_InsertElementOp : LLVM_Op<"insertelement", [Pure, let summary = "Insert an element into an LLVM vector."; let arguments = (ins LLVM_AnyVector:$vector, LLVM_PrimitiveType:$value, - AnyInteger:$position); + AnySignlessInteger:$position); let results = (outs LLVM_AnyVector:$res); let builders = [LLVM_OneResultOpBuilder]; @@ -971,7 +971,7 @@ def LLVM_SwitchOp : LLVM_TerminatorOp<"switch", DeclareOpInterfaceMethods<BranchWeightOpInterface>, Pure]> { let arguments = (ins - AnyInteger:$value, + AnySignlessInteger:$value, Variadic<AnyType>:$defaultOperands, VariadicOfVariadic<AnyType, "case_operand_segments">:$caseOperands, OptionalAttr<AnyIntElementsAttr>:$case_values, @@ -1647,7 +1647,7 @@ def LLVM_ConstantOp // Atomic operations. // -def LLVM_AtomicRMWType : AnyTypeOf<[LLVM_AnyFloat, LLVM_AnyPointer, AnyInteger]>; +def LLVM_AtomicRMWType : AnyTypeOf<[LLVM_AnyFloat, LLVM_AnyPointer, AnySignlessInteger]>; def LLVM_AtomicRMWOp : LLVM_MemAccessOpBase<"atomicrmw", [ TypesMatchWith<"result #0 and operand #1 have the same type", @@ -1696,7 +1696,7 @@ def LLVM_AtomicRMWOp : LLVM_MemAccessOpBase<"atomicrmw", [ let hasVerifier = 1; } -def LLVM_AtomicCmpXchgType : AnyTypeOf<[AnyInteger, LLVM_AnyPointer]>; +def LLVM_AtomicCmpXchgType : AnyTypeOf<[AnySignlessInteger, LLVM_AnyPointer]>; def LLVM_AtomicCmpXchgOp : LLVM_MemAccessOpBase<"cmpxchg", [ TypesMatchWith<"operand #1 and operand #2 have the same type", |