1 //===-- iOperators.cpp - Implement the Binary & Unary Operators --*- C++ -*--=//
3 // This file implements the nontrivial binary & unary operator instructions.
5 //===----------------------------------------------------------------------===//
7 #include "llvm/iOperators.h"
12 //===----------------------------------------------------------------------===//
13 // UnaryOperator Class
14 //===----------------------------------------------------------------------===//
16 UnaryOperator *UnaryOperator::create(UnaryOps Op, Value *Source) {
18 case Not: return new GenericUnaryInst(Op, Source);
20 cerr << "Don't know how to Create UnaryOperator " << Op << "\n";
26 //===----------------------------------------------------------------------===//
27 // GenericUnaryOperator Class
28 //===----------------------------------------------------------------------===//
31 //===----------------------------------------------------------------------===//
32 // BinaryOperator Class
33 //===----------------------------------------------------------------------===//
35 BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
36 const std::string &Name) {
38 // Binary comparison operators...
39 case SetLT: case SetGT: case SetLE:
40 case SetGE: case SetEQ: case SetNE:
41 return new SetCondInst(Op, S1, S2, Name);
44 return new GenericBinaryInst(Op, S1, S2, Name);
48 // swapOperands - Exchange the two operands to this instruction. This
49 // instruction is safe to use on any binary instruction and does not
50 // modify the semantics of the instruction. If the instruction is
51 // order dependant (SetLT f.e.) the opcode is changed.
53 bool BinaryOperator::swapOperands() {
54 switch (getOpcode()) {
55 // Instructions that don't need opcode modification
59 case SetEQ: case SetNE:
61 // Instructions that need opcode modification
62 case SetGT: iType = SetLT; break;
63 case SetLT: iType = SetGT; break;
64 case SetGE: iType = SetLE; break;
65 case SetLE: iType = SetGE; break;
66 // Error on the side of caution
70 std::swap(Operands[0], Operands[1]);
75 //===----------------------------------------------------------------------===//
76 // GenericBinaryInst Class
77 //===----------------------------------------------------------------------===//
80 //===----------------------------------------------------------------------===//
82 //===----------------------------------------------------------------------===//
84 SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2,
85 const std::string &Name)
86 : BinaryOperator(opType, S1, S2, Name) {
89 setType(Type::BoolTy); // setcc instructions always return bool type.
91 // Make sure it's a valid type...
92 assert(getOpcodeName() != 0);