[llvm-commits] [parallel] CVS: llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp
Misha Brukman
brukman at cs.uiuc.edu
Thu May 6 11:35:03 PDT 2004
Changes in directory llvm/lib/Transforms/Parallel:
BreakJoinBlocks.cpp added (r1.1.2.1)
---
Log message:
Break basic blocks at the calls to llvm.join so that they are not extract with
the parallel regions -- we need the join to be on the outside!
---
Diffs of the changes: (+65 -0)
Index: llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp
diff -c /dev/null llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp:1.1.2.1
*** /dev/null Thu May 6 11:35:08 2004
--- llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp Thu May 6 11:34:58 2004
***************
*** 0 ****
--- 1,65 ----
+ //===- BreakJoinBlocks.cpp - Break blocks at calls to join ----------===//
+ //
+ // The LLVM Compiler Infrastructure
+ //
+ // This file was developed by the LLVM research group and is distributed under
+ // the University of Illinois Open Source License. See LICENSE.TXT for details.
+ //
+ //===----------------------------------------------------------------------===//
+ //
+ //
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "llvm/iOther.h"
+ #include "llvm/Function.h"
+ #include "llvm/BasicBlock.h"
+ #include "llvm/Pass.h"
+ #include "llvm/Transforms/Utils/FunctionUtils.h"
+ using namespace llvm;
+
+ namespace {
+
+ /// BreakJoin -
+ ///
+ struct BreakJoin : public FunctionPass {
+ public:
+ BreakJoin() {}
+ bool runOnFunction(Function &F);
+ private:
+ CallInst *findJoin(BasicBlock *BB);
+ };
+
+ RegisterOpt<BreakJoin> X("break-joins", "Break BasicBlocks at joins");
+
+ } // End anonymous namespace
+
+ bool BreakJoin::runOnFunction(Function &F) {
+ bool Changed = false;
+ std::vector<BasicBlock*> Worklist;
+ for (Function::iterator i = F.begin(), e = F.end(); i != e; ++i)
+ Worklist.push_back(i);
+
+ while (!Worklist.empty()) {
+ BasicBlock *BB = Worklist.back();
+ Worklist.pop_back();
+ if (CallInst *CI = findJoin(BB)) {
+ BasicBlock::iterator II(CI);
+ if (II != BB->begin()) {
+ BasicBlock *newBB = BB->splitBasicBlock(II, BB->getName() + "_split");
+ if (newBB) Worklist.push_back(newBB);
+ }
+ }
+ }
+
+ return Changed;
+ }
+
+ CallInst* BreakJoin::findJoin(BasicBlock *BB) {
+ for (BasicBlock::iterator i = BB->begin(), e = BB->end(); i != e; ++i)
+ if (CallInst *CI = dyn_cast<CallInst>(i))
+ if (CI->getCalledFunction()->getName() == "llvm.join")
+ return CI;
+
+ return 0;
+ }
More information about the llvm-commits
mailing list