|
25 | 25 | #include "llvm/Bitcode/BitcodeReader.h"
|
26 | 26 | #include "llvm/Frontend/OpenMP/OMPGridValues.h"
|
27 | 27 | #include "llvm/IR/Attributes.h"
|
| 28 | +#include "llvm/IR/BasicBlock.h" |
28 | 29 | #include "llvm/IR/CFG.h"
|
29 | 30 | #include "llvm/IR/CallingConv.h"
|
30 | 31 | #include "llvm/IR/Constant.h"
|
31 | 32 | #include "llvm/IR/Constants.h"
|
32 | 33 | #include "llvm/IR/DebugInfoMetadata.h"
|
33 | 34 | #include "llvm/IR/DerivedTypes.h"
|
| 35 | +#include "llvm/IR/Function.h" |
34 | 36 | #include "llvm/IR/GlobalVariable.h"
|
35 | 37 | #include "llvm/IR/IRBuilder.h"
|
36 | 38 | #include "llvm/IR/LLVMContext.h"
|
@@ -338,6 +340,104 @@ BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
|
338 | 340 | return splitBB(Builder, CreateBranch, Old->getName() + Suffix);
|
339 | 341 | }
|
340 | 342 |
|
| 343 | +//===----------------------------------------------------------------------===// |
| 344 | +// OpenMPIRBuilderConfig |
| 345 | +//===----------------------------------------------------------------------===// |
| 346 | + |
| 347 | +namespace { |
| 348 | +LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE(); |
| 349 | +/// Values for bit flags for marking which requires clauses have been used. |
| 350 | +enum OpenMPOffloadingRequiresDirFlags { |
| 351 | + /// flag undefined. |
| 352 | + OMP_REQ_UNDEFINED = 0x000, |
| 353 | + /// no requires directive present. |
| 354 | + OMP_REQ_NONE = 0x001, |
| 355 | + /// reverse_offload clause. |
| 356 | + OMP_REQ_REVERSE_OFFLOAD = 0x002, |
| 357 | + /// unified_address clause. |
| 358 | + OMP_REQ_UNIFIED_ADDRESS = 0x004, |
| 359 | + /// unified_shared_memory clause. |
| 360 | + OMP_REQ_UNIFIED_SHARED_MEMORY = 0x008, |
| 361 | + /// dynamic_allocators clause. |
| 362 | + OMP_REQ_DYNAMIC_ALLOCATORS = 0x010, |
| 363 | + LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/OMP_REQ_DYNAMIC_ALLOCATORS) |
| 364 | +}; |
| 365 | + |
| 366 | +} // anonymous namespace |
| 367 | + |
| 368 | +OpenMPIRBuilderConfig::OpenMPIRBuilderConfig() |
| 369 | + : RequiresFlags(OMP_REQ_UNDEFINED) {} |
| 370 | + |
| 371 | +OpenMPIRBuilderConfig::OpenMPIRBuilderConfig( |
| 372 | + bool IsTargetDevice, bool IsGPU, bool OpenMPOffloadMandatory, |
| 373 | + bool HasRequiresReverseOffload, bool HasRequiresUnifiedAddress, |
| 374 | + bool HasRequiresUnifiedSharedMemory, bool HasRequiresDynamicAllocators) |
| 375 | + : IsTargetDevice(IsTargetDevice), IsGPU(IsGPU), |
| 376 | + OpenMPOffloadMandatory(OpenMPOffloadMandatory), |
| 377 | + RequiresFlags(OMP_REQ_UNDEFINED) { |
| 378 | + if (HasRequiresReverseOffload) |
| 379 | + RequiresFlags |= OMP_REQ_REVERSE_OFFLOAD; |
| 380 | + if (HasRequiresUnifiedAddress) |
| 381 | + RequiresFlags |= OMP_REQ_UNIFIED_ADDRESS; |
| 382 | + if (HasRequiresUnifiedSharedMemory) |
| 383 | + RequiresFlags |= OMP_REQ_UNIFIED_SHARED_MEMORY; |
| 384 | + if (HasRequiresDynamicAllocators) |
| 385 | + RequiresFlags |= OMP_REQ_DYNAMIC_ALLOCATORS; |
| 386 | +} |
| 387 | + |
| 388 | +bool OpenMPIRBuilderConfig::hasRequiresReverseOffload() const { |
| 389 | + return RequiresFlags & OMP_REQ_REVERSE_OFFLOAD; |
| 390 | +} |
| 391 | + |
| 392 | +bool OpenMPIRBuilderConfig::hasRequiresUnifiedAddress() const { |
| 393 | + return RequiresFlags & OMP_REQ_UNIFIED_ADDRESS; |
| 394 | +} |
| 395 | + |
| 396 | +bool OpenMPIRBuilderConfig::hasRequiresUnifiedSharedMemory() const { |
| 397 | + return RequiresFlags & OMP_REQ_UNIFIED_SHARED_MEMORY; |
| 398 | +} |
| 399 | + |
| 400 | +bool OpenMPIRBuilderConfig::hasRequiresDynamicAllocators() const { |
| 401 | + return RequiresFlags & OMP_REQ_DYNAMIC_ALLOCATORS; |
| 402 | +} |
| 403 | + |
| 404 | +int64_t OpenMPIRBuilderConfig::getRequiresFlags() const { |
| 405 | + return hasRequiresFlags() ? RequiresFlags |
| 406 | + : static_cast<int64_t>(OMP_REQ_NONE); |
| 407 | +} |
| 408 | + |
| 409 | +void OpenMPIRBuilderConfig::setHasRequiresReverseOffload(bool Value) { |
| 410 | + if (Value) |
| 411 | + RequiresFlags |= OMP_REQ_REVERSE_OFFLOAD; |
| 412 | + else |
| 413 | + RequiresFlags &= ~OMP_REQ_REVERSE_OFFLOAD; |
| 414 | +} |
| 415 | + |
| 416 | +void OpenMPIRBuilderConfig::setHasRequiresUnifiedAddress(bool Value) { |
| 417 | + if (Value) |
| 418 | + RequiresFlags |= OMP_REQ_UNIFIED_ADDRESS; |
| 419 | + else |
| 420 | + RequiresFlags &= ~OMP_REQ_UNIFIED_ADDRESS; |
| 421 | +} |
| 422 | + |
| 423 | +void OpenMPIRBuilderConfig::setHasRequiresUnifiedSharedMemory(bool Value) { |
| 424 | + if (Value) |
| 425 | + RequiresFlags |= OMP_REQ_UNIFIED_SHARED_MEMORY; |
| 426 | + else |
| 427 | + RequiresFlags &= ~OMP_REQ_UNIFIED_SHARED_MEMORY; |
| 428 | +} |
| 429 | + |
| 430 | +void OpenMPIRBuilderConfig::setHasRequiresDynamicAllocators(bool Value) { |
| 431 | + if (Value) |
| 432 | + RequiresFlags |= OMP_REQ_DYNAMIC_ALLOCATORS; |
| 433 | + else |
| 434 | + RequiresFlags &= ~OMP_REQ_DYNAMIC_ALLOCATORS; |
| 435 | +} |
| 436 | + |
| 437 | +//===----------------------------------------------------------------------===// |
| 438 | +// OpenMPIRBuilder |
| 439 | +//===----------------------------------------------------------------------===// |
| 440 | + |
341 | 441 | void OpenMPIRBuilder::getKernelArgsVector(TargetKernelArgs &KernelArgs,
|
342 | 442 | IRBuilderBase &Builder,
|
343 | 443 | SmallVector<Value *> &ArgsVector) {
|
@@ -6106,6 +6206,39 @@ void OpenMPIRBuilder::loadOffloadInfoMetadata(Module &M) {
|
6106 | 6206 | }
|
6107 | 6207 | }
|
6108 | 6208 |
|
| 6209 | +Function *OpenMPIRBuilder::createRegisterRequires(StringRef Name) { |
| 6210 | + // Skip the creation of the registration function if this is device codegen |
| 6211 | + if (Config.isTargetDevice()) |
| 6212 | + return nullptr; |
| 6213 | + |
| 6214 | + Builder.ClearInsertionPoint(); |
| 6215 | + |
| 6216 | + // Create registration function prototype |
| 6217 | + auto *RegFnTy = FunctionType::get(Builder.getVoidTy(), {}); |
| 6218 | + auto *RegFn = Function::Create( |
| 6219 | + RegFnTy, GlobalVariable::LinkageTypes::InternalLinkage, Name, M); |
| 6220 | + RegFn->setSection(".text.startup"); |
| 6221 | + RegFn->addFnAttr(Attribute::NoInline); |
| 6222 | + RegFn->addFnAttr(Attribute::NoUnwind); |
| 6223 | + |
| 6224 | + // Create registration function body |
| 6225 | + auto *BB = BasicBlock::Create(M.getContext(), "entry", RegFn); |
| 6226 | + ConstantInt *FlagsVal = |
| 6227 | + ConstantInt::getSigned(Builder.getInt64Ty(), Config.getRequiresFlags()); |
| 6228 | + Function *RTLRegFn = getOrCreateRuntimeFunctionPtr( |
| 6229 | + omp::RuntimeFunction::OMPRTL___tgt_register_requires); |
| 6230 | + |
| 6231 | + Builder.SetInsertPoint(BB); |
| 6232 | + Builder.CreateCall(RTLRegFn, {FlagsVal}); |
| 6233 | + Builder.CreateRetVoid(); |
| 6234 | + |
| 6235 | + return RegFn; |
| 6236 | +} |
| 6237 | + |
| 6238 | +//===----------------------------------------------------------------------===// |
| 6239 | +// OffloadEntriesInfoManager |
| 6240 | +//===----------------------------------------------------------------------===// |
| 6241 | + |
6109 | 6242 | bool OffloadEntriesInfoManager::empty() const {
|
6110 | 6243 | return OffloadEntriesTargetRegion.empty() &&
|
6111 | 6244 | OffloadEntriesDeviceGlobalVar.empty();
|
@@ -6244,6 +6377,10 @@ void OffloadEntriesInfoManager::actOnDeviceGlobalVarEntriesInfo(
|
6244 | 6377 | Action(E.getKey(), E.getValue());
|
6245 | 6378 | }
|
6246 | 6379 |
|
| 6380 | +//===----------------------------------------------------------------------===// |
| 6381 | +// CanonicalLoopInfo |
| 6382 | +//===----------------------------------------------------------------------===// |
| 6383 | + |
6247 | 6384 | void CanonicalLoopInfo::collectControlBlocks(
|
6248 | 6385 | SmallVectorImpl<BasicBlock *> &BBs) {
|
6249 | 6386 | // We only count those BBs as control block for which we do not need to
|
|
0 commit comments