Hi llvmdev, I've noticed that there is no unary operator in LLVM. For unary operator such as Neg or Or operator, the IR builder just creates a binary operation with one dummy operand, 01823 <http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html#a073c092ce74a122e898e435e60e84599> BinaryOperator <http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html> *BinaryOperator::CreateNeg <http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html#a073c092ce74a122e898e435e60e84599>(Value <http://llvm.org/doxygen/classllvm_1_1Value.html> *Op, const Twine <http://llvm.org/doxygen/classllvm_1_1Twine.html> &Name,01824 BasicBlock <http://llvm.org/doxygen/classllvm_1_1BasicBlock.html> *InsertAtEnd) {01825 Value <http://llvm.org/doxygen/classllvm_1_1Value.html> *zero = ConstantFP::getZeroValueForNegation <http://llvm.org/doxygen/classllvm_1_1ConstantFP.html#ab4d218c572245abd0b1c895d603cba36>(Op->getType <http://llvm.org/doxygen/classllvm_1_1Value.html#a0cf3748dba54f931bb1241ae4adc76bc>());01826 return new BinaryOperator <http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html#acf242c32d995c5276931f545aa2bdd9c>(Instruction::Sub,01827 zero, Op,01828 Op->getType <http://llvm.org/doxygen/classllvm_1_1Value.html#a0cf3748dba54f931bb1241ae4adc76bc>(), Name <http://llvm.org/doxygen/classllvm_1_1BinaryOperator.html#a274586caf47dcc28ed878ad21af28152>, InsertAtEnd); However, I think it's more natural to describe this as unary operation, and may bring benefits to the optimiser and code generator. Can anyone tell me the reason? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111103/1dd6d2ec/attachment.html>
On Thu, Nov 3, 2011 at 3:45 AM, Fan Dawei <fandawei.s at gmail.com> wrote:> Hi llvmdev, > > I've noticed that there is no unary operator in LLVM. For unary operator > such as Neg or Or operator, the IR builder just creates a binary operation > with one dummy operand, > > 01823 BinaryOperator *BinaryOperator::CreateNeg(Value *Op, const Twine > &Name, > 01824 BasicBlock *InsertAtEnd) { > 01825 Value *zero = ConstantFP::getZeroValueForNegation(Op->getType()); > 01826 return new BinaryOperator(Instruction::Sub, > 01827 zero, Op, > 01828 Op->getType(), Name, InsertAtEnd); > > > However, I think it's more natural to describe this as unary operation, and > may bring benefits to the optimiser and code generator. > > Can anyone tell me the reason?We describe it as a binary operation simply to reduce the number of instructions in the IR. There are helper functions for things which are really looking for unary not etc. -Eli
Maybe Matching Threads
- [LLVMdev] Question about method CodeExtractor::severSplitPHINodes
- [LLVMdev] Memory allocation (or deallocation) model?
- [LLVMdev] Changes in llvm::Instruction and subclasses
- [LLVMdev] how to get a void type value in llvm
- [LLVMdev] how to get a void type value in llvm