Value* MultiplicationExpression::getValue() { assert(leftExpression != NULL); assert(rightExpression != NULL); IRBuilder<>* builder = codegen::getBuilder(); return builder->CreateMul(leftExpression->getValue(), rightExpression->getValue()); }
Value* Op::codeGen(CodeGenContext &context) { cout << "Creating Op " << op <<endl; IRBuilder<> *builder = context.currentBuilder(); Value *tape_1; Value *lshValue = lhs.codeGen(context); Value *rshValue = rhs.codeGen(context); switch(op) { case T_PLUS: tape_1 = builder->CreateAdd(lshValue, rshValue, "addtmp"); break; case T_MINUS: tape_1 = builder->CreateSub(lshValue, rshValue, "subtmp"); break; case T_DIV: tape_1 = builder->CreateUDiv(lshValue, rshValue, "divtmp"); break; case T_MUL: tape_1 = builder->CreateMul(lshValue, rshValue, "multmp"); break; case T_LT: tape_1 = builder->CreateICmpSLT(lshValue, rshValue, "lttmp"); break; case T_GT: tape_1 = builder->CreateICmpSGT(lshValue, rshValue, "gttmp"); break; } return tape_1; }
static std::pair<Value*, Value*> getMul64(IRBuilder<> &Builder, Value *LHS, Value *RHS) { Type *I32Ty = Builder.getInt32Ty(); Type *I64Ty = Builder.getInt64Ty(); Value *LHS_EXT64 = Builder.CreateZExt(LHS, I64Ty); Value *RHS_EXT64 = Builder.CreateZExt(RHS, I64Ty); Value *MUL64 = Builder.CreateMul(LHS_EXT64, RHS_EXT64); Value *Lo = Builder.CreateTrunc(MUL64, I32Ty); Value *Hi = Builder.CreateLShr(MUL64, Builder.getInt64(32)); Hi = Builder.CreateTrunc(Hi, I32Ty); return std::make_pair(Lo, Hi); }
void CNodeCodeGenVisitor::Visit(CMul* s) { IRBuilder<> builder = builders_.top(); int op_offset = s->GetOpOffset(); int target_offset = s->GetTargetOffset(); int amt = s->GetAmt(); Value* op_offset_ptr = builder.CreateGEP(ptr_, GetPtrOffset(op_offset)); Value* target_offset_ptr = builder.CreateGEP(ptr_, GetPtrOffset(target_offset)); Value* mul_val = GetDataOffset(amt); Value* op_val = builder.CreateLoad(op_offset_ptr); Value* target_val = builder.CreateLoad(target_offset_ptr); Value* mul_result = builder.CreateMul(op_val, mul_val); Value* add_result = builder.CreateAdd(target_val, mul_result); builder.CreateStore(add_result, target_offset_ptr); VisitNextCNode(s); }