[CodeGen] Avoid more pointer element type accesses

This commit is contained in:
Nikita Popov 2021-12-16 11:12:00 +01:00
parent f5f421e0ee
commit 34eb715f61
4 changed files with 20 additions and 18 deletions

View File

@ -513,7 +513,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
Emitter.finalize(GV);
CharUnits Align = CGM.getContext().getTypeAlignInChars(ArrayQTy);
GV->setAlignment(Align.getAsAlign());
EmitFinalDestCopy(ArrayQTy, CGF.MakeAddrLValue(GV, ArrayQTy, Align));
Address GVAddr(GV, GV->getValueType(), Align);
EmitFinalDestCopy(ArrayQTy, CGF.MakeAddrLValue(GVAddr, ArrayQTy));
return;
}
}

View File

@ -3531,7 +3531,7 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
return CGF.Builder.CreateBitCast(result, pointer->getType());
}
llvm::Type *elemTy = pointer->getType()->getPointerElementType();
llvm::Type *elemTy = CGF.ConvertTypeForMem(elementType);
if (CGF.getLangOpts().isSignedOverflowDefined())
return CGF.Builder.CreateGEP(elemTy, pointer, index, "add.ptr");

View File

@ -2017,12 +2017,13 @@ Address CGOpenMPRuntime::getAddrOfArtificialThreadPrivate(CodeGenFunction &CGF,
StringRef Name) {
std::string Suffix = getName({"artificial", ""});
llvm::Type *VarLVType = CGF.ConvertTypeForMem(VarType);
llvm::Value *GAddr =
llvm::GlobalVariable *GAddr =
getOrCreateInternalVariable(VarLVType, Twine(Name).concat(Suffix));
if (CGM.getLangOpts().OpenMP && CGM.getLangOpts().OpenMPUseTLS &&
CGM.getTarget().isTLSSupported()) {
cast<llvm::GlobalVariable>(GAddr)->setThreadLocal(/*Val=*/true);
return Address(GAddr, CGM.getContext().getTypeAlignInChars(VarType));
GAddr->setThreadLocal(/*Val=*/true);
return Address(GAddr, GAddr->getValueType(),
CGM.getContext().getTypeAlignInChars(VarType));
}
std::string CacheSuffix = getName({"cache", ""});
llvm::Value *Args[] = {
@ -2177,7 +2178,7 @@ Address CGOpenMPRuntime::emitThreadIDAddress(CodeGenFunction &CGF,
return ThreadIDTemp;
}
llvm::Constant *CGOpenMPRuntime::getOrCreateInternalVariable(
llvm::GlobalVariable *CGOpenMPRuntime::getOrCreateInternalVariable(
llvm::Type *Ty, const llvm::Twine &Name, unsigned AddressSpace) {
SmallString<256> Buffer;
llvm::raw_svector_ostream Out(Buffer);
@ -2185,7 +2186,7 @@ llvm::Constant *CGOpenMPRuntime::getOrCreateInternalVariable(
StringRef RuntimeName = Out.str();
auto &Elem = *InternalVars.try_emplace(RuntimeName, nullptr).first;
if (Elem.second) {
assert(Elem.second->getType()->getPointerElementType() == Ty &&
assert(Elem.second->getType()->isOpaqueOrPointeeTypeMatches(Ty) &&
"OMP internal variable has different type than requested");
return &*Elem.second;
}
@ -12684,12 +12685,11 @@ void CGOpenMPRuntime::emitLastprivateConditionalUpdate(CodeGenFunction &CGF,
// Last value of the lastprivate conditional.
// decltype(priv_a) last_a;
llvm::Constant *Last = getOrCreateInternalVariable(
llvm::GlobalVariable *Last = getOrCreateInternalVariable(
CGF.ConvertTypeForMem(LVal.getType()), UniqueDeclName);
cast<llvm::GlobalVariable>(Last)->setAlignment(
LVal.getAlignment().getAsAlign());
LValue LastLVal =
CGF.MakeAddrLValue(Last, LVal.getType(), LVal.getAlignment());
Last->setAlignment(LVal.getAlignment().getAsAlign());
LValue LastLVal = CGF.MakeAddrLValue(
Address(Last, Last->getValueType(), LVal.getAlignment()), LVal.getType());
// Global loop counter. Required to handle inner parallel-for regions.
// iv
@ -12862,7 +12862,8 @@ void CGOpenMPRuntime::emitLastprivateConditionalFinalUpdate(
if (!GV)
return;
LValue LPLVal = CGF.MakeAddrLValue(
GV, PrivLVal.getType().getNonReferenceType(), PrivLVal.getAlignment());
Address(GV, GV->getValueType(), PrivLVal.getAlignment()),
PrivLVal.getType().getNonReferenceType());
llvm::Value *Res = CGF.EmitLoadOfScalar(LPLVal, Loc);
CGF.EmitStoreOfScalar(Res, PrivLVal);
}

View File

@ -471,8 +471,8 @@ private:
/// <critical_section_name> + ".var" for "omp critical" directives; 2)
/// <mangled_name_for_global_var> + ".cache." for cache for threadprivate
/// variables.
llvm::StringMap<llvm::AssertingVH<llvm::Constant>, llvm::BumpPtrAllocator>
InternalVars;
llvm::StringMap<llvm::AssertingVH<llvm::GlobalVariable>,
llvm::BumpPtrAllocator> InternalVars;
/// Type typedef kmp_int32 (* kmp_routine_entry_t)(kmp_int32, void *);
llvm::Type *KmpRoutineEntryPtrTy = nullptr;
QualType KmpRoutineEntryPtrQTy;
@ -829,7 +829,7 @@ private:
/// \param Ty Type of the global variable. If it is exist already the type
/// must be the same.
/// \param Name Name of the variable.
llvm::Constant *getOrCreateInternalVariable(llvm::Type *Ty,
llvm::GlobalVariable *getOrCreateInternalVariable(llvm::Type *Ty,
const llvm::Twine &Name,
unsigned AddressSpace = 0);