source: icGREP/icgrep-devel/icgrep/IR_Gen/FunctionTypeBuilder.h @ 6104

Last change on this file since 6104 was 5425, checked in by nmedfort, 2 years ago

Changes towards separate compilation

File size: 1.5 KB
Line 
1#ifndef FUNCTIONTYPEBUILDER_H
2#define FUNCTIONTYPEBUILDER_H
3
4#include <llvm/IR/TypeBuilder.h>
5
6// NOTE: Currently, LLVM TypeBuilder can deduce FuntionTypes for up to 5 arguments. The following
7// templates have no limit but should be deprecated if the TypeBuilder ever supports n-ary functions.
8
9namespace {
10
11template<unsigned i, typename... Args>
12struct ParameterTypeBuilder;
13
14template<unsigned i, typename A1, typename... An>
15struct ParameterTypeBuilder<i, A1, An...> {
16    static void get(llvm::LLVMContext & C, llvm::Type ** params) {
17        ParameterTypeBuilder<i, A1>::get(C, params);
18        ParameterTypeBuilder<i + 1, An...>::get(C, params);
19    }
20};
21
22template<unsigned i, typename A>
23struct ParameterTypeBuilder<i, A> {
24    static void get(llvm::LLVMContext & C, llvm::Type ** params) {
25        params[i] = llvm::TypeBuilder<A, false>::get(C);
26    }
27};
28
29}
30
31template<typename T>
32struct FunctionTypeBuilder;
33
34template<typename R, typename... Args>
35struct FunctionTypeBuilder<R(Args...)> {
36    static llvm::FunctionType * get(llvm::LLVMContext & C) {
37        llvm::Type * params[sizeof...(Args)];
38        ParameterTypeBuilder<0, Args...>::get(C, params);
39        return llvm::FunctionType::get(llvm::TypeBuilder<R, false>::get(C), params, false);
40    }
41};
42
43template<typename R>
44struct FunctionTypeBuilder<R()> {
45    static llvm::FunctionType * get(llvm::LLVMContext & C) {
46        return llvm::FunctionType::get(llvm::TypeBuilder<R, false>::get(C), false);
47    }
48};
49
50#endif // FUNCTIONTYPEBUILDER_H
Note: See TracBrowser for help on using the repository browser.