[Mesa-dev] [PATCH v2 2/2] clover: Constify llvm::Function handling
Jan Vesely
jan.vesely at rutgers.edu
Sat Jun 25 22:52:24 UTC 2016
v2: fix build using llvm 3.7
Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
.../state_trackers/clover/llvm/invocation.cpp | 33 +++++++++-------------
1 file changed, 14 insertions(+), 19 deletions(-)
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index db748b4..fa73406 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -276,12 +276,12 @@ namespace {
#endif
}
- std::vector<llvm::Function *>
- find_kernels(llvm::Module *mod) {
- std::vector<llvm::Function *> kernels;
+ std::vector<const llvm::Function *>
+ find_kernels(const llvm::Module *mod) {
+ std::vector<const llvm::Function *> kernels;
#if HAVE_LLVM >= 0x0309
- auto &list = mod->getFunctionList();
- for_each(list.begin(), list.end(), [&](llvm::Function &f){
+ const auto &list = mod->getFunctionList();
+ for_each(list.begin(), list.end(), [&](const llvm::Function &f){
if (f.getMetadata("kernel_arg_type"))
kernels.push_back(&f);
});
@@ -293,7 +293,7 @@ namespace {
// require that we return an error here, but there will be an error if
// the user tries to pass this program to a clCreateKernel() call.
if (!kernel_node) {
- return std::vector<llvm::Function *>();
+ return kernels;
}
kernels.reserve(kernel_node->getNumOperands());
@@ -317,7 +317,7 @@ namespace {
llvm::PassManager PM;
#endif
- const std::vector<llvm::Function *> kernels = find_kernels(mod);
+ const std::vector<const llvm::Function *> kernels = find_kernels(mod);
// Add a function internalizer pass.
//
@@ -343,10 +343,7 @@ namespace {
};
#else
std::vector<const char*> export_list;
- for (std::vector<llvm::Function *>::const_iterator I = kernels.begin(),
- E = kernels.end();
- I != E; ++I) {
- llvm::Function *kernel = *I;
+ for (const llvm::Function *kernel : kernels) {
export_list.push_back(kernel->getName().data());
}
#endif
@@ -618,7 +615,7 @@ namespace {
}
module
- build_module_llvm(llvm::Module *mod,
+ build_module_llvm(const llvm::Module *mod,
clang::LangAS::Map& address_spaces) {
module m;
@@ -632,7 +629,7 @@ namespace {
bitcode_ostream.flush();
#endif
- const std::vector<llvm::Function *> kernels = find_kernels(mod);
+ const std::vector<const llvm::Function *> kernels = find_kernels(mod);
for (unsigned i = 0; i < kernels.size(); ++i) {
std::string kernel_name = kernels[i]->getName();
std::vector<module::argument> args =
@@ -735,7 +732,7 @@ namespace {
std::map<std::string, unsigned>
get_kernel_offsets(std::vector<char> &code,
- const std::vector<llvm::Function *> &kernels,
+ const std::vector<const llvm::Function *> &kernels,
std::string &r_log) {
// One of the libelf implementations
@@ -786,9 +783,7 @@ namespace {
// Determine the offsets for each kernel
for (int i = 0; (symbol = gelf_getsym(symtab_data, i, &s)); i++) {
char *name = elf_strptr(elf, symtab_header.sh_link, symbol->st_name);
- for (std::vector<llvm::Function*>::const_iterator it = kernels.begin(),
- e = kernels.end(); it != e; ++it) {
- llvm::Function *f = *it;
+ for (const llvm::Function *f : kernels) {
if (f->getName() == std::string(name))
kernel_offsets[f->getName()] = symbol->st_value;
}
@@ -799,11 +794,11 @@ namespace {
module
build_module_native(std::vector<char> &code,
- llvm::Module *mod,
+ const llvm::Module *mod,
const clang::LangAS::Map &address_spaces,
std::string &r_log) {
- const std::vector<llvm::Function *> kernels = find_kernels(mod);
+ const std::vector<const llvm::Function *> kernels = find_kernels(mod);
std::map<std::string, unsigned> kernel_offsets =
get_kernel_offsets(code, kernels, r_log);
--
2.7.4
More information about the mesa-dev
mailing list