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

Use lighter weight map accesses #288

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
5 changes: 3 additions & 2 deletions llvm/include/llvm/Transforms/Tapir/OpenCilkABI.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class OpenCilkABI final : public TapirTarget {
ValueToValueMapTy DetachCtxToStackFrame;
SmallPtrSet<Function *, 8> Processed;
SmallPtrSet<CallBase *, 8> CallsToInline;
DenseMap<BasicBlock *, SmallVector<IntrinsicInst *, 4>> TapirRTCalls;
using CallVector = SmallVector<IntrinsicInst *, 4>;
DenseMap<BasicBlock *, CallVector> TapirRTCalls;
ValueToValueMapTy DefaultSyncLandingpad;

StringRef RuntimeBCPath = "";
Expand Down Expand Up @@ -141,7 +142,7 @@ class OpenCilkABI final : public TapirTarget {
}

void GetTapirRTCalls(Spindle *TaskFrame, bool IsRootTask, TaskInfo &TI);
void LowerTapirRTCalls(Function &F, BasicBlock *TFEntry);
void LowerTapirRTCalls(Function &F, CallVector &Calls);

Value *CreateStackFrame(Function &F);
Value *GetOrCreateCilkStackFrame(Function &F);
Expand Down
48 changes: 28 additions & 20 deletions llvm/lib/Transforms/Tapir/OpenCilkABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,16 @@ void OpenCilkABI::addHelperAttributes(Function &Helper) {

void OpenCilkABI::remapAfterOutlining(BasicBlock *TFEntry,
ValueToValueMapTy &VMap) {
if (TapirRTCalls[TFEntry].empty())
CallVector &Calls = TapirRTCalls[TFEntry];
if (Calls.empty())
return;

// Update the set of tapir.runtime.{start,end} intrinsics in the taskframe
// rooted at TFEntry to process.
SmallVector<IntrinsicInst *, 4> OldTapirRTCalls(TapirRTCalls[TFEntry]);
TapirRTCalls[TFEntry].clear();
CallVector OldTapirRTCalls(Calls);
Calls.clear();
for (IntrinsicInst *II : OldTapirRTCalls)
TapirRTCalls[TFEntry].push_back(cast<IntrinsicInst>(VMap[II]));
Calls.push_back(cast<IntrinsicInst>(VMap[II]));
}

// Check whether the allocation of a __cilkrts_stack_frame can be inserted after
Expand Down Expand Up @@ -477,12 +478,12 @@ Value *OpenCilkABI::CreateStackFrame(Function &F) {
}

Value* OpenCilkABI::GetOrCreateCilkStackFrame(Function &F) {
if (DetachCtxToStackFrame.count(&F))
return DetachCtxToStackFrame[&F];
Value *SF = DetachCtxToStackFrame.lookup(&F);
if (SF)
return SF;

Value *SF = CreateStackFrame(F);
SF = CreateStackFrame(F);
DetachCtxToStackFrame[&F] = SF;

return SF;
}

Expand Down Expand Up @@ -619,9 +620,9 @@ void OpenCilkABI::InsertStackFramePop(Function &F, bool PromoteCallsToInvokes,
}

// Lower any calls to tapir.runtime.{start,end} that need to be processed.
void OpenCilkABI::LowerTapirRTCalls(Function &F, BasicBlock *TFEntry) {
void OpenCilkABI::LowerTapirRTCalls(Function &F, CallVector &Calls) {
Instruction *SF = cast<Instruction>(GetOrCreateCilkStackFrame(F));
for (IntrinsicInst *II : TapirRTCalls[TFEntry]) {
for (IntrinsicInst *II : Calls) {
IRBuilder<> Builder(II);
if (Intrinsic::tapir_runtime_start == II->getIntrinsicID()) {
// Lower calls to tapir.runtime.start to __cilkrts_enter_frame.
Expand Down Expand Up @@ -688,8 +689,8 @@ Value *OpenCilkABI::lowerGrainsizeCall(CallInst *GrainsizeCall) {
BasicBlock *OpenCilkABI::GetDefaultSyncLandingpad(Function &F, Value *SF,
DebugLoc Loc) {
// Return an existing default sync landingpad, if there is one.
if (DefaultSyncLandingpad.count(&F))
return cast<BasicBlock>(DefaultSyncLandingpad[&F]);
if (Value *BB = DefaultSyncLandingpad.lookup(&F))
return cast<BasicBlock>(BB);

// Create a default cleanup landingpad block.
LLVMContext &C = F.getContext();
Expand All @@ -716,7 +717,7 @@ BasicBlock *OpenCilkABI::GetDefaultSyncLandingpad(Function &F, Value *SF,
// Lower a sync instruction SI.
void OpenCilkABI::lowerSync(SyncInst &SI) {
Function &Fn = *SI.getFunction();
if (!DetachCtxToStackFrame[&Fn])
if (!DetachCtxToStackFrame.count(&Fn))
// If we have not created a stackframe for this function, then we don't need
// to handle the sync.
return;
Expand Down Expand Up @@ -821,10 +822,11 @@ void OpenCilkABI::postProcessOutlinedTask(Function &F, Instruction *DetachPt,

void OpenCilkABI::preProcessRootSpawner(Function &F, BasicBlock *TFEntry) {
MarkSpawner(F);
if (TapirRTCalls[TFEntry].empty()) {
CallVector &Calls = TapirRTCalls[TFEntry];
if (Calls.empty()) {
InsertStackFramePush(F, nullptr, false, true);
} else {
LowerTapirRTCalls(F, TFEntry);
LowerTapirRTCalls(F, Calls);
}
Value *SF = DetachCtxToStackFrame[&F];
for (BasicBlock &BB : F) {
Expand Down Expand Up @@ -872,7 +874,7 @@ void OpenCilkABI::processSubTaskCall(TaskOutlineInfo &TOI, DominatorTree &DT) {

Function &F = *ReplCall->getFunction();
LLVMContext &C = F.getContext();
Value *SF = DetachCtxToStackFrame[&F];
Value *SF = DetachCtxToStackFrame.lookup(&F);
assert(SF && "No frame found for spawning task");

// Find the helper argument for the parent __cilkrts_stack_frame and update
Expand Down Expand Up @@ -1098,11 +1100,16 @@ bool OpenCilkABI::preProcessFunction(Function &F, TaskInfo &TI,
// enter_frame/leave_frame calls.
GetTapirRTCalls(TI.getRootTask()->getEntrySpindle(), true, TI);

if (!TI.isSerial() || TapirRTCalls[&F.getEntryBlock()].empty())
if (!TI.isSerial())
return false;

CallVector &Calls = TapirRTCalls[&F.getEntryBlock()];

if (Calls.empty())
return false;

MarkSpawner(F);
LowerTapirRTCalls(F, &F.getEntryBlock());
LowerTapirRTCalls(F, Calls);
return false;
}

Expand Down Expand Up @@ -1161,8 +1168,9 @@ bool OpenCilkABI::processOrdinaryFunction(Function &F, BasicBlock *TFEntry) {

// If any calls to tapir.runtime.{start,end} were found in this taskframe that
// need processing, lower them now.
if (!TapirRTCalls[TFEntry].empty()) {
LowerTapirRTCalls(F, TFEntry);
CallVector &Calls = TapirRTCalls[TFEntry];
if (!Calls.empty()) {
LowerTapirRTCalls(F, Calls);
Changed = true;
}

Expand Down
Loading