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

tudasc / TypeART / 12974719593

26 Jan 2025 12:40PM UTC coverage: 87.511%. First build
12974719593

Pull #153

github

web-flow
Merge 467600c61 into 9a5045231
Pull Request #153: Silence warnings

148 of 153 new or added lines in 15 files covered. (96.73%)

3959 of 4524 relevant lines covered (87.51%)

111873.46 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)
3,260✔
41
    : module(mod), typeart_functions(typeart_funcs) {
1,630✔
42
}
1,630✔
43

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

51
    if (!fixed_name) {
14,670✔
52
      os << "_" << std::to_string(callback_arguments.size());
×
NEW
53
    }
×
54
    if (with_omp_postfix) {
14,670✔
55
      os << "_"
6,520✔
56
         << "omp";
6,520✔
57
    }
6,520✔
58
    return os.str();
14,670✔
59
  };
14,670✔
60

61
  const auto name = make_fname(basename, args, with_omp);
14,670✔
62

63
  if (auto it = function_map.find(name); it != function_map.end()) {
14,670✔
NEW
64
    return it->second;
×
65
  }
66

67
  auto& c                           = module.getContext();
14,670✔
68
  const auto addOptimizerAttributes = [&](llvm::Function* function) {
14,670✔
69
    function->setDoesNotThrow();
14,670✔
70
    function->setDoesNotFreeMemory();
14,670✔
71
    function->setDoesNotRecurse();
14,670✔
72
#if LLVM_VERSION_MAJOR >= 12
73
    function->setWillReturn();
14,670✔
74
#endif
75
    for (Argument& arg : function->args()) {
45,640✔
76
      if (arg.getType()->isPointerTy()) {
30,970✔
77
        arg.addAttr(Attribute::NoCapture);
11,410✔
78
        arg.addAttr(Attribute::ReadOnly);
11,410✔
79
        arg.addAttr(Attribute::NoFree);
11,410✔
80
      }
11,410✔
81
    }
82
  };
14,670✔
83
  const auto setFunctionLinkageExternal = [](llvm::Function* function) {
11,098✔
84
    function->setLinkage(GlobalValue::ExternalLinkage);
11,098✔
85
    //     f->setLinkage(GlobalValue::ExternalWeakLinkage);
86
  };
11,098✔
87
  const auto do_make = [&](auto& function_name, auto function_type) {
29,340✔
88
    const bool has_func_declared = module.getFunction(function_name) != nullptr;
14,670✔
89
    auto func_in_module          = module.getOrInsertFunction(function_name, function_type);
14,670✔
90

91
    Function* function{nullptr};
14,670✔
92
    if (has_func_declared) {
14,670✔
93
      LOG_WARNING("Function " << function_name << " is already declared in the module.")
3,572✔
94
      function = dyn_cast<Function>(func_in_module.getCallee()->stripPointerCasts());
3,572✔
95
    } else {
3,572✔
96
      function = dyn_cast<Function>(func_in_module.getCallee());
11,098✔
97
      setFunctionLinkageExternal(function);
11,098✔
98
    }
99

100
    addOptimizerAttributes(function);
14,670✔
101
    return function;
14,670✔
102
  };
103

104
  auto generated_function = do_make(name, FunctionType::get(Type::getVoidTy(c), args, false));
14,670✔
105

106
  function_map[name] = generated_function;
14,670✔
107

108
  typeart_functions.putFunctionFor(func_id, generated_function);
14,670✔
109

110
  return generated_function;
14,670✔
111
}
14,670✔
112

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

117
TAFunctions::TAFunctions() = default;
1,642✔
118

119
Function* TAFunctions::getFunctionFor(IFunc id) {
11,215✔
120
  return typeart_callbacks[id];
11,215✔
121
}
122

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

127
}  // 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