Add support for the Switch instruction by running the lowerSwitch pass first
[oota-llvm.git] / lib / Transforms / IPO / Cilkifier.cpp
1 //===- Cilkifier.cpp - Support routines for Cilk code gen. ------*- C++ -*-===//
2 //
3 // This is located here so that the code generator (dis) does not have to
4 // include and link with the libtipo.a archive containing class Cilkifier
5 // and the rest of the automatic parallelization code.
6 //===----------------------------------------------------------------------===//
7
8
9 #include "llvm/Support/Cilkifier.h"
10 #include "llvm/Function.h"
11 #include "llvm/iOther.h"
12 #include "llvm/DerivedTypes.h"
13 #include <vector>
14
15
16 //---------------------------------------------------------------------------- 
17 // Global constants used in marking Cilk functions and function calls.
18 // These should be used only by the auto-parallelization pass.
19 //---------------------------------------------------------------------------- 
20
21 const std::string CilkSuffix(".llvm2cilk");
22 const std::string DummySyncFuncName("__sync.llvm2cilk");
23
24 //---------------------------------------------------------------------------- 
25 // Routines to identify Cilk functions, calls to Cilk functions, and syncs.
26 //---------------------------------------------------------------------------- 
27
28 bool isCilk(const Function& F)
29 {
30   assert(F.hasName());
31   return (F.getName().rfind(CilkSuffix) ==
32           F.getName().size() - CilkSuffix.size());
33 }
34
35 bool isCilkMain(const Function& F)
36 {
37   assert(F.hasName());
38   return (F.getName() == std::string("main") + CilkSuffix);
39 }
40
41
42 bool isCilk(const CallInst& CI)
43 {
44   return (CI.getCalledFunction() != NULL && isCilk(*CI.getCalledFunction()));
45 }
46
47 bool isSync(const CallInst& CI)
48
49   return (CI.getCalledFunction() != NULL &&
50           CI.getCalledFunction()->getName() == DummySyncFuncName);
51 }
52
53
54 //----------------------------------------------------------------------------