LibCallSemantics.cpp [plain text]
#include "llvm/Analysis/LibCallSemantics.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Function.h"
using namespace llvm;
static StringMap<const LibCallFunctionInfo*> *getMap(void *Ptr) {
return static_cast<StringMap<const LibCallFunctionInfo*> *>(Ptr);
}
LibCallInfo::~LibCallInfo() {
delete getMap(Impl);
}
const LibCallLocationInfo &LibCallInfo::getLocationInfo(unsigned LocID) const {
if (NumLocations == 0)
NumLocations = getLocationInfo(Locations);
assert(LocID < NumLocations && "Invalid location ID!");
return Locations[LocID];
}
const LibCallFunctionInfo *LibCallInfo::getFunctionInfo(Function *F) const {
StringMap<const LibCallFunctionInfo*> *Map = getMap(Impl);
if (Map == 0) {
Impl = Map = new StringMap<const LibCallFunctionInfo*>();
const LibCallFunctionInfo *Array = getFunctionInfoArray();
if (Array == 0) return 0;
for (unsigned i = 0; Array[i].Name; ++i)
(*Map)[Array[i].Name] = Array+i;
}
const char *ValueName = F->getNameStart();
StringMap<const LibCallFunctionInfo*>::iterator I =
Map->find(ValueName, ValueName+F->getNameLen());
return I != Map->end() ? I->second : 0;
}