Skip to content

Commit

Permalink
Drop some typed pointer handling
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D156739
  • Loading branch information
bjope committed Aug 2, 2023
1 parent 408cc94 commit e6e9a87
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 89 deletions.
8 changes: 3 additions & 5 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6047,9 +6047,8 @@ static Value *simplifyRelativeLoad(Constant *Ptr, Constant *Offset,
if (!IsConstantOffsetFromGlobal(Ptr, PtrSym, PtrOffset, DL))
return nullptr;

Type *Int8PtrTy = Type::getInt8PtrTy(Ptr->getContext());
Type *UnqualPtrTy = PointerType::getUnqual(Ptr->getContext());
Type *Int32Ty = Type::getInt32Ty(Ptr->getContext());
Type *Int32PtrTy = Int32Ty->getPointerTo();
Type *Int64Ty = Type::getInt64Ty(Ptr->getContext());

auto *OffsetConstInt = dyn_cast<ConstantInt>(Offset);
Expand All @@ -6061,8 +6060,7 @@ static Value *simplifyRelativeLoad(Constant *Ptr, Constant *Offset,
return nullptr;

Constant *C = ConstantExpr::getGetElementPtr(
Int32Ty, ConstantExpr::getBitCast(Ptr, Int32PtrTy),
ConstantInt::get(Int64Ty, OffsetInt / 4));
Int32Ty, Ptr, ConstantInt::get(Int64Ty, OffsetInt / 4));
Constant *Loaded = ConstantFoldLoadFromConstPtr(C, Int32Ty, DL);
if (!Loaded)
return nullptr;
Expand Down Expand Up @@ -6093,7 +6091,7 @@ static Value *simplifyRelativeLoad(Constant *Ptr, Constant *Offset,
PtrSym != LoadedRHSSym || PtrOffset != LoadedRHSOffset)
return nullptr;

return ConstantExpr::getBitCast(LoadedLHSPtr, Int8PtrTy);
return ConstantExpr::getBitCast(LoadedLHSPtr, UnqualPtrTy);
}

