mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-09 18:05:36 +00:00
GlobalISel: Fix address space limit in LLT
The IR enforced limit for the address space is 24-bits, but LLT was only using 23-bits. Additionally, the argument to the constructor was truncating to 16-bits. A similar problem still exists for the number of vector elements. The IR enforces no limit, so if you try to use a vector with > 65535 elements the IRTranslator asserts in the LLT constructor. llvm-svn: 352264
This commit is contained in:
parent
bb01a098b1
commit
cdc201fcde
@ -45,8 +45,8 @@ public:
|
|||||||
SizeInBits, /*AddressSpace=*/0};
|
SizeInBits, /*AddressSpace=*/0};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a low-level pointer in the given address space (defaulting to 0).
|
/// Get a low-level pointer in the given address space.
|
||||||
static LLT pointer(uint16_t AddressSpace, unsigned SizeInBits) {
|
static LLT pointer(unsigned AddressSpace, unsigned SizeInBits) {
|
||||||
assert(SizeInBits > 0 && "invalid pointer size");
|
assert(SizeInBits > 0 && "invalid pointer size");
|
||||||
return LLT{/*isPointer=*/true, /*isVector=*/false, /*NumElements=*/0,
|
return LLT{/*isPointer=*/true, /*isVector=*/false, /*NumElements=*/0,
|
||||||
SizeInBits, AddressSpace};
|
SizeInBits, AddressSpace};
|
||||||
@ -181,10 +181,10 @@ private:
|
|||||||
static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 0};
|
static const constexpr BitFieldInfo ScalarSizeFieldInfo{32, 0};
|
||||||
/// * Pointer (isPointer == 1 && isVector == 0):
|
/// * Pointer (isPointer == 1 && isVector == 0):
|
||||||
/// SizeInBits: 16;
|
/// SizeInBits: 16;
|
||||||
/// AddressSpace: 23;
|
/// AddressSpace: 24;
|
||||||
static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 0};
|
static const constexpr BitFieldInfo PointerSizeFieldInfo{16, 0};
|
||||||
static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{
|
static const constexpr BitFieldInfo PointerAddressSpaceFieldInfo{
|
||||||
23, PointerSizeFieldInfo[0] + PointerSizeFieldInfo[1]};
|
24, PointerSizeFieldInfo[0] + PointerSizeFieldInfo[1]};
|
||||||
/// * Vector-of-non-pointer (isPointer == 0 && isVector == 1):
|
/// * Vector-of-non-pointer (isPointer == 0 && isVector == 1):
|
||||||
/// NumElements: 16;
|
/// NumElements: 16;
|
||||||
/// SizeOfElement: 32;
|
/// SizeOfElement: 32;
|
||||||
@ -194,13 +194,13 @@ private:
|
|||||||
/// * Vector-of-pointer (isPointer == 1 && isVector == 1):
|
/// * Vector-of-pointer (isPointer == 1 && isVector == 1):
|
||||||
/// NumElements: 16;
|
/// NumElements: 16;
|
||||||
/// SizeOfElement: 16;
|
/// SizeOfElement: 16;
|
||||||
/// AddressSpace: 23;
|
/// AddressSpace: 24;
|
||||||
static const constexpr BitFieldInfo PointerVectorElementsFieldInfo{16, 0};
|
static const constexpr BitFieldInfo PointerVectorElementsFieldInfo{16, 0};
|
||||||
static const constexpr BitFieldInfo PointerVectorSizeFieldInfo{
|
static const constexpr BitFieldInfo PointerVectorSizeFieldInfo{
|
||||||
16,
|
16,
|
||||||
PointerVectorElementsFieldInfo[1] + PointerVectorElementsFieldInfo[0]};
|
PointerVectorElementsFieldInfo[1] + PointerVectorElementsFieldInfo[0]};
|
||||||
static const constexpr BitFieldInfo PointerVectorAddressSpaceFieldInfo{
|
static const constexpr BitFieldInfo PointerVectorAddressSpaceFieldInfo{
|
||||||
23, PointerVectorSizeFieldInfo[1] + PointerVectorSizeFieldInfo[0]};
|
24, PointerVectorSizeFieldInfo[1] + PointerVectorSizeFieldInfo[0]};
|
||||||
|
|
||||||
uint64_t IsPointer : 1;
|
uint64_t IsPointer : 1;
|
||||||
uint64_t IsVector : 1;
|
uint64_t IsVector : 1;
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
; RUN: llc -O0 -mtriple=aarch64-apple-ios -global-isel -stop-after=irtranslator %s -o - | FileCheck %s
|
||||||
|
|
||||||
|
; CHECK-LABEL: name: store_max_address_space
|
||||||
|
; CHECK: %0:_(p16777215) = COPY $x0
|
||||||
|
; CHECK: G_STORE %1(s32), %0(p16777215) :: (store 4 into %ir.ptr, addrspace 16777215)
|
||||||
|
define void @store_max_address_space(i32 addrspace(16777215)* %ptr) {
|
||||||
|
store i32 0, i32 addrspace(16777215)* %ptr
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: name: store_max_address_space_vector
|
||||||
|
; CHECK: %0:_(<2 x p16777215>) = COPY $q0
|
||||||
|
; CHECK: %1:_(p16777215) = G_EXTRACT_VECTOR_ELT %0(<2 x p16777215>), %2(s64)
|
||||||
|
; CHECK: %1(p16777215) :: (store 4 into %ir.elt0, addrspace 16777215)
|
||||||
|
define void @store_max_address_space_vector(<2 x i32 addrspace(16777215)*> %vptr) {
|
||||||
|
%elt0 = extractelement <2 x i32 addrspace(16777215)*> %vptr, i32 0
|
||||||
|
store i32 0, i32 addrspace(16777215)* %elt0
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
|
||||||
|
; CHECK-LABEL: name: max_address_space_vector_max_num_elts
|
||||||
|
; CHECK: %0:_(<65535 x p16777215>) = G_LOAD %1(p0) :: (volatile load 524280 from `<65535 x i32 addrspace(16777215)*>* undef`, align 524288)
|
||||||
|
define void @max_address_space_vector_max_num_elts() {
|
||||||
|
%load = load volatile <65535 x i32 addrspace(16777215)*>, <65535 x i32 addrspace(16777215)*>* undef
|
||||||
|
ret void
|
||||||
|
}
|
@ -120,11 +120,14 @@ TEST(LowLevelTypeTest, ScalarOrVector) {
|
|||||||
|
|
||||||
TEST(LowLevelTypeTest, Pointer) {
|
TEST(LowLevelTypeTest, Pointer) {
|
||||||
LLVMContext C;
|
LLVMContext C;
|
||||||
DataLayout DL("");
|
DataLayout DL("p64:64:64-p127:512:512:512-p16777215:65528:8");
|
||||||
|
|
||||||
for (unsigned AS : {0U, 1U, 127U, 0xffffU}) {
|
for (unsigned AS : {0U, 1U, 127U, 0xffffU,
|
||||||
|
static_cast<unsigned>(maxUIntN(23)),
|
||||||
|
static_cast<unsigned>(maxUIntN(24))}) {
|
||||||
|
for (unsigned NumElts : {2, 3, 4, 256, 65535}) {
|
||||||
const LLT Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
|
const LLT Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
|
||||||
const LLT VTy = LLT::vector(4, Ty);
|
const LLT VTy = LLT::vector(NumElts, Ty);
|
||||||
|
|
||||||
// Test kind.
|
// Test kind.
|
||||||
ASSERT_TRUE(Ty.isValid());
|
ASSERT_TRUE(Ty.isValid());
|
||||||
@ -137,6 +140,9 @@ TEST(LowLevelTypeTest, Pointer) {
|
|||||||
ASSERT_TRUE(VTy.isVector());
|
ASSERT_TRUE(VTy.isVector());
|
||||||
ASSERT_TRUE(VTy.getElementType().isPointer());
|
ASSERT_TRUE(VTy.getElementType().isPointer());
|
||||||
|
|
||||||
|
EXPECT_EQ(Ty, VTy.getElementType());
|
||||||
|
EXPECT_EQ(Ty.getSizeInBits(), VTy.getScalarSizeInBits());
|
||||||
|
|
||||||
// Test address space.
|
// Test address space.
|
||||||
EXPECT_EQ(AS, Ty.getAddressSpace());
|
EXPECT_EQ(AS, Ty.getAddressSpace());
|
||||||
EXPECT_EQ(AS, VTy.getElementType().getAddressSpace());
|
EXPECT_EQ(AS, VTy.getElementType().getAddressSpace());
|
||||||
@ -151,10 +157,11 @@ TEST(LowLevelTypeTest, Pointer) {
|
|||||||
Type *IRTy = PointerType::get(IntegerType::get(C, 8), AS);
|
Type *IRTy = PointerType::get(IntegerType::get(C, 8), AS);
|
||||||
EXPECT_EQ(Ty, getLLTForType(*IRTy, DL));
|
EXPECT_EQ(Ty, getLLTForType(*IRTy, DL));
|
||||||
Type *IRVTy =
|
Type *IRVTy =
|
||||||
VectorType::get(PointerType::get(IntegerType::get(C, 8), AS), 4);
|
VectorType::get(PointerType::get(IntegerType::get(C, 8), AS), NumElts);
|
||||||
EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL));
|
EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
TEST(LowLevelTypeTest, Invalid) {
|
TEST(LowLevelTypeTest, Invalid) {
|
||||||
const LLT Ty;
|
const LLT Ty;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user