2007-12-30 04:40:25 +00:00
|
|
|
//===-- llvm/CodeGen/MachineOperand.h - MachineOperand class ----*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the declaration of the MachineOperand class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MACHINEOPERAND_H
|
|
|
|
#define LLVM_CODEGEN_MACHINEOPERAND_H
|
|
|
|
|
2010-11-29 18:16:10 +00:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2007-12-30 04:40:25 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace llvm {
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2009-10-30 00:20:08 +00:00
|
|
|
class BlockAddress;
|
2010-03-03 01:37:50 +00:00
|
|
|
class ConstantFP;
|
2007-12-30 04:40:25 +00:00
|
|
|
class GlobalValue;
|
2010-03-03 01:37:50 +00:00
|
|
|
class MachineBasicBlock;
|
2007-12-30 21:56:09 +00:00
|
|
|
class MachineInstr;
|
2008-01-01 01:12:31 +00:00
|
|
|
class MachineRegisterInfo;
|
2010-01-12 02:01:53 +00:00
|
|
|
class MDNode;
|
2010-03-03 01:37:50 +00:00
|
|
|
class TargetMachine;
|
2010-05-28 18:18:53 +00:00
|
|
|
class TargetRegisterInfo;
|
2008-08-21 00:14:44 +00:00
|
|
|
class raw_ostream;
|
2010-03-13 08:14:18 +00:00
|
|
|
class MCSymbol;
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
/// MachineOperand class - Representation of each machine instruction operand.
|
|
|
|
///
|
|
|
|
class MachineOperand {
|
|
|
|
public:
|
|
|
|
enum MachineOperandType {
|
2009-06-21 01:52:00 +00:00
|
|
|
MO_Register, ///< Register operand.
|
|
|
|
MO_Immediate, ///< Immediate operand
|
|
|
|
MO_FPImmediate, ///< Floating-point immediate operand
|
|
|
|
MO_MachineBasicBlock, ///< MachineBasicBlock reference
|
|
|
|
MO_FrameIndex, ///< Abstract Stack Frame Index
|
|
|
|
MO_ConstantPoolIndex, ///< Address of indexed Constant in Constant Pool
|
|
|
|
MO_JumpTableIndex, ///< Address of indexed Jump Table for switch
|
|
|
|
MO_ExternalSymbol, ///< Name of external global symbol
|
2009-07-01 19:08:07 +00:00
|
|
|
MO_GlobalAddress, ///< Address of a global value
|
2010-01-12 02:01:53 +00:00
|
|
|
MO_BlockAddress, ///< Address of a basic block
|
2010-03-13 08:14:18 +00:00
|
|
|
MO_Metadata, ///< Metadata reference (for debug info)
|
|
|
|
MO_MCSymbol ///< MCSymbol reference (for debug/eh info)
|
2007-12-30 04:40:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2007-12-30 22:24:06 +00:00
|
|
|
/// OpKind - Specify what kind of operand this is. This discriminates the
|
|
|
|
/// union.
|
2009-06-24 17:54:48 +00:00
|
|
|
unsigned char OpKind; // MachineOperandType
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2009-06-24 17:54:48 +00:00
|
|
|
/// SubReg - Subregister number, only valid for MO_Register. A value of 0
|
|
|
|
/// indicates the MO_Register has no subReg.
|
|
|
|
unsigned char SubReg;
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2009-06-24 17:54:48 +00:00
|
|
|
/// TargetFlags - This is a set of target-specific operand flags.
|
|
|
|
unsigned char TargetFlags;
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 22:24:06 +00:00
|
|
|
/// IsDef/IsImp/IsKill/IsDead flags - These are only valid for MO_Register
|
|
|
|
/// operands.
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 22:24:06 +00:00
|
|
|
/// IsDef - True if this is a def, false if this is a use of the register.
|
|
|
|
///
|
|
|
|
bool IsDef : 1;
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 22:24:06 +00:00
|
|
|
/// IsImp - True if this is an implicit def or use, false if it is explicit.
|
|
|
|
///
|
|
|
|
bool IsImp : 1;
|
2007-12-30 04:40:25 +00:00
|
|
|
|
2007-12-30 22:24:06 +00:00
|
|
|
/// IsKill - True if this instruction is the last use of the register on this
|
|
|
|
/// path through the function. This is only valid on uses of registers.
|
|
|
|
bool IsKill : 1;
|
|
|
|
|
|
|
|
/// IsDead - True if this register is never used by a subsequent instruction.
|
|
|
|
/// This is only valid on definitions of registers.
|
|
|
|
bool IsDead : 1;
|
2007-12-30 21:31:53 +00:00
|
|
|
|
2009-06-30 08:49:04 +00:00
|
|
|
/// IsUndef - True if this is a register def / use of "undef", i.e. register
|
|
|
|
/// defined by an IMPLICIT_DEF. This is only valid on registers.
|
|
|
|
bool IsUndef : 1;
|
|
|
|
|
2008-09-21 23:30:17 +00:00
|
|
|
/// IsEarlyClobber - True if this MO_Register 'def' operand is written to
|
|
|
|
/// by the MachineInstr before all input registers are read. This is used to
|
|
|
|
/// model the GCC inline asm '&' constraint modifier.
|
2008-09-12 17:49:03 +00:00
|
|
|
bool IsEarlyClobber : 1;
|
|
|
|
|
2010-02-06 02:28:32 +00:00
|
|
|
/// IsDebug - True if this MO_Register 'use' operand is in a debug pseudo,
|
|
|
|
/// not a real instruction. Such uses should be ignored during codegen.
|
|
|
|
bool IsDebug : 1;
|
|
|
|
|
2010-10-19 20:56:32 +00:00
|
|
|
/// SmallContents - Thisreally should be part of the Contents union, but lives
|
|
|
|
/// out here so we can get a better packed struct.
|
|
|
|
/// MO_Register: Register number.
|
|
|
|
/// OffsetedInfo: Low bits of offset.
|
|
|
|
union {
|
|
|
|
unsigned RegNo; // For MO_Register.
|
|
|
|
unsigned OffsetLo; // Matches Contents.OffsetedInfo.OffsetHi.
|
|
|
|
} SmallContents;
|
|
|
|
|
2010-09-15 16:08:15 +00:00
|
|
|
/// ParentMI - This is the instruction that this operand is embedded into.
|
2007-12-30 22:24:06 +00:00
|
|
|
/// This is valid for all operand types, when the operand is in an instr.
|
|
|
|
MachineInstr *ParentMI;
|
2007-12-30 04:40:25 +00:00
|
|
|
|
2007-12-30 22:24:06 +00:00
|
|
|
/// Contents union - This contains the payload for the various operand types.
|
|
|
|
union {
|
|
|
|
MachineBasicBlock *MBB; // For MO_MachineBasicBlock.
|
2008-09-12 18:08:03 +00:00
|
|
|
const ConstantFP *CFP; // For MO_FPImmediate.
|
2007-12-30 22:24:06 +00:00
|
|
|
int64_t ImmVal; // For MO_Immediate.
|
2010-02-26 19:39:56 +00:00
|
|
|
const MDNode *MD; // For MO_Metadata.
|
2010-03-13 08:14:18 +00:00
|
|
|
MCSymbol *Sym; // For MO_MCSymbol
|
2008-01-01 01:12:31 +00:00
|
|
|
|
|
|
|
struct { // For MO_Register.
|
2010-10-19 20:56:32 +00:00
|
|
|
// Register number is in SmallContents.RegNo.
|
2008-01-01 01:12:31 +00:00
|
|
|
MachineOperand **Prev; // Access list for register.
|
|
|
|
MachineOperand *Next;
|
|
|
|
} Reg;
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 22:24:06 +00:00
|
|
|
/// OffsetedInfo - This struct contains the offset and an object identifier.
|
|
|
|
/// this represent the object as with an optional offset from it.
|
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
int Index; // For MO_*Index - The index itself.
|
|
|
|
const char *SymbolName; // For MO_ExternalSymbol.
|
2010-04-15 01:51:59 +00:00
|
|
|
const GlobalValue *GV; // For MO_GlobalAddress.
|
|
|
|
const BlockAddress *BA; // For MO_BlockAddress.
|
2007-12-30 22:24:06 +00:00
|
|
|
} Val;
|
2010-10-19 20:56:32 +00:00
|
|
|
// Low bits of offset are in SmallContents.OffsetLo.
|
|
|
|
int OffsetHi; // An offset from the object, high 32 bits.
|
2007-12-30 22:24:06 +00:00
|
|
|
} OffsetedInfo;
|
|
|
|
} Contents;
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2009-06-24 17:54:48 +00:00
|
|
|
explicit MachineOperand(MachineOperandType K) : OpKind(K), ParentMI(0) {
|
|
|
|
TargetFlags = 0;
|
|
|
|
}
|
2007-12-30 04:40:25 +00:00
|
|
|
public:
|
|
|
|
/// getType - Returns the MachineOperandType for this operand.
|
|
|
|
///
|
2009-06-24 17:54:48 +00:00
|
|
|
MachineOperandType getType() const { return (MachineOperandType)OpKind; }
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2009-06-24 17:54:48 +00:00
|
|
|
unsigned char getTargetFlags() const { return TargetFlags; }
|
|
|
|
void setTargetFlags(unsigned char F) { TargetFlags = F; }
|
|
|
|
void addTargetFlag(unsigned char F) { TargetFlags |= F; }
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
|
2007-12-30 21:31:53 +00:00
|
|
|
/// getParent - Return the instruction that this operand belongs to.
|
|
|
|
///
|
|
|
|
MachineInstr *getParent() { return ParentMI; }
|
|
|
|
const MachineInstr *getParent() const { return ParentMI; }
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2011-01-09 05:33:21 +00:00
|
|
|
/// clearParent - Reset the parent pointer.
|
|
|
|
///
|
|
|
|
/// The MachineOperand copy constructor also copies ParentMI, expecting the
|
|
|
|
/// original to be deleted. If a MachineOperand is ever stored outside a
|
|
|
|
/// MachineInstr, the parent pointer must be cleared.
|
|
|
|
///
|
|
|
|
/// Never call clearParent() on an operand in a MachineInstr.
|
|
|
|
///
|
|
|
|
void clearParent() { ParentMI = 0; }
|
|
|
|
|
2008-08-21 00:14:44 +00:00
|
|
|
void print(raw_ostream &os, const TargetMachine *TM = 0) const;
|
2007-12-30 21:56:09 +00:00
|
|
|
|
2008-10-03 15:45:36 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Accessors that tell you what kind of MachineOperand you're looking at.
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// isReg - Tests if this is a MO_Register operand.
|
|
|
|
bool isReg() const { return OpKind == MO_Register; }
|
|
|
|
/// isImm - Tests if this is a MO_Immediate operand.
|
|
|
|
bool isImm() const { return OpKind == MO_Immediate; }
|
|
|
|
/// isFPImm - Tests if this is a MO_FPImmediate operand.
|
|
|
|
bool isFPImm() const { return OpKind == MO_FPImmediate; }
|
|
|
|
/// isMBB - Tests if this is a MO_MachineBasicBlock operand.
|
|
|
|
bool isMBB() const { return OpKind == MO_MachineBasicBlock; }
|
|
|
|
/// isFI - Tests if this is a MO_FrameIndex operand.
|
|
|
|
bool isFI() const { return OpKind == MO_FrameIndex; }
|
|
|
|
/// isCPI - Tests if this is a MO_ConstantPoolIndex operand.
|
|
|
|
bool isCPI() const { return OpKind == MO_ConstantPoolIndex; }
|
|
|
|
/// isJTI - Tests if this is a MO_JumpTableIndex operand.
|
|
|
|
bool isJTI() const { return OpKind == MO_JumpTableIndex; }
|
|
|
|
/// isGlobal - Tests if this is a MO_GlobalAddress operand.
|
|
|
|
bool isGlobal() const { return OpKind == MO_GlobalAddress; }
|
|
|
|
/// isSymbol - Tests if this is a MO_ExternalSymbol operand.
|
|
|
|
bool isSymbol() const { return OpKind == MO_ExternalSymbol; }
|
2009-10-30 00:20:08 +00:00
|
|
|
/// isBlockAddress - Tests if this is a MO_BlockAddress operand.
|
|
|
|
bool isBlockAddress() const { return OpKind == MO_BlockAddress; }
|
2010-01-12 02:01:53 +00:00
|
|
|
/// isMetadata - Tests if this is a MO_Metadata operand.
|
|
|
|
bool isMetadata() const { return OpKind == MO_Metadata; }
|
2010-03-13 08:14:18 +00:00
|
|
|
bool isMCSymbol() const { return OpKind == MO_MCSymbol; }
|
2007-12-30 04:40:25 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Accessors for Register Operands
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getReg - Returns the register number.
|
|
|
|
unsigned getReg() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "This is not a register operand!");
|
2010-10-19 20:56:32 +00:00
|
|
|
return SmallContents.RegNo;
|
2007-12-30 21:56:09 +00:00
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
unsigned getSubReg() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
return (unsigned)SubReg;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
|
|
|
bool isUse() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
return !IsDef;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
bool isDef() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
return IsDef;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
|
|
|
bool isImplicit() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
return IsImp;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
bool isDead() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
return IsDead;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
bool isKill() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
return IsKill;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2009-06-30 08:49:04 +00:00
|
|
|
bool isUndef() const {
|
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
|
|
|
return IsUndef;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2008-09-12 17:49:03 +00:00
|
|
|
bool isEarlyClobber() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2008-09-12 17:49:03 +00:00
|
|
|
return IsEarlyClobber;
|
|
|
|
}
|
|
|
|
|
2010-02-06 02:28:32 +00:00
|
|
|
bool isDebug() const {
|
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
|
|
|
return IsDebug;
|
|
|
|
}
|
|
|
|
|
2008-01-01 02:55:32 +00:00
|
|
|
/// getNextOperandForReg - Return the next MachineOperand in the function that
|
|
|
|
/// uses or defines this register.
|
|
|
|
MachineOperand *getNextOperandForReg() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "This is not a register operand!");
|
2008-01-01 02:55:32 +00:00
|
|
|
return Contents.Reg.Next;
|
|
|
|
}
|
2007-12-30 21:56:09 +00:00
|
|
|
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Mutators for Register Operands
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2008-01-01 01:12:31 +00:00
|
|
|
/// Change the register this operand corresponds to.
|
|
|
|
///
|
|
|
|
void setReg(unsigned Reg);
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
void setSubReg(unsigned subReg) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
SubReg = (unsigned char)subReg;
|
|
|
|
}
|
2010-05-28 18:18:53 +00:00
|
|
|
|
|
|
|
/// substVirtReg - Substitute the current register with the virtual
|
|
|
|
/// subregister Reg:SubReg. Take any existing SubReg index into account,
|
|
|
|
/// using TargetRegisterInfo to compose the subreg indices if necessary.
|
|
|
|
/// Reg must be a virtual register, SubIdx can be 0.
|
|
|
|
///
|
|
|
|
void substVirtReg(unsigned Reg, unsigned SubIdx, const TargetRegisterInfo&);
|
|
|
|
|
|
|
|
/// substPhysReg - Substitute the current register with the physical register
|
|
|
|
/// Reg, taking any existing SubReg into account. For instance,
|
|
|
|
/// substPhysReg(%EAX) will change %reg1024:sub_8bit to %AL.
|
|
|
|
///
|
|
|
|
void substPhysReg(unsigned Reg, const TargetRegisterInfo&);
|
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
void setIsUse(bool Val = true) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2010-02-09 00:42:08 +00:00
|
|
|
assert((Val || !isDebug()) && "Marking a debug operation as def");
|
2007-12-30 21:56:09 +00:00
|
|
|
IsDef = !Val;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
void setIsDef(bool Val = true) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2010-02-09 00:42:08 +00:00
|
|
|
assert((!Val || !isDebug()) && "Marking a debug operation as def");
|
2007-12-30 21:56:09 +00:00
|
|
|
IsDef = Val;
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:08:15 +00:00
|
|
|
void setImplicit(bool Val = true) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
IsImp = Val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIsKill(bool Val = true) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && !IsDef && "Wrong MachineOperand accessor");
|
2010-02-09 00:42:08 +00:00
|
|
|
assert((!Val || !isDebug()) && "Marking a debug operation as kill");
|
2007-12-30 21:56:09 +00:00
|
|
|
IsKill = Val;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
void setIsDead(bool Val = true) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && IsDef && "Wrong MachineOperand accessor");
|
2007-12-30 21:56:09 +00:00
|
|
|
IsDead = Val;
|
|
|
|
}
|
|
|
|
|
2009-06-30 08:49:04 +00:00
|
|
|
void setIsUndef(bool Val = true) {
|
|
|
|
assert(isReg() && "Wrong MachineOperand accessor");
|
|
|
|
IsUndef = Val;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2008-09-12 17:49:03 +00:00
|
|
|
void setIsEarlyClobber(bool Val = true) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && IsDef && "Wrong MachineOperand accessor");
|
2008-09-12 17:49:03 +00:00
|
|
|
IsEarlyClobber = Val;
|
|
|
|
}
|
2007-12-30 21:56:09 +00:00
|
|
|
|
2010-03-25 01:38:16 +00:00
|
|
|
void setIsDebug(bool Val = true) {
|
|
|
|
assert(isReg() && IsDef && "Wrong MachineOperand accessor");
|
|
|
|
IsDebug = Val;
|
|
|
|
}
|
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Accessors for various operand types.
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
int64_t getImm() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isImm() && "Wrong MachineOperand accessor");
|
2007-12-30 22:24:06 +00:00
|
|
|
return Contents.ImmVal;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2008-09-12 18:08:03 +00:00
|
|
|
const ConstantFP *getFPImm() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isFPImm() && "Wrong MachineOperand accessor");
|
2008-02-14 07:39:30 +00:00
|
|
|
return Contents.CFP;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
MachineBasicBlock *getMBB() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isMBB() && "Wrong MachineOperand accessor");
|
2007-12-30 22:24:06 +00:00
|
|
|
return Contents.MBB;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2007-12-30 22:24:06 +00:00
|
|
|
|
|
|
|
int getIndex() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert((isFI() || isCPI() || isJTI()) &&
|
2007-12-30 22:24:06 +00:00
|
|
|
"Wrong MachineOperand accessor");
|
|
|
|
return Contents.OffsetedInfo.Val.Index;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const GlobalValue *getGlobal() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isGlobal() && "Wrong MachineOperand accessor");
|
2007-12-30 22:24:06 +00:00
|
|
|
return Contents.OffsetedInfo.Val.GV;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2009-10-30 00:20:08 +00:00
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const BlockAddress *getBlockAddress() const {
|
2009-10-30 00:20:08 +00:00
|
|
|
assert(isBlockAddress() && "Wrong MachineOperand accessor");
|
|
|
|
return Contents.OffsetedInfo.Val.BA;
|
|
|
|
}
|
2010-03-13 08:14:18 +00:00
|
|
|
|
|
|
|
MCSymbol *getMCSymbol() const {
|
|
|
|
assert(isMCSymbol() && "Wrong MachineOperand accessor");
|
|
|
|
return Contents.Sym;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2009-09-03 06:00:00 +00:00
|
|
|
/// getOffset - Return the offset from the symbol in this operand. This always
|
|
|
|
/// returns 0 for ExternalSymbol operands.
|
Teach DAGCombine to fold constant offsets into GlobalAddress nodes,
and add a TargetLowering hook for it to use to determine when this
is legal (i.e. not in PIC mode, etc.)
This allows instruction selection to emit folded constant offsets
in more cases, such as the included testcase, eliminating the need
for explicit arithmetic instructions.
This eliminates the need for the C++ code in X86ISelDAGToDAG.cpp
that attempted to achieve the same effect, but wasn't as effective.
Also, fix handling of offsets in GlobalAddressSDNodes in several
places, including changing GlobalAddressSDNode's offset from
int to int64_t.
The Mips, Alpha, Sparc, and CellSPU targets appear to be
unaware of GlobalAddress offsets currently, so set the hook to
false on those targets.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-10-18 02:06:02 +00:00
|
|
|
int64_t getOffset() const {
|
2009-10-30 00:20:08 +00:00
|
|
|
assert((isGlobal() || isSymbol() || isCPI() || isBlockAddress()) &&
|
2007-12-30 21:56:09 +00:00
|
|
|
"Wrong MachineOperand accessor");
|
2010-10-19 20:56:32 +00:00
|
|
|
return (int64_t(Contents.OffsetedInfo.OffsetHi) << 32) |
|
|
|
|
SmallContents.OffsetLo;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
const char *getSymbolName() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isSymbol() && "Wrong MachineOperand accessor");
|
2007-12-30 22:24:06 +00:00
|
|
|
return Contents.OffsetedInfo.Val.SymbolName;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2010-01-12 02:01:53 +00:00
|
|
|
|
2010-01-13 00:00:24 +00:00
|
|
|
const MDNode *getMetadata() const {
|
2010-01-12 02:01:53 +00:00
|
|
|
assert(isMetadata() && "Wrong MachineOperand accessor");
|
|
|
|
return Contents.MD;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Mutators for various operand types.
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
void setImm(int64_t immVal) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isImm() && "Wrong MachineOperand mutator");
|
2007-12-30 22:24:06 +00:00
|
|
|
Contents.ImmVal = immVal;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
|
|
|
|
Teach DAGCombine to fold constant offsets into GlobalAddress nodes,
and add a TargetLowering hook for it to use to determine when this
is legal (i.e. not in PIC mode, etc.)
This allows instruction selection to emit folded constant offsets
in more cases, such as the included testcase, eliminating the need
for explicit arithmetic instructions.
This eliminates the need for the C++ code in X86ISelDAGToDAG.cpp
that attempted to achieve the same effect, but wasn't as effective.
Also, fix handling of offsets in GlobalAddressSDNodes in several
places, including changing GlobalAddressSDNode's offset from
int to int64_t.
The Mips, Alpha, Sparc, and CellSPU targets appear to be
unaware of GlobalAddress offsets currently, so set the hook to
false on those targets.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-10-18 02:06:02 +00:00
|
|
|
void setOffset(int64_t Offset) {
|
2009-10-30 00:39:25 +00:00
|
|
|
assert((isGlobal() || isSymbol() || isCPI() || isBlockAddress()) &&
|
2007-12-30 04:40:25 +00:00
|
|
|
"Wrong MachineOperand accessor");
|
2010-10-19 20:56:32 +00:00
|
|
|
SmallContents.OffsetLo = unsigned(Offset);
|
|
|
|
Contents.OffsetedInfo.OffsetHi = int(Offset >> 32);
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 22:24:06 +00:00
|
|
|
void setIndex(int Idx) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert((isFI() || isCPI() || isJTI()) &&
|
2007-12-30 22:24:06 +00:00
|
|
|
"Wrong MachineOperand accessor");
|
|
|
|
Contents.OffsetedInfo.Val.Index = Idx;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 23:10:15 +00:00
|
|
|
void setMBB(MachineBasicBlock *MBB) {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isMBB() && "Wrong MachineOperand accessor");
|
2007-12-30 22:24:06 +00:00
|
|
|
Contents.MBB = MBB;
|
2007-12-30 04:40:25 +00:00
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Other methods.
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
/// isIdenticalTo - Return true if this operand is identical to the specified
|
|
|
|
/// operand. Note: This method ignores isKill and isDead properties.
|
|
|
|
bool isIdenticalTo(const MachineOperand &Other) const;
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
/// ChangeToImmediate - Replace this operand with a new immediate operand of
|
|
|
|
/// the specified value. If an operand is known to be an immediate already,
|
2007-12-30 21:31:53 +00:00
|
|
|
/// the setImm method should be used.
|
2008-01-01 01:12:31 +00:00
|
|
|
void ChangeToImmediate(int64_t ImmVal);
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
/// ChangeToRegister - Replace this operand with a new register operand of
|
|
|
|
/// the specified value. If an operand is known to be an register already,
|
|
|
|
/// the setReg method should be used.
|
|
|
|
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp = false,
|
2009-06-30 08:49:04 +00:00
|
|
|
bool isKill = false, bool isDead = false,
|
2010-02-10 00:41:49 +00:00
|
|
|
bool isUndef = false, bool isDebug = false);
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 21:56:09 +00:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Construction methods.
|
|
|
|
//===--------------------------------------------------------------------===//
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
static MachineOperand CreateImm(int64_t Val) {
|
2007-12-30 22:24:06 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_Immediate);
|
|
|
|
Op.setImm(Val);
|
2007-12-30 04:40:25 +00:00
|
|
|
return Op;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2008-09-12 18:08:03 +00:00
|
|
|
static MachineOperand CreateFPImm(const ConstantFP *CFP) {
|
2008-02-14 07:39:30 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_FPImmediate);
|
|
|
|
Op.Contents.CFP = CFP;
|
|
|
|
return Op;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
static MachineOperand CreateReg(unsigned Reg, bool isDef, bool isImp = false,
|
|
|
|
bool isKill = false, bool isDead = false,
|
2009-06-30 08:49:04 +00:00
|
|
|
bool isUndef = false,
|
|
|
|
bool isEarlyClobber = false,
|
2010-02-06 02:28:32 +00:00
|
|
|
unsigned SubReg = 0,
|
|
|
|
bool isDebug = false) {
|
2007-12-30 22:24:06 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_Register);
|
2007-12-30 04:40:25 +00:00
|
|
|
Op.IsDef = isDef;
|
|
|
|
Op.IsImp = isImp;
|
|
|
|
Op.IsKill = isKill;
|
|
|
|
Op.IsDead = isDead;
|
2009-06-30 08:49:04 +00:00
|
|
|
Op.IsUndef = isUndef;
|
2008-09-12 17:49:03 +00:00
|
|
|
Op.IsEarlyClobber = isEarlyClobber;
|
2010-02-06 02:28:32 +00:00
|
|
|
Op.IsDebug = isDebug;
|
2010-10-19 20:56:32 +00:00
|
|
|
Op.SmallContents.RegNo = Reg;
|
2008-01-01 01:12:31 +00:00
|
|
|
Op.Contents.Reg.Prev = 0;
|
|
|
|
Op.Contents.Reg.Next = 0;
|
2007-12-30 21:31:53 +00:00
|
|
|
Op.SubReg = SubReg;
|
2007-12-30 04:40:25 +00:00
|
|
|
return Op;
|
|
|
|
}
|
2009-06-25 01:16:22 +00:00
|
|
|
static MachineOperand CreateMBB(MachineBasicBlock *MBB,
|
|
|
|
unsigned char TargetFlags = 0) {
|
2007-12-30 22:24:06 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_MachineBasicBlock);
|
2007-12-30 23:10:15 +00:00
|
|
|
Op.setMBB(MBB);
|
2009-06-25 01:16:22 +00:00
|
|
|
Op.setTargetFlags(TargetFlags);
|
2007-12-30 04:40:25 +00:00
|
|
|
return Op;
|
|
|
|
}
|
|
|
|
static MachineOperand CreateFI(unsigned Idx) {
|
2007-12-30 22:24:06 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_FrameIndex);
|
|
|
|
Op.setIndex(Idx);
|
2007-12-30 04:40:25 +00:00
|
|
|
return Op;
|
|
|
|
}
|
2009-06-25 01:16:22 +00:00
|
|
|
static MachineOperand CreateCPI(unsigned Idx, int Offset,
|
|
|
|
unsigned char TargetFlags = 0) {
|
2007-12-30 22:24:06 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_ConstantPoolIndex);
|
|
|
|
Op.setIndex(Idx);
|
|
|
|
Op.setOffset(Offset);
|
2009-06-25 01:16:22 +00:00
|
|
|
Op.setTargetFlags(TargetFlags);
|
2007-12-30 04:40:25 +00:00
|
|
|
return Op;
|
|
|
|
}
|
2009-06-25 01:16:22 +00:00
|
|
|
static MachineOperand CreateJTI(unsigned Idx,
|
|
|
|
unsigned char TargetFlags = 0) {
|
2007-12-30 22:24:06 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_JumpTableIndex);
|
|
|
|
Op.setIndex(Idx);
|
2009-06-25 01:16:22 +00:00
|
|
|
Op.setTargetFlags(TargetFlags);
|
2007-12-30 04:40:25 +00:00
|
|
|
return Op;
|
|
|
|
}
|
2010-04-15 01:51:59 +00:00
|
|
|
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset,
|
2009-06-25 01:16:22 +00:00
|
|
|
unsigned char TargetFlags = 0) {
|
2007-12-30 22:24:06 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_GlobalAddress);
|
|
|
|
Op.Contents.OffsetedInfo.Val.GV = GV;
|
|
|
|
Op.setOffset(Offset);
|
2009-06-25 01:16:22 +00:00
|
|
|
Op.setTargetFlags(TargetFlags);
|
2009-07-01 19:08:07 +00:00
|
|
|
return Op;
|
|
|
|
}
|
2009-09-01 22:06:46 +00:00
|
|
|
static MachineOperand CreateES(const char *SymName,
|
2009-06-25 01:16:22 +00:00
|
|
|
unsigned char TargetFlags = 0) {
|
2007-12-30 22:24:06 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_ExternalSymbol);
|
|
|
|
Op.Contents.OffsetedInfo.Val.SymbolName = SymName;
|
2009-09-01 22:06:46 +00:00
|
|
|
Op.setOffset(0); // Offset is always 0.
|
2009-06-25 01:16:22 +00:00
|
|
|
Op.setTargetFlags(TargetFlags);
|
2007-12-30 04:40:25 +00:00
|
|
|
return Op;
|
|
|
|
}
|
2010-04-15 01:51:59 +00:00
|
|
|
static MachineOperand CreateBA(const BlockAddress *BA,
|
2009-11-20 23:18:13 +00:00
|
|
|
unsigned char TargetFlags = 0) {
|
2009-10-30 00:20:08 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_BlockAddress);
|
|
|
|
Op.Contents.OffsetedInfo.Val.BA = BA;
|
|
|
|
Op.setOffset(0); // Offset is always 0.
|
2009-11-20 23:18:13 +00:00
|
|
|
Op.setTargetFlags(TargetFlags);
|
2009-10-30 00:20:08 +00:00
|
|
|
return Op;
|
|
|
|
}
|
2010-02-26 19:39:56 +00:00
|
|
|
static MachineOperand CreateMetadata(const MDNode *Meta) {
|
2010-01-12 02:01:53 +00:00
|
|
|
MachineOperand Op(MachineOperand::MO_Metadata);
|
|
|
|
Op.Contents.MD = Meta;
|
|
|
|
return Op;
|
|
|
|
}
|
2007-12-30 04:40:25 +00:00
|
|
|
|
2010-03-13 08:14:18 +00:00
|
|
|
static MachineOperand CreateMCSymbol(MCSymbol *Sym) {
|
|
|
|
MachineOperand Op(MachineOperand::MO_MCSymbol);
|
|
|
|
Op.Contents.Sym = Sym;
|
|
|
|
return Op;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
friend class MachineInstr;
|
2008-01-01 01:12:31 +00:00
|
|
|
friend class MachineRegisterInfo;
|
|
|
|
private:
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Methods for handling register use/def lists.
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// isOnRegUseList - Return true if this operand is on a register use/def list
|
|
|
|
/// or false if not. This can only be called for register operands that are
|
|
|
|
/// part of a machine instruction.
|
|
|
|
bool isOnRegUseList() const {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(isReg() && "Can only add reg operand to use lists");
|
2008-01-01 01:12:31 +00:00
|
|
|
return Contents.Reg.Prev != 0;
|
|
|
|
}
|
2010-09-15 16:08:15 +00:00
|
|
|
|
2008-01-01 01:12:31 +00:00
|
|
|
/// AddRegOperandToRegInfo - Add this register operand to the specified
|
|
|
|
/// MachineRegisterInfo. If it is null, then the next/prev fields should be
|
|
|
|
/// explicitly nulled out.
|
|
|
|
void AddRegOperandToRegInfo(MachineRegisterInfo *RegInfo);
|
|
|
|
|
2009-04-15 01:17:37 +00:00
|
|
|
/// RemoveRegOperandFromRegInfo - Remove this register operand from the
|
|
|
|
/// MachineRegisterInfo it is linked with.
|
|
|
|
void RemoveRegOperandFromRegInfo();
|
2007-12-30 04:40:25 +00:00
|
|
|
};
|
|
|
|
|
2008-08-21 00:14:44 +00:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const MachineOperand& MO) {
|
|
|
|
MO.print(OS, 0);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2007-12-30 04:40:25 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|