LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NVPTXSplitBBatBar.cpp
Go to the documentation of this file.
1 //===- NVPTXSplitBBatBar.cpp - Split BB at Barrier --*- C++ -*--===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // Split basic blocks so that a basic block that contains a barrier instruction
10 // only contains the barrier instruction.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "NVPTXSplitBBatBar.h"
15 #include "NVPTXUtilities.h"
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/IR/IntrinsicInst.h"
19 #include "llvm/IR/Intrinsics.h"
21 
22 using namespace llvm;
23 
24 namespace llvm { FunctionPass *createSplitBBatBarPass(); }
25 
26 char NVPTXSplitBBatBar::ID = 0;
27 
29 
31  bool changed = false;
32 
33  // Collect all the split points in SplitPoints
34  for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) {
35  BasicBlock::iterator IB = BI->begin();
36  BasicBlock::iterator II = IB;
37  BasicBlock::iterator IE = BI->end();
38 
39  // Skit the first instruction. No splitting is needed at this
40  // point even if this is a bar.
41  while (II != IE) {
42  if (IntrinsicInst *inst = dyn_cast<IntrinsicInst>(II)) {
43  Intrinsic::ID id = inst->getIntrinsicID();
44  // If this is a barrier, split at this instruction
45  // and the next instruction.
46  if (llvm::isBarrierIntrinsic(id)) {
47  if (II != IB)
48  SplitPoints.push_back(II);
49  II++;
50  if ((II != IE) && (!II->isTerminator())) {
51  SplitPoints.push_back(II);
52  II++;
53  }
54  continue;
55  }
56  }
57  II++;
58  }
59  }
60 
61  for (unsigned i = 0; i != SplitPoints.size(); i++) {
62  changed = true;
63  Instruction *inst = SplitPoints[i];
64  inst->getParent()->splitBasicBlock(inst, "bar_split");
65  }
66 
67  return changed;
68 }
69 
70 // This interface will most likely not be necessary, because this pass will
71 // not be invoked by the driver, but will be used as a prerequisite to
72 // another pass.
iterator end()
Definition: Function.h:397
F(f)
iterator begin()
Definition: Function.h:395
FunctionPass * createSplitBBatBarPass()
virtual bool runOnFunction(Function &F)
bool isBarrierIntrinsic(llvm::Intrinsic::ID)
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
Definition: BasicBlock.cpp:298
const BasicBlock * getParent() const
Definition: Instruction.h:52