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

[DO NOT MERGE] Re-enable -fdetach flag #19

Open
wants to merge 1 commit into
base: master
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
2 changes: 1 addition & 1 deletion include/llvm/Transforms/Tapir.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ FunctionPass *createSpawnUnswitchPass();
//
// PromoteDetachToCilk
//
ModulePass *createLowerTapirToTargetPass(tapir::TapirTarget*);
FunctionPass *createLowerTapirToTargetPass(tapir::TapirTarget*);

} // End llvm namespace

Expand Down
23 changes: 17 additions & 6 deletions lib/Transforms/IPO/PassManagerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ void PassManagerBuilder::populateFunctionPassManager(

if (OptLevel == 0) return;

if (tapirTarget && DisableTapirOpts) {// -fdetach
FPM.add(createLowerTapirToTargetPass(tapirTarget));
}

addInitialAliasAnalysisPasses(FPM);

FPM.add(createCFGSimplificationPass());
Expand Down Expand Up @@ -322,6 +326,11 @@ void PassManagerBuilder::addPGOInstrPasses(legacy::PassManagerBase &MPM) {
}
void PassManagerBuilder::addFunctionSimplificationPasses(
legacy::PassManagerBase &MPM) {

if (tapirTarget && DisableTapirOpts) {// -fdetach
MPM.add(createLowerTapirToTargetPass(tapirTarget));
}

// Start of function pass.
// Break up aggregate allocas, using SSAUpdater.
MPM.add(createSROAPass());
Expand Down Expand Up @@ -412,6 +421,14 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
// void PassManagerBuilder::prepopulateModulePassManager(
void PassManagerBuilder::populateModulePassManager(
legacy::PassManagerBase &MPM) {

bool TapirHasBeenLowered = (tapirTarget == nullptr);

if (tapirTarget && DisableTapirOpts) {// -fdetach
MPM.add(createLowerTapirToTargetPass(tapirTarget));
TapirHasBeenLowered = true;
}

if (!PGOSampleUse.empty()) {
MPM.add(createPruneEHPass());
MPM.add(createSampleProfileLoaderPass(PGOSampleUse));
Expand Down Expand Up @@ -485,12 +502,6 @@ void PassManagerBuilder::populateModulePassManager(
DisableUnrollLoops = true;

bool RerunAfterTapirLowering = false;
bool TapirHasBeenLowered = (tapirTarget == nullptr);

if (tapirTarget && DisableTapirOpts) {// -fdetach
MPM.add(createLowerTapirToTargetPass(tapirTarget));
TapirHasBeenLowered = true;
}

do {
RerunAfterTapirLowering =
Expand Down
11 changes: 6 additions & 5 deletions lib/Transforms/Tapir/OpenMPABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// runtime system. This interface does the low-level dirty work of passes
// such as LowerToCilk.
//
//===----------------------------------------------------------------------===//
//===--------------------------------------------------------

#include "llvm/Transforms/Tapir/OpenMPABI.h"
#include "llvm/IR/DebugInfoMetadata.h"
Expand Down Expand Up @@ -202,7 +202,7 @@ CallInst *emitRuntimeCall(Value *Callee, ArrayRef<Value *> Args,
return call;
}

Value *getThreadID(Function *F, IRBuilder<> &IRBuilder) {
Value *getThreadID(Function *F, IRBuilder<> &IRBuilder0) {
Value *ThreadID = nullptr;
auto I = OpenMPThreadIDLoadMap.find(F);
if (I != OpenMPThreadIDLoadMap.end()) {
Expand All @@ -216,9 +216,9 @@ Value *getThreadID(Function *F, IRBuilder<> &IRBuilder) {
if (I2 != OpenMPThreadIDAllocaMap.end()) {
DataLayout DL(F->getParent());
auto Alloca = I2->second;
auto ThreadIDAddrs = IRBuilder.CreateLoad(Alloca);
auto ThreadIDAddrs = IRBuilder0.CreateLoad(Alloca);
ThreadIDAddrs->setAlignment(DL.getTypeAllocSize(ThreadIDAddrs->getType()));
ThreadID = IRBuilder.CreateLoad(ThreadIDAddrs);
ThreadID = IRBuilder0.CreateLoad(ThreadIDAddrs);
((LoadInst *)ThreadID)
->setAlignment(DL.getTypeAllocSize(ThreadID->getType()));
auto &Elem = OpenMPThreadIDLoadMap.FindAndConstruct(F);
Expand All @@ -228,7 +228,8 @@ Value *getThreadID(Function *F, IRBuilder<> &IRBuilder) {

auto GTIDFn = createRuntimeFunction(
OpenMPRuntimeFunction::OMPRTL__kmpc_global_thread_num, F->getParent());
ThreadID = emitRuntimeCall(GTIDFn, {DefaultOpenMPLocation}, "", IRBuilder);
IRBuilder<> b(F->getEntryBlock().getFirstNonPHIOrDbgOrLifetime());
ThreadID = emitRuntimeCall(GTIDFn, {DefaultOpenMPLocation}, "", b);
auto &Elem = OpenMPThreadIDLoadMap.FindAndConstruct(F);
Elem.second = ThreadID;

Expand Down
51 changes: 20 additions & 31 deletions lib/Transforms/Tapir/TapirToTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ using namespace llvm::tapir;

namespace {

struct LowerTapirToTarget : public ModulePass {
struct LowerTapirToTarget : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
TapirTarget* tapirTarget;
explicit LowerTapirToTarget(TapirTarget* tapirTarget = nullptr)
: ModulePass(ID), tapirTarget(tapirTarget) {
: FunctionPass(ID), tapirTarget(tapirTarget) {
assert(tapirTarget);
initializeLowerTapirToTargetPass(*PassRegistry::getPassRegistry());
}
Expand All @@ -40,7 +40,7 @@ struct LowerTapirToTarget : public ModulePass {
return "Simple Lowering of Tapir to Target ABI";
}

bool runOnModule(Module &M) override;
bool runOnFunction(Function &F) override;

void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<AssumptionCacheTracker>();
Expand Down Expand Up @@ -130,6 +130,7 @@ SmallVectorImpl<Function *>
if (!changed) return NewHelpers;

if (verifyFunction(F, &errs())) {
F.getParent()->dump();
DEBUG(F.dump());
assert(0);
}
Expand All @@ -142,46 +143,34 @@ SmallVectorImpl<Function *>
return NewHelpers;
}

bool LowerTapirToTarget::runOnModule(Module &M) {
if (skipModule(M))
bool LowerTapirToTarget::runOnFunction(Function &F) {
if (skipFunction(F))
return false;
bool shouldGo = false;

// Add functions that detach to the work list.
SmallVector<Function *, 4> WorkList;
for (Function &F : M)
for (BasicBlock &BB : F)
if (isa<DetachInst>(BB.getTerminator())) {
WorkList.push_back(&F);
break;
}

if (WorkList.empty())
for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I) {
if (DetachInst* DI = dyn_cast_or_null<DetachInst>(I->getTerminator())) {
shouldGo = true;
} else if (SyncInst* SI = dyn_cast_or_null<SyncInst>(I->getTerminator())) {
shouldGo = true;
}
}
if (shouldGo == false) {
return false;
}

bool Changed = false;
std::unique_ptr<SmallVectorImpl<Function *>> NewHelpers;
while (!WorkList.empty()) {
// Process the next function.
Function *F = WorkList.back();
WorkList.pop_back();
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>(*F).getDomTree();
DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
AssumptionCacheTracker &ACT = getAnalysis<AssumptionCacheTracker>();
NewHelpers.reset(processFunction(*F, DT, ACT.getAssumptionCache(*F)));
Changed |= !NewHelpers->empty();
// Check the generated helper functions to see if any need to be processed,
// that is, to see if any of them themselves detach a subtask.
for (Function *Helper : *NewHelpers)
for (BasicBlock &BB : *Helper)
if (isa<DetachInst>(BB.getTerminator()))
WorkList.push_back(Helper);
}
bool Changed = processFunction(F, DT, ACT.getAssumptionCache(F))->size() > 0;

return Changed;
}

// createLowerTapirToTargetPass - Provide an entry point to create this pass.
//
namespace llvm {
ModulePass *createLowerTapirToTargetPass(TapirTarget* tapirTarget) {
FunctionPass *createLowerTapirToTargetPass(TapirTarget* tapirTarget) {
return new LowerTapirToTarget(tapirTarget);
}
}