mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-09 00:51:41 +00:00
Add support for the select instruction
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13076 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0eb61037f7
commit
759d34ffb7
@ -66,7 +66,9 @@ static GenericValue executeShlInst(GenericValue Src1, GenericValue Src2,
|
|||||||
const Type *Ty);
|
const Type *Ty);
|
||||||
static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2,
|
static GenericValue executeShrInst(GenericValue Src1, GenericValue Src2,
|
||||||
const Type *Ty);
|
const Type *Ty);
|
||||||
|
static GenericValue executeSelectInst(GenericValue Src1, GenericValue Src2,
|
||||||
|
GenericValue Src3);
|
||||||
|
|
||||||
GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
|
GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
|
||||||
ExecutionContext &SF) {
|
ExecutionContext &SF) {
|
||||||
switch (CE->getOpcode()) {
|
switch (CE->getOpcode()) {
|
||||||
@ -139,7 +141,10 @@ GenericValue Interpreter::getConstantExprValue (ConstantExpr *CE,
|
|||||||
return executeShrInst(getOperandValue(CE->getOperand(0), SF),
|
return executeShrInst(getOperandValue(CE->getOperand(0), SF),
|
||||||
getOperandValue(CE->getOperand(1), SF),
|
getOperandValue(CE->getOperand(1), SF),
|
||||||
CE->getOperand(0)->getType());
|
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:
|
default:
|
||||||
std::cerr << "Unhandled ConstantExpr: " << CE << "\n";
|
std::cerr << "Unhandled ConstantExpr: " << CE << "\n";
|
||||||
abort();
|
abort();
|
||||||
@ -518,6 +523,21 @@ void Interpreter::visitBinaryOperator(BinaryOperator &I) {
|
|||||||
SetValue(&I, R, SF);
|
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
|
// Terminator Instruction Implementations
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -137,6 +137,8 @@ public:
|
|||||||
void visitGetElementPtrInst(GetElementPtrInst &I);
|
void visitGetElementPtrInst(GetElementPtrInst &I);
|
||||||
void visitPHINode(PHINode &PN) { assert(0 && "PHI nodes already handled!"); }
|
void visitPHINode(PHINode &PN) { assert(0 && "PHI nodes already handled!"); }
|
||||||
void visitCastInst(CastInst &I);
|
void visitCastInst(CastInst &I);
|
||||||
|
void visitSelectInst(SelectInst &I);
|
||||||
|
|
||||||
|
|
||||||
void visitCallSite(CallSite CS);
|
void visitCallSite(CallSite CS);
|
||||||
void visitCallInst(CallInst &I) { visitCallSite (CallSite (&I)); }
|
void visitCallInst(CallInst &I) { visitCallSite (CallSite (&I)); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user