
The code for unranked memref descriptors assumed that sizeof(!llvm.ptr) == lizeof(!llvm.ptr<N>) for all address spaces N. This is not always true (ex. the AMDGPU compiler backend has sizeof(!llvm.ptr) = 64 bits but sizeof(!llvm.ptr<5>) = 32 bits, where address space 5 is used for stack allocations). While this is merely an overallocation in the case where a non-0 address space has pointers smaller than the default, the existing code could cause OOB memory accesses when sizeof(!llvm.ptr<N>) > sizeof(!llvm.ptr). So, add an address spaces parameter to computeSizes in order to partially resolve this class of bugs. Note that the LLVM data layout in the conversion passes is currently set to "" and not constructed from the MLIR data layout or some other source, but this could change in the future. Depends on D142159 Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D141293
34 lines
1.3 KiB
C++
34 lines
1.3 KiB
C++
//===- StructBuilder.cpp - Helper for building LLVM structs --------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Conversion/LLVMCommon/StructBuilder.h"
|
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
|
|
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
|
|
#include "mlir/IR/Builders.h"
|
|
|
|
using namespace mlir;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// StructBuilder implementation
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
StructBuilder::StructBuilder(Value v) : value(v), structType(v.getType()) {
|
|
assert(value != nullptr && "value cannot be null");
|
|
assert(LLVM::isCompatibleType(structType) && "expected llvm type");
|
|
}
|
|
|
|
Value StructBuilder::extractPtr(OpBuilder &builder, Location loc,
|
|
unsigned pos) const {
|
|
return builder.create<LLVM::ExtractValueOp>(loc, value, pos);
|
|
}
|
|
|
|
void StructBuilder::setPtr(OpBuilder &builder, Location loc, unsigned pos,
|
|
Value ptr) {
|
|
value = builder.create<LLVM::InsertValueOp>(loc, value, ptr, pos);
|
|
}
|