#include "llvm/CodeGen/InstrSelectionSupport.h"
#include "llvm/CodeGen/InstrSelection.h"
#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachineCodeForInstruction.h"
+#include "llvm/CodeGen/MachineCodeForMethod.h"
+#include "llvm/CodeGen/InstrForest.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/MachineRegInfo.h"
-#include "llvm/ConstPoolVals.h"
+#include "llvm/ConstantVals.h"
#include "llvm/Method.h"
#include "llvm/BasicBlock.h"
-#include "llvm/Instruction.h"
#include "llvm/Type.h"
#include "llvm/iMemory.h"
-
+using std::vector;
//*************************** Local Functions ******************************/
vector<TmpInstruction*> tempVec;
// Create a tmp virtual register to hold the constant.
- TmpInstruction* tmpReg =
- new TmpInstruction(TMP_INSTRUCTION_OPCODE, opValue, NULL);
- vmInstr->getMachineInstrVec().addTempValue(tmpReg);
+ TmpInstruction* tmpReg = new TmpInstruction(opValue);
+ MachineCodeForInstruction &MCFI = MachineCodeForInstruction::get(vmInstr);
+ MCFI.addTemp(tmpReg);
target.getInstrInfo().CreateCodeToLoadConst(opValue, tmpReg,
loadConstVec, tempVec);
// Register the new tmp values created for this m/c instruction sequence
for (unsigned i=0; i < tempVec.size(); i++)
- vmInstr->getMachineInstrVec().addTempValue(tempVec[i]);
+ MCFI.addTemp(tempVec[i]);
// Record the mapping from the tmp VM instruction to machine instruction.
// Do this for all machine instructions that were not mapped to any
GetConstantValueAsSignedInt(const Value *V,
bool &isValidConstant)
{
- if (!isa<ConstPoolVal>(V))
+ if (!isa<Constant>(V))
{
isValidConstant = false;
return 0;
isValidConstant = true;
if (V->getType() == Type::BoolTy)
- return (int64_t) ((ConstPoolBool*)V)->getValue();
+ return (int64_t) cast<ConstantBool>(V)->getValue();
if (V->getType()->isIntegral())
{
if (V->getType()->isSigned())
- return ((ConstPoolSInt*)V)->getValue();
+ return cast<ConstantSInt>(V)->getValue();
assert(V->getType()->isUnsigned());
- uint64_t Val = ((ConstPoolUInt*)V)->getValue();
+ uint64_t Val = cast<ConstantUInt>(V)->getValue();
if (Val < INT64_MAX) // then safe to cast to signed
return (int64_t)Val;
}
Value*
FoldGetElemChain(const InstructionNode* getElemInstrNode,
- vector<ConstPoolVal*>& chainIdxVec)
+ vector<Value*>& chainIdxVec)
{
MemAccessInst* getElemInst = (MemAccessInst*)
getElemInstrNode->getInstruction();
// Initialize return values from the incoming instruction
Value* ptrVal = getElemInst->getPointerOperand();
- chainIdxVec = getElemInst->getIndicesBROKEN(); // copies index vector values
+ chainIdxVec = getElemInst->copyIndices();
// Now chase the chain of getElementInstr instructions, if any
InstrTreeNode* ptrChild = getElemInstrNode->leftChild();
// Child is a GetElemPtr instruction
getElemInst = (MemAccessInst*)
((InstructionNode*) ptrChild)->getInstruction();
- const vector<ConstPoolVal*>& idxVec = getElemInst->getIndicesBROKEN();
+ const vector<Value*>& idxVec = getElemInst->copyIndices();
// Get the pointer value out of ptrChild and *prepend* its index vector
ptrVal = getElemInst->getPointerOperand();
// Check for the common case first: argument is not constant
//
- ConstPoolVal *CPV = dyn_cast<ConstPoolVal>(val);
+ Constant *CPV = dyn_cast<Constant>(val);
if (!CPV) return opType;
- if (CPV->getType() == Type::BoolTy)
+ if (ConstantBool *CPB = dyn_cast<ConstantBool>(CPV))
{
- ConstPoolBool *CPB = (ConstPoolBool*)CPV;
if (!CPB->getValue() && target.getRegInfo().getZeroRegNum() >= 0)
{
getMachineRegNum = target.getRegInfo().getZeroRegNum();
}
else if (CPV->getType()->isSigned())
{
- intValue = ((ConstPoolSInt*)CPV)->getValue();
+ intValue = cast<ConstantSInt>(CPV)->getValue();
}
else
{
- uint64_t V = ((ConstPoolUInt*)CPV)->getValue();
+ uint64_t V = cast<ConstantUInt>(CPV)->getValue();
if (V >= INT64_MAX) return opType;
intValue = (int64_t)V;
}
Value* opValue = mop.getVRegValue();
bool constantThatMustBeLoaded = false;
- if (isa<ConstPoolVal>(opValue))
- {
+ if (Constant *OpConst = dyn_cast<Constant>(opValue)) {
unsigned int machineRegNum;
int64_t immedValue;
MachineOperand::MachineOperandType opType =
if (constantThatMustBeLoaded)
{ // register the value so it is emitted in the assembly
- MachineCodeForMethod::get(method).addToConstantPool(
- cast<ConstPoolVal>(opValue));
+ MachineCodeForMethod::get(method).addToConstantPool(OpConst);
}
}
// into a register.
//
for (unsigned i=0, N=minstr->getNumImplicitRefs(); i < N; ++i)
- if (isa<ConstPoolVal>(minstr->getImplicitRef(i)) ||
+ if (isa<Constant>(minstr->getImplicitRef(i)) ||
isa<GlobalValue>(minstr->getImplicitRef(i)))
{
Value* oldVal = minstr->getImplicitRef(i);
InsertCodeToLoadConstant(oldVal, vmInstr, loadConstVec, target);
minstr->setImplicitRef(i, tmpReg);
- if (isa<ConstPoolVal>(oldVal))
+ if (Constant *C = dyn_cast<Constant>(oldVal))
{ // register the value so it is emitted in the assembly
- MachineCodeForMethod::get(method).addToConstantPool(
- cast<ConstPoolVal>(oldVal));
+ MachineCodeForMethod::get(method).addToConstantPool(C);
}
}