-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline_devicefn.cpp
More file actions
76 lines (57 loc) · 2.3 KB
/
inline_devicefn.cpp
File metadata and controls
76 lines (57 loc) · 2.3 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define DEBUG_TYPE "mxpa_ms4"
// LLVM includes
#include "llvm/Support/Debug.h"
// MxPA includes
#include "inline_devicefn.h"
#include "kernel_info_reader.h"
namespace SpmdKernel {
using namespace llvm;
namespace Coarsening {
char DevFnInliner::ID = 0;
namespace {
static
RegisterPass<DevFnInliner> DFIModulePass("mxpa_inliner",
"Mark all non-kernel functions alwaysinline");
}
bool DevFnInliner::runOnModule(Module &M) {
bool Changed = false;
CL_KernelInfo CLKI(M);
std::vector<std::string> KernelNames = CLKI.get_kernel_names();
for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) {
if (FI->isDeclaration())
continue;
std::string fnm = FI->getName().str();
bool IsKernel = (std::find(KernelNames.begin(), KernelNames.end(), fnm) != KernelNames.end());
if (!IsKernel) {
AttributeSet DeviceFnAttr = FI->getAttributes();
//if (!DeviceFnAttr.hasAttribute(AttributeSet::FunctionIndex, Attribute::AlwaysInline)) {
AttrBuilder B;
B.addAttribute(Attribute::NoInline);
AttributeSet NoInlineAttr = AttributeSet::get(FI->getContext(),
AttributeSet::FunctionIndex,
B);
FI->removeAttributes(AttributeSet::FunctionIndex, NoInlineAttr);
FI->addFnAttr(Attribute::AlwaysInline);
FI->setLinkage(GlobalValue::InternalLinkage);
Changed = true;
//}
} else {
AttributeSet KernelAttr = FI->getAttributes();
//if (KernelAttr.hasAttribute(AttributeSet::FunctionIndex, Attribute::AlwaysInline)) {
AttrBuilder B;
B.addAttribute(Attribute::AlwaysInline);
AttributeSet InlineAttr = AttributeSet::get(FI->getContext(),
AttributeSet::FunctionIndex,
B);
FI->removeAttributes(AttributeSet::FunctionIndex, InlineAttr);
FI->addFnAttr(Attribute::NoInline);
FI->setLinkage(GlobalValue::ExternalLinkage);
Changed = true;
//}
DEBUG_WITH_TYPE("mxpa_ms4",errs() << "Function: " << FI->getName() << "\n");
}
}
return Changed;
}
}
}