[llvm-commits] CVS: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp Interpreter.h

Chris Lattner lattner at cs.uiuc.edu
Tue Apr 20 11:44:01 PDT 2004


Changes in directory llvm/lib/ExecutionEngine/Interpreter:

Execution.cpp updated: 1.125 -> 1.126
Interpreter.h updated: 1.63 -> 1.64

---
Log message:

Add support for the select instruction


---
Diffs of the changes:  (+24 -2)

Index: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp
diff -u llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.125 llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.126
--- llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1.125	Fri Mar 12 18:23:29 2004
+++ llvm/lib/ExecutionEngine/Interpreter/Execution.cpp	Tue Apr 20 11:43:21 2004
@@ -66,7 +66,9 @@
 				   const Type *Ty);
 static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2, 
 				   const Type *Ty);
-                                   
+static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, 
+                                      GenericValue Src3);
+
 GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
                                                 ExecutionContext &SF) {
   switch (CE->getOpcode()) {
@@ -139,7 +141,10 @@
     return executeShrInst(getOperandValue(CE->getOperand(0), SF),
                           getOperandValue(CE->getOperand(1), SF),
                           CE->getOperand(0)->getType());
-  
+  case Instruction::Select:
+    return executeSelectInst(getOperandValue(CE->getOperand(0), SF),
+                             getOperandValue(CE->getOperand(1), SF),
+                             getOperandValue(CE->getOperand(2), SF));
   default:
     std::cerr << "Unhandled ConstantExpr: " << CE << "\n";
     abort();
@@ -517,6 +522,21 @@
 
   SetValue(&I, R, SF);
 }
+
+static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2, 
+                                      GenericValue Src3) {
+  return Src1.BoolVal ? Src2 : Src3;
+}
+
+void Interpreter::visitSelectInst(SelectInst &I) {
+  ExecutionContext &SF = ECStack.back();
+  GenericValue Src1 = getOperandValue(I.getOperand(0), SF);
+  GenericValue Src2 = getOperandValue(I.getOperand(1), SF);
+  GenericValue Src3 = getOperandValue(I.getOperand(2), SF);
+  GenericValue R = executeSelectInst(Src1, Src2, Src3);
+  SetValue(&I, R, SF);
+}
+
 
 //===----------------------------------------------------------------------===//
 //                     Terminator Instruction Implementations


Index: llvm/lib/ExecutionEngine/Interpreter/Interpreter.h
diff -u llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.63 llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.64
--- llvm/lib/ExecutionEngine/Interpreter/Interpreter.h:1.63	Sun Apr  4 14:47:06 2004
+++ llvm/lib/ExecutionEngine/Interpreter/Interpreter.h	Tue Apr 20 11:43:21 2004
@@ -137,6 +137,8 @@
   void visitGetElementPtrInst(GetElementPtrInst &I);
   void visitPHINode(PHINode &PN) { assert(0 && "PHI nodes already handled!"); }
   void visitCastInst(CastInst &I);
+  void visitSelectInst(SelectInst &I);
+
 
   void visitCallSite(CallSite CS);
   void visitCallInst(CallInst &I) { visitCallSite (CallSite (&I)); }





More information about the llvm-commits mailing list