mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 02:33:06 +01:00
[mlir][openacc] Initial translation for DataOp to LLVM IR
Add basic translation of acc.data to LLVM IR with runtime calls. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D104301
This commit is contained in:
parent
5b7208da36
commit
c463fa6cad
@ -636,6 +636,31 @@ public:
|
|||||||
createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
|
createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
|
||||||
std::string VarName);
|
std::string VarName);
|
||||||
|
|
||||||
|
struct MapperAllocas {
|
||||||
|
AllocaInst *ArgsBase = nullptr;
|
||||||
|
AllocaInst *Args = nullptr;
|
||||||
|
AllocaInst *ArgSizes = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Create the allocas instruction used in call to mapper functions.
|
||||||
|
void createMapperAllocas(const LocationDescription &Loc,
|
||||||
|
InsertPointTy AllocaIP, unsigned NumOperands,
|
||||||
|
struct MapperAllocas &MapperAllocas);
|
||||||
|
|
||||||
|
/// Create the call for the target mapper function.
|
||||||
|
/// \param Loc The source location description.
|
||||||
|
/// \param MapperFunc Function to be called.
|
||||||
|
/// \param SrcLocInfo Source location information global.
|
||||||
|
/// \param MaptypesArgs
|
||||||
|
/// \param MapnamesArg
|
||||||
|
/// \param MapperAllocas The AllocaInst used for the call.
|
||||||
|
/// \param DeviceID Device ID for the call.
|
||||||
|
/// \param TotalNbOperand Number of operand in the call.
|
||||||
|
void emitMapperCall(const LocationDescription &Loc, Function *MapperFunc,
|
||||||
|
Value *SrcLocInfo, Value *MaptypesArg, Value *MapnamesArg,
|
||||||
|
struct MapperAllocas &MapperAllocas, int64_t DeviceID,
|
||||||
|
unsigned NumOperands);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Generator for __kmpc_copyprivate
|
/// Generator for __kmpc_copyprivate
|
||||||
///
|
///
|
||||||
|
@ -2318,6 +2318,51 @@ OpenMPIRBuilder::createOffloadMaptypes(SmallVectorImpl<uint64_t> &Mappings,
|
|||||||
return MaptypesArrayGlobal;
|
return MaptypesArrayGlobal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenMPIRBuilder::createMapperAllocas(const LocationDescription &Loc,
|
||||||
|
InsertPointTy AllocaIP,
|
||||||
|
unsigned NumOperands,
|
||||||
|
struct MapperAllocas &MapperAllocas) {
|
||||||
|
if (!updateToLocation(Loc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto *ArrI8PtrTy = ArrayType::get(Int8Ptr, NumOperands);
|
||||||
|
auto *ArrI64Ty = ArrayType::get(Int64, NumOperands);
|
||||||
|
Builder.restoreIP(AllocaIP);
|
||||||
|
AllocaInst *ArgsBase = Builder.CreateAlloca(ArrI8PtrTy);
|
||||||
|
AllocaInst *Args = Builder.CreateAlloca(ArrI8PtrTy);
|
||||||
|
AllocaInst *ArgSizes = Builder.CreateAlloca(ArrI64Ty);
|
||||||
|
Builder.restoreIP(Loc.IP);
|
||||||
|
MapperAllocas.ArgsBase = ArgsBase;
|
||||||
|
MapperAllocas.Args = Args;
|
||||||
|
MapperAllocas.ArgSizes = ArgSizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenMPIRBuilder::emitMapperCall(const LocationDescription &Loc,
|
||||||
|
Function *MapperFunc, Value *SrcLocInfo,
|
||||||
|
Value *MaptypesArg, Value *MapnamesArg,
|
||||||
|
struct MapperAllocas &MapperAllocas,
|
||||||
|
int64_t DeviceID, unsigned NumOperands) {
|
||||||
|
if (!updateToLocation(Loc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto *ArrI8PtrTy = ArrayType::get(Int8Ptr, NumOperands);
|
||||||
|
auto *ArrI64Ty = ArrayType::get(Int64, NumOperands);
|
||||||
|
Value *ArgsBaseGEP =
|
||||||
|
Builder.CreateInBoundsGEP(ArrI8PtrTy, MapperAllocas.ArgsBase,
|
||||||
|
{Builder.getInt32(0), Builder.getInt32(0)});
|
||||||
|
Value *ArgsGEP =
|
||||||
|
Builder.CreateInBoundsGEP(ArrI8PtrTy, MapperAllocas.Args,
|
||||||
|
{Builder.getInt32(0), Builder.getInt32(0)});
|
||||||
|
Value *ArgSizesGEP =
|
||||||
|
Builder.CreateInBoundsGEP(ArrI64Ty, MapperAllocas.ArgSizes,
|
||||||
|
{Builder.getInt32(0), Builder.getInt32(0)});
|
||||||
|
Value *NullPtr = Constant::getNullValue(Int8Ptr->getPointerTo());
|
||||||
|
Builder.CreateCall(MapperFunc,
|
||||||
|
{SrcLocInfo, Builder.getInt64(DeviceID),
|
||||||
|
Builder.getInt32(NumOperands), ArgsBaseGEP, ArgsGEP,
|
||||||
|
ArgSizesGEP, MaptypesArg, MapnamesArg, NullPtr});
|
||||||
|
}
|
||||||
|
|
||||||
bool OpenMPIRBuilder::checkAndEmitFlushAfterAtomic(
|
bool OpenMPIRBuilder::checkAndEmitFlushAfterAtomic(
|
||||||
const LocationDescription &Loc, llvm::AtomicOrdering AO, AtomicKind AK) {
|
const LocationDescription &Loc, llvm::AtomicOrdering AO, AtomicKind AK) {
|
||||||
assert(!(AO == AtomicOrdering::NotAtomic ||
|
assert(!(AO == AtomicOrdering::NotAtomic ||
|
||||||
|
@ -2703,4 +2703,110 @@ TEST_F(OpenMPIRBuilderTest, CreateOffloadMapnames) {
|
|||||||
EXPECT_EQ(Initializer->getType()->getArrayNumElements(), Names.size());
|
EXPECT_EQ(Initializer->getType()->getArrayNumElements(), Names.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(OpenMPIRBuilderTest, CreateMapperAllocas) {
|
||||||
|
OpenMPIRBuilder OMPBuilder(*M);
|
||||||
|
OMPBuilder.initialize();
|
||||||
|
F->setName("func");
|
||||||
|
IRBuilder<> Builder(BB);
|
||||||
|
|
||||||
|
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
|
||||||
|
|
||||||
|
unsigned TotalNbOperand = 2;
|
||||||
|
|
||||||
|
OpenMPIRBuilder::MapperAllocas MapperAllocas;
|
||||||
|
IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
|
||||||
|
F->getEntryBlock().getFirstInsertionPt());
|
||||||
|
OMPBuilder.createMapperAllocas(Loc, AllocaIP, TotalNbOperand, MapperAllocas);
|
||||||
|
EXPECT_NE(MapperAllocas.ArgsBase, nullptr);
|
||||||
|
EXPECT_NE(MapperAllocas.Args, nullptr);
|
||||||
|
EXPECT_NE(MapperAllocas.ArgSizes, nullptr);
|
||||||
|
EXPECT_TRUE(MapperAllocas.ArgsBase->getAllocatedType()->isArrayTy());
|
||||||
|
ArrayType *ArrType =
|
||||||
|
dyn_cast<ArrayType>(MapperAllocas.ArgsBase->getAllocatedType());
|
||||||
|
EXPECT_EQ(ArrType->getNumElements(), TotalNbOperand);
|
||||||
|
EXPECT_TRUE(MapperAllocas.ArgsBase->getAllocatedType()
|
||||||
|
->getArrayElementType()
|
||||||
|
->isPointerTy());
|
||||||
|
EXPECT_TRUE(MapperAllocas.ArgsBase->getAllocatedType()
|
||||||
|
->getArrayElementType()
|
||||||
|
->getPointerElementType()
|
||||||
|
->isIntegerTy(8));
|
||||||
|
|
||||||
|
EXPECT_TRUE(MapperAllocas.Args->getAllocatedType()->isArrayTy());
|
||||||
|
ArrType = dyn_cast<ArrayType>(MapperAllocas.Args->getAllocatedType());
|
||||||
|
EXPECT_EQ(ArrType->getNumElements(), TotalNbOperand);
|
||||||
|
EXPECT_TRUE(MapperAllocas.Args->getAllocatedType()
|
||||||
|
->getArrayElementType()
|
||||||
|
->isPointerTy());
|
||||||
|
EXPECT_TRUE(MapperAllocas.Args->getAllocatedType()
|
||||||
|
->getArrayElementType()
|
||||||
|
->getPointerElementType()
|
||||||
|
->isIntegerTy(8));
|
||||||
|
|
||||||
|
EXPECT_TRUE(MapperAllocas.ArgSizes->getAllocatedType()->isArrayTy());
|
||||||
|
ArrType = dyn_cast<ArrayType>(MapperAllocas.ArgSizes->getAllocatedType());
|
||||||
|
EXPECT_EQ(ArrType->getNumElements(), TotalNbOperand);
|
||||||
|
EXPECT_TRUE(MapperAllocas.ArgSizes->getAllocatedType()
|
||||||
|
->getArrayElementType()
|
||||||
|
->isIntegerTy(64));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(OpenMPIRBuilderTest, EmitMapperCall) {
|
||||||
|
OpenMPIRBuilder OMPBuilder(*M);
|
||||||
|
OMPBuilder.initialize();
|
||||||
|
F->setName("func");
|
||||||
|
IRBuilder<> Builder(BB);
|
||||||
|
LLVMContext &Ctx = M->getContext();
|
||||||
|
|
||||||
|
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
|
||||||
|
|
||||||
|
unsigned TotalNbOperand = 2;
|
||||||
|
|
||||||
|
OpenMPIRBuilder::MapperAllocas MapperAllocas;
|
||||||
|
IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
|
||||||
|
F->getEntryBlock().getFirstInsertionPt());
|
||||||
|
OMPBuilder.createMapperAllocas(Loc, AllocaIP, TotalNbOperand, MapperAllocas);
|
||||||
|
|
||||||
|
auto *BeginMapperFunc = OMPBuilder.getOrCreateRuntimeFunctionPtr(
|
||||||
|
omp::OMPRTL___tgt_target_data_begin_mapper);
|
||||||
|
|
||||||
|
SmallVector<uint64_t> Flags = {0, 2};
|
||||||
|
|
||||||
|
Constant *SrcLocCst = OMPBuilder.getOrCreateSrcLocStr("", "file1", 2, 5);
|
||||||
|
Value *SrcLocInfo = OMPBuilder.getOrCreateIdent(SrcLocCst);
|
||||||
|
|
||||||
|
Constant *Cst1 = OMPBuilder.getOrCreateSrcLocStr("array1", "file1", 2, 5);
|
||||||
|
Constant *Cst2 = OMPBuilder.getOrCreateSrcLocStr("array2", "file1", 3, 5);
|
||||||
|
SmallVector<llvm::Constant *> Names = {Cst1, Cst2};
|
||||||
|
|
||||||
|
GlobalVariable *Maptypes =
|
||||||
|
OMPBuilder.createOffloadMaptypes(Flags, ".offload_maptypes");
|
||||||
|
Value *MaptypesArg = Builder.CreateConstInBoundsGEP2_32(
|
||||||
|
ArrayType::get(Type::getInt64Ty(Ctx), TotalNbOperand), Maptypes,
|
||||||
|
/*Idx0=*/0, /*Idx1=*/0);
|
||||||
|
|
||||||
|
GlobalVariable *Mapnames =
|
||||||
|
OMPBuilder.createOffloadMapnames(Names, ".offload_mapnames");
|
||||||
|
Value *MapnamesArg = Builder.CreateConstInBoundsGEP2_32(
|
||||||
|
ArrayType::get(Type::getInt8PtrTy(Ctx), TotalNbOperand), Mapnames,
|
||||||
|
/*Idx0=*/0, /*Idx1=*/0);
|
||||||
|
|
||||||
|
OMPBuilder.emitMapperCall(Builder.saveIP(), BeginMapperFunc, SrcLocInfo,
|
||||||
|
MaptypesArg, MapnamesArg, MapperAllocas, -1,
|
||||||
|
TotalNbOperand);
|
||||||
|
|
||||||
|
CallInst *MapperCall = dyn_cast<CallInst>(&BB->back());
|
||||||
|
EXPECT_NE(MapperCall, nullptr);
|
||||||
|
EXPECT_EQ(MapperCall->getNumArgOperands(), 9U);
|
||||||
|
EXPECT_EQ(MapperCall->getCalledFunction()->getName(),
|
||||||
|
"__tgt_target_data_begin_mapper");
|
||||||
|
EXPECT_EQ(MapperCall->getOperand(0), SrcLocInfo);
|
||||||
|
EXPECT_TRUE(MapperCall->getOperand(1)->getType()->isIntegerTy(64));
|
||||||
|
EXPECT_TRUE(MapperCall->getOperand(2)->getType()->isIntegerTy(32));
|
||||||
|
|
||||||
|
EXPECT_EQ(MapperCall->getOperand(6), MaptypesArg);
|
||||||
|
EXPECT_EQ(MapperCall->getOperand(7), MapnamesArg);
|
||||||
|
EXPECT_TRUE(MapperCall->getOperand(8)->getType()->isPointerTy());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user