Commit 7ad1bed9 by Karl Schimpf

Allow stubbing of called constant addresses using command line argument.

When specified (via command line) replaces all called constant addresses with a stubbed call to the first defined function in the bitcode file. This allows testing of subzero without having to fix that downstream code (after parsing) may not handle such addresses. BUG=None R=jvoung@chromium.org Review URL: https://codereview.chromium.org/902713002
parent 33a5f41d
...@@ -27,10 +27,10 @@ public: ...@@ -27,10 +27,10 @@ public:
UseSandboxing(false), PhiEdgeSplit(false), DecorateAsm(false), UseSandboxing(false), PhiEdgeSplit(false), DecorateAsm(false),
DumpStats(false), AllowUninitializedGlobals(false), DumpStats(false), AllowUninitializedGlobals(false),
TimeEachFunction(false), DisableIRGeneration(false), TimeEachFunction(false), DisableIRGeneration(false),
AllowErrorRecovery(false), GenerateUnitTestMessages(false), AllowErrorRecovery(false), StubConstantCalls(false),
NumTranslationThreads(0), DefaultGlobalPrefix(""), GenerateUnitTestMessages(false), NumTranslationThreads(0),
DefaultFunctionPrefix(""), TimingFocusOn(""), VerboseFocusOn(""), DefaultGlobalPrefix(""), DefaultFunctionPrefix(""), TimingFocusOn(""),
TranslateOnly("") {} VerboseFocusOn(""), TranslateOnly("") {}
bool DisableInternal; bool DisableInternal;
bool SubzeroTimingEnabled; bool SubzeroTimingEnabled;
bool DisableTranslation; bool DisableTranslation;
...@@ -46,6 +46,7 @@ public: ...@@ -46,6 +46,7 @@ public:
bool TimeEachFunction; bool TimeEachFunction;
bool DisableIRGeneration; bool DisableIRGeneration;
bool AllowErrorRecovery; bool AllowErrorRecovery;
bool StubConstantCalls;
bool GenerateUnitTestMessages; bool GenerateUnitTestMessages;
size_t NumTranslationThreads; // 0 means completely sequential size_t NumTranslationThreads; // 0 means completely sequential
IceString DefaultGlobalPrefix; IceString DefaultGlobalPrefix;
......
...@@ -163,7 +163,7 @@ public: ...@@ -163,7 +163,7 @@ public:
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), NextDefiningFunctionID(0), ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0),
BlockParser(nullptr) {} BlockParser(nullptr), StubbedConstCallValue(nullptr) {}
~TopLevelParser() override {} ~TopLevelParser() override {}
...@@ -319,6 +319,24 @@ public: ...@@ -319,6 +319,24 @@ public:
return C; return C;
} }
/// Returns a defined function reference to be used in place of
/// called constant addresses. Returns the corresponding operand
/// to replace the calling address with. Reports an error if
/// a stub could not be found, returning the CallValue.
Ice::Operand *getStubbedConstCallValue(Ice::Operand *CallValue) {
if (StubbedConstCallValue)
return StubbedConstCallValue;
for (unsigned i = 0; i < getNumFunctionIDs(); ++i) {
Ice::FunctionDeclaration *Func = getFunctionByID(i);
if (!Func->isProto()) {
StubbedConstCallValue = getOrCreateGlobalConstantByID(i);
return StubbedConstCallValue;
}
}
Error("Unable to find function definition to stub constant calls with");
return CallValue;
}
/// Returns the number of function declarations in the bitcode file. /// Returns the number of function declarations in the bitcode file.
unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); }
...@@ -393,6 +411,8 @@ private: ...@@ -393,6 +411,8 @@ private:
// The block parser currently being applied. Used for error // The block parser currently being applied. Used for error
// reporting. // reporting.
BlockParserBaseClass *BlockParser; BlockParserBaseClass *BlockParser;
// Value to use to stub constant calls.
Ice::Operand *StubbedConstCallValue;
bool ParseBlock(unsigned BlockID) override; bool ParseBlock(unsigned BlockID) override;
...@@ -2441,6 +2461,10 @@ void FunctionParser::ProcessRecord() { ...@@ -2441,6 +2461,10 @@ void FunctionParser::ProcessRecord() {
} }
} }
} else { } else {
if (getFlags().StubConstantCalls &&
llvm::isa<Ice::ConstantInteger32>(Callee)) {
Callee = Context->getStubbedConstCallValue(Callee);
}
ReturnType = Context->getSimpleTypeByID(Values[2]); ReturnType = Context->getSimpleTypeByID(Values[2]);
} }
......
...@@ -172,6 +172,12 @@ static cl::opt<bool> AllowErrorRecovery( ...@@ -172,6 +172,12 @@ static cl::opt<bool> AllowErrorRecovery(
cl::desc("Allow error recovery when reading PNaCl bitcode."), cl::desc("Allow error recovery when reading PNaCl bitcode."),
cl::init(false)); cl::init(false));
// TODO(kschimpf) Remove once the emitter handles these cases.
static cl::opt<bool>
StubConstantCalls("stub-const-calls",
cl::desc("Stub indirect calls to constants."),
cl::init(false));
static cl::opt<bool> LLVMVerboseErrors( static cl::opt<bool> LLVMVerboseErrors(
"verbose-llvm-parse-errors", "verbose-llvm-parse-errors",
cl::desc("Print out more descriptive PNaCl bitcode parse errors when " cl::desc("Print out more descriptive PNaCl bitcode parse errors when "
...@@ -313,6 +319,7 @@ int main(int argc, char **argv) { ...@@ -313,6 +319,7 @@ int main(int argc, char **argv) {
Flags.TranslateOnly = TranslateOnly; Flags.TranslateOnly = TranslateOnly;
Flags.DisableIRGeneration = DisableIRGeneration; Flags.DisableIRGeneration = DisableIRGeneration;
Flags.AllowErrorRecovery = AllowErrorRecovery; Flags.AllowErrorRecovery = AllowErrorRecovery;
Flags.StubConstantCalls = StubConstantCalls;
// Force -build-on-read=0 for .ll files. // Force -build-on-read=0 for .ll files.
const std::string LLSuffix = ".ll"; const std::string LLSuffix = ".ll";
......
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