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

tudasc / TypeART / 13955121336

19 Mar 2025 07:30PM UTC coverage: 88.842%. First build
13955121336

push

github

web-flow
Merge PR #167 from tudasc/devel

1174 of 1361 new or added lines in 49 files covered. (86.26%)

4212 of 4741 relevant lines covered (88.84%)

261950.04 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)
6,236✔
41
    : module(mod), typeart_functions(typeart_funcs) {
3,118✔
42
}
3,118✔
43

44
llvm::Function* TAFunctionDeclarator::make_function(IFunc func_id, llvm::StringRef basename,
28,062✔
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,
56,124✔
47
                                        bool with_omp_postfix) {
48
    std::string fname;
28,062✔
49
    llvm::raw_string_ostream os(fname);
28,062✔
50
    os << name;
28,062✔
51

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

62
  const auto name = make_fname(basename, args, with_omp);
28,062✔
63

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

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

92
    Function* function{nullptr};
28,062✔
93
    if (has_func_declared) {
28,062✔
94
      LOG_WARNING("Function " << function_name << " is already declared in the module.")
7,134✔
95
      function = dyn_cast<Function>(func_in_module.getCallee()->stripPointerCasts());
7,134✔
96
    } else {
7,134✔
97
      function = dyn_cast<Function>(func_in_module.getCallee());
20,928✔
98
      setFunctionLinkageExternal(function);
20,928✔
99
    }
100

101
    addOptimizerAttributes(function);
28,062✔
102
    return function;
28,062✔
103
  };
104

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

107
  function_map[name] = generated_function;
28,062✔
108

109
  typeart_functions.putFunctionFor(func_id, generated_function);
28,062✔
110

111
  return generated_function;
28,062✔
112
}
28,062✔
113

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

118
TAFunctions::TAFunctions() = default;
5,696✔
119

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

124
void TAFunctions::putFunctionFor(IFunc id, llvm::Function* f) {
28,062✔
125
  typeart_callbacks[id] = f;
28,062✔
126
}
28,062✔
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