From 2b5693d1fd9f0257ba6ce8d03810f73b859de228 Mon Sep 17 00:00:00 2001 From: Yaxun Liu <Yaxun.Liu@amd.com> Date: Thu, 18 Aug 2016 20:01:06 +0000 Subject: [PATCH] Revert [OpenCL] AMDGCN: Fix size_t type due to regressions in test/CodeGen/exprs.c on certain platforms. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@279127 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/TargetInfo.h | 5 -- lib/Basic/TargetInfo.cpp | 5 +- lib/Basic/Targets.cpp | 4 -- lib/CodeGen/CGExprScalar.cpp | 15 ++--- lib/CodeGen/CodeGenModule.cpp | 5 +- lib/CodeGen/CodeGenTypeCache.h | 5 -- test/CodeGenOpenCL/size_t.cl | 110 ------------------------------- 7 files changed, 9 insertions(+), 140 deletions(-) delete mode 100644 test/CodeGenOpenCL/size_t.cl diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index de94cdacd2..a9378f83af 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -294,11 +294,6 @@ public: return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace); } - /// \brief Return the maximum width of pointers on this target. - virtual uint64_t getMaxPointerWidth() const { - return PointerWidth; - } - /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits. unsigned getBoolWidth() const { return BoolWidth; } diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 592b877fad..dec8b7cda4 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -306,9 +306,8 @@ void TargetInfo::adjust(const LangOptions &Opts) { } LongDoubleWidth = LongDoubleAlign = 128; - unsigned MaxPointerWidth = getMaxPointerWidth(); - assert(MaxPointerWidth == 32 || MaxPointerWidth == 64); - bool Is32BitArch = MaxPointerWidth == 32; + assert(PointerWidth == 32 || PointerWidth == 64); + bool Is32BitArch = PointerWidth == 32; SizeType = Is32BitArch ? UnsignedInt : UnsignedLong; PtrDiffType = Is32BitArch ? SignedInt : SignedLong; IntPtrType = Is32BitArch ? SignedInt : SignedLong; diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 36e6d4594f..793b25e928 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -2004,10 +2004,6 @@ public: } } - uint64_t getMaxPointerWidth() const override { - return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32; - } - const char * getClobbers() const override { return ""; } diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 0af4c41816..ba7f49b750 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -787,7 +787,7 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, // Handle pointer conversions next: pointers can only be converted to/from // other pointers and integers. Check for pointer types in terms of LLVM, as // some native types (like Obj-C id) may map to a pointer type. - if (auto DstPT = dyn_cast<llvm::PointerType>(DstTy)) { + if (isa<llvm::PointerType>(DstTy)) { // The source value may be an integer, or a pointer. if (isa<llvm::PointerType>(SrcTy)) return Builder.CreateBitCast(Src, DstTy, "conv"); @@ -795,7 +795,7 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?"); // First, convert to the correct width so that we control the kind of // extension. - llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DstPT); + llvm::Type *MiddleTy = CGF.IntPtrTy; bool InputSigned = SrcType->isSignedIntegerOrEnumerationType(); llvm::Value* IntResult = Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv"); @@ -1510,13 +1510,12 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { // First, convert to the correct width so that we control the kind of // extension. - auto DestLLVMTy = ConvertType(DestTy); - llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy); + llvm::Type *MiddleTy = CGF.IntPtrTy; bool InputSigned = E->getType()->isSignedIntegerOrEnumerationType(); llvm::Value* IntResult = Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv"); - return Builder.CreateIntToPtr(IntResult, DestLLVMTy); + return Builder.CreateIntToPtr(IntResult, ConvertType(DestTy)); } case CK_PointerToIntegral: assert(!DestTy->isBooleanType() && "bool should use PointerToBool"); @@ -2427,7 +2426,6 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF, Value *pointer = op.LHS; Expr *pointerOperand = expr->getLHS(); - auto PtrTy = cast<llvm::PointerType>(pointer->getType()); Value *index = op.RHS; Expr *indexOperand = expr->getRHS(); @@ -2438,12 +2436,11 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF, } unsigned width = cast<llvm::IntegerType>(index->getType())->getBitWidth(); - auto &DL = CGF.CGM.getDataLayout(); - if (width != DL.getTypeSizeInBits(PtrTy)) { + if (width != CGF.PointerWidthInBits) { // Zero-extend or sign-extend the pointer value according to // whether the index is signed or not. bool isSigned = indexOperand->getType()->isSignedIntegerOrEnumerationType(); - index = CGF.Builder.CreateIntCast(index, DL.getIntPtrType(PtrTy), isSigned, + index = CGF.Builder.CreateIntCast(index, CGF.PtrDiffTy, isSigned, "idx.ext"); } diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 1d74e4cd83..2dcccf4c6c 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -101,13 +101,10 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO, PointerWidthInBits = C.getTargetInfo().getPointerWidth(0); PointerAlignInBytes = C.toCharUnitsFromBits(C.getTargetInfo().getPointerAlign(0)).getQuantity(); - SizeSizeInBytes = - C.toCharUnitsFromBits(C.getTargetInfo().getMaxPointerWidth()).getQuantity(); IntAlignInBytes = C.toCharUnitsFromBits(C.getTargetInfo().getIntAlign()).getQuantity(); IntTy = llvm::IntegerType::get(LLVMContext, C.getTargetInfo().getIntWidth()); - IntPtrTy = llvm::IntegerType::get(LLVMContext, - C.getTargetInfo().getMaxPointerWidth()); + IntPtrTy = llvm::IntegerType::get(LLVMContext, PointerWidthInBits); Int8PtrTy = Int8Ty->getPointerTo(0); Int8PtrPtrTy = Int8PtrTy->getPointerTo(0); diff --git a/lib/CodeGen/CodeGenTypeCache.h b/lib/CodeGen/CodeGenTypeCache.h index 47e26bcaa1..c32b66d129 100644 --- a/lib/CodeGen/CodeGenTypeCache.h +++ b/lib/CodeGen/CodeGenTypeCache.h @@ -80,14 +80,9 @@ struct CodeGenTypeCache { union { unsigned char PointerAlignInBytes; unsigned char PointerSizeInBytes; - }; - - /// The size and alignment of size_t. - union { unsigned char SizeSizeInBytes; // sizeof(size_t) unsigned char SizeAlignInBytes; }; - CharUnits getSizeSize() const { return CharUnits::fromQuantity(SizeSizeInBytes); } diff --git a/test/CodeGenOpenCL/size_t.cl b/test/CodeGenOpenCL/size_t.cl deleted file mode 100644 index ed941e0185..0000000000 --- a/test/CodeGenOpenCL/size_t.cl +++ /dev/null @@ -1,110 +0,0 @@ -// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple spir-unknown-unknown -o - | FileCheck --check-prefix=SZ32 %s -// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple spir64-unknown-unknown -o - | FileCheck --check-prefix=SZ64 --check-prefix=SZ64ONLY %s -// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple amdgcn-- -o - | FileCheck --check-prefix=SZ64 --check-prefix=AMDONLY %s - -//SZ32: define{{.*}} i32 @test_ptrtoint_private(i8* %x) -//SZ32: ptrtoint i8* %{{.*}} to i32 -//SZ64: define{{.*}} i64 @test_ptrtoint_private(i8* %x) -//SZ64: ptrtoint i8* %{{.*}} to i64 -size_t test_ptrtoint_private(private char* x) { - return (size_t)x; -} - -//SZ32: define{{.*}} i32 @test_ptrtoint_global(i8 addrspace(1)* %x) -//SZ32: ptrtoint i8 addrspace(1)* %{{.*}} to i32 -//SZ64: define{{.*}} i64 @test_ptrtoint_global(i8 addrspace(1)* %x) -//SZ64: ptrtoint i8 addrspace(1)* %{{.*}} to i64 -intptr_t test_ptrtoint_global(global char* x) { - return (intptr_t)x; -} - -//SZ32: define{{.*}} i32 @test_ptrtoint_constant(i8 addrspace(2)* %x) -//SZ32: ptrtoint i8 addrspace(2)* %{{.*}} to i32 -//SZ64: define{{.*}} i64 @test_ptrtoint_constant(i8 addrspace(2)* %x) -//SZ64: ptrtoint i8 addrspace(2)* %{{.*}} to i64 -uintptr_t test_ptrtoint_constant(constant char* x) { - return (uintptr_t)x; -} - -//SZ32: define{{.*}} i32 @test_ptrtoint_local(i8 addrspace(3)* %x) -//SZ32: ptrtoint i8 addrspace(3)* %{{.*}} to i32 -//SZ64: define{{.*}} i64 @test_ptrtoint_local(i8 addrspace(3)* %x) -//SZ64: ptrtoint i8 addrspace(3)* %{{.*}} to i64 -size_t test_ptrtoint_local(local char* x) { - return (size_t)x; -} - -//SZ32: define{{.*}} i32 @test_ptrtoint_generic(i8 addrspace(4)* %x) -//SZ32: ptrtoint i8 addrspace(4)* %{{.*}} to i32 -//SZ64: define{{.*}} i64 @test_ptrtoint_generic(i8 addrspace(4)* %x) -//SZ64: ptrtoint i8 addrspace(4)* %{{.*}} to i64 -size_t test_ptrtoint_generic(generic char* x) { - return (size_t)x; -} - -//SZ32: define{{.*}} i8* @test_inttoptr_private(i32 %x) -//SZ32: inttoptr i32 %{{.*}} to i8* -//SZ64: define{{.*}} i8* @test_inttoptr_private(i64 %x) -//AMDONLY: trunc i64 %{{.*}} to i32 -//AMDONLY: inttoptr i32 %{{.*}} to i8* -//SZ64ONLY: inttoptr i64 %{{.*}} to i8* -private char* test_inttoptr_private(size_t x) { - return (private char*)x; -} - -//SZ32: define{{.*}} i8 addrspace(1)* @test_inttoptr_global(i32 %x) -//SZ32: inttoptr i32 %{{.*}} to i8 addrspace(1)* -//SZ64: define{{.*}} i8 addrspace(1)* @test_inttoptr_global(i64 %x) -//SZ64: inttoptr i64 %{{.*}} to i8 addrspace(1)* -global char* test_inttoptr_global(size_t x) { - return (global char*)x; -} - -//SZ32: define{{.*}} i8 addrspace(3)* @test_add_local(i8 addrspace(3)* %x, i32 %y) -//SZ32: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i32 -//SZ64: define{{.*}} i8 addrspace(3)* @test_add_local(i8 addrspace(3)* %x, i64 %y) -//AMDONLY: trunc i64 %{{.*}} to i32 -//AMDONLY: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i32 -//SZ64ONLY: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i64 -local char* test_add_local(local char* x, ptrdiff_t y) { - return x + y; -} - -//SZ32: define{{.*}} i8 addrspace(1)* @test_add_global(i8 addrspace(1)* %x, i32 %y) -//SZ32: getelementptr inbounds i8, i8 addrspace(1)* %{{.*}}, i32 -//SZ64: define{{.*}} i8 addrspace(1)* @test_add_global(i8 addrspace(1)* %x, i64 %y) -//SZ64: getelementptr inbounds i8, i8 addrspace(1)* %{{.*}}, i64 -global char* test_add_global(global char* x, ptrdiff_t y) { - return x + y; -} - -//SZ32: define{{.*}} i32 @test_sub_local(i8 addrspace(3)* %x, i8 addrspace(3)* %y) -//SZ32: ptrtoint i8 addrspace(3)* %{{.*}} to i32 -//SZ32: ptrtoint i8 addrspace(3)* %{{.*}} to i32 -//SZ64: define{{.*}} i64 @test_sub_local(i8 addrspace(3)* %x, i8 addrspace(3)* %y) -//SZ64: ptrtoint i8 addrspace(3)* %{{.*}} to i64 -//SZ64: ptrtoint i8 addrspace(3)* %{{.*}} to i64 -ptrdiff_t test_sub_local(local char* x, local char *y) { - return x - y; -} - -//SZ32: define{{.*}} i32 @test_sub_private(i8* %x, i8* %y) -//SZ32: ptrtoint i8* %{{.*}} to i32 -//SZ32: ptrtoint i8* %{{.*}} to i32 -//SZ64: define{{.*}} i64 @test_sub_private(i8* %x, i8* %y) -//SZ64: ptrtoint i8* %{{.*}} to i64 -//SZ64: ptrtoint i8* %{{.*}} to i64 -ptrdiff_t test_sub_private(private char* x, private char *y) { - return x - y; -} - -//SZ32: define{{.*}} i32 @test_sub_mix(i8* %x, i8 addrspace(4)* %y) -//SZ32: ptrtoint i8* %{{.*}} to i32 -//SZ32: ptrtoint i8 addrspace(4)* %{{.*}} to i32 -//SZ64: define{{.*}} i64 @test_sub_mix(i8* %x, i8 addrspace(4)* %y) -//SZ64: ptrtoint i8* %{{.*}} to i64 -//SZ64: ptrtoint i8 addrspace(4)* %{{.*}} to i64 -ptrdiff_t test_sub_mix(private char* x, generic char *y) { - return x - y; -} - -- 2.40.0