Commit 209318af by Karl Schimpf

Change to use arena allocation for function-local data in parser.

Changes to use arena allocator of the CFG associated with function, for vectors in the function parser. BUG=None R=stichnot@chromium.org Review URL: https://codereview.chromium.org/1293343003 .
parent 7a99327d
...@@ -43,8 +43,6 @@ Cfg::Cfg(GlobalContext *Ctx, uint32_t SequenceNumber) ...@@ -43,8 +43,6 @@ Cfg::Cfg(GlobalContext *Ctx, uint32_t SequenceNumber)
VMetadata(new VariablesMetadata(this)), VMetadata(new VariablesMetadata(this)),
TargetAssembler(TargetLowering::createAssembler( TargetAssembler(TargetLowering::createAssembler(
Ctx->getFlags().getTargetArch(), this)) { Ctx->getFlags().getTargetArch(), this)) {
assert(!Ctx->isIRGenerationDisabled() &&
"Attempt to build cfg when IR generation disabled");
} }
Cfg::~Cfg() { assert(ICE_TLS_GET_FIELD(CurrentCfg) == nullptr); } Cfg::~Cfg() { assert(ICE_TLS_GET_FIELD(CurrentCfg) == nullptr); }
......
...@@ -144,11 +144,15 @@ typedef llvm::ilist<Inst> InstList; ...@@ -144,11 +144,15 @@ typedef llvm::ilist<Inst> InstList;
// AssignList, but this runs into issues with SFINAE. // AssignList, but this runs into issues with SFINAE.
typedef InstList PhiList; typedef InstList PhiList;
typedef InstList AssignList; typedef InstList AssignList;
// VarList and NodeList are arena-allocated from the Cfg's allocator.
// Containers that are arena-allocated from the Cfg's allocator.
typedef std::vector<Operand *, CfgLocalAllocator<Operand *>> OperandList;
typedef std::vector<Variable *, CfgLocalAllocator<Variable *>> VarList; typedef std::vector<Variable *, CfgLocalAllocator<Variable *>> VarList;
typedef std::vector<CfgNode *, CfgLocalAllocator<CfgNode *>> NodeList; typedef std::vector<CfgNode *, CfgLocalAllocator<CfgNode *>> NodeList;
typedef std::vector<Constant *> ConstantList;
// Contains that use the default (global) allocator.
typedef std::vector<Constant *> ConstantList;
typedef std::vector<FunctionDeclaration *> FunctionDeclarationList;
typedef std::vector<VariableDeclaration *> VariableDeclarationList; typedef std::vector<VariableDeclaration *> VariableDeclarationList;
/// SizeT is for holding small-ish limits like number of source /// SizeT is for holding small-ish limits like number of source
......
...@@ -166,8 +166,6 @@ class TopLevelParser : public NaClBitcodeParser { ...@@ -166,8 +166,6 @@ class TopLevelParser : public NaClBitcodeParser {
TopLevelParser &operator=(const TopLevelParser &) = delete; TopLevelParser &operator=(const TopLevelParser &) = delete;
public: public:
typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType;
TopLevelParser(Ice::Translator &Translator, NaClBitstreamCursor &Cursor, TopLevelParser(Ice::Translator &Translator, NaClBitstreamCursor &Cursor,
Ice::ErrorCode &ErrorStatus) Ice::ErrorCode &ErrorStatus)
: NaClBitcodeParser(Cursor), Translator(Translator), : NaClBitcodeParser(Cursor), Translator(Translator),
...@@ -247,16 +245,16 @@ public: ...@@ -247,16 +245,16 @@ public:
/// Sets the next function ID to the given LLVM function. /// Sets the next function ID to the given LLVM function.
void setNextFunctionID(Ice::FunctionDeclaration *Fcn) { void setNextFunctionID(Ice::FunctionDeclaration *Fcn) {
FunctionDeclarationList.push_back(Fcn); FunctionDeclarations.push_back(Fcn);
} }
/// Returns the value id that should be associated with the the /// Returns the value id that should be associated with the the
/// current function block. Increments internal counters during call /// current function block. Increments internal counters during call
/// so that it will be in correct position for next function block. /// so that it will be in correct position for next function block.
NaClBcIndexSize_t getNextFunctionBlockValueID() { NaClBcIndexSize_t getNextFunctionBlockValueID() {
size_t NumDeclaredFunctions = FunctionDeclarationList.size(); size_t NumDeclaredFunctions = FunctionDeclarations.size();
while (NextDefiningFunctionID < NumDeclaredFunctions && while (NextDefiningFunctionID < NumDeclaredFunctions &&
FunctionDeclarationList[NextDefiningFunctionID]->isProto()) FunctionDeclarations[NextDefiningFunctionID]->isProto())
++NextDefiningFunctionID; ++NextDefiningFunctionID;
if (NextDefiningFunctionID >= NumDeclaredFunctions) if (NextDefiningFunctionID >= NumDeclaredFunctions)
Fatal("More function blocks than defined function addresses"); Fatal("More function blocks than defined function addresses");
...@@ -265,8 +263,8 @@ public: ...@@ -265,8 +263,8 @@ public:
/// Returns the function associated with ID. /// Returns the function associated with ID.
Ice::FunctionDeclaration *getFunctionByID(NaClBcIndexSize_t ID) { Ice::FunctionDeclaration *getFunctionByID(NaClBcIndexSize_t ID) {
if (ID < FunctionDeclarationList.size()) if (ID < FunctionDeclarations.size())
return FunctionDeclarationList[ID]; return FunctionDeclarations[ID];
return reportGetFunctionByIDError(ID); return reportGetFunctionByIDError(ID);
} }
...@@ -288,19 +286,19 @@ public: ...@@ -288,19 +286,19 @@ public:
void createValueIDs() { void createValueIDs() {
assert(VariableDeclarations); assert(VariableDeclarations);
ValueIDConstants.reserve(VariableDeclarations->size() + ValueIDConstants.reserve(VariableDeclarations->size() +
FunctionDeclarationList.size()); FunctionDeclarations.size());
createValueIDsForFunctions(); createValueIDsForFunctions();
createValueIDsForGlobalVars(); createValueIDsForGlobalVars();
} }
/// Returns the number of function declarations in the bitcode file. /// Returns the number of function declarations in the bitcode file.
size_t getNumFunctionIDs() const { return FunctionDeclarationList.size(); } size_t getNumFunctionIDs() const { return FunctionDeclarations.size(); }
/// Returns the number of global declarations (i.e. IDs) defined in /// Returns the number of global declarations (i.e. IDs) defined in
/// the bitcode file. /// the bitcode file.
size_t getNumGlobalIDs() const { size_t getNumGlobalIDs() const {
if (VariableDeclarations) { if (VariableDeclarations) {
return FunctionDeclarationList.size() + VariableDeclarations->size(); return FunctionDeclarations.size() + VariableDeclarations->size();
} else { } else {
return ValueIDConstants.size(); return ValueIDConstants.size();
} }
...@@ -324,7 +322,7 @@ public: ...@@ -324,7 +322,7 @@ public:
/// Returns the global declaration (variable or function) with the /// Returns the global declaration (variable or function) with the
/// given Index. /// given Index.
Ice::GlobalDeclaration *getGlobalDeclarationByID(NaClBcIndexSize_t Index) { Ice::GlobalDeclaration *getGlobalDeclarationByID(NaClBcIndexSize_t Index) {
size_t NumFunctionIds = FunctionDeclarationList.size(); size_t NumFunctionIds = FunctionDeclarations.size();
if (Index < NumFunctionIds) if (Index < NumFunctionIds)
return getFunctionByID(Index); return getFunctionByID(Index);
else else
...@@ -353,18 +351,17 @@ private: ...@@ -353,18 +351,17 @@ private:
// The types associated with each type ID. // The types associated with each type ID.
std::vector<ExtendedType> TypeIDValues; std::vector<ExtendedType> TypeIDValues;
// The set of functions (prototype and defined). // The set of functions (prototype and defined).
FunctionDeclarationListType FunctionDeclarationList; Ice::FunctionDeclarationList FunctionDeclarations;
// The ID of the next possible defined function ID in // The ID of the next possible defined function ID in FunctionDeclarations.
// FunctionDeclarationList. FunctionDeclarationList is filled // FunctionDeclarations is filled first. It's the set of functions (either
// first. It's the set of functions (either defined or isproto). Then // defined or isproto). Then function definitions are encountered/parsed and
// function definitions are encountered/parsed and // NextDefiningFunctionID is incremented to track the next actually-defined
// NextDefiningFunctionID is incremented to track the next // function.
// actually-defined function.
size_t NextDefiningFunctionID = 0; size_t NextDefiningFunctionID = 0;
// The set of global variables. // The set of global variables.
std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations; std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations;
// Relocatable constants associated with global declarations. // Relocatable constants associated with global declarations.
std::vector<Ice::Constant *> ValueIDConstants; Ice::ConstantList ValueIDConstants;
// Error recovery value to use when getFuncSigTypeByID fails. // Error recovery value to use when getFuncSigTypeByID fails.
Ice::FuncSigType UndefinedFuncSigType; Ice::FuncSigType UndefinedFuncSigType;
// The block parser currently being applied. Used for error // The block parser currently being applied. Used for error
...@@ -427,7 +424,7 @@ private: ...@@ -427,7 +424,7 @@ private:
getTranslator().getFlags().getDefaultFunctionPrefix(); getTranslator().getFlags().getDefaultFunctionPrefix();
if (!FunctionPrefix.empty()) { if (!FunctionPrefix.empty()) {
NaClBcIndexSize_t NameIndex = 0; NaClBcIndexSize_t NameIndex = 0;
for (Ice::FunctionDeclaration *Func : FunctionDeclarationList) { for (Ice::FunctionDeclaration *Func : FunctionDeclarations) {
installDeclarationName(Func, FunctionPrefix, "function", NameIndex); installDeclarationName(Func, FunctionPrefix, "function", NameIndex);
} }
} }
...@@ -448,7 +445,7 @@ private: ...@@ -448,7 +445,7 @@ private:
// Converts function declarations into constant value IDs. // Converts function declarations into constant value IDs.
void createValueIDsForFunctions() { void createValueIDsForFunctions() {
for (const Ice::FunctionDeclaration *Func : FunctionDeclarationList) { for (const Ice::FunctionDeclaration *Func : FunctionDeclarations) {
Ice::Constant *C = nullptr; Ice::Constant *C = nullptr;
if (!isIRGenerationDisabled()) { if (!isIRGenerationDisabled()) {
C = getConstantSym(Func->getName(), Func->getSuppressMangling(), C = getConstantSym(Func->getName(), Func->getSuppressMangling(),
...@@ -524,10 +521,10 @@ TopLevelParser::reportGetFunctionByIDError(NaClBcIndexSize_t ID) { ...@@ -524,10 +521,10 @@ TopLevelParser::reportGetFunctionByIDError(NaClBcIndexSize_t ID) {
raw_string_ostream StrBuf(Buffer); raw_string_ostream StrBuf(Buffer);
StrBuf << "Function index " << ID StrBuf << "Function index " << ID
<< " not allowed. Out of range. Must be less than " << " not allowed. Out of range. Must be less than "
<< FunctionDeclarationList.size(); << FunctionDeclarations.size();
blockError(StrBuf.str()); blockError(StrBuf.str());
if (!FunctionDeclarationList.empty()) if (!FunctionDeclarations.empty())
return FunctionDeclarationList[0]; return FunctionDeclarations[0];
Fatal(); Fatal();
} }
...@@ -1233,9 +1230,10 @@ public: ...@@ -1233,9 +1230,10 @@ public:
getTranslator().getContext()->pushTimer(TimerID, StackID); getTranslator().getContext()->pushTimer(TimerID, StackID);
} }
if (!isIRGenerationDisabled()) // Note: The Cfg is created, even when IR generation is disabled. This
Func = Ice::Cfg::create(getTranslator().getContext(), // is done to install a CfgLocalAllocator for various internal containers.
getTranslator().getNextSequenceNumber()); Func = Ice::Cfg::create(getTranslator().getContext(),
getTranslator().getNextSequenceNumber());
Ice::Cfg::setCurrentCfg(Func.get()); Ice::Cfg::setCurrentCfg(Func.get());
// TODO(kschimpf) Clean up API to add a function signature to // TODO(kschimpf) Clean up API to add a function signature to
...@@ -1336,7 +1334,7 @@ private: ...@@ -1336,7 +1334,7 @@ private:
size_t CachedNumGlobalValueIDs; size_t CachedNumGlobalValueIDs;
// Holds operands local to the function block, based on indices // Holds operands local to the function block, based on indices
// defined in the bitcode file. // defined in the bitcode file.
std::vector<Ice::Operand *> LocalOperands; Ice::OperandList LocalOperands;
// Holds the index within LocalOperands corresponding to the next // Holds the index within LocalOperands corresponding to the next
// instruction that generates a value. // instruction that generates a value.
NaClBcIndexSize_t NextLocalInstIndex; NaClBcIndexSize_t NextLocalInstIndex;
......
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