Implement switch constructs.
Bug swiftshader:6
Change-Id: Ifd28cab11e814dd09515ad8721f8d3d86123f19c
Reviewed-on: https://swiftshader-review.googlesource.com/7970
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-on: https://swiftshader-review.googlesource.com/8165
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index 20843d5..62a240a 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -72,6 +72,7 @@
};
class Value : public Ice::Variable {};
+ class SwitchCases : public Ice::InstSwitch {};
class BasicBlock : public Ice::CfgNode {};
Ice::Type T(Type *t)
@@ -218,15 +219,15 @@
case R_X86_64_NONE:
// No relocation
break;
- // case R_X86_64_64:
- // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation->r_addend;
- // break;
+ case R_X86_64_64:
+ *(int64_t*)patchSite = (int64_t)((intptr_t)symbolValue + *(int64_t*)patchSite) + relocation.r_addend;
+ break;
case R_X86_64_PC32:
*patchSite = (int32_t)((intptr_t)symbolValue + *patchSite - (intptr_t)patchSite) + relocation.r_addend;
break;
- // case R_X86_64_32S:
- // *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend;
- // break;
+ case R_X86_64_32S:
+ *patchSite = (int32_t)((intptr_t)symbolValue + *patchSite) + relocation.r_addend;
+ break;
default:
assert(false && "Unsupported relocation type");
return nullptr;
@@ -446,6 +447,7 @@
objectWriter->writeFunctionCode(::function->getFunctionName(), false, assembler.get());
::context->lowerGlobals("last");
::context->lowerConstants();
+ ::context->lowerJumpTables();
objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
objectWriter->writeNonUserSections();
@@ -1034,14 +1036,17 @@
return V(result);
}
- Value *Nucleus::createSwitch(Value *v, BasicBlock *Dest, unsigned NumCases)
+ SwitchCases *Nucleus::createSwitch(Value *control, BasicBlock *defaultBranch, unsigned numCases)
{
- assert(false && "UNIMPLEMENTED"); return nullptr;
+ auto switchInst = Ice::InstSwitch::create(::function, numCases, control, defaultBranch);
+ ::basicBlock->appendInst(switchInst);
+
+ return reinterpret_cast<SwitchCases*>(switchInst);
}
- void Nucleus::addSwitchCase(Value *Switch, int Case, BasicBlock *Branch)
+ void Nucleus::addSwitchCase(SwitchCases *switchCases, int label, BasicBlock *branch)
{
- assert(false && "UNIMPLEMENTED"); return;
+ switchCases->addBranch(label, label, branch);
}
void Nucleus::createUnreachable()