LLVM API Documentation
00001 //===- LibCallSemantics.cpp - Describe library semantics ------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements interfaces that can be used to describe language 00011 // specific runtime library interfaces (e.g. libc, libm, etc) to LLVM 00012 // optimizers. 00013 // 00014 //===----------------------------------------------------------------------===// 00015 00016 #include "llvm/Analysis/LibCallSemantics.h" 00017 #include "llvm/ADT/StringMap.h" 00018 #include "llvm/IR/Function.h" 00019 using namespace llvm; 00020 00021 /// getMap - This impl pointer in ~LibCallInfo is actually a StringMap. This 00022 /// helper does the cast. 00023 static StringMap<const LibCallFunctionInfo*> *getMap(void *Ptr) { 00024 return static_cast<StringMap<const LibCallFunctionInfo*> *>(Ptr); 00025 } 00026 00027 LibCallInfo::~LibCallInfo() { 00028 delete getMap(Impl); 00029 } 00030 00031 const LibCallLocationInfo &LibCallInfo::getLocationInfo(unsigned LocID) const { 00032 // Get location info on the first call. 00033 if (NumLocations == 0) 00034 NumLocations = getLocationInfo(Locations); 00035 00036 assert(LocID < NumLocations && "Invalid location ID!"); 00037 return Locations[LocID]; 00038 } 00039 00040 00041 /// getFunctionInfo - Return the LibCallFunctionInfo object corresponding to 00042 /// the specified function if we have it. If not, return null. 00043 const LibCallFunctionInfo * 00044 LibCallInfo::getFunctionInfo(const Function *F) const { 00045 StringMap<const LibCallFunctionInfo*> *Map = getMap(Impl); 00046 00047 /// If this is the first time we are querying for this info, lazily construct 00048 /// the StringMap to index it. 00049 if (!Map) { 00050 Impl = Map = new StringMap<const LibCallFunctionInfo*>(); 00051 00052 const LibCallFunctionInfo *Array = getFunctionInfoArray(); 00053 if (!Array) return nullptr; 00054 00055 // We now have the array of entries. Populate the StringMap. 00056 for (unsigned i = 0; Array[i].Name; ++i) 00057 (*Map)[Array[i].Name] = Array+i; 00058 } 00059 00060 // Look up this function in the string map. 00061 return Map->lookup(F->getName()); 00062 } 00063