Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: src/PNaClTranslator.cpp

Issue 641193002: Introduce the notion of function addresses in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Clean up code and fix nits. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/PNaClTranslator.cpp
diff --git a/src/PNaClTranslator.cpp b/src/PNaClTranslator.cpp
index 6642ba977bbc57b588503bfb6416e5bd02f14db8..c6dae457d33221cc0a793c812b65efa731a3e052 100644
--- a/src/PNaClTranslator.cpp
+++ b/src/PNaClTranslator.cpp
@@ -24,7 +24,6 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/ValueHandle.h"
#include "IceCfg.h"
#include "IceCfgNode.h"
@@ -160,19 +159,21 @@ class TopLevelParser : public NaClBitcodeParser {
TopLevelParser &operator=(const TopLevelParser &) = delete;
public:
+ typedef std::vector<Ice::Function *> FunctionListType;
+
TopLevelParser(Ice::Translator &Translator, const std::string &InputName,
NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor,
bool &ErrorStatus)
: NaClBitcodeParser(Cursor), Translator(Translator),
Mod(new Module(InputName, getGlobalContext())), DL(PNaClDataLayout),
- Header(Header), TypeConverter(getLLVMContext()),
+ Header(Header), TypeConverter(Mod->getContext()),
ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0),
NumFunctionBlocks(0) {
Mod->setDataLayout(PNaClDataLayout);
setErrStream(Translator.getContext()->getStrDump());
}
- ~TopLevelParser() override { DeleteContainerPointers(GlobalIDAddresses); }
+ ~TopLevelParser() override {}
Ice::Translator &getTranslator() { return Translator; }
@@ -198,9 +199,6 @@ public:
/// Returns the number of bytes in the bitcode header.
size_t getHeaderSize() const { return Header.getHeaderSize(); }
- /// Returns the llvm context to use.
- LLVMContext &getLLVMContext() const { return Mod->getContext(); }
-
/// Changes the size of the type list to the given size.
void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); }
@@ -236,15 +234,15 @@ public:
}
/// Sets the next function ID to the given LLVM function.
- void setNextFunctionID(Function *Fcn) {
+ void setNextFunctionID(Ice::Function *Fcn) {
++NumFunctionIds;
- FunctionIDValues.push_back(Fcn);
+ FunctionList.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() {
- DefiningFunctionsList.push_back(FunctionIDValues.size());
+ DefiningFunctionsList.push_back(FunctionList.size());
}
/// Returns the value id that should be associated with the the
@@ -257,14 +255,16 @@ public:
return DefiningFunctionsList[NumFunctionBlocks++];
}
- /// Returns the LLVM Function address associated with ID.
- Function *getFunctionByID(unsigned ID) const {
- if (ID >= FunctionIDValues.size())
- return nullptr;
- Value *V = FunctionIDValues[ID];
- return cast<Function>(V);
+ /// Returns the function associated with ID.
+ Ice::Function *getFunctionByID(unsigned ID) {
+ if (ID < FunctionList.size())
+ return FunctionList[ID];
+ return reportGetFunctionByIDError(ID);
}
+ /// Returns the list of function addresses.
+ const FunctionListType &getFunctionList() { return FunctionList; }
jvoung (off chromium) 2014/10/10 01:47:28 const ?
Karl 2014/10/10 20:17:30 Done.
+
/// Returns the corresponding constant associated with a global value
/// (i.e. relocatable).
Ice::Constant *getOrCreateGlobalConstantByID(unsigned ID) {
@@ -272,8 +272,7 @@ public:
Ice::Constant *C;
if (ID >= ValueIDConstants.size()) {
C = nullptr;
- unsigned ExpectedSize =
- FunctionIDValues.size() + GlobalIDAddresses.size();
+ unsigned ExpectedSize = FunctionList.size() + GlobalVariables.size();
if (ID >= ExpectedSize)
ExpectedSize = ID;
ValueIDConstants.resize(ExpectedSize);
@@ -285,11 +284,11 @@ public:
// If reached, no such constant exists, create one.
std::string Name;
- unsigned FcnIDSize = FunctionIDValues.size();
+ unsigned FcnIDSize = FunctionList.size();
if (ID < FcnIDSize) {
- Name = FunctionIDValues[ID]->getName();
- } else if ((ID - FcnIDSize) < GlobalIDAddresses.size()) {
- Name = GlobalIDAddresses[ID - FcnIDSize]->getName();
+ Name = FunctionList[ID]->getName();
+ } else if ((ID - FcnIDSize) < GlobalVariables.size()) {
+ Name = GlobalVariables[ID - FcnIDSize]->getName();
} else {
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
@@ -311,40 +310,40 @@ public:
/// Returns the number of global IDs (function and global addresses)
/// defined in the bitcode file.
unsigned getNumGlobalIDs() const {
- return FunctionIDValues.size() + GlobalIDAddresses.size();
+ return FunctionList.size() + GlobalVariables.size();
}
/// Creates Count global addresses.
- void CreateGlobalAddresses(size_t Count) {
- assert(GlobalIDAddresses.empty());
+ void CreateGlobalVariables(size_t Count) {
+ assert(GlobalVariables.empty());
+ Ice::GlobalContext *Context = getTranslator().getContext();
for (size_t i = 0; i < Count; ++i) {
- GlobalIDAddresses.push_back(new Ice::GlobalAddress());
+ GlobalVariables.push_back(Ice::GlobalVariable::create(Context));
}
}
/// Returns the number of global addresses (i.e. ID's) defined in
/// the bitcode file.
- Ice::SizeT getNumGlobalAddresses() const { return GlobalIDAddresses.size(); }
+ Ice::SizeT getNumGlobalVariables() const { return GlobalVariables.size(); }
/// Returns the global address with the given index.
- Ice::GlobalAddress *getGlobalAddress(size_t Index) {
- if (Index < GlobalIDAddresses.size())
- return GlobalIDAddresses[Index];
- std::string Buffer;
- raw_string_ostream StrBuf(Buffer);
- StrBuf << "Global index " << Index
- << " not allowed. Out of range. Must be less than "
- << GlobalIDAddresses.size();
- Error(StrBuf.str());
- // TODO(kschimpf) Remove error recovery once implementation complete.
- if (!GlobalIDAddresses.empty())
- return GlobalIDAddresses[0];
- report_fatal_error("Unable to continue");
+ Ice::GlobalVariable *getGlobalVariableByID(unsigned Index) {
+ if (Index < GlobalVariables.size())
+ return GlobalVariables[Index];
+ return reportGetGlobalVariableByIDError(Index);
+ }
+
+ /// Returns the global address (variable or function) with the given Index.
+ Ice::GlobalAddress *getGlobalAddressByID(size_t Index) {
+ if (Index < NumFunctionIds)
+ return getFunctionByID(Index);
+ else
+ return getGlobalVariableByID(Index - NumFunctionIds);
}
/// Returns the list of read global addresses.
- const Ice::Translator::GlobalAddressList &getGlobalIDAddresses() {
- return GlobalIDAddresses;
+ const Ice::Translator::GlobalVariableListType &getGlobalVariables() {
+ return GlobalVariables;
}
/// Returns the corresponding ICE type for LLVMTy.
@@ -383,12 +382,12 @@ private:
unsigned NumErrors;
// The types associated with each type ID.
std::vector<ExtendedType> TypeIDValues;
- // The set of function value IDs.
- std::vector<WeakVH> FunctionIDValues;
- // The set of global addresses IDs.
- Ice::Translator::GlobalAddressList GlobalIDAddresses;
- // Relocatable constants associated with FunctionIDValues and
- // GlobalIDAddresses.
+ // The set of functions.
+ FunctionListType FunctionList;
+ // The set of global variables.
+ Ice::Translator::GlobalVariableListType GlobalVariables;
+ // Relocatable constants associated with FunctionList and
+ // GlobalVariables.
std::vector<Ice::Constant *> ValueIDConstants;
// The number of function IDs.
unsigned NumFunctionIds;
@@ -396,6 +395,8 @@ private:
unsigned NumFunctionBlocks;
// The list of value IDs (in the order found) of defining function
// addresses.
+ // TODO(kschimpf): Instead of using this list, just use FunctionList,
+ // and the isProto member function.
std::vector<unsigned> DefiningFunctionsList;
// Error recovery value to use when getFuncSigTypeByID fails.
Ice::FuncSigType UndefinedFuncSigType;
@@ -423,6 +424,14 @@ private:
void reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty,
ExtendedType::TypeKind WantedType);
+ // Reports that there is no function address for ID. Returns
Jim Stichnoth 2014/10/10 13:15:00 fill-paragraph?
Karl 2014/10/10 20:17:30 Done.
+ // an error recovery value to use.
+ Ice::Function *reportGetFunctionByIDError(unsigned ID);
+
+ // Reports that there is not global variable address for ID. Returns
+ // an error recovery value to use.
+ Ice::GlobalVariable *reportGetGlobalVariableByIDError(unsigned Index);
+
// Reports that there is no corresponding ICE type for LLVMTy, and
// returns ICE::IceType_void.
Ice::Type convertToIceTypeError(Type *LLVMTy);
@@ -440,6 +449,33 @@ void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty,
Error(StrBuf.str());
}
+Ice::Function *TopLevelParser::reportGetFunctionByIDError(unsigned ID) {
+ std::string Buffer;
+ raw_string_ostream StrBuf(Buffer);
+ StrBuf << "Function index " << ID
+ << " not allowed. Out of range. Must be less than "
+ << FunctionList.size();
+ Error(StrBuf.str());
+ // TODO(kschimpf) Remove error recovery once implementation complete.
+ if (!FunctionList.empty())
+ return FunctionList[0];
+ report_fatal_error("Unable to continue");
+}
+
+Ice::GlobalVariable *
+TopLevelParser::reportGetGlobalVariableByIDError(unsigned Index) {
+ std::string Buffer;
+ raw_string_ostream StrBuf(Buffer);
+ StrBuf << "Global index " << Index
+ << " not allowed. Out of range. Must be less than "
+ << GlobalVariables.size();
+ Error(StrBuf.str());
+ // TODO(kschimpf) Remove error recovery once implementation complete.
+ if (!GlobalVariables.empty())
+ return GlobalVariables[0];
+ report_fatal_error("Unable to continue");
+}
+
Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) {
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
@@ -752,9 +788,9 @@ class GlobalsParser : public BlockParserBaseClass {
public:
GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser)
: BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0),
- NextGlobalID(0), CurrentAddress(&DummyAddress) {}
-
- ~GlobalsParser() override {}
+ NextGlobalID(0), DummyGlobalVar(Ice::GlobalVariable::create(
+ getTranslator().getContext())),
+ CurGlobalVar(DummyGlobalVar) {}
private:
// Keeps track of how many initializers are expected for the global variable
@@ -764,16 +800,16 @@ private:
// The index of the next global variable.
unsigned NextGlobalID;
- // Holds the current global address whose initializer is being defined.
- Ice::GlobalAddress *CurrentAddress;
+ // Dummy global variable to guarantee CurGlobalVar is always defined
+ // (allowing code to not need to check if CurGlobalVar is nullptr).
+ Ice::GlobalVariable *DummyGlobalVar;
- // Dummy global address to guarantee CurrentAddress is always defined
- // (allowing code to not need to check if CurrentAddress is nullptr).
- Ice::GlobalAddress DummyAddress;
+ // Holds the current global variable being built.
+ Ice::GlobalVariable *CurGlobalVar;
void ExitBlock() override {
verifyNoMissingInitializers();
- unsigned NumIDs = Context->getNumGlobalAddresses();
+ unsigned NumIDs = Context->getNumGlobalVariables();
if (NextGlobalID < NumIDs) {
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
@@ -786,12 +822,12 @@ private:
void ProcessRecord() override;
- // Checks if the number of initializers for the CurrentAddress is the same as
+ // Checks if the number of initializers for the CurGlobalVar is the same as
// the number found in the bitcode file. If different, and error message is
// generated, and the internal state of the parser is fixed so this condition
// is no longer violated.
void verifyNoMissingInitializers() {
- size_t NumInits = CurrentAddress->getInitializers().size();
+ size_t NumInits = CurGlobalVar->getInitializers().size();
if (InitializersNeeded != NumInits) {
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
@@ -812,11 +848,11 @@ void GlobalsParser::ProcessRecord() {
// COUNT: [n]
if (!isValidRecordSize(1, "Globals count"))
return;
- if (NextGlobalID != Context->getNumGlobalAddresses()) {
+ if (NextGlobalID != Context->getNumGlobalVariables()) {
Error("Globals count record not first in block.");
return;
}
- Context->CreateGlobalAddresses(Values[0]);
+ Context->CreateGlobalVariables(Values[0]);
return;
case naclbitc::GLOBALVAR_VAR: {
// VAR: [align, isconst]
@@ -824,9 +860,9 @@ void GlobalsParser::ProcessRecord() {
return;
verifyNoMissingInitializers();
InitializersNeeded = 1;
- CurrentAddress = Context->getGlobalAddress(NextGlobalID);
- CurrentAddress->setAlignment((1 << Values[0]) >> 1);
- CurrentAddress->setIsConstant(Values[1] != 0);
+ CurGlobalVar = Context->getGlobalVariableByID(NextGlobalID);
+ CurGlobalVar->setAlignment((1 << Values[0]) >> 1);
+ CurGlobalVar->setIsConstant(Values[1] != 0);
++NextGlobalID;
return;
}
@@ -834,7 +870,7 @@ void GlobalsParser::ProcessRecord() {
// COMPOUND: [size]
if (!isValidRecordSize(1, "globals compound"))
return;
- if (!CurrentAddress->getInitializers().empty()) {
+ if (!CurGlobalVar->getInitializers().empty()) {
Error("Globals compound record not first initializer");
return;
}
@@ -851,17 +887,17 @@ void GlobalsParser::ProcessRecord() {
// ZEROFILL: [size]
if (!isValidRecordSize(1, "Globals zerofill"))
return;
- CurrentAddress->addInitializer(
- new Ice::GlobalAddress::ZeroInitializer(Values[0]));
- break;
+ CurGlobalVar->addInitializer(
+ new Ice::GlobalVariable::ZeroInitializer(Values[0]));
+ return;
}
case naclbitc::GLOBALVAR_DATA: {
// DATA: [b0, b1, ...]
if (!isValidRecordSizeAtLeast(1, "Globals data"))
return;
- CurrentAddress->addInitializer(
- new Ice::GlobalAddress::DataInitializer(Values));
- break;
+ CurGlobalVar->addInitializer(
+ new Ice::GlobalVariable::DataInitializer(Values));
+ return;
}
case naclbitc::GLOBALVAR_RELOC: {
// RELOC: [val, [addend]]
@@ -871,19 +907,9 @@ void GlobalsParser::ProcessRecord() {
Ice::SizeT Offset = 0;
if (Values.size() == 2)
Offset = Values[1];
- unsigned NumFunctions = Context->getNumFunctionIDs();
- if (Index < NumFunctions) {
- llvm::Function *Fcn = Context->getFunctionByID(Index);
- Ice::GlobalAddress::RelocationAddress Addr(Fcn);
- CurrentAddress->addInitializer(
- new Ice::GlobalAddress::RelocInitializer(Addr, Offset));
- } else {
- Ice::GlobalAddress::RelocationAddress Addr(
- Context->getGlobalAddress(Index - NumFunctions));
- CurrentAddress->addInitializer(
- new Ice::GlobalAddress::RelocInitializer(Addr, Offset));
- }
- break;
+ CurGlobalVar->addInitializer(new Ice::GlobalVariable::RelocInitializer(
+ Context->getGlobalAddressByID(Index), Offset));
+ return;
}
default:
BlockParserBaseClass::ProcessRecord();
@@ -964,23 +990,25 @@ public:
: BlockParserBaseClass(BlockID, EnclosingParser),
Func(new Ice::Cfg(getTranslator().getContext())), CurrentBbIndex(0),
FcnId(Context->getNextFunctionBlockValueID()),
- LLVMFunc(Context->getFunctionByID(FcnId)),
+ FuncDecl(Context->getFunctionByID(FcnId)),
CachedNumGlobalValueIDs(Context->getNumGlobalIDs()),
NextLocalInstIndex(Context->getNumGlobalIDs()),
InstIsTerminating(false) {
- Func->setFunctionName(LLVMFunc->getName());
+ Func->setFunctionName(FuncDecl->getName());
if (getFlags().TimeEachFunction)
getTranslator().getContext()->pushTimer(
getTranslator().getContext()->getTimerID(
Ice::GlobalContext::TSK_Funcs, Func->getFunctionName()),
Ice::GlobalContext::TSK_Funcs);
- Func->setReturnType(Context->convertToIceType(LLVMFunc->getReturnType()));
- Func->setInternal(LLVMFunc->hasInternalLinkage());
+ // TODO(kschimpf) Clean up API to add a function signature to
+ // a CFG.
+ const Ice::FuncSigType &Signature = FuncDecl->getSignature();
+ Func->setReturnType(Signature.getReturnType());
+ Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage);
CurrentNode = InstallNextBasicBlock();
Func->setEntryNode(CurrentNode);
- for (auto ArgI = LLVMFunc->arg_begin(), ArgE = LLVMFunc->arg_end();
- ArgI != ArgE; ++ArgI) {
- Func->addArg(getNextInstVar(Context->convertToIceType(ArgI->getType())));
+ for (Ice::Type ArgType : Signature.getArgList()) {
+ Func->addArg(getNextInstVar(ArgType));
}
}
@@ -1000,8 +1028,8 @@ private:
Ice::CfgNode *CurrentNode;
// The ID for the function.
unsigned FcnId;
- // The corresponding LLVM function.
- Function *LLVMFunc;
+ // The corresponding function declaration.
+ Ice::Function *FuncDecl;
// Holds the dividing point between local and global absolute value indices.
uint32_t CachedNumGlobalValueIDs;
// Holds operands local to the function block, based on indices
@@ -2034,17 +2062,9 @@ void FunctionParser::ProcessRecord() {
Ice::Type ReturnType = Ice::IceType_void;
const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr;
if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) {
- Function *Fcn = Context->getFunctionByID(CalleeIndex);
- if (Fcn == nullptr) {
- std::string Buffer;
- raw_string_ostream StrBuf(Buffer);
- StrBuf << "Function call to non-function: " << *Callee;
- Error(StrBuf.str());
- return;
- }
-
- FunctionType *FcnTy = Fcn->getFunctionType();
- ReturnType = Context->convertToIceType(FcnTy->getReturnType());
+ Ice::Function *Fcn = Context->getFunctionByID(CalleeIndex);
+ const Ice::FuncSigType &Signature = Fcn->getSignature();
+ ReturnType = Signature.getReturnType();
// Check if this direct call is to an Intrinsic (starts with "llvm.")
static Ice::IceString LLVMPrefix("llvm.");
@@ -2348,36 +2368,49 @@ private:
// and generated global constant initializers.
bool GlobalAddressNamesAndInitializersInstalled;
- // Generates names for unnamed global addresses, and lowers global
- // constant initializers to the target. May be called multiple
- // times. Only the first call will do the installation.
- void InstallGlobalAddressNamesAndInitializers() {
+ // Generates names for unnamed global addresses (i.e. functions and
+ // global variables). Then lowers global variable initializers to
+ // the target. May be called multiple times. Only the first call
+ // will do the installation.
+ void InstallGlobalNamesAndGlobalVarInitializers() {
if (!GlobalAddressNamesAndInitializersInstalled) {
Ice::Translator &Trans = getTranslator();
const Ice::IceString &GlobalPrefix = getFlags().DefaultGlobalPrefix;
if (!GlobalPrefix.empty()) {
uint32_t NameIndex = 0;
- for (Ice::GlobalAddress *Address : Context->getGlobalIDAddresses()) {
- if (!Address->hasName()) {
- Address->setName(Trans.createUnnamedName(GlobalPrefix, NameIndex));
- ++NameIndex;
- } else {
- Trans.checkIfUnnamedNameSafe(Address->getName(), "global",
- GlobalPrefix,
- Trans.getContext()->getStrDump());
- }
+ for (Ice::GlobalVariable *Vbl : Context->getGlobalVariables()) {
+ installAddressName(Trans, Vbl, GlobalPrefix, "global", NameIndex);
}
}
- Trans.nameUnnamedFunctions(Context->getModule());
- getTranslator().lowerGlobals(Context->getGlobalIDAddresses());
+ const Ice::IceString &FunctionPrefix = getFlags().DefaultFunctionPrefix;
+ if (!FunctionPrefix.empty()) {
+ uint32_t NameIndex = 0;
+ for (Ice::Function *Func : Context->getFunctionList()) {
+ installAddressName(Trans, Func, FunctionPrefix, "function",
+ NameIndex);
+ }
+ }
+ getTranslator().lowerGlobals(Context->getGlobalVariables());
GlobalAddressNamesAndInitializersInstalled = true;
}
}
+ void installAddressName(Ice::Translator &Trans, Ice::GlobalAddress *Address,
+ const Ice::IceString &Prefix, const char *Context,
+ uint32_t &NameIndex) {
+ if (!Address->hasName()) {
+ Address->setName(Trans.createUnnamedName(Prefix, NameIndex));
+ ++NameIndex;
+ } else {
+ Trans.checkIfUnnamedNameSafe(Address->getName(), Context, Prefix,
+ Trans.getContext()->getStrDump());
+ }
+ }
+
bool ParseBlock(unsigned BlockID) override;
void ExitBlock() override {
- InstallGlobalAddressNamesAndInitializers();
+ InstallGlobalNamesAndGlobalVarInitializers();
getTranslator().emitConstants();
}
@@ -2400,26 +2433,8 @@ private:
};
void ModuleValuesymtabParser::setValueName(uint64_t Index, StringType &Name) {
- if (Index < Context->getNumFunctionIDs()) {
- Function *Fcn = Context->getFunctionByID(Index);
- if (Fcn != nullptr) {
- Fcn->setName(StringRef(Name.data(), Name.size()));
- return;
- }
- } else {
- unsigned NumFunctions = Context->getNumFunctionIDs();
- if (Index >= NumFunctions) {
- Context->getGlobalAddress(Index - NumFunctions)
- ->setName(StringRef(Name.data(), Name.size()));
- }
- return;
- }
-
- std::string Buffer;
- raw_string_ostream StrBuf(Buffer);
- StrBuf << "Invalid global address ID in valuesymtab: " << Index;
- Error(StrBuf.str());
- return;
+ Context->getGlobalAddressByID(Index)
+ ->setName(StringRef(Name.data(), Name.size()));
}
void ModuleValuesymtabParser::setBbName(uint64_t Index, StringType &Name) {
@@ -2447,7 +2462,7 @@ bool ModuleParser::ParseBlock(unsigned BlockID) {
return Parser.ParseThisBlock();
}
case naclbitc::FUNCTION_BLOCK_ID: {
- InstallGlobalAddressNamesAndInitializers();
+ InstallGlobalNamesAndGlobalVarInitializers();
FunctionParser Parser(BlockID, this);
return Parser.ParseThisBlock();
}
@@ -2476,7 +2491,7 @@ void ModuleParser::ProcessRecord() {
// FUNCTION: [type, callingconv, isproto, linkage]
if (!isValidRecordSize(4, "Function heading"))
return;
- const Ice::FuncSigType &Ty = Context->getFuncSigTypeByID(Values[0]);
+ const Ice::FuncSigType &Signature = Context->getFuncSigTypeByID(Values[0]);
CallingConv::ID CallingConv;
if (!naclbitc::DecodeCallingConv(Values[1], CallingConv)) {
std::string Buffer;
@@ -2494,19 +2509,12 @@ void ModuleParser::ProcessRecord() {
Error(StrBuf.str());
return;
}
- SmallVector<Type *, 8> ArgTys;
- for (Ice::Type ArgType : Ty.getArgList()) {
- ArgTys.push_back(Context->convertToLLVMType(ArgType));
- }
- Function *Func = Function::Create(
- FunctionType::get(Context->convertToLLVMType(Ty.getReturnType()),
- ArgTys, false),
- Linkage, "", Context->getModule());
- Func->setCallingConv(CallingConv);
+ Ice::Function *Func =
+ Ice::Function::create(getTranslator().getContext(), Signature,
+ CallingConv, Linkage, Values[2] == 0);
if (Values[2] == 0)
Context->setNextValueIDAsImplementedFunction();
Context->setNextFunctionID(Func);
- // TODO(kschimpf) verify if Func matches PNaCl ABI.
return;
}
default:

Powered by Google App Engine
This is Rietveld 408576698