Пример #1
0
void Timer::stopTimer() {
  Time += TimeRecord::getCurrentTime(false);

  if (ActiveTimers->back() == this) {
    ActiveTimers->pop_back();
  } else {
    std::vector<Timer*>::iterator I =
      std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
    assert(I != ActiveTimers->end() && "stop but no startTimer?");
    ActiveTimers->erase(I);
  }
}
Пример #2
0
GenericValue Interpreter::callExternalFunction(Function *F,
                                               ArrayRef<GenericValue> ArgVals) {
  TheInterpreter = this;

  unique_lock<sys::Mutex> Guard(*FunctionsLock);

  // Do a lookup to see if the function is in our cache... this should just be a
  // deferred annotation!
  std::map<const Function *, ExFunc>::iterator FI = ExportedFunctions->find(F);
  if (ExFunc Fn = (FI == ExportedFunctions->end()) ? lookupFunction(F)
                                                   : FI->second) {
    Guard.unlock();
    return Fn(F->getFunctionType(), ArgVals);
  }

#ifdef USE_LIBFFI
  std::map<const Function *, RawFunc>::iterator RF = RawFunctions->find(F);
  RawFunc RawFn;
  if (RF == RawFunctions->end()) {
    RawFn = (RawFunc)(intptr_t)
      sys::DynamicLibrary::SearchForAddressOfSymbol(F->getName());
    if (!RawFn)
      RawFn = (RawFunc)(intptr_t)getPointerToGlobalIfAvailable(F);
    if (RawFn != 0)
      RawFunctions->insert(std::make_pair(F, RawFn));  // Cache for later
  } else {
    RawFn = RF->second;
  }

  Guard.unlock();

  GenericValue Result;
  if (RawFn != 0 && ffiInvoke(RawFn, F, ArgVals, getDataLayout(), Result))
    return Result;
#endif // USE_LIBFFI

  if (F->getName() == "__main")
    errs() << "Tried to execute an unknown external function: "
      << *F->getType() << " __main\n";
  else
    report_fatal_error("Tried to execute an unknown external function: " +
                       F->getName());
#ifndef USE_LIBFFI
  errs() << "Recompiling LLVM with --enable-libffi might help.\n";
#endif
  return GenericValue();
}
Пример #3
0
AnnotationID AnnotationManager::getID(const std::string &Name) {  // Name -> ID
  IDMapType::iterator I = IDMap->find(Name);
  if (I == IDMap->end()) {
    (*IDMap)[Name] = IDCounter++;   // Add a new element
    return IDCounter-1;
  }
  return I->second;
}
Пример #4
0
static Timer &getNamedRegionTimer(const std::string &Name) {
    sys::SmartScopedLock<true> L(*TimerLock);
    Name2Timer::iterator I = NamedTimers->find(Name);
    if (I != NamedTimers->end())
        return I->second;

    return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second;
}
Пример #5
0
/// addPeakMemoryMeasurement - This method should be called whenever memory
/// usage needs to be checked.  It adds a peak memory measurement to the
/// currently active timers, which will be printed when the timer group prints
///
void Timer::addPeakMemoryMeasurement() {
    sys::SmartScopedLock<true> L(*TimerLock);
    size_t MemUsed = getMemUsage();

    for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
            E = ActiveTimers->end(); I != E; ++I)
        (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
}
Пример #6
0
void Timer::stopTimer() {
    sys::SmartScopedLock<true> L(*TimerLock);
    TimeRecord TR = getTimeRecord(false);
    Elapsed    += TR.Elapsed;
    UserTime   += TR.UserTime;
    SystemTime += TR.SystemTime;
    MemUsed    += TR.MemUsed;

    if (ActiveTimers->back() == this) {
        ActiveTimers->pop_back();
    } else {
        std::vector<Timer*>::iterator I =
            std::find(ActiveTimers->begin(), ActiveTimers->end(), this);
        assert(I != ActiveTimers->end() && "stop but no startTimer?");
        ActiveTimers->erase(I);
    }
}
Пример #7
0
/// addPeakMemoryMeasurement - This method should be called whenever memory
/// usage needs to be checked.  It adds a peak memory measurement to the
/// currently active timers, which will be printed when the timer group prints
///
void Timer::addPeakMemoryMeasurement() {
  size_t MemUsed = getMemUsage();

  for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
         E = ActiveTimers->end(); I != E; ++I) {
    (*I)->Lock.acquire();
    (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
    (*I)->Lock.release();
  }
}
Пример #8
0
static Timer &getNamedRegionTimer(const std::string &Name,
                                  const std::string &GroupName) {
    sys::SmartScopedLock<true> L(*TimerLock);

    Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
    if (I == NamedGroupedTimers->end()) {
        TimerGroup TG(GroupName);
        std::pair<TimerGroup, Name2Timer> Pair(TG, Name2Timer());
        I = NamedGroupedTimers->insert(I, std::make_pair(GroupName, Pair));
    }

    Name2Timer::iterator J = I->second.second.find(Name);
    if (J == I->second.second.end())
        J = I->second.second.insert(J,
                                    std::make_pair(Name,
                                            Timer(Name,
                                                    I->second.first)));

    return J->second;
}
Пример #9
0
GenericValue Interpreter::callExternalFunction(Function *F,
                                     const std::vector<GenericValue> &ArgVals) {
  TheInterpreter = this;

  // Do a lookup to see if the function is in our cache... this should just be a
  // deferred annotation!
  std::map<const Function *, ExFunc>::iterator FI = Functions->find(F);
  ExFunc Fn = (FI == Functions->end()) ? lookupFunction(F) : FI->second;
  if (Fn == 0) {
    cerr << "Tried to execute an unknown external function: "
         << F->getType()->getDescription() << " " << F->getName() << "\n";
    if (F->getName() == "__main")
      return GenericValue();
    abort();
  }

  // TODO: FIXME when types are not const!
  GenericValue Result = Fn(const_cast<FunctionType*>(F->getFunctionType()),
                           ArgVals);
  return Result;
}