aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/IPO/Cilkifier.cpp
blob: 498c58b6fd8b51f85bce83210ac6142e433358e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//===- Cilkifier.cpp - Support routines for Cilk code gen. ------*- C++ -*-===//
//
// This is located here so that the code generator (dis) does not have to
// include and link with the libtipo.a archive containing class Cilkifier
// and the rest of the automatic parallelization code.
//===----------------------------------------------------------------------===//


#include "llvm/Support/Cilkifier.h"
#include "llvm/Function.h"
#include "llvm/iOther.h"
#include "llvm/DerivedTypes.h"
#include <vector>


//---------------------------------------------------------------------------- 
// Global constants used in marking Cilk functions and function calls.
// These should be used only by the auto-parallelization pass.
//---------------------------------------------------------------------------- 

const std::string CilkSuffix(".llvm2cilk");
const std::string DummySyncFuncName("__sync.llvm2cilk");

//---------------------------------------------------------------------------- 
// Routines to identify Cilk functions, calls to Cilk functions, and syncs.
//---------------------------------------------------------------------------- 

bool isCilk(const Function& F)
{
  assert(F.hasName());
  return (F.getName().rfind(CilkSuffix) ==
          F.getName().size() - CilkSuffix.size());
}

bool isCilkMain(const Function& F)
{
  assert(F.hasName());
  return (F.getName() == std::string("main") + CilkSuffix);
}


bool isCilk(const CallInst& CI)
{
  return (CI.getCalledFunction() != NULL && isCilk(*CI.getCalledFunction()));
}

bool isSync(const CallInst& CI)
{ 
  return (CI.getCalledFunction() != NULL &&
          CI.getCalledFunction()->getName() == DummySyncFuncName);
}


//----------------------------------------------------------------------------