Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: an API to register externally defined tapir target #26

Open
wants to merge 1 commit into
base: release/9.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/include/llvm/Analysis/TargetLibraryInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
#define LLVM_ANALYSIS_TARGETLIBRARYINFO_H

#include <functional>
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/Triple.h"
Expand All @@ -18,6 +19,7 @@
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/Tapir/TapirTargetIDs.h"
#include "llvm/Transforms/Tapir/LoweringUtils.h"

namespace llvm {
template <typename T> class ArrayRef;
Expand All @@ -38,6 +40,8 @@ struct VecDesc {
NumLibFuncs
};

using TapirTargetFactory = std::function<TapirTarget *(Module &)>;

/// Implementation of the target library information.
///
/// This class constructs tables that hold the target library information and
Expand Down Expand Up @@ -204,6 +208,8 @@ class TargetLibraryInfoImpl {
TapirTarget = TargetID;
}

void setTapirTarget(TapirTargetFactory target);

/// Return the ID of the target for Tapir lowering.
TapirTargetID getTapirTarget() const {
return TapirTarget;
Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/Transforms/Tapir/LoweringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LOWERING_UTILS_H_
#define LOWERING_UTILS_H_

#include <functional>
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SetVector.h"
Expand Down Expand Up @@ -409,6 +410,8 @@ class LoopOutlineProcessor {
/// Generate a TapirTarget object for the specified TapirTargetID.
TapirTarget *getTapirTargetFromID(Module &M, TapirTargetID TargetID);

void setCustomTapirTarget(std::function<TapirTarget *(Module &)>);

/// Find all inputs to tasks within a function \p F, including nested tasks.
TaskValueSetMap findAllTaskInputs(Function &F, const DominatorTree &DT,
const TaskInfo &TI);
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Transforms/Tapir/TapirTargetIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum class TapirTargetID {
OpenCilk, // Lower to OpenCilk ABI
OpenMP, // Lower to OpenMP
Qthreads, // Lower to Qthreads
Custom,
Last_TapirTargetID
};

Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Transforms/Tapir/LoweringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ using namespace llvm;
static const char TimerGroupName[] = DEBUG_TYPE;
static const char TimerGroupDescription[] = "Tapir lowering";

static TapirTargetFactory CUSTOM_TAPIR_TARGET;

void llvm::TargetLibraryInfoImpl::setTapirTarget(TapirTargetFactory target) {
TapirTarget = TapirTargetID::Custom;
CUSTOM_TAPIR_TARGET = target;
}

TapirTarget *llvm::getTapirTargetFromID(Module &M, TapirTargetID ID) {
switch (ID) {
case TapirTargetID::None:
Expand All @@ -53,6 +60,8 @@ TapirTarget *llvm::getTapirTargetFromID(Module &M, TapirTargetID ID) {
return new OpenMPABI(M);
case TapirTargetID::Qthreads:
return new QthreadsABI(M);
case TapirTargetID::Custom:
return CUSTOM_TAPIR_TARGET(M);
default:
llvm_unreachable("Invalid TapirTargetID");
}
Expand Down