summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp')
-rw-r--r--clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp61
1 files changed, 34 insertions, 27 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
index 24a49275772..b4c943d9dec 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
@@ -1477,49 +1477,53 @@ void CGOpenMPRuntimeNVPTX::emitSpmdParallelCall(
}
/// Cast value to the specified type.
-static llvm::Value *
-castValueToType(CodeGenFunction &CGF, llvm::Value *Val, llvm::Type *CastTy,
- llvm::Optional<bool> IsSigned = llvm::None) {
- if (Val->getType() == CastTy)
+static llvm::Value *castValueToType(CodeGenFunction &CGF, llvm::Value *Val,
+ QualType ValTy, QualType CastTy,
+ SourceLocation Loc) {
+ assert(!CGF.getContext().getTypeSizeInChars(CastTy).isZero() &&
+ "Cast type must sized.");
+ assert(!CGF.getContext().getTypeSizeInChars(ValTy).isZero() &&
+ "Val type must sized.");
+ llvm::Type *LLVMCastTy = CGF.ConvertTypeForMem(CastTy);
+ if (ValTy == CastTy)
return Val;
- if (Val->getType()->getPrimitiveSizeInBits() > 0 &&
- CastTy->getPrimitiveSizeInBits() > 0 &&
- Val->getType()->getPrimitiveSizeInBits() ==
- CastTy->getPrimitiveSizeInBits())
- return CGF.Builder.CreateBitCast(Val, CastTy);
- if (IsSigned.hasValue() && CastTy->isIntegerTy() &&
- Val->getType()->isIntegerTy())
- return CGF.Builder.CreateIntCast(Val, CastTy, *IsSigned);
- Address CastItem = CGF.CreateTempAlloca(
- CastTy,
- CharUnits::fromQuantity(
- CGF.CGM.getDataLayout().getPrefTypeAlignment(Val->getType())));
+ if (CGF.getContext().getTypeSizeInChars(ValTy) ==
+ CGF.getContext().getTypeSizeInChars(CastTy))
+ return CGF.Builder.CreateBitCast(Val, LLVMCastTy);
+ if (CastTy->isIntegerType() && ValTy->isIntegerType())
+ return CGF.Builder.CreateIntCast(Val, LLVMCastTy,
+ CastTy->hasSignedIntegerRepresentation());
+ Address CastItem = CGF.CreateMemTemp(CastTy);
Address ValCastItem = CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
CastItem, Val->getType()->getPointerTo(CastItem.getAddressSpace()));
- CGF.Builder.CreateStore(Val, ValCastItem);
- return CGF.Builder.CreateLoad(CastItem);
+ CGF.EmitStoreOfScalar(Val, ValCastItem, /*Volatile=*/false, ValTy);
+ return CGF.EmitLoadOfScalar(CastItem, /*Volatile=*/false, CastTy, Loc);
}
/// This function creates calls to one of two shuffle functions to copy
/// variables between lanes in a warp.
static llvm::Value *createRuntimeShuffleFunction(CodeGenFunction &CGF,
llvm::Value *Elem,
- llvm::Value *Offset) {
+ QualType ElemType,
+ llvm::Value *Offset,
+ SourceLocation Loc) {
auto &CGM = CGF.CGM;
auto &Bld = CGF.Builder;
CGOpenMPRuntimeNVPTX &RT =
*(static_cast<CGOpenMPRuntimeNVPTX *>(&CGM.getOpenMPRuntime()));
- unsigned Size = CGM.getDataLayout().getTypeStoreSize(Elem->getType());
- assert(Size <= 8 && "Unsupported bitwidth in shuffle instruction.");
+ CharUnits Size = CGF.getContext().getTypeSizeInChars(ElemType);
+ assert(Size.getQuantity() <= 8 &&
+ "Unsupported bitwidth in shuffle instruction.");
- OpenMPRTLFunctionNVPTX ShuffleFn = Size <= 4
+ OpenMPRTLFunctionNVPTX ShuffleFn = Size.getQuantity() <= 4
? OMPRTL_NVPTX__kmpc_shuffle_int32
: OMPRTL_NVPTX__kmpc_shuffle_int64;
// Cast all types to 32- or 64-bit values before calling shuffle routines.
- llvm::Type *CastTy = Size <= 4 ? CGM.Int32Ty : CGM.Int64Ty;
- llvm::Value *ElemCast = castValueToType(CGF, Elem, CastTy, /*isSigned=*/true);
+ QualType CastTy = CGF.getContext().getIntTypeForBitwidth(
+ Size.getQuantity() <= 4 ? 32 : 64, /*Signed=*/1);
+ llvm::Value *ElemCast = castValueToType(CGF, Elem, ElemType, CastTy, Loc);
auto *WarpSize =
Bld.CreateIntCast(getNVPTXWarpSize(CGF), CGM.Int16Ty, /*isSigned=*/true);
@@ -1527,7 +1531,7 @@ static llvm::Value *createRuntimeShuffleFunction(CodeGenFunction &CGF,
CGF.EmitRuntimeCall(RT.createNVPTXRuntimeFunction(ShuffleFn),
{ElemCast, Offset, WarpSize});
- return castValueToType(CGF, ShuffledVal, Elem->getType(), /*isSigned=*/true);
+ return castValueToType(CGF, ShuffledVal, CastTy, ElemType, Loc);
}
namespace {
@@ -1681,8 +1685,11 @@ static void emitReductionListCopy(
// Now that all active lanes have read the element in the
// Reduce list, shuffle over the value from the remote lane.
- if (ShuffleInElement)
- Elem = createRuntimeShuffleFunction(CGF, Elem, RemoteLaneOffset);
+ if (ShuffleInElement) {
+ Elem =
+ createRuntimeShuffleFunction(CGF, Elem, Private->getType(),
+ RemoteLaneOffset, Private->getExprLoc());
+ }
DestElementAddr = Bld.CreateElementBitCast(DestElementAddr,
SrcElementAddr.getElementType());
OpenPOWER on IntegriCloud