2 //***************************************************************************
9 // 10/15/01 - Vikram Adve - Created
10 //**************************************************************************/
13 #include "SparcInternals.h"
14 #include "SparcInstrSelectionSupport.h"
15 #include "llvm/Target/Sparc.h"
16 #include "llvm/CodeGen/InstrSelection.h"
17 #include "llvm/CodeGen/InstrSelectionSupport.h"
18 #include "llvm/CodeGen/MachineInstr.h"
19 #include "llvm/ConstPoolVals.h"
20 #include "llvm/Type.h"
23 //************************ Internal Functions ******************************/
26 static inline MachineInstr*
27 CreateIntSetInstruction(int64_t C, bool isSigned, Value* dest)
32 minstr = new MachineInstr(SETSW);
33 minstr->SetMachineOperand(0, MachineOperand::MO_SignExtendedImmed, C);
37 minstr = new MachineInstr(SETUW);
38 minstr->SetMachineOperand(0, MachineOperand::MO_UnextendedImmed, C);
41 minstr->SetMachineOperand(1, MachineOperand::MO_VirtualRegister, dest);
46 //************************* External Classes *******************************/
48 //---------------------------------------------------------------------------
49 // class UltraSparcInstrInfo
52 // Information about individual instructions.
53 // Most information is stored in the SparcMachineInstrDesc array above.
54 // Other information is computed on demand, and most such functions
55 // default to member functions in base class MachineInstrInfo.
56 //---------------------------------------------------------------------------
59 UltraSparcInstrInfo::UltraSparcInstrInfo()
60 : MachineInstrInfo(SparcMachineInstrDesc,
61 /*descSize = */ NUM_TOTAL_OPCODES,
62 /*numRealOpCodes = */ NUM_REAL_OPCODES)
67 // Create an instruction sequence to put the constant `val' into
68 // the virtual register `dest'. `val' may be a ConstPoolVal or a
69 // GlobalValue, viz., the constant address of a global variable or function.
70 // The generated instructions are returned in `minstrVec'.
71 // Any temp. registers (TmpInstruction) created are returned in `tempVec'.
74 UltraSparcInstrInfo::CreateCodeToLoadConst(Value* val,
76 vector<MachineInstr*>& minstrVec,
77 vector<TmpInstruction*>& tempVec) const
81 assert(isa<ConstPoolVal>(val) || isa<GlobalValue>(val) &&
82 "I only know about constant values and global addresses");
84 // Use a "set" instruction for known constants that can go in an integer reg.
85 // Use a "load" instruction for all other constants, in particular,
86 // floating point constants and addresses of globals.
88 const Type* valType = val->getType();
90 if (valType->isIntegral() || valType == Type::BoolTy)
93 int64_t C = GetConstantValueAsSignedInt(val, isValidConstant);
94 assert(isValidConstant && "Unrecognized constant");
95 minstr = CreateIntSetInstruction(C, valType->isSigned(), dest);
96 minstrVec.push_back(minstr);
100 // Make an instruction sequence to load the constant, viz:
101 // SETSW <addr-of-constant>, addrReg
102 // LOAD /*addr*/ addrReg, /*offset*/ 0, dest
103 // Only the SETSW is needed if `val' is a GlobalValue, i.e,. it is
104 // itself a constant address. Otherwise, both are needed.
107 int64_t zeroOffset = 0; // to avoid ambiguity with (Value*) 0
109 if (isa<ConstPoolVal>(val))
111 // Create another TmpInstruction for the hidden integer register
112 TmpInstruction* addrReg =
113 new TmpInstruction(Instruction::UserOp1, val, NULL);
114 tempVec.push_back(addrReg);
120 minstr = new MachineInstr(SETUW);
121 minstr->SetMachineOperand(0, MachineOperand::MO_PCRelativeDisp, val);
122 minstr->SetMachineOperand(1, MachineOperand::MO_VirtualRegister,addrVal);
123 minstrVec.push_back(minstr);
125 if (isa<ConstPoolVal>(val))
127 // addrVal->addMachineInstruction(minstr);
129 minstr = new MachineInstr(ChooseLoadInstruction(val->getType()));
130 minstr->SetMachineOperand(0, MachineOperand::MO_VirtualRegister,
132 minstr->SetMachineOperand(1, MachineOperand::MO_SignExtendedImmed,
134 minstr->SetMachineOperand(2, MachineOperand::MO_VirtualRegister,
136 minstrVec.push_back(minstr);
142 //************************ External Functions ******************************/