Ignore:
Timestamp:
Apr 8, 2017, 12:56:07 PM (2 years ago)
Author:
nmedfort
Message:

Bug fixes for object cache. Minor optimization of FunctionTypeBuilder?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/toolchain.h

    r5398 r5399  
    100100namespace {
    101101
    102 // NOTE: Currently, LLVM TypeBuilder only work for up to 5 arguments. The following templates
    103 // avoid that limit but should be deprecated if the TypeBuilder ever supports n-ary functions.
     102// NOTE: Currently, LLVM TypeBuilder can deduce FuntionTypes for only up to 5 arguments. The following
     103// templates have no limit but should be deprecated if the TypeBuilder ever supports n-ary functions.
    104104
    105 template <typename... Args>
     105template<unsigned i, typename... Args>
    106106class ParameterTypeBuilder;
    107107
    108 template<typename A1, typename... An>
    109 struct ParameterTypeBuilder<A1, An...> {
    110     static void get(llvm::LLVMContext & C, std::vector<llvm::Type *> & params) {
    111         ParameterTypeBuilder<A1>::get(C, params);
    112         ParameterTypeBuilder<An...>::get(C, params);
     108template<unsigned i, typename A1, typename... An>
     109struct ParameterTypeBuilder<i, A1, An...> {
     110    static void get(llvm::LLVMContext & C, llvm::Type ** params) {
     111        ParameterTypeBuilder<i, A1>::get(C, params);
     112        ParameterTypeBuilder<i + 1, An...>::get(C, params);
    113113    }
    114114};
    115115
    116 template<typename A>
    117 struct ParameterTypeBuilder<A> {
    118     static void get(llvm::LLVMContext & C, std::vector<llvm::Type *> & params) {
    119         params.push_back(llvm::TypeBuilder<A, false>::get(C));
     116template<unsigned i, typename A>
     117struct ParameterTypeBuilder<i, A> {
     118    static void get(llvm::LLVMContext & C, llvm::Type ** params) {
     119        params[i] = llvm::TypeBuilder<A, false>::get(C);
    120120    }
    121121};
     
    127127struct FunctionTypeBuilder<R(Args...)> {
    128128    static llvm::FunctionType * get(llvm::LLVMContext & C) {
    129         auto result = llvm::TypeBuilder<R, false>::get(C);
    130         std::vector<llvm::Type *> params(0);
    131         params.reserve(sizeof...(Args));
    132         ParameterTypeBuilder<Args...>::get(C, params);
    133         return llvm::FunctionType::get(result, params, false);
     129        llvm::Type * params[sizeof...(Args)];
     130        ParameterTypeBuilder<0, Args...>::get(C, params);
     131        return llvm::FunctionType::get(llvm::TypeBuilder<R, false>::get(C), params, false);
    134132    }
    135133};
     
    138136struct FunctionTypeBuilder<R()> {
    139137    static llvm::FunctionType * get(llvm::LLVMContext & C) {
    140         auto result = llvm::TypeBuilder<R, false>::get(C);
    141         return llvm::FunctionType::get(result, false);
     138        return llvm::FunctionType::get(llvm::TypeBuilder<R, false>::get(C), false);
    142139    }
    143140};
     
    148145void ParabixDriver::addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
    149146    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(iBuilder->getContext());
    150     assert ("FunctionTypeBuilder did not correctly resolve the current function type." && type);
     147    assert ("FunctionTypeBuilder did not resolve a function type." && type);
    151148    addExternalLink(kb, name, type, reinterpret_cast<void *>(functionPtr));
    152149}
Note: See TracChangeset for help on using the changeset viewer.