~ryan-rmarcus/pocl/pocl

« back to all changes in this revision

Viewing changes to lib/llvmopencl/LoopBarriers.cc

  • Committer: Carlos Sánchez de La Lama
  • Date: 2011-12-12 04:35:55 UTC
  • mto: This revision was merged to the branch mainline in revision 109.
  • Revision ID: carlos.delalama@urjc.es-20111212043555-ct245z61erk23htj
Using intrinsic (sort of) for barriers, working & tests updates.
New class ParallelRegion & Barrier (still unused).

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#define BARRIER_FUNCTION_NAME "pocl.barrier"
33
33
 
34
34
static bool is_barrier(Instruction *i);
35
 
static CallInst *new_barrier();
 
35
static CallInst *create_barrier(Instruction *InsertBefore);
36
36
 
37
37
static Function *barrier = NULL;
38
38
 
98
98
            (!is_barrier(preheader->getTerminator()->getPrevNode()))) {
99
99
          // Avoid adding a barrier here if there is already a barrier
100
100
          // just before the terminator.
101
 
          new_barrier()->insertBefore(preheader->getTerminator());
 
101
          create_barrier(preheader->getTerminator());
102
102
          preheader->setName(preheader->getName() + ".loopbarrier");
103
103
        }
104
104
 
111
111
          // barrier just before the terminator.
112
112
          if ((latch->size() == 1) ||
113
113
              (!is_barrier(latch->getTerminator()->getPrevNode()))) {
114
 
            new_barrier()->insertBefore(latch->getTerminator());
 
114
            create_barrier(latch->getTerminator());
115
115
            latch->setName(latch->getName() + ".latchbarrier");
116
116
          }
117
117
 
137
137
              // there is no need to add an additional barrier.
138
138
              if ((Latch->size() == 1) ||
139
139
                  (!is_barrier(Latch->getTerminator()->getPrevNode()))) {
140
 
                new_barrier()->insertBefore(Latch->getTerminator());
 
140
                create_barrier(Latch->getTerminator());
141
141
                Latch->setName(Latch->getName() + ".latchbarrier");
142
142
              }
143
143
            }
156
156
static bool
157
157
is_barrier(Instruction *i)
158
158
{
159
 
  if (CallInst *c = dyn_cast<CallInst>(i)) {
160
 
    if (Function *f = c->getCalledFunction()) {
161
 
      if (f == barrier)
162
 
        return true;
163
 
    }
 
159
  if (CallInst *C = dyn_cast<CallInst>(i)) {
 
160
    return C->getCalledFunction()->getName() == BARRIER_FUNCTION_NAME;
164
161
  }
165
162
 
166
163
  return false;
167
164
}
168
165
 
169
166
static CallInst *
170
 
new_barrier()
 
167
create_barrier(Instruction *InsertBefore)
171
168
{
172
 
  assert (barrier != NULL && "No barrier function!");
173
 
  Constant *zero =
174
 
    ConstantInt::get(barrier->getArgumentList().front().getType(), 0);
175
 
  SmallVector<Value *, 1> sv(1, zero);
176
 
  return CallInst::Create(barrier, ArrayRef<Value *>(sv));
 
169
  Module *M = InsertBefore->getParent()->getParent()->getParent();
 
170
  Function *F =
 
171
    cast<Function>(M->getOrInsertFunction(BARRIER_FUNCTION_NAME,
 
172
                                          Type::getVoidTy(M->getContext()),
 
173
                                          NULL));
 
174
  return CallInst::Create(F, "", InsertBefore);
177
175
}