Support a new type of MachineOperand, MO_FPImmediate, used for holding

FP Immediates, crazily enough

llvm-svn: 47117
This commit is contained in:
Nate Begeman 2008-02-14 07:39:30 +00:00
parent 5005b4d0d8
commit 8352abdd98
2 changed files with 25 additions and 0 deletions

View File

@ -21,6 +21,7 @@
namespace llvm { namespace llvm {
class ConstantFP;
class MachineBasicBlock; class MachineBasicBlock;
class GlobalValue; class GlobalValue;
class MachineInstr; class MachineInstr;
@ -34,6 +35,7 @@ public:
enum MachineOperandType { enum MachineOperandType {
MO_Register, // Register operand. MO_Register, // Register operand.
MO_Immediate, // Immediate Operand MO_Immediate, // Immediate Operand
MO_FPImmediate,
MO_MachineBasicBlock, // MachineBasicBlock reference MO_MachineBasicBlock, // MachineBasicBlock reference
MO_FrameIndex, // Abstract Stack Frame Index MO_FrameIndex, // Abstract Stack Frame Index
MO_ConstantPoolIndex, // Address of indexed Constant in Constant Pool MO_ConstantPoolIndex, // Address of indexed Constant in Constant Pool
@ -77,6 +79,7 @@ private:
/// Contents union - This contains the payload for the various operand types. /// Contents union - This contains the payload for the various operand types.
union { union {
MachineBasicBlock *MBB; // For MO_MachineBasicBlock. MachineBasicBlock *MBB; // For MO_MachineBasicBlock.
ConstantFP *CFP; // For MO_FPImmediate.
int64_t ImmVal; // For MO_Immediate. int64_t ImmVal; // For MO_Immediate.
struct { // For MO_Register. struct { // For MO_Register.
@ -120,6 +123,7 @@ public:
/// ///
bool isRegister() const { return OpKind == MO_Register; } bool isRegister() const { return OpKind == MO_Register; }
bool isImmediate() const { return OpKind == MO_Immediate; } bool isImmediate() const { return OpKind == MO_Immediate; }
bool isFPImmediate() const { return OpKind == MO_FPImmediate; }
bool isMachineBasicBlock() const { return OpKind == MO_MachineBasicBlock; } bool isMachineBasicBlock() const { return OpKind == MO_MachineBasicBlock; }
bool isFrameIndex() const { return OpKind == MO_FrameIndex; } bool isFrameIndex() const { return OpKind == MO_FrameIndex; }
bool isConstantPoolIndex() const { return OpKind == MO_ConstantPoolIndex; } bool isConstantPoolIndex() const { return OpKind == MO_ConstantPoolIndex; }
@ -231,6 +235,11 @@ public:
return Contents.ImmVal; return Contents.ImmVal;
} }
ConstantFP *getFPImm() const {
assert(isFPImmediate() && "Wrong MachineOperand accessor");
return Contents.CFP;
}
MachineBasicBlock *getMBB() const { MachineBasicBlock *getMBB() const {
assert(isMachineBasicBlock() && "Wrong MachineOperand accessor"); assert(isMachineBasicBlock() && "Wrong MachineOperand accessor");
return Contents.MBB; return Contents.MBB;
@ -313,6 +322,12 @@ public:
return Op; return Op;
} }
static MachineOperand CreateFPImm(ConstantFP *CFP) {
MachineOperand Op(MachineOperand::MO_FPImmediate);
Op.Contents.CFP = CFP;
return Op;
}
static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false, static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false,
bool isKill = false, bool isDead = false, bool isKill = false, bool isDead = false,
unsigned SubReg = 0) { unsigned SubReg = 0) {

View File

@ -11,6 +11,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Constants.h"
#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstr.h"
#include "llvm/Value.h" #include "llvm/Value.h"
#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunction.h"
@ -138,6 +139,8 @@ bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
getSubReg() == Other.getSubReg(); getSubReg() == Other.getSubReg();
case MachineOperand::MO_Immediate: case MachineOperand::MO_Immediate:
return getImm() == Other.getImm(); return getImm() == Other.getImm();
case MachineOperand::MO_FPImmediate:
return getFPImm() == Other.getFPImm();
case MachineOperand::MO_MachineBasicBlock: case MachineOperand::MO_MachineBasicBlock:
return getMBB() == Other.getMBB(); return getMBB() == Other.getMBB();
case MachineOperand::MO_FrameIndex: case MachineOperand::MO_FrameIndex:
@ -197,6 +200,13 @@ void MachineOperand::print(std::ostream &OS, const TargetMachine *TM) const {
case MachineOperand::MO_Immediate: case MachineOperand::MO_Immediate:
OS << getImm(); OS << getImm();
break; break;
case MachineOperand::MO_FPImmediate:
if (getFPImm()->getType() == Type::FloatTy) {
OS << getFPImm()->getValueAPF().convertToFloat();
} else {
OS << getFPImm()->getValueAPF().convertToDouble();
}
break;
case MachineOperand::MO_MachineBasicBlock: case MachineOperand::MO_MachineBasicBlock:
OS << "mbb<" OS << "mbb<"
<< ((Value*)getMBB()->getBasicBlock())->getName() << ((Value*)getMBB()->getBasicBlock())->getName()