LLVM  3.7.0
LibCallSemantics.cpp
Go to the documentation of this file.
1 //===- LibCallSemantics.cpp - Describe library semantics ------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements interfaces that can be used to describe language
11 // specific runtime library interfaces (e.g. libc, libm, etc) to LLVM
12 // optimizers.
13 //
14 //===----------------------------------------------------------------------===//
15 
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/ADT/StringSwitch.h"
19 #include "llvm/IR/Function.h"
20 using namespace llvm;
21 
22 /// This impl pointer in ~LibCallInfo is actually a StringMap. This
23 /// helper does the cast.
25  return static_cast<StringMap<const LibCallFunctionInfo*> *>(Ptr);
26 }
27 
29  delete getMap(Impl);
30 }
31 
32 const LibCallLocationInfo &LibCallInfo::getLocationInfo(unsigned LocID) const {
33  // Get location info on the first call.
34  if (NumLocations == 0)
35  NumLocations = getLocationInfo(Locations);
36 
37  assert(LocID < NumLocations && "Invalid location ID!");
38  return Locations[LocID];
39 }
40 
41 
42 /// Return the LibCallFunctionInfo object corresponding to
43 /// the specified function if we have it. If not, return null.
44 const LibCallFunctionInfo *
47 
48  /// If this is the first time we are querying for this info, lazily construct
49  /// the StringMap to index it.
50  if (!Map) {
51  Impl = Map = new StringMap<const LibCallFunctionInfo*>();
52 
54  if (!Array) return nullptr;
55 
56  // We now have the array of entries. Populate the StringMap.
57  for (unsigned i = 0; Array[i].Name; ++i)
58  (*Map)[Array[i].Name] = Array+i;
59  }
60 
61  // Look up this function in the string map.
62  return Map->lookup(F->getName());
63 }
64 
65 /// See if the given exception handling personality function is one that we
66 /// understand. If so, return a description of it; otherwise return Unknown.
68  const Function *F = dyn_cast<Function>(Pers->stripPointerCasts());
69  if (!F)
72  .Case("__gnat_eh_personality", EHPersonality::GNU_Ada)
73  .Case("__gxx_personality_v0", EHPersonality::GNU_CXX)
74  .Case("__gcc_personality_v0", EHPersonality::GNU_C)
75  .Case("__objc_personality_v0", EHPersonality::GNU_ObjC)
76  .Case("_except_handler3", EHPersonality::MSVC_X86SEH)
77  .Case("_except_handler4", EHPersonality::MSVC_X86SEH)
78  .Case("__C_specific_handler", EHPersonality::MSVC_Win64SEH)
79  .Case("__CxxFrameHandler3", EHPersonality::MSVC_CXX)
81 }
82 
85  // We can't simplify any invokes to nounwind functions if the personality
86  // function wants to catch asynch exceptions. The nounwind attribute only
87  // implies that the function does not throw synchronous exceptions.
88  return !isAsynchronousEHPersonality(Personality);
89 }
const LibCallFunctionInfo * getFunctionInfo(const Function *F) const
getFunctionInfo - Return the LibCallFunctionInfo object corresponding to the specified function if we...
F(f)
StringSwitch & Case(const char(&S)[N], const T &Value)
Definition: StringSwitch.h:55
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:188
bool canSimplifyInvokeNoUnwind(const Function *F)
LibCallFunctionInfo - Each record in the array of FunctionInfo structs records the behavior of one li...
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
virtual const LibCallFunctionInfo * getFunctionInfoArray() const =0
getFunctionInfoArray - Return an array of descriptors that describe the set of libcalls represented b...
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: StringMap.h:279
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
Definition: Value.cpp:458
R Default(const T &Value) const
Definition: StringSwitch.h:111
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:214
static StringMap< const LibCallFunctionInfo * > * getMap(void *Ptr)
This impl pointer in ~LibCallInfo is actually a StringMap.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:285
Constant * getPersonalityFn() const
Definition: Function.h:133
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
LLVM Value Representation.
Definition: Value.h:69
const LibCallLocationInfo & getLocationInfo(unsigned LocID) const
getLocationInfo - Return information about the specified LocationID.
LibCallLocationInfo - This struct describes a set of memory locations that are accessed by libcalls...