llvm/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

//===- llvm/unittest/IR/OpenMPIRBuilderTest.cpp - OpenMPIRBuilder tests ---===//
//
// 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 "llvm/Frontend/OpenMP/OMPConstants.h"
#include "llvm/Frontend/OpenMP/OMPDeviceConstants.h"
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Support/Casting.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <optional>

usingnamespacellvm;
usingnamespaceomp;

namespace {

/// Create an instruction that uses the values in \p Values. We use "printf"
/// just because it is often used for this purpose in test code, but it is never
/// executed here.
static CallInst *createPrintfCall(IRBuilder<> &Builder, StringRef FormatStr,
                                  ArrayRef<Value *> Values) {}

/// Verify that blocks in \p RefOrder are corresponds to the depth-first visit
/// order the control flow of \p F.
///
/// This is an easy way to verify the branching structure of the CFG without
/// checking every branch instruction individually. For the CFG of a
/// CanonicalLoopInfo, the Cond BB's terminating branch's first edge is entering
/// the body, i.e. the DFS order corresponds to the execution order with one
/// loop iteration.
static testing::AssertionResult
verifyDFSOrder(Function *F, ArrayRef<BasicBlock *> RefOrder) {}

/// Verify that blocks in \p RefOrder are in the same relative order in the
/// linked lists of blocks in \p F. The linked list may contain additional
/// blocks in-between.
///
/// While the order in the linked list is not relevant for semantics, keeping
/// the order roughly in execution order makes its printout easier to read.
static testing::AssertionResult
verifyListOrder(Function *F, ArrayRef<BasicBlock *> RefOrder) {}

/// Populate Calls with call instructions calling the function with the given
/// FnID from the given function F.
static void findCalls(Function *F, omp::RuntimeFunction FnID,
                      OpenMPIRBuilder &OMPBuilder,
                      SmallVectorImpl<CallInst *> &Calls) {}

/// Assuming \p F contains only one call to the function with the given \p FnID,
/// return that call.
static CallInst *findSingleCall(Function *F, omp::RuntimeFunction FnID,
                                OpenMPIRBuilder &OMPBuilder) {}

static omp::ScheduleKind getSchedKind(omp::OMPScheduleType SchedType) {}

class OpenMPIRBuilderTest : public testing::Test {};

class OpenMPIRBuilderTestWithParams
    : public OpenMPIRBuilderTest,
      public ::testing::WithParamInterface<omp::OMPScheduleType> {};

class OpenMPIRBuilderTestWithIVBits
    : public OpenMPIRBuilderTest,
      public ::testing::WithParamInterface<int> {};

// Returns the value stored in the given allocation. Returns null if the given
// value is not a result of an InstTy instruction, if no value is stored or if
// there is more than one store.
template <typename InstTy> static Value *findStoredValue(Value *AllocaValue) {}

// Returns the value stored in the aggregate argument of an outlined function,
// or nullptr if it is not found.
static Value *findStoredValueInAggregateAt(LLVMContext &Ctx, Value *Aggregate,
                                           unsigned Idx) {}

// Returns the aggregate that the value is originating from.
static Value *findAggregateFromValue(Value *V) {}

TEST_F(OpenMPIRBuilderTest, CreateBarrier) {}

TEST_F(OpenMPIRBuilderTest, CreateCancel) {}

TEST_F(OpenMPIRBuilderTest, CreateCancelIfCond) {}

TEST_F(OpenMPIRBuilderTest, CreateCancelBarrier) {}

TEST_F(OpenMPIRBuilderTest, DbgLoc) {}

TEST_F(OpenMPIRBuilderTest, ParallelSimpleGPU) {}

TEST_F(OpenMPIRBuilderTest, ParallelSimple) {}

TEST_F(OpenMPIRBuilderTest, ParallelNested) {}

TEST_F(OpenMPIRBuilderTest, ParallelNested2Inner) {}

TEST_F(OpenMPIRBuilderTest, ParallelIfCond) {}

TEST_F(OpenMPIRBuilderTest, ParallelCancelBarrier) {}

TEST_F(OpenMPIRBuilderTest, ParallelForwardAsPointers) {}

TEST_F(OpenMPIRBuilderTest, CanonicalLoopSimple) {}

TEST_F(OpenMPIRBuilderTest, CanonicalLoopBounds) {}

TEST_F(OpenMPIRBuilderTest, CollapseNestedLoops) {}

TEST_F(OpenMPIRBuilderTest, TileSingleLoop) {}

TEST_F(OpenMPIRBuilderTest, TileNestedLoops) {}

TEST_F(OpenMPIRBuilderTest, TileNestedLoopsWithBounds) {}

TEST_F(OpenMPIRBuilderTest, TileSingleLoopCounts) {}

TEST_F(OpenMPIRBuilderTest, ApplySimd) {}

TEST_F(OpenMPIRBuilderTest, ApplySimdCustomAligned) {}
TEST_F(OpenMPIRBuilderTest, ApplySimdlen) {}

TEST_F(OpenMPIRBuilderTest, ApplySafelenOrderConcurrent) {}

TEST_F(OpenMPIRBuilderTest, ApplySafelen) {}

TEST_F(OpenMPIRBuilderTest, ApplySimdlenSafelen) {}

TEST_F(OpenMPIRBuilderTest, ApplySimdIf) {}

TEST_F(OpenMPIRBuilderTest, UnrollLoopFull) {}

TEST_F(OpenMPIRBuilderTest, UnrollLoopPartial) {}

TEST_F(OpenMPIRBuilderTest, UnrollLoopHeuristic) {}

TEST_F(OpenMPIRBuilderTest, StaticWorkshareLoopTarget) {}

TEST_F(OpenMPIRBuilderTest, StaticWorkShareLoop) {}

TEST_P(OpenMPIRBuilderTestWithIVBits, StaticChunkedWorkshareLoop) {}

INSTANTIATE_TEST_SUITE_P();

TEST_P(OpenMPIRBuilderTestWithParams, DynamicWorkShareLoop) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(OpenMPIRBuilderTest, DynamicWorkShareLoopOrdered) {}

TEST_F(OpenMPIRBuilderTest, MasterDirective) {}

TEST_F(OpenMPIRBuilderTest, MaskedDirective) {}

TEST_F(OpenMPIRBuilderTest, CriticalDirective) {}

TEST_F(OpenMPIRBuilderTest, OrderedDirectiveDependSource) {}

TEST_F(OpenMPIRBuilderTest, OrderedDirectiveDependSink) {}

TEST_F(OpenMPIRBuilderTest, OrderedDirectiveThreads) {}

TEST_F(OpenMPIRBuilderTest, OrderedDirectiveSimd) {}

TEST_F(OpenMPIRBuilderTest, CopyinBlocks) {}

TEST_F(OpenMPIRBuilderTest, SingleDirective) {}

TEST_F(OpenMPIRBuilderTest, SingleDirectiveNowait) {}

// Helper class to check each instruction of a BB.
class BBInstIter {};

TEST_F(OpenMPIRBuilderTest, SingleDirectiveCopyPrivate) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicReadFlt) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicReadInt) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicWriteFlt) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicWriteInt) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdate) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateFloat) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicUpdateIntr) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicCapture) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicCompare) {}

TEST_F(OpenMPIRBuilderTest, OMPAtomicCompareCapture) {}

TEST_F(OpenMPIRBuilderTest, CreateTeams) {}

TEST_F(OpenMPIRBuilderTest, CreateTeamsWithThreadLimit) {}

TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsUpper) {}

TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsBoth) {}

TEST_F(OpenMPIRBuilderTest, CreateTeamsWithNumTeamsAndThreadLimit) {}

TEST_F(OpenMPIRBuilderTest, CreateTeamsWithIfCondition) {}

TEST_F(OpenMPIRBuilderTest, CreateTeamsWithIfConditionAndNumTeams) {}

/// Returns the single instruction of InstTy type in BB that uses the value V.
/// If there is more than one such instruction, returns null.
template <typename InstTy>
static InstTy *findSingleUserInBlock(Value *V, BasicBlock *BB) {}

/// Returns true if BB contains a simple binary reduction that loads a value
/// from Accum, performs some binary operation with it, and stores it back to
/// Accum.
static bool isSimpleBinaryReduction(Value *Accum, BasicBlock *BB,
                                    Instruction::BinaryOps *OpCode = nullptr) {}

/// Returns true if BB contains a binary reduction that reduces V using a binary
/// operator into an accumulator that is a function argument.
static bool isValueReducedToFuncArg(Value *V, BasicBlock *BB) {}

