[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Tue May 25 16:01:02 PDT 2004


Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.27 -> 1.28

---
Log message:

Share code for shift bytecodes and make the unsigned shift really work.


---
Diffs of the changes:  (+26 -14)

Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.27 llvm-java/lib/Compiler/Compiler.cpp:1.28
--- llvm-java/lib/Compiler/Compiler.cpp:1.27	Tue May 25 15:23:17 2004
+++ llvm-java/lib/Compiler/Compiler.cpp	Tue May 25 15:57:52 2004
@@ -390,28 +390,40 @@
         }
 
         void do_shl(unsigned bcI) {
-            Value* v2 = opStack_.top(); opStack_.pop();
-            Value* v1 = opStack_.top(); opStack_.pop();
-            Instruction* in = new ShiftInst(Instruction::Shl, v1, v2, TMP);
-            bc2bbMap_[bcI]->getInstList().push_back(in);
-            opStack_.push(in);
+            do_shift_common(bcI, Instruction::Shl);
         }
 
         void do_shr(unsigned bcI) {
-            Value* v2 = opStack_.top(); opStack_.pop();
-            Value* v1 = opStack_.top(); opStack_.pop();
-            Instruction* in = new ShiftInst(Instruction::Shr, v1, v2, TMP);
+            do_shift_common(bcI, Instruction::Shr);
+        }
+
+        void do_ushr(unsigned bcI) {
+            // cast value to be shifted into its unsigned version
+            do_swap(bcI);
+            Value* value = opStack_.top(); opStack_.pop();
+            Instruction* in = new CastInst
+                (value, value->getType()->getUnsignedVersion(), TMP);
+            bc2bbMap_[bcI]->getInstList().push_back(in);
+            opStack_.push(in);
+            do_swap(bcI);
+
+            do_shift_common(bcI, Instruction::Shr);
+
+            // cast shifted value back to its original signed version
+            value = opStack_.top(); opStack_.pop();
+            in = new CastInst
+                (value, value->getType()->getSignedVersion(), TMP);
             bc2bbMap_[bcI]->getInstList().push_back(in);
             opStack_.push(in);
         }
 
-        void do_ushr(unsigned bcI) {
-            Value* v2 = opStack_.top(); opStack_.pop();
-            Value* v1 = opStack_.top(); opStack_.pop();
-            Instruction* in =
-                new CastInst(v1, v1->getType()->getUnsignedVersion(), TMP);
+        void do_shift_common(unsigned bcI, Instruction::OtherOps op) {
+            Value* amount = opStack_.top(); opStack_.pop();
+            Value* value = opStack_.top(); opStack_.pop();
+            Instruction* in = new CastInst(amount, Type::UByteTy, TMP);
             bc2bbMap_[bcI]->getInstList().push_back(in);
-            in = new ShiftInst(Instruction::Shr, in, v2, TMP);
+            amount = in;
+            in = new ShiftInst(op, value, amount, TMP);
             bc2bbMap_[bcI]->getInstList().push_back(in);
             opStack_.push(in);
         }





More information about the llvm-commits mailing list