|
23 | 23 | #include "llvm/Analysis/ScalarEvolution.h" |
24 | 24 | #include "llvm/Analysis/TargetLibraryInfo.h" |
25 | 25 | #include "llvm/Bitcode/BitcodeReader.h" |
| 26 | +#include "llvm/Frontend/Offloading/Utility.h" |
26 | 27 | #include "llvm/Frontend/OpenMP/OMPGridValues.h" |
27 | 28 | #include "llvm/IR/Attributes.h" |
28 | 29 | #include "llvm/IR/BasicBlock.h" |
@@ -958,44 +959,6 @@ OpenMPIRBuilder::createCancel(const LocationDescription &Loc, |
958 | 959 | return Builder.saveIP(); |
959 | 960 | } |
960 | 961 |
|
961 | | -void OpenMPIRBuilder::emitOffloadingEntry(Constant *Addr, StringRef Name, |
962 | | - uint64_t Size, int32_t Flags, |
963 | | - StringRef SectionName) { |
964 | | - Type *Int8PtrTy = Type::getInt8PtrTy(M.getContext()); |
965 | | - Type *Int32Ty = Type::getInt32Ty(M.getContext()); |
966 | | - Type *SizeTy = M.getDataLayout().getIntPtrType(M.getContext()); |
967 | | - |
968 | | - Constant *AddrName = ConstantDataArray::getString(M.getContext(), Name); |
969 | | - |
970 | | - // Create the constant string used to look up the symbol in the device. |
971 | | - auto *Str = |
972 | | - new llvm::GlobalVariable(M, AddrName->getType(), /*isConstant=*/true, |
973 | | - llvm::GlobalValue::InternalLinkage, AddrName, |
974 | | - ".omp_offloading.entry_name"); |
975 | | - Str->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); |
976 | | - |
977 | | - // Construct the offloading entry. |
978 | | - Constant *EntryData[] = { |
979 | | - ConstantExpr::getPointerBitCastOrAddrSpaceCast(Addr, Int8PtrTy), |
980 | | - ConstantExpr::getPointerBitCastOrAddrSpaceCast(Str, Int8PtrTy), |
981 | | - ConstantInt::get(SizeTy, Size), |
982 | | - ConstantInt::get(Int32Ty, Flags), |
983 | | - ConstantInt::get(Int32Ty, 0), |
984 | | - }; |
985 | | - Constant *EntryInitializer = |
986 | | - ConstantStruct::get(OpenMPIRBuilder::OffloadEntry, EntryData); |
987 | | - |
988 | | - auto *Entry = new GlobalVariable( |
989 | | - M, OpenMPIRBuilder::OffloadEntry, |
990 | | - /* isConstant = */ true, GlobalValue::WeakAnyLinkage, EntryInitializer, |
991 | | - ".omp_offloading.entry." + Name, nullptr, GlobalValue::NotThreadLocal, |
992 | | - M.getDataLayout().getDefaultGlobalsAddressSpace()); |
993 | | - |
994 | | - // The entry has to be created in the section the linker expects it to be. |
995 | | - Entry->setSection(SectionName); |
996 | | - Entry->setAlignment(Align(1)); |
997 | | -} |
998 | | - |
999 | 962 | OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetKernel( |
1000 | 963 | const LocationDescription &Loc, InsertPointTy AllocaIP, Value *&Return, |
1001 | 964 | Value *Ident, Value *DeviceID, Value *NumTeams, Value *NumThreads, |
@@ -5928,7 +5891,9 @@ void OpenMPIRBuilder::createOffloadEntry(Constant *ID, Constant *Addr, |
5928 | 5891 | GlobalValue::LinkageTypes, |
5929 | 5892 | StringRef Name) { |
5930 | 5893 | if (!Config.isGPU()) { |
5931 | | - emitOffloadingEntry(ID, Name.empty() ? Addr->getName() : Name, Size, Flags); |
| 5894 | + llvm::offloading::emitOffloadingEntry( |
| 5895 | + M, ID, Name.empty() ? Addr->getName() : Name, Size, Flags, |
| 5896 | + "omp_offloading_entries"); |
5932 | 5897 | return; |
5933 | 5898 | } |
5934 | 5899 | // TODO: Add support for global variables on the device after declare target |
|
0 commit comments