bool LLVMVisitor::leaveAddExpression(AddExpression* expr) { if(expr->getRule() == AddExpressionEnum::Plus || expr->getRule() == AddExpressionEnum::Minus) { ASSERT_T_MSG(this->valueStack.size() >= 2u, format("%u stackSize(%u)", expr->getId(), this->valueStack.size()) ); auto rhs = this->valueStack.top(); auto rhsType = rhs->getType(); this->valueStack.pop(); auto lhs = this->valueStack.top(); auto lhsType = lhs->getType(); this->valueStack.pop(); LLVMDump(lhs); LLVMDump(rhs); ASSERT_EQ(valueStack.size(), 0u); if(rhsType->isIntegerTy() && rhsType->isIntegerTy()) { if(rhsType->getIntegerBitWidth() == lhsType->getIntegerBitWidth()) { this->valueStack.push( expr->getRule() == AddExpressionEnum::Plus ? this->builder.CreateAdd(lhs, rhs, "Add") : this->builder.CreateSub(lhs, rhs, "Sub") ); } else { throw LLVMVisitorException(format("%s operation" " between Integers of different size lhs(%u) rhs(%u)", expr->getRule() == AddExpressionEnum::Plus ? "Add" : "Minus", lhsType->getIntegerBitWidth(), rhsType->getIntegerBitWidth()), Loc()); } } if((rhsType->isFloatTy() || rhsType->isDoubleTy() || rhsType->isX86_FP80Ty()) && rhsType->getTypeID() == lhsType->getTypeID()) { this->valueStack.push( expr->getRule() == AddExpressionEnum::Plus ? this->builder.CreateFAdd(lhs, rhs, "Add") : this->builder.CreateFSub(lhs, rhs, "Sub") ); } else { throw LLVMVisitorException(format("%s operation" " between different float types of different size " "lhs(%u) rhs(%u)", expr->getRule() == AddExpressionEnum::Plus ? "Add" : "Minus", lhsType->getTypeID(), rhsType->getTypeID()), Loc()); } ASSERT_EQ(valueStack.size(), 1u); LLVMDump(this->valueStack.top()); } return true; }
bool FunctionState::hasValue(llvm::Instruction const *ForInstruction) const { if (!isDominatedByActive(ForInstruction)) return false; auto const Type = ForInstruction->getType(); if (Type->isIntegerTy()) { return ValuesUInt64.count(ForInstruction); } else if (Type->isPointerTy()) { return ValuesPtr.count(ForInstruction); } else if (Type->isFloatTy()) { return ValuesFloat.count(ForInstruction); } else if (Type->isDoubleTy()) { return ValuesDouble.count(ForInstruction); } else if (Type->isX86_FP80Ty() || Type->isFP128Ty() || Type->isPPC_FP128Ty()) { return ValuesAPFloat.count(ForInstruction); } else { return false; } }
void FunctionState::clearValue(llvm::Instruction const *ForInstruction) { auto const Type = ForInstruction->getType(); if (Type->isIntegerTy()) { ValuesUInt64.erase(ForInstruction); } else if (Type->isPointerTy()) { ValuesPtr.erase(ForInstruction); } else if (Type->isFloatTy()) { ValuesFloat.erase(ForInstruction); } else if (Type->isDoubleTy()) { ValuesDouble.erase(ForInstruction); } else if (Type->isX86_FP80Ty() || Type->isFP128Ty() || Type->isPPC_FP128Ty()) { ValuesAPFloat.erase(ForInstruction); } }