summaryrefslogtreecommitdiffstats
path: root/polly/lib/CodeGen/PPCGCodeGeneration.cpp
diff options
context:
space:
mode:
authorSiddharth Bhat <siddu.druid@gmail.com>2017-08-09 08:29:16 +0000
committerSiddharth Bhat <siddu.druid@gmail.com>2017-08-09 08:29:16 +0000
commit34eeabbca3157958f62131fd4b7beeb4d9c203f8 (patch)
tree0bb2f1ca40b42af274e4501c76b6920cfe97328d /polly/lib/CodeGen/PPCGCodeGeneration.cpp
parentb049158a559ca1d7082b17af201f2a5d68a46c36 (diff)
downloadbcm5719-llvm-34eeabbca3157958f62131fd4b7beeb4d9c203f8.tar.gz
bcm5719-llvm-34eeabbca3157958f62131fd4b7beeb4d9c203f8.zip
[PPCGCodeGeneration] Compute element size in bytes for arrays correctly.
Previously, we used to compute this with `elementSizeInBits / 8`. This would yield an element size of 0 when the array had element size < 8 in bits. To fix this, ask data layout what the size in bytes should be. Differential Revision: https://reviews.llvm.org/D36459 llvm-svn: 310448
Diffstat (limited to 'polly/lib/CodeGen/PPCGCodeGeneration.cpp')
-rw-r--r--polly/lib/CodeGen/PPCGCodeGeneration.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp
index 3ab1b6496c3..619fe062a7d 100644
--- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp
+++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp
@@ -778,6 +778,19 @@ void GPUNodeBuilder::allocateDeviceArrays() {
ArraySize,
Builder.CreateMul(Offset,
Builder.getInt64(ScopArray->getElemSizeInBytes())));
+ const SCEV *SizeSCEV = SE.getSCEV(ArraySize);
+ // It makes no sense to have an array of size 0. The CUDA API will
+ // throw an error anyway if we invoke `cuMallocManaged` with size `0`. We
+ // choose to be defensive and catch this at the compile phase. It is
+ // most likely that we are doing something wrong with size computation.
+ if (SizeSCEV->isZero()) {
+ errs() << getUniqueScopName(&S)
+ << " has computed array size 0: " << *ArraySize
+ << " | for array: " << *(ScopArray->getBasePtr())
+ << ". This is illegal, exiting.\n";
+ report_fatal_error("array size was computed to be 0");
+ }
+
Value *DevArray = createCallAllocateMemoryForDevice(ArraySize);
DevArray->setName(DevArrayName);
DeviceAllocations[ScopArray] = DevArray;
@@ -2905,7 +2918,7 @@ public:
PPCGArray.space = Array->getSpace().release();
PPCGArray.type = strdup(TypeName.c_str());
- PPCGArray.size = Array->getElementType()->getPrimitiveSizeInBits() / 8;
+ PPCGArray.size = DL->getTypeAllocSize(Array->getElementType());
PPCGArray.name = strdup(Array->getName().c_str());
PPCGArray.extent = nullptr;
PPCGArray.n_index = Array->getNumberOfDimensions();
OpenPOWER on IntegriCloud