aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/CppBackend/CPPBackend.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-11-22 15:54:08 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-11-22 15:54:08 -0800
commit2f231412e31b8a79f3378d1b8331130634e78d0c (patch)
tree12204a6ff77ea62ef67d48b8c1051667fdf3adf0 /lib/Target/CppBackend/CPPBackend.cpp
parent52d85bf3381566f834cd0c81b003c5743f1bb652 (diff)
Math.imul
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r--lib/Target/CppBackend/CPPBackend.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp
index 06ab671cee..5972a4383f 100644
--- a/lib/Target/CppBackend/CPPBackend.cpp
+++ b/lib/Target/CppBackend/CPPBackend.cpp
@@ -194,6 +194,7 @@ namespace {
std::string getCast(const StringRef &, const Type *);
std::string getParenCast(const StringRef &, const Type *);
std::string getDoubleToInt(const StringRef &);
+ std::string getIMul(const Value *, const Value *);
void printConstant(const Constant *CPV);
void printConstants(const Module* M);
@@ -810,6 +811,11 @@ std::string CppWriter::getDoubleToInt(const StringRef &s) {
return ("~~(" + s + ")").str();
}
+std::string CppWriter::getIMul(const Value *V1, const Value *V2) {
+ // TODO: if small enough, emit direct multiply
+ return "Math_imul(" + getValueAsStr(V1) + ", " + getValueAsStr(V2) + ")";
+}
+
// printConstant - Print out a constant pool entry...
void CppWriter::printConstant(const Constant *CV) {
// First, if the constant is actually a GlobalValue (variable or function)
@@ -1299,7 +1305,7 @@ std::string CppWriter::generateInstruction(const Instruction *I) {
switch (I->getOpcode()) {
case Instruction::Add: text += getParenCast(getValueAsParenStr(I->getOperand(0)) + " + " + getValueAsParenStr(I->getOperand(1)), I->getType()) + ";"; break;
case Instruction::Sub: text += getParenCast(getValueAsParenStr(I->getOperand(0)) + " - " + getValueAsParenStr(I->getOperand(1)), I->getType()) + ";"; break;
- case Instruction::Mul: text += getParenCast(getValueAsParenStr(I->getOperand(0)) + " * " + getValueAsParenStr(I->getOperand(1)), I->getType()) + ";"; break;
+ case Instruction::Mul: text += getIMul(I->getOperand(0), I->getOperand(1)) + ";"; break;
case Instruction::SRem: text += getDoubleToInt(getValueAsParenStr(I->getOperand(0)) + " % " + getValueAsParenStr(I->getOperand(1))) + ";"; break;
case Instruction::SDiv: text += getDoubleToInt(getValueAsParenStr(I->getOperand(0)) + " / " + getValueAsParenStr(I->getOperand(1))) + ";"; break;
case Instruction::FMul: text += getParenCast(getValueAsStr(I->getOperand(0)) + " * " + getValueAsStr(I->getOperand(1)), I->getType()) + ";"; break; // TODO: not cast, but ensurefloat here