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

Framework for handling combined lowering of ops/overriding default conversion functions #44

Closed
wants to merge 4 commits into from
Closed
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
74 changes: 7 additions & 67 deletions llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1246,26 +1246,23 @@ class OpenMPIRBuilder {
getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
StringRef ParentName = "");

// using ReductionGenTy =
// function_ref<InsertPointTy(InsertPointTy, Value *, Value *, Value *&)>;

// using AtomicReductionGenTy =
// function_ref<InsertPointTy(InsertPointTy, Type *, Value *, Value *)>;

/// Owning equivalents of OpenMPIRBuilder::(Atomic)ReductionGen that are used
/// to
/// store lambdas with capture.
/// Functions used to generate reductions. Such functions take two Values
/// representing LHS and RHS of the reduction, respectively, and a reference
/// to the value that is updated to refer to the reduction result.
using ReductionGenTy = std::function<OpenMPIRBuilder::InsertPointTy(
OpenMPIRBuilder::InsertPointTy, Value *, Value *, Value *&)>;
using ReductionGenTy =
function_ref<InsertPointTy(InsertPointTy, Value *, Value *, Value *&)>;

/// Functions used to generate atomic reductions. Such functions take two
/// Values representing pointers to LHS and RHS of the reduction, as well as
/// the element type of these pointers. They are expected to atomically
/// update the LHS to the reduced value.
using AtomicReductionGenTy = std::function<OpenMPIRBuilder::InsertPointTy(
OpenMPIRBuilder::InsertPointTy, Type *, Value *, Value *)>;
using AtomicReductionGenTy =
function_ref<InsertPointTy(InsertPointTy, Type *, Value *, Value *)>;



/// Information about an OpenMP reduction.
struct ReductionInfo {
Expand All @@ -1275,10 +1272,6 @@ class OpenMPIRBuilder {
: ElementType(ElementType), Variable(Variable),
PrivateVariable(PrivateVariable), ReductionGen(ReductionGen),
AtomicReductionGen(AtomicReductionGen) {}
ReductionInfo(Value *PrivateVariable)
: ElementType(nullptr), Variable(nullptr),
PrivateVariable(PrivateVariable), ReductionGen(),
AtomicReductionGen() {}

/// Reduction element type, must match pointee type of variable.
Type *ElementType;
Expand All @@ -1301,56 +1294,6 @@ class OpenMPIRBuilder {
AtomicReductionGenTy AtomicReductionGen;
};

/// A class that manages the reduction info to facilitate lowering of
/// reductions at multiple levels of parallelism. For example handling teams
/// and parallel reductions on GPUs

class ReductionInfoManager {
private:
SmallVector<ReductionInfo> ReductionInfos;
std::optional<InsertPointTy> PrivateVarAllocaIP;

public:
ReductionInfoManager() {};
void clear() {
ReductionInfos.clear();
PrivateVarAllocaIP.reset();
}

Value *allocatePrivateReductionVar(
IRBuilderBase &builder,
llvm::OpenMPIRBuilder::InsertPointTy &allocaIP,
Type *VarType) {
llvm::Type *ptrTy = llvm::PointerType::getUnqual(builder.getContext());
llvm::Value *var = builder.CreateAlloca(VarType);
var->setName("private_redvar");
llvm::Value *castVar =
builder.CreatePointerBitCastOrAddrSpaceCast(var, ptrTy);
ReductionInfos.push_back(ReductionInfo(castVar));
return castVar;
}

ReductionInfo getReductionInfo(unsigned Index) {
return ReductionInfos[Index];
}
ReductionInfo setReductionInfo(unsigned Index, ReductionInfo &RI) {
return ReductionInfos[Index] = RI;
}
Value *getPrivateReductionVariable(unsigned Index) {
return ReductionInfos[Index].PrivateVariable;
}
SmallVector<ReductionInfo> &getReductionInfos() {
return ReductionInfos;
}

bool hasPrivateVarAllocaIP() { return PrivateVarAllocaIP.has_value(); }
InsertPointTy getPrivateVarAllocaIP() {
assert(PrivateVarAllocaIP.has_value() && "AllocaIP not set");
return *PrivateVarAllocaIP;
}
void setPrivateVarAllocaIP(InsertPointTy IP) { PrivateVarAllocaIP = IP; }
};

/// \param Loc The location where the reduction was
/// encountered. Must be within the associate
/// directive and after the last local access to the
Expand Down Expand Up @@ -1573,9 +1516,6 @@ class OpenMPIRBuilder {
/// Info manager to keep track of target regions.
OffloadEntriesInfoManager OffloadInfoManager;

/// Info manager to keep track of reduction information;
ReductionInfoManager RIManager;

/// The target triple of the underlying module.
const Triple T;

Expand Down
Loading