static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
Expand Down
41 changes: 18 additions & 23 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4585,10 +4585,11 @@ void OpenMPIRBuilder::emitOffloadingArraysArgument(IRBuilderBase &Builder,
bool ForEndCall) {
assert((!ForEndCall || Info.separateBeginEndCalls()) &&
"expected region end call to runtime only when end call is separate");
auto VoidPtrTy = Type::getInt8PtrTy(M.getContext());
auto VoidPtrPtrTy = VoidPtrTy->getPointerTo(0);
auto UnqualPtrTy = PointerType::getUnqual(M.getContext());
auto VoidPtrTy = UnqualPtrTy;
auto VoidPtrPtrTy = UnqualPtrTy;
auto Int64Ty = Type::getInt64Ty(M.getContext());
auto Int64PtrTy = Type::getInt64PtrTy(M.getContext());
auto Int64PtrTy = UnqualPtrTy;

if (!Info.NumberOfPtrs) {
RTArgs.BasePointersArray = ConstantPointerNull::get(VoidPtrPtrTy);
Expand Down Expand Up @@ -4737,7 +4738,7 @@ void OpenMPIRBuilder::emitOffloadingArrays(
// need to fill up the arrays as we do for the pointers.
Type *Int64Ty = Builder.getInt64Ty();
SmallVector<Constant *> ConstSizes(CombinedInfo.Sizes.size(),
ConstantInt::get(Builder.getInt64Ty(), 0));
ConstantInt::get(Int64Ty, 0));
SmallBitVector RuntimeSizes(CombinedInfo.Sizes.size());
for (unsigned I = 0, E = CombinedInfo.Sizes.size(); I < E; ++I) {
if (auto *CI = dyn_cast<Constant>(CombinedInfo.Sizes[I])) {
Expand All @@ -4746,7 +4747,7 @@ void OpenMPIRBuilder::emitOffloadingArrays(
static_cast<std::underlying_type_t<OpenMPOffloadMappingFlags>>(
CombinedInfo.Types[I] &
OpenMPOffloadMappingFlags::OMP_MAP_NON_CONTIG))
ConstSizes[I] = ConstantInt::get(Builder.getInt64Ty(),
ConstSizes[I] = ConstantInt::get(Int64Ty,
CombinedInfo.NonContigInfo.Dims[I]);
else
ConstSizes[I] = CI;
Expand Down Expand Up @@ -4780,11 +4781,9 @@ void OpenMPIRBuilder::emitOffloadingArrays(
SizeArrayType, /* ArraySize = */ nullptr, ".offload_sizes");
Buffer->setAlignment(OffloadSizeAlign);
Builder.restoreIP(CodeGenIP);
Value *GblConstPtr = Builder.CreatePointerBitCastOrAddrSpaceCast(
SizesArrayGbl, Int64Ty->getPointerTo());
Builder.CreateMemCpy(
Buffer, M.getDataLayout().getPrefTypeAlign(Buffer->getType()),
GblConstPtr, OffloadSizeAlign,
SizesArrayGbl, OffloadSizeAlign,
Builder.getIntN(
IndexSize,
Buffer->getAllocationSize(M.getDataLayout())->getFixedValue()));
Expand Down Expand Up @@ -4813,7 +4812,7 @@ void OpenMPIRBuilder::emitOffloadingArrays(
Info.RTArgs.MapNamesArray = MapNamesArrayGbl;
} else {
Info.RTArgs.MapNamesArray = Constant::getNullValue(
Type::getInt8Ty(Builder.getContext())->getPointerTo());
PointerType::getUnqual(Builder.getContext()));
}

// If there's a present map type modifier, it must not be applied to the end
Expand All @@ -4834,22 +4833,20 @@ void OpenMPIRBuilder::emitOffloadingArrays(
}
}

PointerType *PtrTy = Builder.getPtrTy();
for (unsigned I = 0; I < Info.NumberOfPtrs; ++I) {
Value *BPVal = CombinedInfo.BasePointers[I];
Value *BP = Builder.CreateConstInBoundsGEP2_32(
ArrayType::get(Builder.getInt8PtrTy(), Info.NumberOfPtrs),
ArrayType::get(PtrTy, Info.NumberOfPtrs),
Info.RTArgs.BasePointersArray, 0, I);
BP = Builder.CreatePointerBitCastOrAddrSpaceCast(
BP, BPVal->getType()->getPointerTo(/*AddrSpace=*/0));
Builder.CreateAlignedStore(
BPVal, BP, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
BPVal, BP, M.getDataLayout().getPrefTypeAlign(PtrTy));

if (Info.requiresDevicePointerInfo()) {
if (CombinedInfo.DevicePointers[I] == DeviceInfoTy::Pointer) {
CodeGenIP = Builder.saveIP();
Builder.restoreIP(AllocaIP);
Info.DevicePtrInfoMap[BPVal] = {
BP, Builder.CreateAlloca(Builder.getPtrTy())};
Info.DevicePtrInfoMap[BPVal] = {BP, Builder.CreateAlloca(PtrTy)};
Builder.restoreIP(CodeGenIP);
assert(DeviceAddrCB &&
"DeviceAddrCB missing for DevicePtr code generation");
Expand All @@ -4864,13 +4861,11 @@ void OpenMPIRBuilder::emitOffloadingArrays(

Value *PVal = CombinedInfo.Pointers[I];
Value *P = Builder.CreateConstInBoundsGEP2_32(
ArrayType::get(Builder.getInt8PtrTy(), Info.NumberOfPtrs),
ArrayType::get(PtrTy, Info.NumberOfPtrs),
Info.RTArgs.PointersArray, 0, I);
P = Builder.CreatePointerBitCastOrAddrSpaceCast(
P, PVal->getType()->getPointerTo(/*AddrSpace=*/0));
// TODO: Check alignment correct.
Builder.CreateAlignedStore(
PVal, P, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
PVal, P, M.getDataLayout().getPrefTypeAlign(PtrTy));

if (RuntimeSizes.test(I)) {
Value *S = Builder.CreateConstInBoundsGEP2_32(
Expand All @@ -4880,14 +4875,14 @@ void OpenMPIRBuilder::emitOffloadingArrays(
Builder.CreateAlignedStore(
Builder.CreateIntCast(CombinedInfo.Sizes[I], Int64Ty,
/*isSigned=*/true),
S, M.getDataLayout().getPrefTypeAlign(Builder.getInt8PtrTy()));
S, M.getDataLayout().getPrefTypeAlign(PtrTy));
}
// Fill up the mapper array.
unsigned IndexSize = M.getDataLayout().getIndexSizeInBits(0);
Value *MFunc = ConstantPointerNull::get(Builder.getInt8PtrTy());
Value *MFunc = ConstantPointerNull::get(PtrTy);
if (CustomMapperCB)
if (Value *CustomMFunc = CustomMapperCB(I))
MFunc = Builder.CreatePointerCast(CustomMFunc, Builder.getInt8PtrTy());
MFunc = Builder.CreatePointerCast(CustomMFunc, PtrTy);
Value *MAddr = Builder.CreateInBoundsGEP(
MappersArray->getAllocatedType(), MappersArray,
{Builder.getIntN(IndexSize, 0), Builder.getIntN(IndexSize, I)});
Expand Down Expand Up @@ -5483,7 +5478,7 @@ OpenMPIRBuilder::createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
std::string VarName) {
llvm::Constant *MapNamesArrayInit = llvm::ConstantArray::get(
llvm::ArrayType::get(
llvm::Type::getInt8Ty(M.getContext())->getPointerTo(), Names.size()),
llvm::PointerType::getUnqual(M.getContext()), Names.size()),
Names);
auto *MapNamesArrayGlobal = new llvm::GlobalVariable(
M, MapNamesArrayInit->getType(),
Expand Down
13 changes: 4 additions & 9 deletions llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2263,11 +2263,11 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,

if (DestVolatile) {
Type *Int32Ty = Type::getInt32Ty(Ctx);
Type *Int32PtrTy = Type::getInt32PtrTy(Ctx);
Type *PtrTy = PointerType::get(Ctx, 0);
Type *VoidTy = Type::getVoidTy(Ctx);
Module *M = Func->getParent();
FunctionCallee Fn = M->getOrInsertFunction(
HexagonVolatileMemcpyName, VoidTy, Int32PtrTy, Int32PtrTy, Int32Ty);
HexagonVolatileMemcpyName, VoidTy, PtrTy, PtrTy, Int32Ty);

const SCEV *OneS = SE->getConstant(Int32Ty, 1);
const SCEV *BECount32 = SE->getTruncateOrZeroExtend(BECount, Int32Ty);
Expand All @@ -2278,13 +2278,8 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
if (Value *Simp = simplifyInstruction(In, {*DL, TLI, DT}))
NumWords = Simp;

Value *Op0 = (StoreBasePtr->getType() == Int32PtrTy)
? StoreBasePtr
: CondBuilder.CreateBitCast(StoreBasePtr, Int32PtrTy);
Value *Op1 = (LoadBasePtr->getType() == Int32PtrTy)
? LoadBasePtr
: CondBuilder.CreateBitCast(LoadBasePtr, Int32PtrTy);
NewCall = CondBuilder.CreateCall(Fn, {Op0, Op1, NumWords});
NewCall = CondBuilder.CreateCall(Fn,
{StoreBasePtr, LoadBasePtr, NumWords});
} else {
NewCall = CondBuilder.CreateMemMove(
StoreBasePtr, SI->getAlign(), LoadBasePtr, LI->getAlign(), NumBytes);
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ static Value *constructPointer(Type *ResTy, Type *PtrElemTy, Value *Ptr,

// If an offset is left we use byte-wise adjustment.
if (IntOffset != 0) {
Ptr = IRB.CreateBitCast(Ptr, IRB.getInt8PtrTy());
Ptr = IRB.CreateGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(IntOffset),
GEPName + ".b" + Twine(IntOffset.getZExtValue()));
}
Expand Down
15 changes: 6 additions & 9 deletions llvm/lib/Transforms/IPO/GlobalOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1905,10 +1905,8 @@ static void RemovePreallocated(Function *F) {
Builder.SetInsertPoint(InsertBefore);
auto *Alloca =
Builder.CreateAlloca(ArgType, AddressSpace, nullptr, "paarg");
auto *BitCast = Builder.CreateBitCast(
Alloca, Type::getInt8PtrTy(M->getContext()), UseCall->getName());
ArgAllocas[AllocArgIndex] = BitCast;
AllocaReplacement = BitCast;
ArgAllocas[AllocArgIndex] = Alloca;
AllocaReplacement = Alloca;
}

UseCall->replaceAllUsesWith(AllocaReplacement);
Expand Down Expand Up @@ -2117,19 +2115,18 @@ static void setUsedInitializer(GlobalVariable &V,
const auto *VEPT = cast<PointerType>(VAT->getArrayElementType());

// Type of pointer to the array of pointers.
PointerType *Int8PtrTy =
Type::getInt8PtrTy(V.getContext(), VEPT->getAddressSpace());
PointerType *PtrTy =
PointerType::get(V.getContext(), VEPT->getAddressSpace());

SmallVector<Constant *, 8> UsedArray;
for (GlobalValue *GV : Init) {
Constant *Cast =
ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, Int8PtrTy);
Constant *Cast = ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, PtrTy);
UsedArray.push_back(Cast);
}

// Sort to get deterministic order.
array_pod_sort(UsedArray.begin(), UsedArray.end(), compareNames);
ArrayType *ATy = ArrayType::get(Int8PtrTy, UsedArray.size());
ArrayType *ATy = ArrayType::get(PtrTy, UsedArray.size());

Module *M = V.getParent();
V.removeFromParent();
Expand Down
Loading

0 comments on commit e6e9a87

Please sign in to comment.