• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tudasc / TypeART / 13528988609

25 Feb 2025 07:06PM UTC coverage: 88.854% (-1.9%) from 90.735%
13528988609

Pull #163

github

web-flow
Merge e4a2d80f6 into d2e14acc5
Pull Request #163: LLVM 18 support

974 of 1122 new or added lines in 38 files covered. (86.81%)

30 existing lines in 6 files now uncovered.

4201 of 4728 relevant lines covered (88.85%)

190054.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.8
/lib/passes/instrumentation/TypeARTFunctions.cpp
1
// TypeART library
2
//
3
// Copyright (c) 2017-2025 TypeART Authors
4
// Distributed under the BSD 3-Clause license.
5
// (See accompanying file LICENSE.txt or copy at
6
// https://opensource.org/licenses/BSD-3-Clause)
7
//
8
// Project home: https://github.com/tudasc/TypeART
9
//
10
// SPDX-License-Identifier: BSD-3-Clause
11
//
12

13
#include "TypeARTFunctions.h"
14

15
#include "support/Logger.h"
16

17
#include "llvm/ADT/ArrayRef.h"
18
#include "llvm/ADT/StringMap.h"
19
#include "llvm/ADT/StringRef.h"
20
#include "llvm/IR/Argument.h"
21
#include "llvm/IR/Attributes.h"
22
#include "llvm/IR/DerivedTypes.h"
23
#include "llvm/IR/Function.h"
24
#include "llvm/IR/GlobalValue.h"
25
#include "llvm/IR/Module.h"
26
#include "llvm/IR/Type.h"
27
#include "llvm/Support/Casting.h"
28
#include "llvm/Support/raw_ostream.h"
29

30
#include <string>
31

32
namespace typeart {
33
class InstrumentationHelper;
34
}  // namespace typeart
35

36
using namespace llvm;
37

38
namespace typeart {
39

40
TAFunctionDeclarator::TAFunctionDeclarator(Module& mod, InstrumentationHelper&, TAFunctions& typeart_funcs)
4,700✔
41
    : module(mod), typeart_functions(typeart_funcs) {
2,350✔
42
}
2,350✔
43

44
llvm::Function* TAFunctionDeclarator::make_function(IFunc func_id, llvm::StringRef basename,
21,150✔
45
                                                    llvm::ArrayRef<llvm::Type*> args, bool with_omp, bool fixed_name) {
46
  const auto make_fname = [&fixed_name](llvm::StringRef name, llvm::ArrayRef<llvm::Type*> callback_arguments,
42,300✔
47
                                        bool with_omp_postfix) {
48
    std::string fname;
21,150✔
49
    llvm::raw_string_ostream os(fname);
21,150✔
50
    os << name;
21,150✔
51

52
    if (!fixed_name) {
21,150✔
NEW
53
      os << "_" << std::to_string(callback_arguments.size());
×
54
    }
×
55
    if (with_omp_postfix) {
21,150✔
56
      os << "_"
9,400✔
57
         << "omp";
9,400✔
58
    }
9,400✔
59
    return os.str();
21,150✔
60
  };
21,150✔
61

62
  const auto name = make_fname(basename, args, with_omp);
21,150✔
63

64
  if (auto it = function_map.find(name); it != function_map.end()) {
21,150✔
65
    return it->second;
×
66
  }
67

68
  auto& c                           = module.getContext();
21,150✔
69
  const auto addOptimizerAttributes = [&](llvm::Function* function) {
21,150✔
70
    function->setDoesNotThrow();
21,150✔
71
    function->setDoesNotFreeMemory();
21,150✔
72
    function->setDoesNotRecurse();
21,150✔
73
#if LLVM_VERSION_MAJOR >= 12
74
    function->setWillReturn();
21,150✔
75
#endif
76
    for (Argument& arg : function->args()) {
65,800✔
77
      if (arg.getType()->isPointerTy()) {
44,650✔
78
        arg.addAttr(Attribute::NoCapture);
16,450✔
79
        arg.addAttr(Attribute::ReadOnly);
16,450✔
80
        arg.addAttr(Attribute::NoFree);
16,450✔
81
      }
16,450✔
82
    }
83
  };
21,150✔
84
  const auto setFunctionLinkageExternal = [](llvm::Function* function) {
15,770✔
85
    function->setLinkage(GlobalValue::ExternalLinkage);
15,770✔
86
    //     f->setLinkage(GlobalValue::ExternalWeakLinkage);
87
  };
15,770✔
88
  const auto do_make = [&](auto& function_name, auto function_type) {
42,300✔
89
    const bool has_func_declared = module.getFunction(function_name) != nullptr;
21,150✔
90
    auto func_in_module          = module.getOrInsertFunction(function_name, function_type);
21,150✔
91

92
    Function* function{nullptr};
21,150✔
93
    if (has_func_declared) {
21,150✔
94
      LOG_WARNING("Function " << function_name << " is already declared in the module.")
5,380✔
95
      function = dyn_cast<Function>(func_in_module.getCallee()->stripPointerCasts());
5,380✔
96
    } else {
5,380✔
97
      function = dyn_cast<Function>(func_in_module.getCallee());
15,770✔
98
      setFunctionLinkageExternal(function);
15,770✔
99
    }
100

101
    addOptimizerAttributes(function);
21,150✔
102
    return function;
21,150✔
103
  };
104

105
  auto generated_function = do_make(name, FunctionType::get(Type::getVoidTy(c), args, false));
21,150✔
106

107
  function_map[name] = generated_function;
21,150✔
108

109
  typeart_functions.putFunctionFor(func_id, generated_function);
21,150✔
110

111
  return generated_function;
21,150✔
112
}
21,150✔
113

114
const llvm::StringMap<llvm::Function*>& TAFunctionDeclarator::getFunctionMap() const {
×
NEW
115
  return function_map;
×
116
}
117

118
TAFunctions::TAFunctions() = default;
4,298✔
119

120
Function* TAFunctions::getFunctionFor(IFunc id) {
14,770✔
121
  return typeart_callbacks[id];
14,770✔
122
}
123

124
void TAFunctions::putFunctionFor(IFunc id, llvm::Function* f) {
21,150✔
125
  typeart_callbacks[id] = f;
21,150✔
126
}
21,150✔
127

128
}  // namespace typeart
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc