@@ -4006,157 +4006,6 @@ void CGOpenMPRuntime::OffloadEntriesInfoManagerTy::
4006
4006
Action(E.getKey(), E.getValue());
4007
4007
}
4008
4008
4009
- llvm::Function *
4010
- CGOpenMPRuntime::createOffloadingBinaryDescriptorRegistration() {
4011
- // If we don't have entries or if we are emitting code for the device, we
4012
- // don't need to do anything.
4013
- if (CGM.getLangOpts().OpenMPIsDevice || OffloadEntriesInfoManager.empty())
4014
- return nullptr;
4015
-
4016
- llvm::Module &M = CGM.getModule();
4017
- ASTContext &C = CGM.getContext();
4018
-
4019
- // Get list of devices we care about
4020
- const std::vector<llvm::Triple> &Devices = CGM.getLangOpts().OMPTargetTriples;
4021
-
4022
- // We should be creating an offloading descriptor only if there are devices
4023
- // specified.
4024
- assert(!Devices.empty() && "No OpenMP offloading devices??");
4025
-
4026
- // Create the external variables that will point to the begin and end of the
4027
- // host entries section. These will be defined by the linker.
4028
- llvm::Type *OffloadEntryTy =
4029
- CGM.getTypes().ConvertTypeForMem(getTgtOffloadEntryQTy());
4030
- auto *HostEntriesBegin = new llvm::GlobalVariable(
4031
- M, OffloadEntryTy, /*isConstant=*/true,
4032
- llvm::GlobalValue::ExternalLinkage, /*Initializer=*/nullptr,
4033
- "__start_omp_offloading_entries");
4034
- HostEntriesBegin->setVisibility(llvm::GlobalValue::HiddenVisibility);
4035
- auto *HostEntriesEnd = new llvm::GlobalVariable(
4036
- M, OffloadEntryTy, /*isConstant=*/true,
4037
- llvm::GlobalValue::ExternalLinkage,
4038
- /*Initializer=*/nullptr, "__stop_omp_offloading_entries");
4039
- HostEntriesEnd->setVisibility(llvm::GlobalValue::HiddenVisibility);
4040
-
4041
- // Create all device images
4042
- auto *DeviceImageTy = cast<llvm::StructType>(
4043
- CGM.getTypes().ConvertTypeForMem(getTgtDeviceImageQTy()));
4044
- ConstantInitBuilder DeviceImagesBuilder(CGM);
4045
- ConstantArrayBuilder DeviceImagesEntries =
4046
- DeviceImagesBuilder.beginArray(DeviceImageTy);
4047
-
4048
- for (const llvm::Triple &Device : Devices) {
4049
- StringRef T = Device.getTriple();
4050
- std::string BeginName = getName({"omp_offloading", "img_start", ""});
4051
- auto *ImgBegin = new llvm::GlobalVariable(
4052
- M, CGM.Int8Ty, /*isConstant=*/true,
4053
- llvm::GlobalValue::ExternalWeakLinkage,
4054
- /*Initializer=*/nullptr, Twine(BeginName).concat(T));
4055
- std::string EndName = getName({"omp_offloading", "img_end", ""});
4056
- auto *ImgEnd = new llvm::GlobalVariable(
4057
- M, CGM.Int8Ty, /*isConstant=*/true,
4058
- llvm::GlobalValue::ExternalWeakLinkage,
4059
- /*Initializer=*/nullptr, Twine(EndName).concat(T));
4060
-
4061
- llvm::Constant *Data[] = {ImgBegin, ImgEnd, HostEntriesBegin,
4062
- HostEntriesEnd};
4063
- createConstantGlobalStructAndAddToParent(CGM, getTgtDeviceImageQTy(), Data,
4064
- DeviceImagesEntries);
4065
- }
4066
-
4067
- // Create device images global array.
4068
- std::string ImagesName = getName({"omp_offloading", "device_images"});
4069
- llvm::GlobalVariable *DeviceImages =
4070
- DeviceImagesEntries.finishAndCreateGlobal(ImagesName,
4071
- CGM.getPointerAlign(),
4072
- /*isConstant=*/true);
4073
- DeviceImages->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
4074
-
4075
- // This is a Zero array to be used in the creation of the constant expressions
4076
- llvm::Constant *Index[] = {llvm::Constant::getNullValue(CGM.Int32Ty),
4077
- llvm::Constant::getNullValue(CGM.Int32Ty)};
4078
-
4079
- // Create the target region descriptor.
4080
- llvm::Constant *Data[] = {
4081
- llvm::ConstantInt::get(CGM.Int32Ty, Devices.size()),
4082
- llvm::ConstantExpr::getGetElementPtr(DeviceImages->getValueType(),
4083
- DeviceImages, Index),
4084
- HostEntriesBegin, HostEntriesEnd};
4085
- std::string Descriptor = getName({"omp_offloading", "descriptor"});
4086
- llvm::GlobalVariable *Desc = createGlobalStruct(
4087
- CGM, getTgtBinaryDescriptorQTy(), /*IsConstant=*/true, Data, Descriptor);
4088
-
4089
- // Emit code to register or unregister the descriptor at execution
4090
- // startup or closing, respectively.
4091
-
4092
- llvm::Function *UnRegFn;
4093
- {
4094
- FunctionArgList Args;
4095
- ImplicitParamDecl DummyPtr(C, C.VoidPtrTy, ImplicitParamDecl::Other);
4096
- Args.push_back(&DummyPtr);
4097
-
4098
- CodeGenFunction CGF(CGM);
4099
- // Disable debug info for global (de-)initializer because they are not part
4100
- // of some particular construct.
4101
- CGF.disableDebugInfo();
4102
- const auto &FI =
4103
- CGM.getTypes().arrangeBuiltinFunctionDeclaration(C.VoidTy, Args);
4104
- llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
4105
- std::string UnregName = getName({"omp_offloading", "descriptor_unreg"});
4106
- UnRegFn = CGM.CreateGlobalInitOrDestructFunction(FTy, UnregName, FI);
4107
- CGF.StartFunction(GlobalDecl(), C.VoidTy, UnRegFn, FI, Args);
4108
- CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_unregister_lib),
4109
- Desc);
4110
- CGF.FinishFunction();
4111
- }
4112
- llvm::Function *RegFn;
4113
- {
4114
- CodeGenFunction CGF(CGM);
4115
- // Disable debug info for global (de-)initializer because they are not part
4116
- // of some particular construct.
4117
- CGF.disableDebugInfo();
4118
- const auto &FI = CGM.getTypes().arrangeNullaryFunction();
4119
- llvm::FunctionType *FTy = CGM.getTypes().GetFunctionType(FI);
4120
-
4121
- // Encode offload target triples into the registration function name. It
4122
- // will serve as a comdat key for the registration/unregistration code for
4123
- // this particular combination of offloading targets.
4124
- SmallVector<StringRef, 4U> RegFnNameParts(Devices.size() + 2U);
4125
- RegFnNameParts[0] = "omp_offloading";
4126
- RegFnNameParts[1] = "descriptor_reg";
4127
- llvm::transform(Devices, std::next(RegFnNameParts.begin(), 2),
4128
- [](const llvm::Triple &T) -> const std::string& {
4129
- return T.getTriple();
4130
- });
4131
- llvm::sort(std::next(RegFnNameParts.begin(), 2), RegFnNameParts.end());
4132
- std::string Descriptor = getName(RegFnNameParts);
4133
- RegFn = CGM.CreateGlobalInitOrDestructFunction(FTy, Descriptor, FI);
4134
- CGF.StartFunction(GlobalDecl(), C.VoidTy, RegFn, FI, FunctionArgList());
4135
- CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__tgt_register_lib), Desc);
4136
- // Create a variable to drive the registration and unregistration of the
4137
- // descriptor, so we can reuse the logic that emits Ctors and Dtors.
4138
- ImplicitParamDecl RegUnregVar(C, C.getTranslationUnitDecl(),
4139
- SourceLocation(), nullptr, C.CharTy,
4140
- ImplicitParamDecl::Other);
4141
- CGM.getCXXABI().registerGlobalDtor(CGF, RegUnregVar, UnRegFn, Desc);
4142
- CGF.FinishFunction();
4143
- }
4144
- if (CGM.supportsCOMDAT()) {
4145
- // It is sufficient to call registration function only once, so create a
4146
- // COMDAT group for registration/unregistration functions and associated
4147
- // data. That would reduce startup time and code size. Registration
4148
- // function serves as a COMDAT group key.
4149
- llvm::Comdat *ComdatKey = M.getOrInsertComdat(RegFn->getName());
4150
- RegFn->setLinkage(llvm::GlobalValue::LinkOnceAnyLinkage);
4151
- RegFn->setVisibility(llvm::GlobalValue::HiddenVisibility);
4152
- RegFn->setComdat(ComdatKey);
4153
- UnRegFn->setComdat(ComdatKey);
4154
- DeviceImages->setComdat(ComdatKey);
4155
- Desc->setComdat(ComdatKey);
4156
- }
4157
- return RegFn;
4158
- }
4159
-
4160
4009
void CGOpenMPRuntime::createOffloadEntry(
4161
4010
llvm::Constant *ID, llvm::Constant *Addr, uint64_t Size, int32_t Flags,
4162
4011
llvm::GlobalValue::LinkageTypes Linkage) {
@@ -4197,8 +4046,9 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
4197
4046
// Right now we only generate metadata for function that contain target
4198
4047
// regions.
4199
4048
4200
- // If we do not have entries, we don't need to do anything.
4201
- if (OffloadEntriesInfoManager.empty())
4049
+ // If we are in simd mode or there are no entries, we don't need to do
4050
+ // anything.
4051
+ if (CGM.getLangOpts().OpenMPSimd || OffloadEntriesInfoManager.empty())
4202
4052
return;
4203
4053
4204
4054
llvm::Module &M = CGM.getModule();
@@ -10031,17 +9881,6 @@ llvm::Function *CGOpenMPRuntime::emitRequiresDirectiveRegFun() {
10031
9881
return RequiresRegFn;
10032
9882
}
10033
9883
10034
- llvm::Function *CGOpenMPRuntime::emitRegistrationFunction() {
10035
- // If we have offloading in the current module, we need to emit the entries
10036
- // now and register the offloading descriptor.
10037
- createOffloadEntriesAndInfoMetadata();
10038
-
10039
- // Create and register the offloading binary descriptors. This is the main
10040
- // entity that captures all the information about offloading in the current
10041
- // compilation unit.
10042
- return createOffloadingBinaryDescriptorRegistration();
10043
- }
10044
-
10045
9884
void CGOpenMPRuntime::emitTeamsCall(CodeGenFunction &CGF,
10046
9885
const OMPExecutableDirective &D,
10047
9886
SourceLocation Loc,
@@ -11534,10 +11373,6 @@ bool CGOpenMPSIMDRuntime::emitTargetGlobal(GlobalDecl GD) {
11534
11373
return false;
11535
11374
}
11536
11375
11537
- llvm::Function *CGOpenMPSIMDRuntime::emitRegistrationFunction() {
11538
- return nullptr;
11539
- }
11540
-
11541
11376
void CGOpenMPSIMDRuntime::emitTeamsCall(CodeGenFunction &CGF,
11542
11377
const OMPExecutableDirective &D,
11543
11378
SourceLocation Loc,
0 commit comments