OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AnnotateInternalFunctionsPass Class Reference

#include <AnnotateInternalFunctionsPass.h>

+ Inheritance diagram for AnnotateInternalFunctionsPass:
+ Collaboration diagram for AnnotateInternalFunctionsPass:

Public Member Functions

 AnnotateInternalFunctionsPass ()
 
bool runOnSCC (llvm::CallGraphSCC &SCC) override
 
llvm::StringRef getPassName () const override
 

Static Public Attributes

static char ID = 0
 

Static Private Member Functions

static bool isInternalStatelessFunction (const llvm::StringRef &func_name)
 
static bool isInternalMathFunction (const llvm::StringRef &func_name)
 

Static Private Attributes

static const std::set
< std::string > 
extension_functions
 
static const std::set
< std::string > 
math_builtins
 

Detailed Description

Annotates internal functions with function attributes designating the function as one which does not modify memory, does not throw, does not synchronize state with other functions/parts of the program, and is guaranteed to return. This allows the LLVM optimizer to more aggressively remove / reorder these functions and is particularly important for dead code elimination.

Definition at line 34 of file AnnotateInternalFunctionsPass.h.

Constructor & Destructor Documentation

AnnotateInternalFunctionsPass::AnnotateInternalFunctionsPass ( )
inline

Definition at line 37 of file AnnotateInternalFunctionsPass.h.

37 : CallGraphSCCPass(ID) {}

Member Function Documentation

llvm::StringRef AnnotateInternalFunctionsPass::getPassName ( ) const
inlineoverride

Definition at line 70 of file AnnotateInternalFunctionsPass.h.

70 { return "AnnotateInternalFunctionsPass"; }
static bool AnnotateInternalFunctionsPass::isInternalMathFunction ( const llvm::StringRef &  func_name)
inlinestaticprivate

Definition at line 82 of file AnnotateInternalFunctionsPass.h.

References math_builtins.

Referenced by runOnSCC().

82  {
83  // include all math functions from ExtensionFunctions.hpp
84  return math_builtins.count(func_name.str()) > 0;
85  }
static const std::set< std::string > math_builtins

+ Here is the caller graph for this function:

static bool AnnotateInternalFunctionsPass::isInternalStatelessFunction ( const llvm::StringRef &  func_name)
inlinestaticprivate

Definition at line 75 of file AnnotateInternalFunctionsPass.h.

References extension_functions.

Referenced by runOnSCC().

75  {
76  // extension functions or non-inlined builtins which do not modify any state
77  return extension_functions.count(func_name.str()) > 0;
78  }
static const std::set< std::string > extension_functions

+ Here is the caller graph for this function:

bool AnnotateInternalFunctionsPass::runOnSCC ( llvm::CallGraphSCC &  SCC)
inlineoverride

Definition at line 39 of file AnnotateInternalFunctionsPass.h.

References CHECK, isInternalMathFunction(), and isInternalStatelessFunction().

39  {
40  bool updated_function_defs = false;
41 
42  // iterate the call graph
43  for (auto& node : SCC) {
44  CHECK(node);
45  auto fcn = node->getFunction();
46  if (!fcn) {
47  continue;
48  }
49  if (isInternalStatelessFunction(fcn->getName()) ||
50  isInternalMathFunction(fcn->getName())) {
51  updated_function_defs = true;
52  std::vector<llvm::Attribute::AttrKind> attrs{llvm::Attribute::NoFree,
53  llvm::Attribute::NoSync,
54  llvm::Attribute::NoUnwind,
55  llvm::Attribute::WillReturn,
56  llvm::Attribute::ReadNone,
57  llvm::Attribute::Speculatable};
58  // WriteOnly is automatically added to all math functions in llvm 14.0
59  // https://reviews.llvm.org/D116426 which is incompatible with ReadNone.
60  fcn->removeFnAttr(llvm::Attribute::WriteOnly);
61  for (const auto& attr : attrs) {
62  fcn->addFnAttr(attr);
63  }
64  }
65  }
66 
67  return updated_function_defs;
68  }
static bool isInternalStatelessFunction(const llvm::StringRef &func_name)
#define CHECK(condition)
Definition: Logger.h:291
static bool isInternalMathFunction(const llvm::StringRef &func_name)

+ Here is the call graph for this function:

Member Data Documentation

const std::set< std::string > AnnotateInternalFunctionsPass::extension_functions
staticprivate
Initial value:
=
std::set<std::string>{"point_coord_array_is_null",
"decompress_x_coord_geoint",
"decompress_y_coord_geoint",
"compress_x_coord_geoint",
"compress_y_coord_geoint",
"transform_4326_900913_x",
"transform_4326_900913_y",
"transform_900913_4326_x",
"transform_900913_4326_y",
"conv_4326_900913_x",
"conv_4326_900913_y",
"distance_in_meters",
"approx_distance_in_meters",
"rect_pixel_bin_x",
"rect_pixel_bin_y",
"rect_pixel_bin_packed",
"reg_hex_horiz_pixel_bin_x",
"reg_hex_horiz_pixel_bin_y",
"reg_hex_horiz_pixel_bin_packed",
"reg_hex_vert_pixel_bin_x",
"reg_hex_vert_pixel_bin_y",
"reg_hex_vert_pixel_bin_packed",
"convert_meters_to_merc_pixel_width",
"convert_meters_to_merc_pixel_height",
"is_point_in_merc_view",
"is_point_size_in_merc_view"}

Definition at line 73 of file AnnotateInternalFunctionsPass.h.

Referenced by isInternalStatelessFunction().

char AnnotateInternalFunctionsPass::ID = 0
static

Definition at line 36 of file AnnotateInternalFunctionsPass.h.

const std::set< std::string > AnnotateInternalFunctionsPass::math_builtins
staticprivate
Initial value:
=
std::set<std::string>{"Acos", "Asin", "Atan", "Atan2", "Ceil", "Cos",
"Cot", "degrees", "Exp", "Floor", "ln", "Log",
"Log10", "log", "pi", "power", "radians", "Round",
"Sin", "Tan", "tan", "Truncate", "is_nan", "is_inf"}

Definition at line 80 of file AnnotateInternalFunctionsPass.h.

Referenced by isInternalMathFunction().


The documentation for this class was generated from the following file: