Commit 0c729c8c by Karl Schimpf

Remove unnecessary fields in top-level parser of Subzero.

Cleans up code by removing unnecessary fields/data structures in top-level parser of Subzero. In particular: 1) Uses FunctionDeclarationList.size() instead of NumFunctionIds. 2) Removes the need for vector DefiningFunctionDeclarationList. Instead uses an (incremented) index NextDefiningFunctionID into vector FunctionDeclarationList. BUG=None R=jvoung@chromium.org, stichnot@chromium.org Review URL: https://codereview.chromium.org/883493002
parent 1573e081
...@@ -162,8 +162,8 @@ public: ...@@ -162,8 +162,8 @@ public:
TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header,
NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus)
: NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header),
ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0),
NumFunctionBlocks(0), BlockParser(nullptr) {} BlockParser(nullptr) {}
~TopLevelParser() override {} ~TopLevelParser() override {}
...@@ -228,24 +228,21 @@ public: ...@@ -228,24 +228,21 @@ 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) {
++NumFunctionIds;
FunctionDeclarationList.push_back(Fcn); FunctionDeclarationList.push_back(Fcn);
} }
/// Defines the next function ID as one that has an implementation
/// (i.e a corresponding function block in the bitcode).
void setNextValueIDAsImplementedFunction() {
DefiningFunctionDeclarationsList.push_back(FunctionDeclarationList.size());
}
/// 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.
unsigned getNextFunctionBlockValueID() { size_t getNextFunctionBlockValueID() {
if (NumFunctionBlocks >= DefiningFunctionDeclarationsList.size()) size_t NumDeclaredFunctions = FunctionDeclarationList.size();
while (NextDefiningFunctionID < NumDeclaredFunctions &&
FunctionDeclarationList[NextDefiningFunctionID]->isProto())
++NextDefiningFunctionID;
if (NextDefiningFunctionID >= NumDeclaredFunctions)
report_fatal_error( report_fatal_error(
"More function blocks than defined function addresses"); "More function blocks than defined function addresses");
return DefiningFunctionDeclarationsList[NumFunctionBlocks++]; return NextDefiningFunctionID++;
} }
/// Returns the function associated with ID. /// Returns the function associated with ID.
...@@ -314,7 +311,7 @@ public: ...@@ -314,7 +311,7 @@ public:
} }
/// Returns the number of function declarations in the bitcode file. /// Returns the number of function declarations in the bitcode file.
unsigned getNumFunctionIDs() const { return NumFunctionIds; } unsigned getNumFunctionIDs() const { return FunctionDeclarationList.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.
...@@ -346,6 +343,7 @@ public: ...@@ -346,6 +343,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(size_t Index) { Ice::GlobalDeclaration *getGlobalDeclarationByID(size_t Index) {
size_t NumFunctionIds = FunctionDeclarationList.size();
if (Index < NumFunctionIds) if (Index < NumFunctionIds)
return getFunctionByID(Index); return getFunctionByID(Index);
else else
...@@ -368,21 +366,19 @@ private: ...@@ -368,21 +366,19 @@ private:
unsigned NumErrors; unsigned NumErrors;
// 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. // The set of functions (prototype and defined).
FunctionDeclarationListType FunctionDeclarationList; FunctionDeclarationListType FunctionDeclarationList;
// The ID of the next possible defined function ID in
// FunctionDeclarationList. FunctionDeclarationList is filled
// first. It's the set of functions (either defined or isproto). Then
// function definitions are encountered/parsed and
// NextDefiningFunctionID is incremented to track the next
// actually-defined function.
size_t NextDefiningFunctionID;
// The set of global variables. // The set of global variables.
Ice::Translator::VariableDeclarationListType VariableDeclarations; Ice::Translator::VariableDeclarationListType VariableDeclarations;
// Relocatable constants associated with global declarations. // Relocatable constants associated with global declarations.
std::vector<Ice::Constant *> ValueIDConstants; std::vector<Ice::Constant *> ValueIDConstants;
// The number of function declarations (i.e. IDs).
unsigned NumFunctionIds;
// The number of function blocks (processed so far).
unsigned NumFunctionBlocks;
// The list of function declaration IDs (in the order found) that
// aren't just proto declarations.
// TODO(kschimpf): Instead of using this list, just use
// FunctionDeclarationList, and the isProto member function.
std::vector<unsigned> DefiningFunctionDeclarationsList;
// 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
...@@ -2902,10 +2898,9 @@ void ModuleParser::ProcessRecord() { ...@@ -2902,10 +2898,9 @@ void ModuleParser::ProcessRecord() {
Error(StrBuf.str()); Error(StrBuf.str());
return; return;
} }
bool IsProto = Values[2] == 1;
Ice::FunctionDeclaration *Func = Ice::FunctionDeclaration::create( Ice::FunctionDeclaration *Func = Ice::FunctionDeclaration::create(
Signature, CallingConv, Linkage, Values[2] == 0); Signature, CallingConv, Linkage, IsProto);
if (Values[2] == 0)
Context->setNextValueIDAsImplementedFunction();
Context->setNextFunctionID(Func); Context->setNextFunctionID(Func);
return; return;
} }
......
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