/// Finds among users of Ptr a pair of GEP instructions with indices [0, 0] and
/// [0, 1], respectively, and assigns results of these instructions to Zero and
/// One. Returns true on success, false on failure or if such instructions are
/// not unique among the users of Ptr.
static bool findGEPZeroOne(Value *Ptr, Value *&Zero, Value *&One) {}

static OpenMPIRBuilder::InsertPointTy
sumReduction(OpenMPIRBuilder::InsertPointTy IP, Value *LHS, Value *RHS,
             Value *&Result) {}

static OpenMPIRBuilder::InsertPointTy
sumAtomicReduction(OpenMPIRBuilder::InsertPointTy IP, Type *Ty, Value *LHS,
                   Value *RHS) {}

static OpenMPIRBuilder::InsertPointTy
xorReduction(OpenMPIRBuilder::InsertPointTy IP, Value *LHS, Value *RHS,
             Value *&Result) {}

static OpenMPIRBuilder::InsertPointTy
xorAtomicReduction(OpenMPIRBuilder::InsertPointTy IP, Type *Ty, Value *LHS,
                   Value *RHS) {}

TEST_F(OpenMPIRBuilderTest, CreateReductions) {}

TEST_F(OpenMPIRBuilderTest, CreateTwoReductions) {}

TEST_F(OpenMPIRBuilderTest, CreateSectionsSimple) {}

TEST_F(OpenMPIRBuilderTest, CreateSections) {}

TEST_F(OpenMPIRBuilderTest, CreateSectionsNoWait) {}

TEST_F(OpenMPIRBuilderTest, CreateOffloadMaptypes) {}

TEST_F(OpenMPIRBuilderTest, CreateOffloadMapnames) {}

TEST_F(OpenMPIRBuilderTest, CreateMapperAllocas) {}

TEST_F(OpenMPIRBuilderTest, EmitMapperCall) {}

TEST_F(OpenMPIRBuilderTest, TargetEnterData) {}

TEST_F(OpenMPIRBuilderTest, TargetExitData) {}

TEST_F(OpenMPIRBuilderTest, TargetDataRegion) {}

namespace {
// Some basic handling of argument mapping for the moment
void CreateDefaultMapInfos(llvm::OpenMPIRBuilder &OmpBuilder,
                           llvm::SmallVectorImpl<llvm::Value *> &Args,
                           llvm::OpenMPIRBuilder::MapInfosTy &CombinedInfo) {}
} // namespace

TEST_F(OpenMPIRBuilderTest, TargetRegion) {}

TEST_F(OpenMPIRBuilderTest, TargetRegionDevice) {}

TEST_F(OpenMPIRBuilderTest, ConstantAllocaRaise) {}

TEST_F(OpenMPIRBuilderTest, CreateTask) {}

TEST_F(OpenMPIRBuilderTest, CreateTaskNoArgs) {}

TEST_F(OpenMPIRBuilderTest, CreateTaskUntied) {}

TEST_F(OpenMPIRBuilderTest, CreateTaskDepend) {}

TEST_F(OpenMPIRBuilderTest, CreateTaskFinal) {}

TEST_F(OpenMPIRBuilderTest, CreateTaskIfCondition) {}

TEST_F(OpenMPIRBuilderTest, CreateTaskgroup) {}

TEST_F(OpenMPIRBuilderTest, CreateTaskgroupWithTasks) {}

TEST_F(OpenMPIRBuilderTest, EmitOffloadingArraysArguments) {}

TEST_F(OpenMPIRBuilderTest, OffloadEntriesInfoManager) {}

// Tests both registerTargetGlobalVariable and getAddrOfDeclareTargetVar as they
// call each other (recursively in some cases). The test case test these
// functions by utilising them for host code generation for declare target
// global variables
TEST_F(OpenMPIRBuilderTest, registerTargetGlobalVariable) {}

TEST_F(OpenMPIRBuilderTest, createGPUOffloadEntry) {}

} // namespace