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:
UseSandboxing(false), PhiEdgeSplit(false), DecorateAsm(false),
DumpStats(false), AllowUninitializedGlobals(false),
TimeEachFunction(false), DisableIRGeneration(false),
AllowErrorRecovery(false), GenerateUnitTestMessages(false),
NumTranslationThreads(0), DefaultGlobalPrefix(""),
DefaultFunctionPrefix(""), TimingFocusOn(""), VerboseFocusOn(""),
TranslateOnly("") {}
AllowErrorRecovery(false), StubConstantCalls(false),
GenerateUnitTestMessages(false), NumTranslationThreads(0),
DefaultGlobalPrefix(""), DefaultFunctionPrefix(""), TimingFocusOn(""),
VerboseFocusOn(""), TranslateOnly("") {}
bool DisableInternal;
bool SubzeroTimingEnabled;
bool DisableTranslation;
......@@ -46,6 +46,7 @@ public:
bool TimeEachFunction;
bool DisableIRGeneration;
bool AllowErrorRecovery;
bool StubConstantCalls;
bool GenerateUnitTestMessages;
size_t NumTranslationThreads; // 0 means completely sequential
IceString DefaultGlobalPrefix;
......
......@@ -163,7 +163,7 @@ public:
NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus)
: NaClBitcodeParser(Cursor), Translator(Translator), Header(Header),
ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0),
BlockParser(nullptr) {}
BlockParser(nullptr), StubbedConstCallValue(nullptr) {}
~TopLevelParser() override {}
......@@ -319,6 +319,24 @@ public:
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.
unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); }
......@@ -393,6 +411,8 @@ private:
// The block parser currently being applied. Used for error
// reporting.
BlockParserBaseClass *BlockParser;
// Value to use to stub constant calls.
Ice::Operand *StubbedConstCallValue;
bool ParseBlock(unsigned BlockID) override;
......@@ -2441,6 +2461,10 @@ void FunctionParser::ProcessRecord() {
}
}
} else {
if (getFlags().StubConstantCalls &&
llvm::isa<Ice::ConstantInteger32>(Callee)) {
Callee = Context->getStubbedConstCallValue(Callee);
}
ReturnType = Context->getSimpleTypeByID(Values[2]);
}
......
......@@ -172,6 +172,12 @@ static cl::opt<bool> AllowErrorRecovery(
cl::desc("Allow error recovery when reading PNaCl bitcode."),
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(
"verbose-llvm-parse-errors",
cl::desc("Print out more descriptive PNaCl bitcode parse errors when "
......@@ -313,6 +319,7 @@ int main(int argc, char **argv) {
Flags.TranslateOnly = TranslateOnly;
Flags.DisableIRGeneration = DisableIRGeneration;
Flags.AllowErrorRecovery = AllowErrorRecovery;
Flags.StubConstantCalls = StubConstantCalls;
// Force -build-on-read=0 for .ll files.
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