X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FSparcV9%2FSparcV9InstrSelection.cpp;h=5195f4ac29faef839c3603f35fff817e89f62238;hb=edf3a727b7106cfa9f10aadd5e6f603bcc0b879f;hp=2cde093bb250a2d91be2c1fa5adb3111755dad58;hpb=4a8bb2bf2392ca842c7139b1992cd5730cb4b7b9;p=oota-llvm.git diff --git a/lib/Target/SparcV9/SparcV9InstrSelection.cpp b/lib/Target/SparcV9/SparcV9InstrSelection.cpp index 2cde093bb25..5195f4ac29f 100644 --- a/lib/Target/SparcV9/SparcV9InstrSelection.cpp +++ b/lib/Target/SparcV9/SparcV9InstrSelection.cpp @@ -20,6 +20,7 @@ #include "llvm/iOther.h" #include "llvm/Function.h" #include "llvm/Constants.h" +#include "llvm/ConstantHandling.h" #include "Support/MathExtras.h" #include using std::vector; @@ -664,18 +665,10 @@ CreateCheapestMulConstInstruction(const TargetMachine &target, { Value* constOp; if (isa(lval) && isa(rval)) - { // both operands are constant: try both orders! - vector mvec1, mvec2; - unsigned int lcost = CreateMulConstInstruction(target, F, lval, rval, - destVal, mvec1, mcfi); - unsigned int rcost = CreateMulConstInstruction(target, F, rval, lval, - destVal, mvec2, mcfi); - vector& mincostMvec = (lcost <= rcost)? mvec1 : mvec2; - vector& maxcostMvec = (lcost <= rcost)? mvec2 : mvec1; - mvec.insert(mvec.end(), mincostMvec.begin(), mincostMvec.end()); - - for (unsigned int i=0; i < maxcostMvec.size(); ++i) - delete maxcostMvec[i]; + { // both operands are constant: evaluate and "set" in dest + Constant* P = ConstantFoldBinaryInstruction(Instruction::Mul, + cast(lval), cast(rval)); + target.getInstrInfo().CreateCodeToLoadConst(target,F,P,destVal,mvec,mcfi); } else if (isa(rval)) // rval is constant, but not lval CreateMulConstInstruction(target, F, lval, rval, destVal, mvec, mcfi); @@ -841,7 +834,8 @@ CreateCodeForVariableSizeAlloca(const TargetMachine& target, vector& getMvec) { MachineInstr* M; - + MachineCodeForInstruction& mcfi = MachineCodeForInstruction::get(result); + // Create a Value to hold the (constant) element size Value* tsizeVal = ConstantSInt::get(Type::IntTy, tsize); @@ -858,14 +852,11 @@ CreateCodeForVariableSizeAlloca(const TargetMachine& target, // Create a temporary value to hold the result of MUL TmpInstruction* tmpProd = new TmpInstruction(numElementsVal, tsizeVal); - MachineCodeForInstruction::get(result).addTemp(tmpProd); + mcfi.addTemp(tmpProd); // Instruction 1: mul numElements, typeSize -> tmpProd - M = new MachineInstr(MULX); - M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, numElementsVal); - M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, tsizeVal); - M->SetMachineOperandVal(2, MachineOperand::MO_VirtualRegister, tmpProd); - getMvec.push_back(M); + CreateMulInstruction(target, F, numElementsVal, tsizeVal, tmpProd, getMvec, + mcfi, INVALID_MACHINE_OPCODE); // Instruction 2: sub %sp, tmpProd -> %sp M = new MachineInstr(SUB); @@ -890,6 +881,7 @@ CreateCodeForFixedSizeAlloca(const TargetMachine& target, unsigned int numElements, vector& getMvec) { + assert(tsize > 0 && "Illegal (zero) type size for alloca"); assert(result && result->getParent() && "Result value is not part of a function?"); Function *F = result->getParent()->getParent(); @@ -946,7 +938,7 @@ CreateCodeForFixedSizeAlloca(const TargetMachine& target, static void SetOperandsForMemInstr(vector& mvec, - const InstructionNode* vmInstrNode, + InstructionNode* vmInstrNode, const TargetMachine& target) { Instruction* memInst = vmInstrNode->getInstruction(); @@ -1009,13 +1001,11 @@ SetOperandsForMemInstr(vector& mvec, target.DataLayout.getTypeSize(eltType)); // CreateMulInstruction() folds constants intelligently enough. - CreateMulInstruction(target, - memInst->getParent()->getParent(), + CreateMulInstruction(target, memInst->getParent()->getParent(), idxVal, /* lval, not likely to be const*/ eltSizeVal, /* rval, likely to be constant */ addr, /* result */ - mulVec, - MachineCodeForInstruction::get(memInst), + mulVec, MachineCodeForInstruction::get(memInst), INVALID_MACHINE_OPCODE); // Insert mulVec[] before *mvecI in mvec[] and update mvecI @@ -1925,18 +1915,18 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, mvec.push_back(new MachineInstr(ADD)); SetOperandsForMemInstr(mvec, subtreeRoot, target); break; - + case 57: // reg: Alloca: Implement as 1 instruction: { // add %fp, offsetFromFP -> result AllocationInst* instr = cast(subtreeRoot->getInstruction()); unsigned int tsize = - target.findOptimalStorageSize(instr->getAllocatedType()); + target.DataLayout.getTypeSize(instr->getAllocatedType()); assert(tsize != 0); CreateCodeForFixedSizeAlloca(target, instr, tsize, 1, mvec); break; } - + case 58: // reg: Alloca(reg): Implement as 3 instructions: // mul num, typeSz -> tmp // sub %sp, tmp -> %sp @@ -1946,7 +1936,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, const Type* eltType = instr->getAllocatedType(); // If #elements is constant, use simpler code for fixed-size allocas - int tsize = (int) target.findOptimalStorageSize(eltType); + int tsize = (int) target.DataLayout.getTypeSize(eltType); Value* numElementsVal = NULL; bool isArray = instr->isArrayAllocation(); @@ -1963,7 +1953,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, numElementsVal, mvec); break; } - + case 61: // reg: Call { // Generate a direct (CALL) or indirect (JMPL) call. // Mark the return-address register, the indirection @@ -2027,7 +2017,7 @@ GetInstructionsByRule(InstructionNode* subtreeRoot, // If this arg. is in the first $K$ regs, add a copy // float-to-int instruction to pass the value as an integer. - if (i < target.getRegInfo().GetNumOfIntArgRegs()) + if (i <= target.getRegInfo().GetNumOfIntArgRegs()) { MachineCodeForInstruction &destMCFI = MachineCodeForInstruction::get(callInstr);