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

tudasc / TypeART / 12974755744

26 Jan 2025 12:45PM UTC coverage: 87.511%. First build
12974755744

Pull #153

github

web-flow
Merge 861ea04cf into 9a5045231
Pull Request #153: Silence warnings

160 of 164 new or added lines in 15 files covered. (97.56%)

3959 of 4524 relevant lines covered (87.51%)

105358.71 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,
29,340✔
47
                                        bool with_omp_postfix) {
48
    std::string fname;
14,670✔
49
    llvm::raw_string_ostream os(fname);
14,670✔
50
    os << name;
14,670✔
51

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

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

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

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

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

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

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

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

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

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

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

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

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

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