2004-02-29 00:27:00 +00:00
|
|
|
//===-- InstSelectSimple.cpp - A simple instruction selector for SparcV8 --===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a simple peephole instruction selector for the V8 target
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SparcV8.h"
|
2004-03-03 23:03:14 +00:00
|
|
|
#include "SparcV8InstrInfo.h"
|
2004-06-17 22:34:08 +00:00
|
|
|
#include "Support/Debug.h"
|
2004-02-29 00:27:00 +00:00
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Pass.h"
|
2004-03-03 23:03:14 +00:00
|
|
|
#include "llvm/Constants.h"
|
2004-06-20 07:49:54 +00:00
|
|
|
#include "llvm/CodeGen/IntrinsicLowering.h"
|
2004-02-29 00:27:00 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2004-06-15 19:16:07 +00:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
2004-06-18 05:19:16 +00:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2004-02-29 00:27:00 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2004-03-03 23:03:14 +00:00
|
|
|
#include "llvm/CodeGen/SSARegMap.h"
|
2004-02-29 00:27:00 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Support/GetElementPtrTypeIterator.h"
|
|
|
|
#include "llvm/Support/InstVisitor.h"
|
|
|
|
#include "llvm/Support/CFG.h"
|
2004-07-04 17:19:21 +00:00
|
|
|
#include <iostream>
|
2004-02-29 00:27:00 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct V8ISel : public FunctionPass, public InstVisitor<V8ISel> {
|
|
|
|
TargetMachine &TM;
|
|
|
|
MachineFunction *F; // The function we are compiling into
|
|
|
|
MachineBasicBlock *BB; // The current MBB we are compiling
|
|
|
|
|
|
|
|
std::map<Value*, unsigned> RegMap; // Mapping between Val's and SSA Regs
|
|
|
|
|
|
|
|
// MBBMap - Mapping between LLVM BB -> Machine BB
|
|
|
|
std::map<const BasicBlock*, MachineBasicBlock*> MBBMap;
|
|
|
|
|
|
|
|
V8ISel(TargetMachine &tm) : TM(tm), F(0), BB(0) {}
|
|
|
|
|
|
|
|
/// runOnFunction - Top level implementation of instruction selection for
|
|
|
|
/// the entire function.
|
|
|
|
///
|
|
|
|
bool runOnFunction(Function &Fn);
|
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "SparcV8 Simple Instruction Selection";
|
|
|
|
}
|
|
|
|
|
2004-05-08 04:21:17 +00:00
|
|
|
/// emitGEPOperation - Common code shared between visitGetElementPtrInst and
|
|
|
|
/// constant expression GEP support.
|
|
|
|
///
|
|
|
|
void emitGEPOperation(MachineBasicBlock *BB, MachineBasicBlock::iterator IP,
|
|
|
|
Value *Src, User::op_iterator IdxBegin,
|
|
|
|
User::op_iterator IdxEnd, unsigned TargetReg);
|
|
|
|
|
2004-06-24 06:33:00 +00:00
|
|
|
/// emitCastOperation - Common code shared between visitCastInst and
|
|
|
|
/// constant expression cast support.
|
|
|
|
///
|
|
|
|
void emitCastOperation(MachineBasicBlock *BB,MachineBasicBlock::iterator IP,
|
|
|
|
Value *Src, const Type *DestTy, unsigned TargetReg);
|
|
|
|
|
2004-02-29 00:27:00 +00:00
|
|
|
/// visitBasicBlock - This method is called when we are visiting a new basic
|
|
|
|
/// block. This simply creates a new MachineBasicBlock to emit code into
|
|
|
|
/// and adds it to the current MachineFunction. Subsequent visit* for
|
|
|
|
/// instructions will be invoked for all instructions in the basic block.
|
|
|
|
///
|
|
|
|
void visitBasicBlock(BasicBlock &LLVM_BB) {
|
|
|
|
BB = MBBMap[&LLVM_BB];
|
|
|
|
}
|
|
|
|
|
2004-04-07 04:27:16 +00:00
|
|
|
void visitBinaryOperator(Instruction &I);
|
2004-06-15 21:09:46 +00:00
|
|
|
void visitShiftInst (ShiftInst &SI) { visitBinaryOperator (SI); }
|
2004-06-30 21:47:40 +00:00
|
|
|
void visitSetCondInst(SetCondInst &I);
|
2004-04-07 04:27:16 +00:00
|
|
|
void visitCallInst(CallInst &I);
|
2004-04-07 17:29:37 +00:00
|
|
|
void visitReturnInst(ReturnInst &I);
|
2004-05-08 04:21:17 +00:00
|
|
|
void visitBranchInst(BranchInst &I);
|
2004-04-13 18:27:46 +00:00
|
|
|
void visitCastInst(CastInst &I);
|
2004-04-07 17:29:37 +00:00
|
|
|
void visitLoadInst(LoadInst &I);
|
|
|
|
void visitStoreInst(StoreInst &I);
|
2004-05-08 04:21:17 +00:00
|
|
|
void visitPHINode(PHINode &I) {} // PHI nodes handled by second pass
|
|
|
|
void visitGetElementPtrInst(GetElementPtrInst &I);
|
2004-06-18 05:19:16 +00:00
|
|
|
void visitAllocaInst(AllocaInst &I);
|
2004-05-08 04:21:17 +00:00
|
|
|
|
2004-02-29 00:27:00 +00:00
|
|
|
void visitInstruction(Instruction &I) {
|
|
|
|
std::cerr << "Unhandled instruction: " << I;
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// LowerUnknownIntrinsicFunctionCalls - This performs a prepass over the
|
|
|
|
/// function, lowering any calls to unknown intrinsic functions into the
|
|
|
|
/// equivalent LLVM code.
|
|
|
|
void LowerUnknownIntrinsicFunctionCalls(Function &F);
|
2004-03-03 23:03:14 +00:00
|
|
|
void visitIntrinsicCall(Intrinsic::ID ID, CallInst &CI);
|
2004-02-29 00:27:00 +00:00
|
|
|
|
2004-04-07 17:04:09 +00:00
|
|
|
void LoadArgumentsToVirtualRegs(Function *F);
|
|
|
|
|
2004-06-17 22:34:08 +00:00
|
|
|
/// SelectPHINodes - Insert machine code to generate phis. This is tricky
|
|
|
|
/// because we have to generate our sources into the source basic blocks,
|
|
|
|
/// not the current one.
|
|
|
|
///
|
|
|
|
void SelectPHINodes();
|
|
|
|
|
2004-03-03 23:03:14 +00:00
|
|
|
/// copyConstantToRegister - Output the instructions required to put the
|
|
|
|
/// specified constant into the specified register.
|
|
|
|
///
|
|
|
|
void copyConstantToRegister(MachineBasicBlock *MBB,
|
|
|
|
MachineBasicBlock::iterator IP,
|
|
|
|
Constant *C, unsigned R);
|
2004-02-29 00:27:00 +00:00
|
|
|
|
2004-03-03 23:03:14 +00:00
|
|
|
/// makeAnotherReg - This method returns the next register number we haven't
|
|
|
|
/// yet used.
|
|
|
|
///
|
|
|
|
/// Long values are handled somewhat specially. They are always allocated
|
|
|
|
/// as pairs of 32 bit integer values. The register number returned is the
|
|
|
|
/// lower 32 bits of the long value, and the regNum+1 is the upper 32 bits
|
|
|
|
/// of the long value.
|
|
|
|
///
|
|
|
|
unsigned makeAnotherReg(const Type *Ty) {
|
|
|
|
assert(dynamic_cast<const SparcV8RegisterInfo*>(TM.getRegisterInfo()) &&
|
|
|
|
"Current target doesn't have SparcV8 reg info??");
|
|
|
|
const SparcV8RegisterInfo *MRI =
|
|
|
|
static_cast<const SparcV8RegisterInfo*>(TM.getRegisterInfo());
|
|
|
|
if (Ty == Type::LongTy || Ty == Type::ULongTy) {
|
|
|
|
const TargetRegisterClass *RC = MRI->getRegClassForType(Type::IntTy);
|
|
|
|
// Create the lower part
|
|
|
|
F->getSSARegMap()->createVirtualRegister(RC);
|
|
|
|
// Create the upper part.
|
|
|
|
return F->getSSARegMap()->createVirtualRegister(RC)-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the mapping of regnumber => reg class to MachineFunction
|
|
|
|
const TargetRegisterClass *RC = MRI->getRegClassForType(Ty);
|
|
|
|
return F->getSSARegMap()->createVirtualRegister(RC);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getReg(Value &V) { return getReg (&V); } // allow refs.
|
|
|
|
unsigned getReg(Value *V) {
|
|
|
|
// Just append to the end of the current bb.
|
|
|
|
MachineBasicBlock::iterator It = BB->end();
|
|
|
|
return getReg(V, BB, It);
|
|
|
|
}
|
|
|
|
unsigned getReg(Value *V, MachineBasicBlock *MBB,
|
|
|
|
MachineBasicBlock::iterator IPt) {
|
|
|
|
unsigned &Reg = RegMap[V];
|
|
|
|
if (Reg == 0) {
|
|
|
|
Reg = makeAnotherReg(V->getType());
|
|
|
|
RegMap[V] = Reg;
|
|
|
|
}
|
|
|
|
// If this operand is a constant, emit the code to copy the constant into
|
|
|
|
// the register here...
|
|
|
|
//
|
|
|
|
if (Constant *C = dyn_cast<Constant>(V)) {
|
|
|
|
copyConstantToRegister(MBB, IPt, C, Reg);
|
|
|
|
RegMap.erase(V); // Assign a new name to this constant if ref'd again
|
|
|
|
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
|
|
|
|
// Move the address of the global into the register
|
2004-03-09 04:49:13 +00:00
|
|
|
unsigned TmpReg = makeAnotherReg(V->getType());
|
|
|
|
BuildMI (*MBB, IPt, V8::SETHIi, 1, TmpReg).addGlobalAddress (GV);
|
|
|
|
BuildMI (*MBB, IPt, V8::ORri, 2, Reg).addReg (TmpReg)
|
|
|
|
.addGlobalAddress (GV);
|
2004-03-03 23:03:14 +00:00
|
|
|
RegMap.erase(V); // Assign a new name to this address if ref'd again
|
|
|
|
}
|
|
|
|
|
|
|
|
return Reg;
|
|
|
|
}
|
2004-02-29 00:27:00 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
FunctionPass *llvm::createSparcV8SimpleInstructionSelector(TargetMachine &TM) {
|
|
|
|
return new V8ISel(TM);
|
|
|
|
}
|
|
|
|
|
2004-03-03 23:03:14 +00:00
|
|
|
enum TypeClass {
|
2004-03-16 22:37:11 +00:00
|
|
|
cByte, cShort, cInt, cLong, cFloat, cDouble
|
2004-03-03 23:03:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static TypeClass getClass (const Type *T) {
|
2004-06-17 18:19:28 +00:00
|
|
|
switch (T->getTypeID()) {
|
2004-03-03 23:03:14 +00:00
|
|
|
case Type::UByteTyID: case Type::SByteTyID: return cByte;
|
|
|
|
case Type::UShortTyID: case Type::ShortTyID: return cShort;
|
2004-04-07 17:04:09 +00:00
|
|
|
case Type::PointerTyID:
|
2004-03-03 23:03:14 +00:00
|
|
|
case Type::UIntTyID: case Type::IntTyID: return cInt;
|
2004-03-16 22:37:11 +00:00
|
|
|
case Type::ULongTyID: case Type::LongTyID: return cLong;
|
2004-03-03 23:03:14 +00:00
|
|
|
case Type::FloatTyID: return cFloat;
|
|
|
|
case Type::DoubleTyID: return cDouble;
|
|
|
|
default:
|
|
|
|
assert (0 && "Type of unknown class passed to getClass?");
|
|
|
|
return cByte;
|
|
|
|
}
|
|
|
|
}
|
2004-04-07 04:36:53 +00:00
|
|
|
static TypeClass getClassB(const Type *T) {
|
|
|
|
if (T == Type::BoolTy) return cByte;
|
|
|
|
return getClass(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-03 23:03:14 +00:00
|
|
|
|
|
|
|
/// copyConstantToRegister - Output the instructions required to put the
|
|
|
|
/// specified constant into the specified register.
|
|
|
|
///
|
|
|
|
void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB,
|
|
|
|
MachineBasicBlock::iterator IP,
|
|
|
|
Constant *C, unsigned R) {
|
2004-06-15 19:16:07 +00:00
|
|
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
|
|
|
|
switch (CE->getOpcode()) {
|
|
|
|
case Instruction::GetElementPtr:
|
|
|
|
emitGEPOperation(MBB, IP, CE->getOperand(0),
|
|
|
|
CE->op_begin()+1, CE->op_end(), R);
|
|
|
|
return;
|
2004-06-24 06:33:00 +00:00
|
|
|
case Instruction::Cast:
|
|
|
|
emitCastOperation(MBB, IP, CE->getOperand(0), CE->getType(), R);
|
|
|
|
return;
|
2004-06-15 19:16:07 +00:00
|
|
|
default:
|
|
|
|
std::cerr << "Copying this constant expr not yet handled: " << *CE;
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-07 21:39:30 +00:00
|
|
|
if (C->getType()->isIntegral ()) {
|
|
|
|
uint64_t Val;
|
2004-06-15 19:16:07 +00:00
|
|
|
unsigned Class = getClassB (C->getType ());
|
|
|
|
if (Class == cLong) {
|
|
|
|
unsigned TmpReg = makeAnotherReg (Type::IntTy);
|
|
|
|
unsigned TmpReg2 = makeAnotherReg (Type::IntTy);
|
|
|
|
// Copy the value into the register pair.
|
|
|
|
// R = top(more-significant) half, R+1 = bottom(less-significant) half
|
|
|
|
uint64_t Val = cast<ConstantInt>(C)->getRawValue();
|
|
|
|
unsigned topHalf = Val & 0xffffffffU;
|
|
|
|
unsigned bottomHalf = Val >> 32;
|
|
|
|
unsigned HH = topHalf >> 10;
|
|
|
|
unsigned HM = topHalf & 0x03ff;
|
|
|
|
unsigned LM = bottomHalf >> 10;
|
|
|
|
unsigned LO = bottomHalf & 0x03ff;
|
2004-06-24 08:55:09 +00:00
|
|
|
BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addZImm(HH);
|
2004-06-15 19:16:07 +00:00
|
|
|
BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg)
|
2004-06-24 08:55:09 +00:00
|
|
|
.addSImm (HM);
|
|
|
|
BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg2).addZImm(LM);
|
2004-06-15 19:16:07 +00:00
|
|
|
BuildMI (*MBB, IP, V8::ORri, 2, R+1).addReg (TmpReg2)
|
2004-06-24 08:55:09 +00:00
|
|
|
.addSImm (LO);
|
2004-06-15 19:16:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(Class <= cInt && "Type not handled yet!");
|
|
|
|
|
2004-05-07 21:39:30 +00:00
|
|
|
if (C->getType() == Type::BoolTy) {
|
|
|
|
Val = (C == ConstantBool::True);
|
|
|
|
} else {
|
2004-06-24 09:17:47 +00:00
|
|
|
ConstantInt *CI = cast<ConstantInt> (C);
|
2004-05-07 21:39:30 +00:00
|
|
|
Val = CI->getRawValue ();
|
|
|
|
}
|
2004-06-15 19:16:07 +00:00
|
|
|
switch (Class) {
|
2004-06-24 09:17:47 +00:00
|
|
|
case cByte: Val = (int8_t) Val; break;
|
|
|
|
case cShort: Val = (int16_t) Val; break;
|
|
|
|
case cInt: Val = (int32_t) Val; break;
|
2004-03-04 00:56:25 +00:00
|
|
|
default:
|
2004-04-07 04:00:49 +00:00
|
|
|
std::cerr << "Offending constant: " << *C << "\n";
|
2004-03-04 04:37:45 +00:00
|
|
|
assert (0 && "Can't copy this kind of constant into register yet");
|
2004-03-04 00:56:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-06-24 09:17:47 +00:00
|
|
|
if (Val == 0) {
|
|
|
|
BuildMI (*MBB, IP, V8::ORrr, 2, R).addReg (V8::G0).addReg(V8::G0);
|
|
|
|
} else if (((int64_t)Val >= -4096) && ((int64_t)Val <= 4095)) {
|
|
|
|
BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm(Val);
|
|
|
|
} else {
|
|
|
|
unsigned TmpReg = makeAnotherReg (C->getType ());
|
|
|
|
BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg)
|
|
|
|
.addSImm (((uint32_t) Val) >> 10);
|
|
|
|
BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg)
|
|
|
|
.addSImm (((uint32_t) Val) & 0x03ff);
|
|
|
|
return;
|
|
|
|
}
|
2004-06-18 05:19:16 +00:00
|
|
|
} else if (ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
|
|
|
|
// We need to spill the constant to memory...
|
|
|
|
MachineConstantPool *CP = F->getConstantPool();
|
|
|
|
unsigned CPI = CP->getConstantPoolIndex(CFP);
|
|
|
|
const Type *Ty = CFP->getType();
|
|
|
|
|
|
|
|
assert(Ty == Type::FloatTy || Ty == Type::DoubleTy && "Unknown FP type!");
|
2004-06-24 07:36:48 +00:00
|
|
|
unsigned LoadOpcode = Ty == Type::FloatTy ? V8::LDFri : V8::LDDFri;
|
2004-06-18 05:19:16 +00:00
|
|
|
BuildMI (*MBB, IP, LoadOpcode, 2, R).addConstantPoolIndex (CPI).addSImm (0);
|
2004-06-15 19:16:07 +00:00
|
|
|
} else if (isa<ConstantPointerNull>(C)) {
|
|
|
|
// Copy zero (null pointer) to the register.
|
2004-06-24 08:55:09 +00:00
|
|
|
BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm (0);
|
2004-06-15 19:16:07 +00:00
|
|
|
} else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) {
|
|
|
|
// Copy it with a SETHI/OR pair; the JIT + asmwriter should recognize
|
|
|
|
// that SETHI %reg,global == SETHI %reg,%hi(global) and
|
|
|
|
// OR %reg,global,%reg == OR %reg,%lo(global),%reg.
|
|
|
|
unsigned TmpReg = makeAnotherReg (C->getType ());
|
|
|
|
BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addGlobalAddress (CPR->getValue());
|
|
|
|
BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg)
|
|
|
|
.addGlobalAddress (CPR->getValue ());
|
|
|
|
} else {
|
|
|
|
std::cerr << "Offending constant: " << *C << "\n";
|
|
|
|
assert (0 && "Can't copy this kind of constant into register yet");
|
2004-03-03 23:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
2004-02-29 00:27:00 +00:00
|
|
|
|
2004-04-07 17:04:09 +00:00
|
|
|
void V8ISel::LoadArgumentsToVirtualRegs (Function *F) {
|
|
|
|
unsigned ArgOffset = 0;
|
|
|
|
static const unsigned IncomingArgRegs[] = { V8::I0, V8::I1, V8::I2,
|
|
|
|
V8::I3, V8::I4, V8::I5 };
|
|
|
|
assert (F->asize () < 7
|
|
|
|
&& "Can't handle loading excess call args off the stack yet");
|
|
|
|
|
|
|
|
for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I) {
|
|
|
|
unsigned Reg = getReg(*I);
|
|
|
|
switch (getClassB(I->getType())) {
|
|
|
|
case cByte:
|
|
|
|
case cShort:
|
|
|
|
case cInt:
|
|
|
|
BuildMI(BB, V8::ORrr, 2, Reg).addReg (V8::G0)
|
|
|
|
.addReg (IncomingArgRegs[ArgOffset]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert (0 && "Only <=32-bit, integral arguments currently handled");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++ArgOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-17 22:34:08 +00:00
|
|
|
void V8ISel::SelectPHINodes() {
|
|
|
|
const TargetInstrInfo &TII = *TM.getInstrInfo();
|
|
|
|
const Function &LF = *F->getFunction(); // The LLVM function...
|
|
|
|
for (Function::const_iterator I = LF.begin(), E = LF.end(); I != E; ++I) {
|
|
|
|
const BasicBlock *BB = I;
|
|
|
|
MachineBasicBlock &MBB = *MBBMap[I];
|
|
|
|
|
|
|
|
// Loop over all of the PHI nodes in the LLVM basic block...
|
|
|
|
MachineBasicBlock::iterator PHIInsertPoint = MBB.begin();
|
|
|
|
for (BasicBlock::const_iterator I = BB->begin();
|
|
|
|
PHINode *PN = const_cast<PHINode*>(dyn_cast<PHINode>(I)); ++I) {
|
|
|
|
|
|
|
|
// Create a new machine instr PHI node, and insert it.
|
|
|
|
unsigned PHIReg = getReg(*PN);
|
|
|
|
MachineInstr *PhiMI = BuildMI(MBB, PHIInsertPoint,
|
|
|
|
V8::PHI, PN->getNumOperands(), PHIReg);
|
|
|
|
|
|
|
|
MachineInstr *LongPhiMI = 0;
|
|
|
|
if (PN->getType() == Type::LongTy || PN->getType() == Type::ULongTy)
|
|
|
|
LongPhiMI = BuildMI(MBB, PHIInsertPoint,
|
|
|
|
V8::PHI, PN->getNumOperands(), PHIReg+1);
|
|
|
|
|
|
|
|
// PHIValues - Map of blocks to incoming virtual registers. We use this
|
|
|
|
// so that we only initialize one incoming value for a particular block,
|
|
|
|
// even if the block has multiple entries in the PHI node.
|
|
|
|
//
|
|
|
|
std::map<MachineBasicBlock*, unsigned> PHIValues;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
|
|
|
|
MachineBasicBlock *PredMBB = 0;
|
|
|
|
for (MachineBasicBlock::pred_iterator PI = MBB.pred_begin (),
|
|
|
|
PE = MBB.pred_end (); PI != PE; ++PI)
|
|
|
|
if (PN->getIncomingBlock(i) == (*PI)->getBasicBlock()) {
|
|
|
|
PredMBB = *PI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert (PredMBB && "Couldn't find incoming machine-cfg edge for phi");
|
|
|
|
|
|
|
|
unsigned ValReg;
|
|
|
|
std::map<MachineBasicBlock*, unsigned>::iterator EntryIt =
|
|
|
|
PHIValues.lower_bound(PredMBB);
|
|
|
|
|
|
|
|
if (EntryIt != PHIValues.end() && EntryIt->first == PredMBB) {
|
|
|
|
// We already inserted an initialization of the register for this
|
|
|
|
// predecessor. Recycle it.
|
|
|
|
ValReg = EntryIt->second;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Get the incoming value into a virtual register.
|
|
|
|
//
|
|
|
|
Value *Val = PN->getIncomingValue(i);
|
|
|
|
|
|
|
|
// If this is a constant or GlobalValue, we may have to insert code
|
|
|
|
// into the basic block to compute it into a virtual register.
|
|
|
|
if ((isa<Constant>(Val) && !isa<ConstantExpr>(Val)) ||
|
|
|
|
isa<GlobalValue>(Val)) {
|
|
|
|
// Simple constants get emitted at the end of the basic block,
|
|
|
|
// before any terminator instructions. We "know" that the code to
|
|
|
|
// move a constant into a register will never clobber any flags.
|
|
|
|
ValReg = getReg(Val, PredMBB, PredMBB->getFirstTerminator());
|
|
|
|
} else {
|
|
|
|
// Because we don't want to clobber any values which might be in
|
|
|
|
// physical registers with the computation of this constant (which
|
|
|
|
// might be arbitrarily complex if it is a constant expression),
|
|
|
|
// just insert the computation at the top of the basic block.
|
|
|
|
MachineBasicBlock::iterator PI = PredMBB->begin();
|
|
|
|
|
|
|
|
// Skip over any PHI nodes though!
|
|
|
|
while (PI != PredMBB->end() && PI->getOpcode() == V8::PHI)
|
|
|
|
++PI;
|
|
|
|
|
|
|
|
ValReg = getReg(Val, PredMBB, PI);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember that we inserted a value for this PHI for this predecessor
|
|
|
|
PHIValues.insert(EntryIt, std::make_pair(PredMBB, ValReg));
|
|
|
|
}
|
|
|
|
|
|
|
|
PhiMI->addRegOperand(ValReg);
|
|
|
|
PhiMI->addMachineBasicBlockOperand(PredMBB);
|
|
|
|
if (LongPhiMI) {
|
|
|
|
LongPhiMI->addRegOperand(ValReg+1);
|
|
|
|
LongPhiMI->addMachineBasicBlockOperand(PredMBB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now that we emitted all of the incoming values for the PHI node, make
|
|
|
|
// sure to reposition the InsertPoint after the PHI that we just added.
|
|
|
|
// This is needed because we might have inserted a constant into this
|
|
|
|
// block, right after the PHI's which is before the old insert point!
|
|
|
|
PHIInsertPoint = LongPhiMI ? LongPhiMI : PhiMI;
|
|
|
|
++PHIInsertPoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-29 00:27:00 +00:00
|
|
|
bool V8ISel::runOnFunction(Function &Fn) {
|
|
|
|
// First pass over the function, lower any unknown intrinsic functions
|
|
|
|
// with the IntrinsicLowering class.
|
|
|
|
LowerUnknownIntrinsicFunctionCalls(Fn);
|
|
|
|
|
|
|
|
F = &MachineFunction::construct(&Fn, TM);
|
|
|
|
|
|
|
|
// Create all of the machine basic blocks for the function...
|
|
|
|
for (Function::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I)
|
|
|
|
F->getBasicBlockList().push_back(MBBMap[I] = new MachineBasicBlock(I));
|
|
|
|
|
|
|
|
BB = &F->front();
|
|
|
|
|
|
|
|
// Set up a frame object for the return address. This is used by the
|
|
|
|
// llvm.returnaddress & llvm.frameaddress intrinisics.
|
|
|
|
//ReturnAddressIndex = F->getFrameInfo()->CreateFixedObject(4, -4);
|
|
|
|
|
|
|
|
// Copy incoming arguments off of the stack and out of fixed registers.
|
2004-04-07 17:04:09 +00:00
|
|
|
LoadArgumentsToVirtualRegs(&Fn);
|
2004-02-29 00:27:00 +00:00
|
|
|
|
|
|
|
// Instruction select everything except PHI nodes
|
|
|
|
visit(Fn);
|
|
|
|
|
|
|
|
// Select the PHI nodes
|
2004-06-17 22:34:08 +00:00
|
|
|
SelectPHINodes();
|
2004-02-29 00:27:00 +00:00
|
|
|
|
|
|
|
RegMap.clear();
|
|
|
|
MBBMap.clear();
|
|
|
|
F = 0;
|
|
|
|
// We always build a machine code representation for the function
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-04-13 18:27:46 +00:00
|
|
|
void V8ISel::visitCastInst(CastInst &I) {
|
2004-06-24 06:33:00 +00:00
|
|
|
Value *Op = I.getOperand(0);
|
|
|
|
unsigned DestReg = getReg(I);
|
|
|
|
MachineBasicBlock::iterator MI = BB->end();
|
|
|
|
emitCastOperation(BB, MI, Op, I.getType(), DestReg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// emitCastOperation - Common code shared between visitCastInst and constant
|
|
|
|
/// expression cast support.
|
|
|
|
///
|
|
|
|
void V8ISel::emitCastOperation(MachineBasicBlock *BB,
|
|
|
|
MachineBasicBlock::iterator IP,
|
|
|
|
Value *Src, const Type *DestTy,
|
|
|
|
unsigned DestReg) {
|
|
|
|
const Type *SrcTy = Src->getType();
|
|
|
|
unsigned SrcClass = getClassB(SrcTy);
|
|
|
|
unsigned DestClass = getClassB(DestTy);
|
|
|
|
unsigned SrcReg = getReg(Src, BB, IP);
|
|
|
|
|
|
|
|
const Type *oldTy = SrcTy;
|
|
|
|
const Type *newTy = DestTy;
|
|
|
|
unsigned oldTyClass = SrcClass;
|
|
|
|
unsigned newTyClass = DestClass;
|
2004-05-07 21:39:30 +00:00
|
|
|
|
2004-05-08 06:36:14 +00:00
|
|
|
if (oldTyClass < cLong && newTyClass < cLong) {
|
|
|
|
if (oldTyClass >= newTyClass) {
|
|
|
|
// Emit a reg->reg copy to do a equal-size or narrowing cast,
|
|
|
|
// and do sign/zero extension (necessary if we change signedness).
|
|
|
|
unsigned TmpReg1 = makeAnotherReg (newTy);
|
|
|
|
unsigned TmpReg2 = makeAnotherReg (newTy);
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI (*BB, IP, V8::ORrr, 2, TmpReg1).addReg (V8::G0).addReg (SrcReg);
|
2004-05-08 06:36:14 +00:00
|
|
|
unsigned shiftWidth = 32 - (8 * TM.getTargetData ().getTypeSize (newTy));
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI (*BB, IP, V8::SLLri, 2, TmpReg2).addZImm (shiftWidth).addReg(TmpReg1);
|
2004-05-08 06:36:14 +00:00
|
|
|
if (newTy->isSigned ()) { // sign-extend with SRA
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI(*BB, IP, V8::SRAri, 2, DestReg).addZImm (shiftWidth).addReg(TmpReg2);
|
2004-05-08 06:36:14 +00:00
|
|
|
} else { // zero-extend with SRL
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI(*BB, IP, V8::SRLri, 2, DestReg).addZImm (shiftWidth).addReg(TmpReg2);
|
2004-05-08 06:36:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned TmpReg1 = makeAnotherReg (oldTy);
|
|
|
|
unsigned TmpReg2 = makeAnotherReg (newTy);
|
|
|
|
unsigned TmpReg3 = makeAnotherReg (newTy);
|
|
|
|
// Widening integer cast. Make sure it's fully sign/zero-extended
|
|
|
|
// wrt the input type, then make sure it's fully sign/zero-extended wrt
|
|
|
|
// the output type. Kind of stupid, but simple...
|
|
|
|
unsigned shiftWidth = 32 - (8 * TM.getTargetData ().getTypeSize (oldTy));
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI (*BB, IP, V8::SLLri, 2, TmpReg1).addZImm (shiftWidth).addReg(SrcReg);
|
2004-05-08 06:36:14 +00:00
|
|
|
if (oldTy->isSigned ()) { // sign-extend with SRA
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI(*BB, IP, V8::SRAri, 2, TmpReg2).addZImm (shiftWidth).addReg(TmpReg1);
|
2004-05-08 06:36:14 +00:00
|
|
|
} else { // zero-extend with SRL
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI(*BB, IP, V8::SRLri, 2, TmpReg2).addZImm (shiftWidth).addReg(TmpReg1);
|
2004-05-08 06:36:14 +00:00
|
|
|
}
|
|
|
|
shiftWidth = 32 - (8 * TM.getTargetData ().getTypeSize (newTy));
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI (*BB, IP, V8::SLLri, 2, TmpReg3).addZImm (shiftWidth).addReg(TmpReg2);
|
2004-05-08 06:36:14 +00:00
|
|
|
if (newTy->isSigned ()) { // sign-extend with SRA
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI(*BB, IP, V8::SRAri, 2, DestReg).addZImm (shiftWidth).addReg(TmpReg3);
|
2004-05-08 06:36:14 +00:00
|
|
|
} else { // zero-extend with SRL
|
2004-06-24 06:33:00 +00:00
|
|
|
BuildMI(*BB, IP, V8::SRLri, 2, DestReg).addZImm (shiftWidth).addReg(TmpReg3);
|
2004-05-08 06:36:14 +00:00
|
|
|
}
|
2004-05-07 21:39:30 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-06-24 21:22:08 +00:00
|
|
|
if (newTyClass == cFloat) {
|
2004-06-27 22:47:33 +00:00
|
|
|
assert (oldTyClass != cLong && "cast long to float not implemented yet");
|
2004-06-24 21:22:08 +00:00
|
|
|
switch (oldTyClass) {
|
|
|
|
case cFloat:
|
|
|
|
BuildMI (*BB, IP, V8::FMOVS, 1, DestReg).addReg (SrcReg);
|
|
|
|
break;
|
|
|
|
case cDouble:
|
|
|
|
BuildMI (*BB, IP, V8::FDTOS, 1, DestReg).addReg (SrcReg);
|
|
|
|
break;
|
2004-06-27 22:47:33 +00:00
|
|
|
default: {
|
|
|
|
unsigned FltAlign = TM.getTargetData().getFloatAlignment();
|
2004-06-24 21:22:08 +00:00
|
|
|
// cast int to float. Store it to a stack slot and then load
|
|
|
|
// it using ldf into a floating point register. then do fitos.
|
2004-06-27 22:47:33 +00:00
|
|
|
unsigned TmpReg = makeAnotherReg (newTy);
|
|
|
|
int FI = F->getFrameInfo()->CreateStackObject(4, FltAlign);
|
|
|
|
BuildMI (*BB, IP, V8::ST, 3).addFrameIndex (FI).addSImm (0)
|
|
|
|
.addReg (SrcReg);
|
|
|
|
BuildMI (*BB, IP, V8::LDFri, 2, TmpReg).addFrameIndex (FI).addSImm (0);
|
|
|
|
BuildMI (*BB, IP, V8::FITOS, 1, DestReg).addReg(TmpReg);
|
2004-06-24 21:22:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-06-27 22:47:33 +00:00
|
|
|
}
|
2004-06-24 21:22:08 +00:00
|
|
|
} else if (newTyClass == cDouble) {
|
2004-06-27 22:47:33 +00:00
|
|
|
assert (oldTyClass != cLong && "cast long to double not implemented yet");
|
2004-06-24 21:22:08 +00:00
|
|
|
switch (oldTyClass) {
|
|
|
|
case cFloat:
|
|
|
|
BuildMI (*BB, IP, V8::FSTOD, 1, DestReg).addReg (SrcReg);
|
|
|
|
break;
|
2004-06-27 22:47:33 +00:00
|
|
|
case cDouble: {
|
|
|
|
// go through memory, for now
|
|
|
|
unsigned DoubleAlignment = TM.getTargetData().getDoubleAlignment();
|
|
|
|
int FI = F->getFrameInfo()->CreateStackObject(8, DoubleAlignment);
|
|
|
|
BuildMI (*BB, IP, V8::STDFri, 3).addFrameIndex (FI).addSImm (0)
|
|
|
|
.addReg (SrcReg);
|
|
|
|
BuildMI (*BB, IP, V8::LDDFri, 2, DestReg).addFrameIndex (FI)
|
|
|
|
.addSImm (0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
unsigned DoubleAlignment = TM.getTargetData().getDoubleAlignment();
|
|
|
|
unsigned TmpReg = makeAnotherReg (newTy);
|
|
|
|
int FI = F->getFrameInfo()->CreateStackObject(8, DoubleAlignment);
|
|
|
|
BuildMI (*BB, IP, V8::ST, 3).addFrameIndex (FI).addSImm (0)
|
|
|
|
.addReg (SrcReg);
|
|
|
|
BuildMI (*BB, IP, V8::LDDFri, 2, TmpReg).addFrameIndex (FI).addSImm (0);
|
|
|
|
BuildMI (*BB, IP, V8::FITOD, 1, DestReg).addReg(TmpReg);
|
2004-06-24 21:22:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-06-27 22:47:33 +00:00
|
|
|
}
|
2004-06-24 07:36:48 +00:00
|
|
|
} else {
|
|
|
|
std::cerr << "Cast still unsupported: SrcTy = "
|
|
|
|
<< *SrcTy << ", DestTy = " << *DestTy << "\n";
|
|
|
|
abort ();
|
|
|
|
}
|
2004-05-07 21:39:30 +00:00
|
|
|
}
|
2004-04-13 18:27:46 +00:00
|
|
|
}
|
|
|
|
|
2004-04-07 17:29:37 +00:00
|
|
|
void V8ISel::visitLoadInst(LoadInst &I) {
|
|
|
|
unsigned DestReg = getReg (I);
|
|
|
|
unsigned PtrReg = getReg (I.getOperand (0));
|
2004-05-08 04:21:17 +00:00
|
|
|
switch (getClassB (I.getType ())) {
|
2004-04-07 17:29:37 +00:00
|
|
|
case cByte:
|
|
|
|
if (I.getType ()->isSigned ())
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::LDSB, 2, DestReg).addReg (PtrReg).addSImm(0);
|
2004-04-07 17:29:37 +00:00
|
|
|
else
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::LDUB, 2, DestReg).addReg (PtrReg).addSImm(0);
|
2004-04-07 17:29:37 +00:00
|
|
|
return;
|
|
|
|
case cShort:
|
|
|
|
if (I.getType ()->isSigned ())
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::LDSH, 2, DestReg).addReg (PtrReg).addSImm(0);
|
2004-04-07 17:29:37 +00:00
|
|
|
else
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::LDUH, 2, DestReg).addReg (PtrReg).addSImm(0);
|
2004-04-07 17:29:37 +00:00
|
|
|
return;
|
|
|
|
case cInt:
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::LD, 2, DestReg).addReg (PtrReg).addSImm(0);
|
2004-04-07 17:29:37 +00:00
|
|
|
return;
|
|
|
|
case cLong:
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::LD, 2, DestReg).addReg (PtrReg).addSImm(0);
|
|
|
|
BuildMI (BB, V8::LD, 2, DestReg+1).addReg (PtrReg).addSImm(4);
|
|
|
|
return;
|
|
|
|
case cFloat:
|
|
|
|
BuildMI (BB, V8::LDFri, 2, DestReg).addReg (PtrReg).addSImm(0);
|
|
|
|
return;
|
|
|
|
case cDouble:
|
|
|
|
BuildMI (BB, V8::LDDFri, 2, DestReg).addReg (PtrReg).addSImm(0);
|
2004-04-07 17:29:37 +00:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
std::cerr << "Load instruction not handled: " << I;
|
|
|
|
abort ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void V8ISel::visitStoreInst(StoreInst &I) {
|
2004-05-08 04:21:17 +00:00
|
|
|
Value *SrcVal = I.getOperand (0);
|
|
|
|
unsigned SrcReg = getReg (SrcVal);
|
2004-04-07 17:29:37 +00:00
|
|
|
unsigned PtrReg = getReg (I.getOperand (1));
|
2004-05-08 04:21:17 +00:00
|
|
|
switch (getClassB (SrcVal->getType ())) {
|
|
|
|
case cByte:
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::STB, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg);
|
2004-05-08 04:21:17 +00:00
|
|
|
return;
|
|
|
|
case cShort:
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::STH, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg);
|
2004-05-08 04:21:17 +00:00
|
|
|
return;
|
|
|
|
case cInt:
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::ST, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg);
|
2004-05-08 04:21:17 +00:00
|
|
|
return;
|
|
|
|
case cLong:
|
2004-06-24 07:36:48 +00:00
|
|
|
BuildMI (BB, V8::ST, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg);
|
|
|
|
BuildMI (BB, V8::ST, 3).addReg (PtrReg).addSImm (4).addReg (SrcReg+1);
|
|
|
|
return;
|
|
|
|
case cFloat:
|
|
|
|
BuildMI (BB, V8::STFri, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg);
|
|
|
|
return;
|
|
|
|
case cDouble:
|
|
|
|
BuildMI (BB, V8::STDFri, 3).addReg (PtrReg).addSImm (0).addReg (SrcReg);
|
2004-05-08 04:21:17 +00:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
std::cerr << "Store instruction not handled: " << I;
|
|
|
|
abort ();
|
|
|
|
return;
|
|
|
|
}
|
2004-04-07 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
2004-04-02 20:53:33 +00:00
|
|
|
void V8ISel::visitCallInst(CallInst &I) {
|
2004-06-18 06:27:48 +00:00
|
|
|
MachineInstr *TheCall;
|
|
|
|
// Is it an intrinsic function call?
|
|
|
|
if (Function *F = I.getCalledFunction()) {
|
|
|
|
if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) {
|
|
|
|
visitIntrinsicCall(ID, I); // Special intrinsics are not handled here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deal with args
|
2004-04-07 16:41:22 +00:00
|
|
|
assert (I.getNumOperands () < 8
|
|
|
|
&& "Can't handle pushing excess call args on the stack yet");
|
2004-04-07 17:04:09 +00:00
|
|
|
static const unsigned OutgoingArgRegs[] = { V8::O0, V8::O1, V8::O2, V8::O3,
|
2004-04-07 16:41:22 +00:00
|
|
|
V8::O4, V8::O5 };
|
|
|
|
for (unsigned i = 1; i < 7; ++i)
|
|
|
|
if (i < I.getNumOperands ()) {
|
2004-06-27 22:47:33 +00:00
|
|
|
assert (getClassB (I.getOperand (i)->getType ()) < cLong
|
|
|
|
&& "Can't handle long or fp function call arguments yet");
|
2004-04-07 16:41:22 +00:00
|
|
|
unsigned ArgReg = getReg (I.getOperand (i));
|
|
|
|
// Schlep it over into the incoming arg register
|
2004-04-07 17:04:09 +00:00
|
|
|
BuildMI (BB, V8::ORrr, 2, OutgoingArgRegs[i - 1]).addReg (V8::G0)
|
2004-04-07 16:41:22 +00:00
|
|
|
.addReg (ArgReg);
|
|
|
|
}
|
|
|
|
|
2004-06-18 06:27:48 +00:00
|
|
|
// Emit call instruction
|
|
|
|
if (Function *F = I.getCalledFunction ()) {
|
|
|
|
BuildMI (BB, V8::CALL, 1).addGlobalAddress (F, true);
|
|
|
|
} else { // Emit an indirect call...
|
|
|
|
unsigned Reg = getReg (I.getCalledValue ());
|
|
|
|
BuildMI (BB, V8::JMPLrr, 3, V8::O7).addReg (Reg).addReg (V8::G0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deal w/ return value: schlep it over into the destination register
|
2004-06-15 20:06:32 +00:00
|
|
|
if (I.getType () == Type::VoidTy)
|
2004-04-06 22:09:23 +00:00
|
|
|
return;
|
2004-06-15 20:06:32 +00:00
|
|
|
unsigned DestReg = getReg (I);
|
2004-04-06 22:09:23 +00:00
|
|
|
switch (getClass (I.getType ())) {
|
|
|
|
case cByte:
|
|
|
|
case cShort:
|
|
|
|
case cInt:
|
|
|
|
BuildMI (BB, V8::ORrr, 2, DestReg).addReg(V8::G0).addReg(V8::O0);
|
|
|
|
break;
|
2004-06-18 06:27:48 +00:00
|
|
|
case cFloat:
|
|
|
|
BuildMI (BB, V8::FMOVS, 2, DestReg).addReg(V8::F0);
|
|
|
|
break;
|
2004-04-06 22:09:23 +00:00
|
|
|
default:
|
2004-05-08 04:21:17 +00:00
|
|
|
std::cerr << "Return type of call instruction not handled: " << I;
|
|
|
|
abort ();
|
2004-04-06 22:09:23 +00:00
|
|
|
}
|
2004-04-02 20:53:33 +00:00
|
|
|
}
|
2004-02-29 00:27:00 +00:00
|
|
|
|
|
|
|
void V8ISel::visitReturnInst(ReturnInst &I) {
|
2004-03-06 05:32:28 +00:00
|
|
|
if (I.getNumOperands () == 1) {
|
|
|
|
unsigned RetValReg = getReg (I.getOperand (0));
|
|
|
|
switch (getClass (I.getOperand (0)->getType ())) {
|
|
|
|
case cByte:
|
|
|
|
case cShort:
|
|
|
|
case cInt:
|
|
|
|
// Schlep it over into i0 (where it will become o0 after restore).
|
|
|
|
BuildMI (BB, V8::ORrr, 2, V8::I0).addReg(V8::G0).addReg(RetValReg);
|
|
|
|
break;
|
2004-07-08 07:22:27 +00:00
|
|
|
case cFloat:
|
|
|
|
BuildMI (BB, V8::FMOVS, 2, V8::F0).addReg(RetValReg);
|
|
|
|
break;
|
2004-03-06 05:32:28 +00:00
|
|
|
default:
|
2004-05-08 04:21:17 +00:00
|
|
|
std::cerr << "Return instruction of this type not handled: " << I;
|
|
|
|
abort ();
|
2004-03-06 05:32:28 +00:00
|
|
|
}
|
2004-02-29 00:27:00 +00:00
|
|
|
}
|
2004-04-07 04:36:53 +00:00
|
|
|
|
2004-03-06 05:32:28 +00:00
|
|
|
// Just emit a 'retl' instruction to return.
|
|
|
|
BuildMI(BB, V8::RETL, 0);
|
|
|
|
return;
|
2004-02-29 00:27:00 +00:00
|
|
|
}
|
|
|
|
|
2004-05-08 04:21:17 +00:00
|
|
|
static inline BasicBlock *getBlockAfter(BasicBlock *BB) {
|
|
|
|
Function::iterator I = BB; ++I; // Get iterator to next block
|
|
|
|
return I != BB->getParent()->end() ? &*I : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// visitBranchInst - Handles conditional and unconditional branches.
|
|
|
|
///
|
|
|
|
void V8ISel::visitBranchInst(BranchInst &I) {
|
|
|
|
BasicBlock *takenSucc = I.getSuccessor (0);
|
2004-06-17 22:34:08 +00:00
|
|
|
MachineBasicBlock *takenSuccMBB = MBBMap[takenSucc];
|
|
|
|
BB->addSuccessor (takenSuccMBB);
|
|
|
|
if (I.isConditional()) { // conditional branch
|
|
|
|
BasicBlock *notTakenSucc = I.getSuccessor (1);
|
|
|
|
MachineBasicBlock *notTakenSuccMBB = MBBMap[notTakenSucc];
|
|
|
|
BB->addSuccessor (notTakenSuccMBB);
|
|
|
|
|
|
|
|
// CondReg=(<condition>);
|
|
|
|
// If (CondReg==0) goto notTakenSuccMBB;
|
|
|
|
unsigned CondReg = getReg (I.getCondition ());
|
|
|
|
BuildMI (BB, V8::CMPri, 2).addSImm (0).addReg (CondReg);
|
|
|
|
BuildMI (BB, V8::BE, 1).addMBB (notTakenSuccMBB);
|
2004-05-08 04:21:17 +00:00
|
|
|
}
|
2004-06-17 22:34:08 +00:00
|
|
|
// goto takenSuccMBB;
|
|
|
|
BuildMI (BB, V8::BA, 1).addMBB (takenSuccMBB);
|
2004-05-08 04:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// emitGEPOperation - Common code shared between visitGetElementPtrInst and
|
|
|
|
/// constant expression GEP support.
|
|
|
|
///
|
2004-05-08 05:27:20 +00:00
|
|
|
void V8ISel::emitGEPOperation (MachineBasicBlock *MBB,
|
2004-05-08 04:21:17 +00:00
|
|
|
MachineBasicBlock::iterator IP,
|
|
|
|
Value *Src, User::op_iterator IdxBegin,
|
|
|
|
User::op_iterator IdxEnd, unsigned TargetReg) {
|
2004-05-08 05:27:20 +00:00
|
|
|
const TargetData &TD = TM.getTargetData ();
|
|
|
|
const Type *Ty = Src->getType ();
|
2004-06-24 08:55:09 +00:00
|
|
|
unsigned basePtrReg = getReg (Src, MBB, IP);
|
2004-05-08 05:27:20 +00:00
|
|
|
|
|
|
|
// GEPs have zero or more indices; we must perform a struct access
|
|
|
|
// or array access for each one.
|
|
|
|
for (GetElementPtrInst::op_iterator oi = IdxBegin, oe = IdxEnd; oi != oe;
|
|
|
|
++oi) {
|
|
|
|
Value *idx = *oi;
|
|
|
|
unsigned nextBasePtrReg = makeAnotherReg (Type::UIntTy);
|
|
|
|
if (const StructType *StTy = dyn_cast<StructType> (Ty)) {
|
|
|
|
// It's a struct access. idx is the index into the structure,
|
|
|
|
// which names the field. Use the TargetData structure to
|
|
|
|
// pick out what the layout of the structure is in memory.
|
|
|
|
// Use the (constant) structure index's value to find the
|
|
|
|
// right byte offset from the StructLayout class's list of
|
|
|
|
// structure member offsets.
|
|
|
|
unsigned fieldIndex = cast<ConstantUInt> (idx)->getValue ();
|
|
|
|
unsigned memberOffset =
|
|
|
|
TD.getStructLayout (StTy)->MemberOffsets[fieldIndex];
|
|
|
|
// Emit an ADD to add memberOffset to the basePtr.
|
|
|
|
BuildMI (*MBB, IP, V8::ADDri, 2,
|
|
|
|
nextBasePtrReg).addReg (basePtrReg).addZImm (memberOffset);
|
|
|
|
// The next type is the member of the structure selected by the
|
|
|
|
// index.
|
|
|
|
Ty = StTy->getElementType (fieldIndex);
|
|
|
|
} else if (const SequentialType *SqTy = dyn_cast<SequentialType> (Ty)) {
|
|
|
|
// It's an array or pointer access: [ArraySize x ElementType].
|
|
|
|
// We want to add basePtrReg to (idxReg * sizeof ElementType). First, we
|
|
|
|
// must find the size of the pointed-to type (Not coincidentally, the next
|
|
|
|
// type is the type of the elements in the array).
|
|
|
|
Ty = SqTy->getElementType ();
|
|
|
|
unsigned elementSize = TD.getTypeSize (Ty);
|
|
|
|
unsigned idxReg = getReg (idx, MBB, IP);
|
|
|
|
unsigned OffsetReg = makeAnotherReg (Type::IntTy);
|
|
|
|
unsigned elementSizeReg = makeAnotherReg (Type::UIntTy);
|
2004-06-24 08:55:09 +00:00
|
|
|
copyConstantToRegister (MBB, IP,
|
|
|
|
ConstantUInt::get(Type::UIntTy, elementSize), elementSizeReg);
|
2004-05-08 05:27:20 +00:00
|
|
|
// Emit a SMUL to multiply the register holding the index by
|
|
|
|
// elementSize, putting the result in OffsetReg.
|
|
|
|
BuildMI (*MBB, IP, V8::SMULrr, 2,
|
|
|
|
OffsetReg).addReg (elementSizeReg).addReg (idxReg);
|
|
|
|
// Emit an ADD to add OffsetReg to the basePtr.
|
|
|
|
BuildMI (*MBB, IP, V8::ADDrr, 2,
|
|
|
|
nextBasePtrReg).addReg (basePtrReg).addReg (OffsetReg);
|
|
|
|
}
|
|
|
|
basePtrReg = nextBasePtrReg;
|
|
|
|
}
|
|
|
|
// After we have processed all the indices, the result is left in
|
|
|
|
// basePtrReg. Move it to the register where we were expected to
|
|
|
|
// put the answer.
|
|
|
|
BuildMI (BB, V8::ORrr, 1, TargetReg).addReg (V8::G0).addReg (basePtrReg);
|
2004-05-08 04:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void V8ISel::visitGetElementPtrInst (GetElementPtrInst &I) {
|
|
|
|
unsigned outputReg = getReg (I);
|
|
|
|
emitGEPOperation (BB, BB->end (), I.getOperand (0),
|
|
|
|
I.op_begin ()+1, I.op_end (), outputReg);
|
|
|
|
}
|
|
|
|
|
2004-06-15 21:09:46 +00:00
|
|
|
|
2004-04-07 04:27:16 +00:00
|
|
|
void V8ISel::visitBinaryOperator (Instruction &I) {
|
2004-03-03 23:03:14 +00:00
|
|
|
unsigned DestReg = getReg (I);
|
|
|
|
unsigned Op0Reg = getReg (I.getOperand (0));
|
|
|
|
unsigned Op1Reg = getReg (I.getOperand (1));
|
|
|
|
|
2004-06-27 22:47:33 +00:00
|
|
|
unsigned Class = getClassB (I.getType());
|
|
|
|
unsigned OpCase = ~0;
|
|
|
|
|
|
|
|
if (Class > cLong) {
|
|
|
|
switch (I.getOpcode ()) {
|
|
|
|
case Instruction::Add: OpCase = 0; break;
|
|
|
|
case Instruction::Sub: OpCase = 1; break;
|
|
|
|
case Instruction::Mul: OpCase = 2; break;
|
|
|
|
case Instruction::Div: OpCase = 3; break;
|
|
|
|
default: visitInstruction (I); return;
|
|
|
|
}
|
|
|
|
static unsigned Opcodes[] = { V8::FADDS, V8::FADDD,
|
|
|
|
V8::FSUBS, V8::FSUBD,
|
|
|
|
V8::FMULS, V8::FMULD,
|
|
|
|
V8::FDIVS, V8::FDIVD };
|
|
|
|
BuildMI (BB, Opcodes[2*OpCase + (Class - cFloat)], 2, DestReg)
|
|
|
|
.addReg (Op0Reg).addReg (Op1Reg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-04-07 04:36:53 +00:00
|
|
|
unsigned ResultReg = DestReg;
|
2004-06-27 22:47:33 +00:00
|
|
|
if (Class != cInt)
|
2004-04-07 04:36:53 +00:00
|
|
|
ResultReg = makeAnotherReg (I.getType ());
|
2004-04-07 04:06:46 +00:00
|
|
|
|
2004-04-07 04:00:49 +00:00
|
|
|
// FIXME: support long, ulong, fp.
|
2004-03-03 23:03:14 +00:00
|
|
|
switch (I.getOpcode ()) {
|
2004-04-07 04:06:46 +00:00
|
|
|
case Instruction::Add: OpCase = 0; break;
|
|
|
|
case Instruction::Sub: OpCase = 1; break;
|
|
|
|
case Instruction::Mul: OpCase = 2; break;
|
|
|
|
case Instruction::And: OpCase = 3; break;
|
|
|
|
case Instruction::Or: OpCase = 4; break;
|
|
|
|
case Instruction::Xor: OpCase = 5; break;
|
2004-04-07 04:27:16 +00:00
|
|
|
case Instruction::Shl: OpCase = 6; break;
|
|
|
|
case Instruction::Shr: OpCase = 7+I.getType()->isSigned(); break;
|
2004-04-07 04:06:46 +00:00
|
|
|
|
|
|
|
case Instruction::Div:
|
|
|
|
case Instruction::Rem: {
|
|
|
|
unsigned Dest = ResultReg;
|
|
|
|
if (I.getOpcode() == Instruction::Rem)
|
|
|
|
Dest = makeAnotherReg(I.getType());
|
|
|
|
|
|
|
|
// FIXME: this is probably only right for 32 bit operands.
|
|
|
|
if (I.getType ()->isSigned()) {
|
|
|
|
unsigned Tmp = makeAnotherReg (I.getType ());
|
|
|
|
// Sign extend into the Y register
|
|
|
|
BuildMI (BB, V8::SRAri, 2, Tmp).addReg (Op0Reg).addZImm (31);
|
|
|
|
BuildMI (BB, V8::WRrr, 2, V8::Y).addReg (Tmp).addReg (V8::G0);
|
|
|
|
BuildMI (BB, V8::SDIVrr, 2, Dest).addReg (Op0Reg).addReg (Op1Reg);
|
|
|
|
} else {
|
|
|
|
// Zero extend into the Y register, ie, just set it to zero
|
|
|
|
BuildMI (BB, V8::WRrr, 2, V8::Y).addReg (V8::G0).addReg (V8::G0);
|
|
|
|
BuildMI (BB, V8::UDIVrr, 2, Dest).addReg (Op0Reg).addReg (Op1Reg);
|
2004-04-07 04:00:49 +00:00
|
|
|
}
|
2004-04-07 04:06:46 +00:00
|
|
|
|
|
|
|
if (I.getOpcode() == Instruction::Rem) {
|
|
|
|
unsigned Tmp = makeAnotherReg (I.getType ());
|
|
|
|
BuildMI (BB, V8::SMULrr, 2, Tmp).addReg(Dest).addReg(Op1Reg);
|
|
|
|
BuildMI (BB, V8::SUBrr, 2, ResultReg).addReg(Op0Reg).addReg(Tmp);
|
2004-03-16 22:37:11 +00:00
|
|
|
}
|
2004-04-07 04:06:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
visitInstruction (I);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-24 08:55:09 +00:00
|
|
|
static const unsigned Opcodes[] = {
|
|
|
|
V8::ADDrr, V8::SUBrr, V8::SMULrr, V8::ANDrr, V8::ORrr, V8::XORrr,
|
|
|
|
V8::SLLrr, V8::SRLrr, V8::SRArr
|
|
|
|
};
|
2004-04-07 04:06:46 +00:00
|
|
|
if (OpCase != ~0U) {
|
|
|
|
BuildMI (BB, Opcodes[OpCase], 2, ResultReg).addReg (Op0Reg).addReg (Op1Reg);
|
2004-03-03 23:03:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (getClass (I.getType ())) {
|
|
|
|
case cByte:
|
2004-03-06 05:32:28 +00:00
|
|
|
if (I.getType ()->isSigned ()) { // add byte
|
|
|
|
BuildMI (BB, V8::ANDri, 2, DestReg).addReg (ResultReg).addZImm (0xff);
|
|
|
|
} else { // add ubyte
|
|
|
|
unsigned TmpReg = makeAnotherReg (I.getType ());
|
|
|
|
BuildMI (BB, V8::SLLri, 2, TmpReg).addReg (ResultReg).addZImm (24);
|
|
|
|
BuildMI (BB, V8::SRAri, 2, DestReg).addReg (TmpReg).addZImm (24);
|
|
|
|
}
|
2004-03-03 23:03:14 +00:00
|
|
|
break;
|
|
|
|
case cShort:
|
2004-03-06 05:32:28 +00:00
|
|
|
if (I.getType ()->isSigned ()) { // add short
|
|
|
|
unsigned TmpReg = makeAnotherReg (I.getType ());
|
|
|
|
BuildMI (BB, V8::SLLri, 2, TmpReg).addReg (ResultReg).addZImm (16);
|
|
|
|
BuildMI (BB, V8::SRAri, 2, DestReg).addReg (TmpReg).addZImm (16);
|
|
|
|
} else { // add ushort
|
|
|
|
unsigned TmpReg = makeAnotherReg (I.getType ());
|
2004-03-16 22:45:42 +00:00
|
|
|
BuildMI (BB, V8::SLLri, 2, TmpReg).addReg (ResultReg).addZImm (16);
|
|
|
|
BuildMI (BB, V8::SRLri, 2, DestReg).addReg (TmpReg).addZImm (16);
|
2004-03-06 05:32:28 +00:00
|
|
|
}
|
2004-03-03 23:03:14 +00:00
|
|
|
break;
|
|
|
|
case cInt:
|
2004-04-07 04:36:53 +00:00
|
|
|
// Nothing todo here.
|
2004-03-03 23:03:14 +00:00
|
|
|
break;
|
2004-06-24 08:55:09 +00:00
|
|
|
case cLong:
|
|
|
|
// Only support and, or, xor.
|
|
|
|
if (OpCase < 3 || OpCase > 5) {
|
|
|
|
visitInstruction (I);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Do the other half of the value:
|
2004-06-27 22:47:33 +00:00
|
|
|
BuildMI (BB, Opcodes[OpCase], 2, ResultReg+1).addReg (Op0Reg+1)
|
|
|
|
.addReg (Op1Reg+1);
|
2004-06-24 08:55:09 +00:00
|
|
|
break;
|
2004-03-03 23:03:14 +00:00
|
|
|
default:
|
2004-03-06 05:32:28 +00:00
|
|
|
visitInstruction (I);
|
2004-03-03 23:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-30 21:47:40 +00:00
|
|
|
void V8ISel::visitSetCondInst(SetCondInst &I) {
|
2004-04-07 05:04:51 +00:00
|
|
|
unsigned Op0Reg = getReg (I.getOperand (0));
|
|
|
|
unsigned Op1Reg = getReg (I.getOperand (1));
|
|
|
|
unsigned DestReg = getReg (I);
|
2004-05-08 06:36:14 +00:00
|
|
|
const Type *Ty = I.getOperand (0)->getType ();
|
2004-04-07 05:04:51 +00:00
|
|
|
|
2004-06-27 22:47:33 +00:00
|
|
|
assert (getClass (Ty) < cLong && "can't setcc on longs or fp yet");
|
2004-04-07 05:04:51 +00:00
|
|
|
// Compare the two values.
|
|
|
|
BuildMI(BB, V8::SUBCCrr, 2, V8::G0).addReg(Op0Reg).addReg(Op1Reg);
|
|
|
|
|
2004-05-08 06:36:14 +00:00
|
|
|
unsigned BranchIdx;
|
2004-04-07 05:04:51 +00:00
|
|
|
switch (I.getOpcode()) {
|
|
|
|
default: assert(0 && "Unknown setcc instruction!");
|
2004-05-08 06:36:14 +00:00
|
|
|
case Instruction::SetEQ: BranchIdx = 0; break;
|
|
|
|
case Instruction::SetNE: BranchIdx = 1; break;
|
|
|
|
case Instruction::SetLT: BranchIdx = 2; break;
|
|
|
|
case Instruction::SetGT: BranchIdx = 3; break;
|
|
|
|
case Instruction::SetLE: BranchIdx = 4; break;
|
|
|
|
case Instruction::SetGE: BranchIdx = 5; break;
|
2004-04-07 05:04:51 +00:00
|
|
|
}
|
2004-05-08 06:36:14 +00:00
|
|
|
static unsigned OpcodeTab[12] = {
|
2004-06-30 22:11:03 +00:00
|
|
|
// LLVM SparcV8
|
|
|
|
// unsigned signed
|
|
|
|
V8::BE, V8::BE, // seteq = be be
|
|
|
|
V8::BNE, V8::BNE, // setne = bne bne
|
|
|
|
V8::BCS, V8::BL, // setlt = bcs bl
|
|
|
|
V8::BGU, V8::BG, // setgt = bgu bg
|
|
|
|
V8::BLEU, V8::BLE, // setle = bleu ble
|
|
|
|
V8::BCC, V8::BGE // setge = bcc bge
|
2004-05-08 06:36:14 +00:00
|
|
|
};
|
2004-06-17 22:34:08 +00:00
|
|
|
unsigned Opcode = OpcodeTab[2*BranchIdx + (Ty->isSigned() ? 1 : 0)];
|
|
|
|
|
|
|
|
MachineBasicBlock *thisMBB = BB;
|
|
|
|
const BasicBlock *LLVM_BB = BB->getBasicBlock ();
|
|
|
|
// thisMBB:
|
|
|
|
// ...
|
|
|
|
// subcc %reg0, %reg1, %g0
|
|
|
|
// bCC copy1MBB
|
|
|
|
// ba copy0MBB
|
|
|
|
|
|
|
|
// FIXME: we wouldn't need copy0MBB (we could fold it into thisMBB)
|
|
|
|
// if we could insert other, non-terminator instructions after the
|
|
|
|
// bCC. But MBB->getFirstTerminator() can't understand this.
|
|
|
|
MachineBasicBlock *copy1MBB = new MachineBasicBlock (LLVM_BB);
|
|
|
|
F->getBasicBlockList ().push_back (copy1MBB);
|
|
|
|
BuildMI (BB, Opcode, 1).addMBB (copy1MBB);
|
|
|
|
MachineBasicBlock *copy0MBB = new MachineBasicBlock (LLVM_BB);
|
|
|
|
F->getBasicBlockList ().push_back (copy0MBB);
|
|
|
|
BuildMI (BB, V8::BA, 1).addMBB (copy0MBB);
|
|
|
|
// Update machine-CFG edges
|
|
|
|
BB->addSuccessor (copy1MBB);
|
|
|
|
BB->addSuccessor (copy0MBB);
|
|
|
|
|
|
|
|
// copy0MBB:
|
|
|
|
// %FalseValue = or %G0, 0
|
|
|
|
// ba sinkMBB
|
|
|
|
BB = copy0MBB;
|
|
|
|
unsigned FalseValue = makeAnotherReg (I.getType ());
|
|
|
|
BuildMI (BB, V8::ORri, 2, FalseValue).addReg (V8::G0).addZImm (0);
|
|
|
|
MachineBasicBlock *sinkMBB = new MachineBasicBlock (LLVM_BB);
|
|
|
|
F->getBasicBlockList ().push_back (sinkMBB);
|
|
|
|
BuildMI (BB, V8::BA, 1).addMBB (sinkMBB);
|
|
|
|
// Update machine-CFG edges
|
|
|
|
BB->addSuccessor (sinkMBB);
|
|
|
|
|
|
|
|
DEBUG (std::cerr << "thisMBB is at " << (void*)thisMBB << "\n");
|
|
|
|
DEBUG (std::cerr << "copy1MBB is at " << (void*)copy1MBB << "\n");
|
|
|
|
DEBUG (std::cerr << "copy0MBB is at " << (void*)copy0MBB << "\n");
|
|
|
|
DEBUG (std::cerr << "sinkMBB is at " << (void*)sinkMBB << "\n");
|
|
|
|
|
|
|
|
// copy1MBB:
|
|
|
|
// %TrueValue = or %G0, 1
|
|
|
|
// ba sinkMBB
|
|
|
|
BB = copy1MBB;
|
|
|
|
unsigned TrueValue = makeAnotherReg (I.getType ());
|
|
|
|
BuildMI (BB, V8::ORri, 2, TrueValue).addReg (V8::G0).addZImm (1);
|
|
|
|
BuildMI (BB, V8::BA, 1).addMBB (sinkMBB);
|
|
|
|
// Update machine-CFG edges
|
|
|
|
BB->addSuccessor (sinkMBB);
|
|
|
|
|
|
|
|
// sinkMBB:
|
|
|
|
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, copy1MBB ]
|
|
|
|
// ...
|
|
|
|
BB = sinkMBB;
|
|
|
|
BuildMI (BB, V8::PHI, 4, DestReg).addReg (FalseValue)
|
|
|
|
.addMBB (copy0MBB).addReg (TrueValue).addMBB (copy1MBB);
|
2004-04-07 05:04:51 +00:00
|
|
|
}
|
|
|
|
|
2004-06-18 05:19:16 +00:00
|
|
|
void V8ISel::visitAllocaInst(AllocaInst &I) {
|
|
|
|
// Find the data size of the alloca inst's getAllocatedType.
|
|
|
|
const Type *Ty = I.getAllocatedType();
|
|
|
|
unsigned TySize = TM.getTargetData().getTypeSize(Ty);
|
2004-04-07 05:04:51 +00:00
|
|
|
|
2004-06-18 05:19:16 +00:00
|
|
|
unsigned ArraySizeReg = getReg (I.getArraySize ());
|
|
|
|
unsigned TySizeReg = getReg (ConstantUInt::get (Type::UIntTy, TySize));
|
|
|
|
unsigned TmpReg1 = makeAnotherReg (Type::UIntTy);
|
|
|
|
unsigned TmpReg2 = makeAnotherReg (Type::UIntTy);
|
|
|
|
unsigned StackAdjReg = makeAnotherReg (Type::UIntTy);
|
|
|
|
|
|
|
|
// StackAdjReg = (ArraySize * TySize) rounded up to nearest doubleword boundary
|
|
|
|
BuildMI (BB, V8::UMULrr, 2, TmpReg1).addReg (ArraySizeReg).addReg (TySizeReg);
|
2004-06-18 08:45:52 +00:00
|
|
|
|
2004-06-18 05:19:16 +00:00
|
|
|
// Round up TmpReg1 to nearest doubleword boundary:
|
|
|
|
BuildMI (BB, V8::ADDri, 2, TmpReg2).addReg (TmpReg1).addSImm (7);
|
|
|
|
BuildMI (BB, V8::ANDri, 2, StackAdjReg).addReg (TmpReg2).addSImm (-8);
|
2004-06-18 08:45:52 +00:00
|
|
|
|
|
|
|
// Subtract size from stack pointer, thereby allocating some space.
|
2004-06-18 05:19:16 +00:00
|
|
|
BuildMI (BB, V8::SUBrr, 2, V8::SP).addReg (V8::SP).addReg (StackAdjReg);
|
2004-06-18 08:45:52 +00:00
|
|
|
|
|
|
|
// Put a pointer to the space into the result register, by copying
|
|
|
|
// the stack pointer.
|
|
|
|
BuildMI (BB, V8::ADDri, 2, getReg(I)).addReg (V8::SP).addSImm (96);
|
|
|
|
|
|
|
|
// Inform the Frame Information that we have just allocated a variable-sized
|
|
|
|
// object.
|
|
|
|
F->getFrameInfo()->CreateVariableSizedObject();
|
2004-06-18 05:19:16 +00:00
|
|
|
}
|
2004-02-29 00:27:00 +00:00
|
|
|
|
|
|
|
/// LowerUnknownIntrinsicFunctionCalls - This performs a prepass over the
|
|
|
|
/// function, lowering any calls to unknown intrinsic functions into the
|
|
|
|
/// equivalent LLVM code.
|
|
|
|
void V8ISel::LowerUnknownIntrinsicFunctionCalls(Function &F) {
|
|
|
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
|
|
|
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; )
|
|
|
|
if (CallInst *CI = dyn_cast<CallInst>(I++))
|
|
|
|
if (Function *F = CI->getCalledFunction())
|
|
|
|
switch (F->getIntrinsicID()) {
|
|
|
|
case Intrinsic::not_intrinsic: break;
|
|
|
|
default:
|
|
|
|
// All other intrinsic calls we must lower.
|
|
|
|
Instruction *Before = CI->getPrev();
|
|
|
|
TM.getIntrinsicLowering().LowerIntrinsicCall(CI);
|
|
|
|
if (Before) { // Move iterator to instruction after call
|
|
|
|
I = Before; ++I;
|
|
|
|
} else {
|
|
|
|
I = BB->begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void V8ISel::visitIntrinsicCall(Intrinsic::ID ID, CallInst &CI) {
|
|
|
|
unsigned TmpReg1, TmpReg2;
|
|
|
|
switch (ID) {
|
|
|
|
default: assert(0 && "Intrinsic not supported!");
|
|
|
|
}
|
|
|
|
}
|