#include "AlphaRegisterInfo.h"
#include "llvm/Constants.h" // FIXME: REMOVE
#include "llvm/Function.h"
+#include "llvm/Module.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineConstantPool.h" // FIXME: REMOVE
#include "llvm/CodeGen/MachineFunction.h"
/// ISel - Alpha specific code to select Alpha machine instructions for
/// SelectionDAG operations.
//===--------------------------------------------------------------------===//
-class ISel : public SelectionDAGISel {
+class AlphaISel : public SelectionDAGISel {
/// AlphaLowering - This object fully describes how to lower LLVM code to an
/// Alpha-specific SelectionDAG.
int max_depth;
public:
- ISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM)
+ AlphaISel(TargetMachine &TM) : SelectionDAGISel(AlphaLowering), AlphaLowering(TM)
{}
/// InstructionSelectBasicBlock - This callback is invoked by
};
}
-void ISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
+void AlphaISel::EmitFunctionEntryCode(Function &Fn, MachineFunction &MF) {
// If this function has live-in values, emit the copies from pregs to vregs at
// the top of the function, before anything else.
MachineBasicBlock *BB = MF.begin();
//Find the offset of the arg in it's parent's function
static int getValueOffset(const Value* v)
{
+ static int uniqneg = -1;
if (v == NULL)
- return 0;
+ return uniqneg--;
const Instruction* itarget = dyn_cast<Instruction>(v);
const BasicBlock* btarget = itarget->getParent();
return i;
}
+//Find the offset of the function in it's module
+static int getFunctionOffset(const Function* fun)
+{
+ const Module* M = fun->getParent();
+
+ //offset due to earlier BBs
+ int i = 0;
+ for(Module::const_iterator ii = M->begin(); &*ii != fun; ++ii)
+ ++i;
+
+ return i;
+}
+
+static int getUID()
+{
+ static int id = 0;
+ return ++id;
+}
//Factorize a number using the list of constants
static bool factorize(int v[], int res[], int size, uint64_t c)
/// return a DAG expression to select that will generate the same value by
/// multiplying by a magic number. See:
/// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
-SDOperand ISel::BuildSDIVSequence(SDOperand N) {
+SDOperand AlphaISel::BuildSDIVSequence(SDOperand N) {
int64_t d = (int64_t)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
ms magics = magic(d);
// Multiply the numerator (operand 0) by the magic value
/// return a DAG expression to select that will generate the same value by
/// multiplying by a magic number. See:
/// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html>
-SDOperand ISel::BuildUDIVSequence(SDOperand N) {
+SDOperand AlphaISel::BuildUDIVSequence(SDOperand N) {
unsigned d =
(unsigned)cast<ConstantSDNode>(N.getOperand(1))->getSignExtended();
mu magics = magicu(d);
}
}
-void ISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble)
+void AlphaISel::MoveFP2Int(unsigned src, unsigned dst, bool isDouble)
{
unsigned Opc;
if (EnableAlphaFTOI) {
}
}
-void ISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble)
+void AlphaISel::MoveInt2FP(unsigned src, unsigned dst, bool isDouble)
{
unsigned Opc;
if (EnableAlphaFTOI) {
}
}
-bool ISel::SelectFPSetCC(SDOperand N, unsigned dst)
+bool AlphaISel::SelectFPSetCC(SDOperand N, unsigned dst)
{
SDNode *Node = N.Val;
unsigned Opc, Tmp1, Tmp2, Tmp3;
}
//Check to see if the load is a constant offset from a base register
-void ISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
+void AlphaISel::SelectAddr(SDOperand N, unsigned& Reg, long& offset)
{
unsigned opcode = N.getOpcode();
if (opcode == ISD::ADD) {
return;
}
-void ISel::SelectBranchCC(SDOperand N)
+void AlphaISel::SelectBranchCC(SDOperand N)
{
assert(N.getOpcode() == ISD::BRCOND && "Not a BranchCC???");
MachineBasicBlock *Dest =
abort(); //Should never be reached
}
-unsigned ISel::SelectExprFP(SDOperand N, unsigned Result)
+unsigned AlphaISel::SelectExprFP(SDOperand N, unsigned Result)
{
unsigned Tmp1, Tmp2, Tmp3;
unsigned Opc = 0;
if (EnableAlphaLSMark)
{
int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue());
- BuildMI(BB, Alpha::MEMLABEL, 2).addImm(i);
+ int j = getFunctionOffset(BB->getParent()->getFunction());
+ BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID());
}
if (Address.getOpcode() == ISD::GlobalAddress) {
return 0;
}
-unsigned ISel::SelectExpr(SDOperand N) {
+unsigned AlphaISel::SelectExpr(SDOperand N) {
unsigned Result;
unsigned Tmp1, Tmp2 = 0, Tmp3;
unsigned Opc = 0;
assert(opcode != ISD::SEXTLOAD && "Not zext"); break;
}
+ if (EnableAlphaLSMark)
+ {
+ int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(2))->getValue());
+ int j = getFunctionOffset(BB->getParent()->getFunction());
+ BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID());
+ }
+
if (Address.getOpcode() == ISD::GlobalAddress) {
AlphaLowering.restoreGP(BB);
Opc = GetSymVersion(Opc);
return 0;
}
-void ISel::Select(SDOperand N) {
+void AlphaISel::Select(SDOperand N) {
unsigned Tmp1, Tmp2, Opc;
unsigned opcode = N.getOpcode();
}
}
+ if (EnableAlphaLSMark)
+ {
+ int i = getValueOffset(dyn_cast<SrcValueSDNode>(N.getOperand(3))->getValue());
+ int j = getFunctionOffset(BB->getParent()->getFunction());
+ BuildMI(BB, Alpha::MEMLABEL, 3).addImm(j).addImm(i).addImm(getUID());
+ }
+
if (Address.getOpcode() == ISD::GlobalAddress)
{
AlphaLowering.restoreGP(BB);
/// description file.
///
FunctionPass *llvm::createAlphaPatternInstructionSelector(TargetMachine &TM) {
- return new ISel(TM);
+ return new AlphaISel(TM);
}