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

Unified Diff: src/IceTargetLoweringARM32.cpp

Issue 1213593002: Implement ARM32 switch lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add TODOs for jvoung suggested in review Created 5 years, 6 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
« no previous file with comments | « src/IceTargetLoweringARM32.h ('k') | tests_lit/llvm2ice_tests/switch-opt.ll » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceTargetLoweringARM32.cpp
diff --git a/src/IceTargetLoweringARM32.cpp b/src/IceTargetLoweringARM32.cpp
index 9bb2386b387ff42631ad4dce6e8361e1f7b0e7f9..55d77141483fc26bbee5a0c625c264284494fdc4 100644
--- a/src/IceTargetLoweringARM32.cpp
+++ b/src/IceTargetLoweringARM32.cpp
@@ -1925,8 +1925,36 @@ void TargetARM32::doAddressOptStore() {
}
void TargetARM32::lowerSwitch(const InstSwitch *Inst) {
- (void)Inst;
- UnimplementedError(Func->getContext()->getFlags());
+ // This implements the most naive possible lowering.
+ // cmp a,val[0]; jeq label[0]; cmp a,val[1]; jeq label[1]; ... jmp default
+ Operand *Src0 = Inst->getComparison();
+ SizeT NumCases = Inst->getNumCases();
+ if (Src0->getType() == IceType_i64) {
+ // TODO(jvoung): handle and test undef for Src0
+ Variable *Src0Lo = legalizeToVar(loOperand(Src0));
+ Variable *Src0Hi = legalizeToVar(hiOperand(Src0));
+ for (SizeT I = 0; I < NumCases; ++I) {
+ Operand *ValueLo = Ctx->getConstantInt32(Inst->getValue(I));
+ Operand *ValueHi = Ctx->getConstantInt32(Inst->getValue(I) >> 32);
+ ValueLo = legalize(ValueLo, Legal_Reg | Legal_Flex);
+ ValueHi = legalize(ValueHi, Legal_Reg | Legal_Flex);
+ _cmp(Src0Lo, ValueLo);
+ _cmp(Src0Hi, ValueHi, CondARM32::EQ);
+ _br(Inst->getLabel(I), CondARM32::EQ);
+ }
+ _br(Inst->getLabelDefault());
+ return;
+ }
+
+ // 32 bit integer
+ Variable *Src0Var = legalizeToVar(Src0);
+ for (SizeT I = 0; I < NumCases; ++I) {
+ Operand *Value = Ctx->getConstantInt32(Inst->getValue(I));
+ Value = legalize(Value, Legal_Reg | Legal_Flex);
+ _cmp(Src0Var, Value);
+ _br(Inst->getLabel(I), CondARM32::EQ);
+ }
+ _br(Inst->getLabelDefault());
}
void TargetARM32::lowerUnreachable(const InstUnreachable * /*Inst*/) {
« no previous file with comments | « src/IceTargetLoweringARM32.h ('k') | tests_lit/llvm2ice_tests/switch-opt.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698