Commit db1515d2 by Nicolas Capens Committed by Nicolas Capens

Estimate the function size based on the average instruction size.

BUG=15907357 Change-Id: I75c30a62d4a935a66ab25b4f7d581dbd0dff12a8 Reviewed-on: https://swiftshader-review.googlesource.com/1143Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent f1a30659
...@@ -12,11 +12,16 @@ ...@@ -12,11 +12,16 @@
#include "RoutineManager.hpp" #include "RoutineManager.hpp"
#include "Nucleus.hpp" #include "Nucleus.hpp"
#include "llvm/Function.h"
#include "../Common/Memory.hpp"
#include "../Common/Thread.hpp"
namespace sw namespace sw
{ {
using namespace llvm; using namespace llvm;
volatile int RoutineManager::averageInstructionSize = 4;
RoutineManager::RoutineManager() RoutineManager::RoutineManager()
{ {
routine = 0; routine = 0;
...@@ -41,12 +46,24 @@ namespace sw ...@@ -41,12 +46,24 @@ namespace sw
uint8_t *RoutineManager::startFunctionBody(const llvm::Function *function, uintptr_t &actualSize) uint8_t *RoutineManager::startFunctionBody(const llvm::Function *function, uintptr_t &actualSize)
{ {
if(actualSize == 0) if(actualSize == 0) // Estimate size
{
int instructionCount = 0;
for(llvm::Function::const_iterator basicBlock = function->begin(); basicBlock != function->end(); basicBlock++)
{
instructionCount += basicBlock->size();
}
actualSize = instructionCount * averageInstructionSize;
}
else // Estimate was too low
{ {
actualSize = 4096; sw::atomicIncrement(&averageInstructionSize);
} }
actualSize = (actualSize + 15) & -16; // Round up to the next page size
size_t pageSize = memoryPageSize();
actualSize = (actualSize + pageSize - 1) & -pageSize;
delete routine; delete routine;
routine = new Routine(actualSize); routine = new Routine(actualSize);
......
...@@ -46,6 +46,8 @@ namespace sw ...@@ -46,6 +46,8 @@ namespace sw
private: private:
Routine *routine; Routine *routine;
static volatile int averageInstructionSize;
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment