blob: 39d6dcc6a15aac75082aa1725048b49c79c4bc50 [file] [log] [blame]
Chris Lattner035dfbe2002-08-09 20:08:06 +00001//===-- SparcInstrInfo.cpp ------------------------------------------------===//
2//
3//===----------------------------------------------------------------------===//
Vikram S. Adve30764b82001-10-18 00:01:48 +00004
5#include "SparcInternals.h"
6#include "SparcInstrSelectionSupport.h"
Vikram S. Adve30764b82001-10-18 00:01:48 +00007#include "llvm/CodeGen/InstrSelection.h"
8#include "llvm/CodeGen/InstrSelectionSupport.h"
Misha Brukmanfce11432002-10-28 00:28:31 +00009#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner2ef9a6a2002-12-28 20:18:21 +000010#include "llvm/CodeGen/MachineFunctionInfo.h"
Vikram S. Adve242a8082002-05-19 15:25:51 +000011#include "llvm/CodeGen/MachineCodeForInstruction.h"
Chris Lattnere5b1ed92003-01-15 00:03:28 +000012#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattner2fbfdcf2002-04-07 20:49:59 +000013#include "llvm/Function.h"
Chris Lattner31bcdb82002-04-28 19:55:58 +000014#include "llvm/Constants.h"
Vikram S. Adveb9c38632001-11-08 04:57:53 +000015#include "llvm/DerivedTypes.h"
John Criswell7a73b802003-06-30 21:59:07 +000016#include "Config/stdlib.h"
Vikram S. Adve30764b82001-10-18 00:01:48 +000017
Vikram S. Adve53fd4002002-07-10 21:39:50 +000018static const uint32_t MAXLO = (1 << 10) - 1; // set bits set by %lo(*)
19static const uint32_t MAXSIMM = (1 << 12) - 1; // set bits in simm13 field of OR
20
21
Chris Lattner795ba6c2003-01-15 21:36:50 +000022//---------------------------------------------------------------------------
23// Function GetConstantValueAsUnsignedInt
24// Function GetConstantValueAsSignedInt
25//
26// Convenience functions to get the value of an integral constant, for an
27// appropriate integer or non-integer type that can be held in a signed
28// or unsigned integer respectively. The type of the argument must be
29// the following:
30// Signed or unsigned integer
31// Boolean
32// Pointer
33//
34// isValidConstant is set to true if a valid constant was found.
35//---------------------------------------------------------------------------
36
37static uint64_t
38GetConstantValueAsUnsignedInt(const Value *V,
39 bool &isValidConstant)
40{
41 isValidConstant = true;
42
43 if (isa<Constant>(V))
44 if (const ConstantBool *CB = dyn_cast<ConstantBool>(V))
45 return (int64_t)CB->getValue();
Chris Lattnerc07736a2003-07-23 15:22:26 +000046 else if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
47 return CI->getRawValue();
Chris Lattner795ba6c2003-01-15 21:36:50 +000048
49 isValidConstant = false;
50 return 0;
51}
52
53int64_t
54GetConstantValueAsSignedInt(const Value *V, bool &isValidConstant)
55{
56 uint64_t C = GetConstantValueAsUnsignedInt(V, isValidConstant);
57 if (isValidConstant) {
58 if (V->getType()->isSigned() || C < INT64_MAX) // safe to cast to signed
59 return (int64_t) C;
60 else
61 isValidConstant = false;
62 }
63 return 0;
64}
65
66
Vikram S. Adve6c0c3012002-08-13 18:04:08 +000067//----------------------------------------------------------------------------
68// Function: CreateSETUWConst
Vikram S. Adve53fd4002002-07-10 21:39:50 +000069//
Vikram S. Adve6c0c3012002-08-13 18:04:08 +000070// Set a 32-bit unsigned constant in the register `dest', using
71// SETHI, OR in the worst case. This function correctly emulates
72// the SETUW pseudo-op for SPARC v9 (if argument isSigned == false).
73//
74// The isSigned=true case is used to implement SETSW without duplicating code.
75//
76// Optimize some common cases:
77// (1) Small value that fits in simm13 field of OR: don't need SETHI.
78// (2) isSigned = true and C is a small negative signed value, i.e.,
79// high bits are 1, and the remaining bits fit in simm13(OR).
80//----------------------------------------------------------------------------
81
Vikram S. Adve53fd4002002-07-10 21:39:50 +000082static inline void
83CreateSETUWConst(const TargetMachine& target, uint32_t C,
Misha Brukmana98cd452003-05-20 20:32:24 +000084 Instruction* dest, std::vector<MachineInstr*>& mvec,
Vikram S. Adve6c0c3012002-08-13 18:04:08 +000085 bool isSigned = false)
Vikram S. Adve53fd4002002-07-10 21:39:50 +000086{
87 MachineInstr *miSETHI = NULL, *miOR = NULL;
Vikram S. Adve6c0c3012002-08-13 18:04:08 +000088
Vikram S. Adve53fd4002002-07-10 21:39:50 +000089 // In order to get efficient code, we should not generate the SETHI if
90 // all high bits are 1 (i.e., this is a small signed value that fits in
91 // the simm13 field of OR). So we check for and handle that case specially.
92 // NOTE: The value C = 0x80000000 is bad: sC < 0 *and* -sC < 0.
93 // In fact, sC == -sC, so we have to check for this explicitly.
94 int32_t sC = (int32_t) C;
Vikram S. Adve6c0c3012002-08-13 18:04:08 +000095 bool smallNegValue =isSigned && sC < 0 && sC != -sC && -sC < (int32_t)MAXSIMM;
96
Vikram S. Adve53fd4002002-07-10 21:39:50 +000097 // Set the high 22 bits in dest if non-zero and simm13 field of OR not enough
Misha Brukman81b06862003-05-21 18:48:06 +000098 if (!smallNegValue && (C & ~MAXLO) && C > MAXSIMM) {
99 miSETHI = BuildMI(V9::SETHI, 2).addZImm(C).addRegDef(dest);
100 miSETHI->setOperandHi32(0);
101 mvec.push_back(miSETHI);
102 }
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000103
104 // Set the low 10 or 12 bits in dest. This is necessary if no SETHI
105 // was generated, or if the low 10 bits are non-zero.
Misha Brukman81b06862003-05-21 18:48:06 +0000106 if (miSETHI==NULL || C & MAXLO) {
107 if (miSETHI) {
108 // unsigned value with high-order bits set using SETHI
Misha Brukman71ed1c92003-05-27 22:35:43 +0000109 miOR = BuildMI(V9::ORi,3).addReg(dest).addZImm(C).addRegDef(dest);
Misha Brukman81b06862003-05-21 18:48:06 +0000110 miOR->setOperandLo32(1);
111 } else {
112 // unsigned or small signed value that fits in simm13 field of OR
113 assert(smallNegValue || (C & ~MAXSIMM) == 0);
Misha Brukman71ed1c92003-05-27 22:35:43 +0000114 miOR = BuildMI(V9::ORi, 3).addMReg(target.getRegInfo()
Misha Brukman81b06862003-05-21 18:48:06 +0000115 .getZeroRegNum())
116 .addSImm(sC).addRegDef(dest);
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000117 }
Misha Brukman81b06862003-05-21 18:48:06 +0000118 mvec.push_back(miOR);
119 }
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000120
121 assert((miSETHI || miOR) && "Oops, no code was generated!");
122}
123
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000124
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000125//----------------------------------------------------------------------------
126// Function: CreateSETSWConst
127//
128// Set a 32-bit signed constant in the register `dest', with sign-extension
129// to 64 bits. This uses SETHI, OR, SRA in the worst case.
130// This function correctly emulates the SETSW pseudo-op for SPARC v9.
131//
132// Optimize the same cases as SETUWConst, plus:
133// (1) SRA is not needed for positive or small negative values.
134//----------------------------------------------------------------------------
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000135
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000136static inline void
137CreateSETSWConst(const TargetMachine& target, int32_t C,
Misha Brukmana98cd452003-05-20 20:32:24 +0000138 Instruction* dest, std::vector<MachineInstr*>& mvec)
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000139{
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000140 // Set the low 32 bits of dest
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000141 CreateSETUWConst(target, (uint32_t) C, dest, mvec, /*isSigned*/true);
142
Vikram S. Advec2f09392003-05-25 21:58:11 +0000143 // Sign-extend to the high 32 bits if needed.
144 // NOTE: The value C = 0x80000000 is bad: -C == C and so -C is < MAXSIMM
145 if (C < 0 && (C == -C || -C > (int32_t) MAXSIMM))
Misha Brukmand36e30e2003-06-06 09:52:23 +0000146 mvec.push_back(BuildMI(V9::SRAi5,3).addReg(dest).addZImm(0).addRegDef(dest));
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000147}
148
149
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000150//----------------------------------------------------------------------------
151// Function: CreateSETXConst
152//
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000153// Set a 64-bit signed or unsigned constant in the register `dest'.
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000154// Use SETUWConst for each 32 bit word, plus a left-shift-by-32 in between.
155// This function correctly emulates the SETX pseudo-op for SPARC v9.
156//
157// Optimize the same cases as SETUWConst for each 32 bit word.
158//----------------------------------------------------------------------------
159
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000160static inline void
161CreateSETXConst(const TargetMachine& target, uint64_t C,
162 Instruction* tmpReg, Instruction* dest,
Misha Brukmana98cd452003-05-20 20:32:24 +0000163 std::vector<MachineInstr*>& mvec)
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000164{
165 assert(C > (unsigned int) ~0 && "Use SETUW/SETSW for 32-bit values!");
166
167 MachineInstr* MI;
168
169 // Code to set the upper 32 bits of the value in register `tmpReg'
170 CreateSETUWConst(target, (C >> 32), tmpReg, mvec);
171
172 // Shift tmpReg left by 32 bits
Misha Brukman71ed1c92003-05-27 22:35:43 +0000173 mvec.push_back(BuildMI(V9::SLLXi6, 3).addReg(tmpReg).addZImm(32)
Misha Brukmana98cd452003-05-20 20:32:24 +0000174 .addRegDef(tmpReg));
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000175
176 // Code to set the low 32 bits of the value in register `dest'
177 CreateSETUWConst(target, C, dest, mvec);
178
179 // dest = OR(tmpReg, dest)
Misha Brukman71ed1c92003-05-27 22:35:43 +0000180 mvec.push_back(BuildMI(V9::ORr,3).addReg(dest).addReg(tmpReg).addRegDef(dest));
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000181}
182
183
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000184//----------------------------------------------------------------------------
185// Function: CreateSETUWLabel
186//
187// Set a 32-bit constant (given by a symbolic label) in the register `dest'.
188//----------------------------------------------------------------------------
189
190static inline void
191CreateSETUWLabel(const TargetMachine& target, Value* val,
Misha Brukmana98cd452003-05-20 20:32:24 +0000192 Instruction* dest, std::vector<MachineInstr*>& mvec)
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000193{
194 MachineInstr* MI;
195
196 // Set the high 22 bits in dest
Misha Brukmana98cd452003-05-20 20:32:24 +0000197 MI = BuildMI(V9::SETHI, 2).addReg(val).addRegDef(dest);
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000198 MI->setOperandHi32(0);
199 mvec.push_back(MI);
200
201 // Set the low 10 bits in dest
Misha Brukman71ed1c92003-05-27 22:35:43 +0000202 MI = BuildMI(V9::ORr, 3).addReg(dest).addReg(val).addRegDef(dest);
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000203 MI->setOperandLo32(1);
204 mvec.push_back(MI);
205}
206
207
208//----------------------------------------------------------------------------
209// Function: CreateSETXLabel
210//
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000211// Set a 64-bit constant (given by a symbolic label) in the register `dest'.
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000212//----------------------------------------------------------------------------
213
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000214static inline void
215CreateSETXLabel(const TargetMachine& target,
216 Value* val, Instruction* tmpReg, Instruction* dest,
Misha Brukmana98cd452003-05-20 20:32:24 +0000217 std::vector<MachineInstr*>& mvec)
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000218{
219 assert(isa<Constant>(val) || isa<GlobalValue>(val) &&
220 "I only know about constant values and global addresses");
221
222 MachineInstr* MI;
223
Misha Brukmana98cd452003-05-20 20:32:24 +0000224 MI = BuildMI(V9::SETHI, 2).addPCDisp(val).addRegDef(tmpReg);
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000225 MI->setOperandHi64(0);
226 mvec.push_back(MI);
227
Misha Brukman71ed1c92003-05-27 22:35:43 +0000228 MI = BuildMI(V9::ORi, 3).addReg(tmpReg).addPCDisp(val).addRegDef(tmpReg);
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000229 MI->setOperandLo64(1);
230 mvec.push_back(MI);
231
Misha Brukman71ed1c92003-05-27 22:35:43 +0000232 mvec.push_back(BuildMI(V9::SLLXi6, 3).addReg(tmpReg).addZImm(32)
Misha Brukmana98cd452003-05-20 20:32:24 +0000233 .addRegDef(tmpReg));
234 MI = BuildMI(V9::SETHI, 2).addPCDisp(val).addRegDef(dest);
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000235 MI->setOperandHi32(0);
236 mvec.push_back(MI);
237
Misha Brukman71ed1c92003-05-27 22:35:43 +0000238 MI = BuildMI(V9::ORr, 3).addReg(dest).addReg(tmpReg).addRegDef(dest);
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000239 mvec.push_back(MI);
240
Misha Brukman71ed1c92003-05-27 22:35:43 +0000241 MI = BuildMI(V9::ORi, 3).addReg(dest).addPCDisp(val).addRegDef(dest);
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000242 MI->setOperandLo32(1);
243 mvec.push_back(MI);
244}
245
Vikram S. Adve30764b82001-10-18 00:01:48 +0000246
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000247//----------------------------------------------------------------------------
248// Function: CreateUIntSetInstruction
249//
250// Create code to Set an unsigned constant in the register `dest'.
251// Uses CreateSETUWConst, CreateSETSWConst or CreateSETXConst as needed.
252// CreateSETSWConst is an optimization for the case that the unsigned value
253// has all ones in the 33 high bits (so that sign-extension sets them all).
254//----------------------------------------------------------------------------
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000255
Vikram S. Adve242a8082002-05-19 15:25:51 +0000256static inline void
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000257CreateUIntSetInstruction(const TargetMachine& target,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000258 uint64_t C, Instruction* dest,
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000259 std::vector<MachineInstr*>& mvec,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000260 MachineCodeForInstruction& mcfi)
Vikram S. Advecee9d1c2001-12-15 00:33:36 +0000261{
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000262 static const uint64_t lo32 = (uint32_t) ~0;
263 if (C <= lo32) // High 32 bits are 0. Set low 32 bits.
264 CreateSETUWConst(target, (uint32_t) C, dest, mvec);
Vikram S. Adve940a3a42003-07-10 19:48:19 +0000265 else if ((C & ~lo32) == ~lo32 && (C & (1U << 31))) {
Misha Brukman81b06862003-05-21 18:48:06 +0000266 // All high 33 (not 32) bits are 1s: sign-extension will take care
267 // of high 32 bits, so use the sequence for signed int
268 CreateSETSWConst(target, (int32_t) C, dest, mvec);
269 } else if (C > lo32) {
270 // C does not fit in 32 bits
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000271 TmpInstruction* tmpReg = new TmpInstruction(mcfi, Type::IntTy);
Misha Brukman81b06862003-05-21 18:48:06 +0000272 CreateSETXConst(target, C, tmpReg, dest, mvec);
273 }
Vikram S. Adve30764b82001-10-18 00:01:48 +0000274}
275
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000276
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000277//----------------------------------------------------------------------------
278// Function: CreateIntSetInstruction
279//
280// Create code to Set a signed constant in the register `dest'.
281// Really the same as CreateUIntSetInstruction.
282//----------------------------------------------------------------------------
283
284static inline void
285CreateIntSetInstruction(const TargetMachine& target,
286 int64_t C, Instruction* dest,
287 std::vector<MachineInstr*>& mvec,
288 MachineCodeForInstruction& mcfi)
289{
290 CreateUIntSetInstruction(target, (uint64_t) C, dest, mvec, mcfi);
291}
Chris Lattner035dfbe2002-08-09 20:08:06 +0000292
Vikram S. Adve30764b82001-10-18 00:01:48 +0000293
294//---------------------------------------------------------------------------
Vikram S. Adve49001162002-09-16 15:56:01 +0000295// Create a table of LLVM opcode -> max. immediate constant likely to
296// be usable for that operation.
297//---------------------------------------------------------------------------
298
299// Entry == 0 ==> no immediate constant field exists at all.
300// Entry > 0 ==> abs(immediate constant) <= Entry
301//
Misha Brukmana98cd452003-05-20 20:32:24 +0000302std::vector<int> MaxConstantsTable(Instruction::OtherOpsEnd);
Vikram S. Adve49001162002-09-16 15:56:01 +0000303
304static int
305MaxConstantForInstr(unsigned llvmOpCode)
306{
307 int modelOpCode = -1;
308
Chris Lattner0b16ae22002-10-13 19:39:16 +0000309 if (llvmOpCode >= Instruction::BinaryOpsBegin &&
310 llvmOpCode < Instruction::BinaryOpsEnd)
Misha Brukman71ed1c92003-05-27 22:35:43 +0000311 modelOpCode = V9::ADDi;
Vikram S. Adve49001162002-09-16 15:56:01 +0000312 else
313 switch(llvmOpCode) {
Misha Brukman71ed1c92003-05-27 22:35:43 +0000314 case Instruction::Ret: modelOpCode = V9::JMPLCALLi; break;
Vikram S. Adve49001162002-09-16 15:56:01 +0000315
316 case Instruction::Malloc:
317 case Instruction::Alloca:
318 case Instruction::GetElementPtr:
319 case Instruction::PHINode:
320 case Instruction::Cast:
Misha Brukman71ed1c92003-05-27 22:35:43 +0000321 case Instruction::Call: modelOpCode = V9::ADDi; break;
Vikram S. Adve49001162002-09-16 15:56:01 +0000322
323 case Instruction::Shl:
Misha Brukman71ed1c92003-05-27 22:35:43 +0000324 case Instruction::Shr: modelOpCode = V9::SLLXi6; break;
Vikram S. Adve49001162002-09-16 15:56:01 +0000325
326 default: break;
327 };
328
329 return (modelOpCode < 0)? 0: SparcMachineInstrDesc[modelOpCode].maxImmedConst;
330}
331
332static void
333InitializeMaxConstantsTable()
334{
335 unsigned op;
Chris Lattner0b16ae22002-10-13 19:39:16 +0000336 assert(MaxConstantsTable.size() == Instruction::OtherOpsEnd &&
Vikram S. Adve49001162002-09-16 15:56:01 +0000337 "assignments below will be illegal!");
Chris Lattner0b16ae22002-10-13 19:39:16 +0000338 for (op = Instruction::TermOpsBegin; op < Instruction::TermOpsEnd; ++op)
Vikram S. Adve49001162002-09-16 15:56:01 +0000339 MaxConstantsTable[op] = MaxConstantForInstr(op);
Chris Lattner0b16ae22002-10-13 19:39:16 +0000340 for (op = Instruction::BinaryOpsBegin; op < Instruction::BinaryOpsEnd; ++op)
Vikram S. Adve49001162002-09-16 15:56:01 +0000341 MaxConstantsTable[op] = MaxConstantForInstr(op);
Chris Lattner0b16ae22002-10-13 19:39:16 +0000342 for (op = Instruction::MemoryOpsBegin; op < Instruction::MemoryOpsEnd; ++op)
Vikram S. Adve49001162002-09-16 15:56:01 +0000343 MaxConstantsTable[op] = MaxConstantForInstr(op);
Chris Lattner0b16ae22002-10-13 19:39:16 +0000344 for (op = Instruction::OtherOpsBegin; op < Instruction::OtherOpsEnd; ++op)
Vikram S. Adve49001162002-09-16 15:56:01 +0000345 MaxConstantsTable[op] = MaxConstantForInstr(op);
346}
347
348
349//---------------------------------------------------------------------------
Vikram S. Adve30764b82001-10-18 00:01:48 +0000350// class UltraSparcInstrInfo
351//
352// Purpose:
353// Information about individual instructions.
354// Most information is stored in the SparcMachineInstrDesc array above.
355// Other information is computed on demand, and most such functions
Chris Lattner3501fea2003-01-14 22:00:31 +0000356// default to member functions in base class TargetInstrInfo.
Vikram S. Adve30764b82001-10-18 00:01:48 +0000357//---------------------------------------------------------------------------
358
359/*ctor*/
Chris Lattner047bbaf2002-10-29 15:45:20 +0000360UltraSparcInstrInfo::UltraSparcInstrInfo()
Chris Lattner3501fea2003-01-14 22:00:31 +0000361 : TargetInstrInfo(SparcMachineInstrDesc,
Misha Brukmana98cd452003-05-20 20:32:24 +0000362 /*descSize = */ V9::NUM_TOTAL_OPCODES,
363 /*numRealOpCodes = */ V9::NUM_REAL_OPCODES)
Vikram S. Adve30764b82001-10-18 00:01:48 +0000364{
Vikram S. Adve49001162002-09-16 15:56:01 +0000365 InitializeMaxConstantsTable();
366}
367
368bool
369UltraSparcInstrInfo::ConstantMayNotFitInImmedField(const Constant* CV,
370 const Instruction* I) const
371{
372 if (I->getOpcode() >= MaxConstantsTable.size()) // user-defined op (or bug!)
373 return true;
374
375 if (isa<ConstantPointerNull>(CV)) // can always use %g0
376 return false;
377
Chris Lattnerc07736a2003-07-23 15:22:26 +0000378 if (const ConstantInt* CI = dyn_cast<ConstantInt>(CV))
379 return labs((int64_t)CI->getRawValue()) > MaxConstantsTable[I->getOpcode()];
Vikram S. Adve49001162002-09-16 15:56:01 +0000380
381 if (isa<ConstantBool>(CV))
Chris Lattnerc07736a2003-07-23 15:22:26 +0000382 return 1 > MaxConstantsTable[I->getOpcode()];
Vikram S. Adve49001162002-09-16 15:56:01 +0000383
384 return true;
Vikram S. Adve30764b82001-10-18 00:01:48 +0000385}
386
Vikram S. Advee76af292002-03-18 03:09:15 +0000387//
Vikram S. Adve30764b82001-10-18 00:01:48 +0000388// Create an instruction sequence to put the constant `val' into
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000389// the virtual register `dest'. `val' may be a Constant or a
Vikram S. Adve30764b82001-10-18 00:01:48 +0000390// GlobalValue, viz., the constant address of a global variable or function.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000391// The generated instructions are returned in `mvec'.
392// Any temp. registers (TmpInstruction) created are recorded in mcfi.
Misha Brukmanfce11432002-10-28 00:28:31 +0000393// Any stack space required is allocated via MachineFunction.
Vikram S. Adve30764b82001-10-18 00:01:48 +0000394//
395void
Vikram S. Adve242a8082002-05-19 15:25:51 +0000396UltraSparcInstrInfo::CreateCodeToLoadConst(const TargetMachine& target,
397 Function* F,
398 Value* val,
Vikram S. Advee76af292002-03-18 03:09:15 +0000399 Instruction* dest,
Misha Brukmana98cd452003-05-20 20:32:24 +0000400 std::vector<MachineInstr*>& mvec,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000401 MachineCodeForInstruction& mcfi) const
Vikram S. Adve30764b82001-10-18 00:01:48 +0000402{
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000403 assert(isa<Constant>(val) || isa<GlobalValue>(val) &&
Vikram S. Adve30764b82001-10-18 00:01:48 +0000404 "I only know about constant values and global addresses");
405
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000406 // Use a "set" instruction for known constants or symbolic constants (labels)
407 // that can go in an integer reg.
408 // We have to use a "load" instruction for all other constants,
409 // in particular, floating point constants.
Vikram S. Adve30764b82001-10-18 00:01:48 +0000410 //
411 const Type* valType = val->getType();
412
Vikram S. Adve893cace2002-10-13 00:04:26 +0000413 // Unfortunate special case: a ConstantPointerRef is just a
414 // reference to GlobalValue.
415 if (isa<ConstantPointerRef>(val))
416 val = cast<ConstantPointerRef>(val)->getValue();
417
Misha Brukman81b06862003-05-21 18:48:06 +0000418 if (isa<GlobalValue>(val)) {
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000419 TmpInstruction* tmpReg =
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000420 new TmpInstruction(mcfi, PointerType::get(val->getType()), val);
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000421 CreateSETXLabel(target, val, tmpReg, dest, mvec);
Misha Brukman81b06862003-05-21 18:48:06 +0000422 } else if (valType->isIntegral()) {
423 bool isValidConstant;
424 unsigned opSize = target.getTargetData().getTypeSize(val->getType());
425 unsigned destSize = target.getTargetData().getTypeSize(dest->getType());
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000426
Misha Brukman81b06862003-05-21 18:48:06 +0000427 if (! dest->getType()->isSigned()) {
428 uint64_t C = GetConstantValueAsUnsignedInt(val, isValidConstant);
429 assert(isValidConstant && "Unrecognized constant");
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000430
Misha Brukman81b06862003-05-21 18:48:06 +0000431 if (opSize > destSize || (val->getType()->isSigned() && destSize < 8)) {
432 // operand is larger than dest,
433 // OR both are equal but smaller than the full register size
434 // AND operand is signed, so it may have extra sign bits:
435 // mask high bits
436 C = C & ((1U << 8*destSize) - 1);
437 }
438 CreateUIntSetInstruction(target, C, dest, mvec, mcfi);
439 } else {
440 int64_t C = GetConstantValueAsSignedInt(val, isValidConstant);
441 assert(isValidConstant && "Unrecognized constant");
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000442
Misha Brukman81b06862003-05-21 18:48:06 +0000443 if (opSize > destSize)
444 // operand is larger than dest: mask high bits
445 C = C & ((1U << 8*destSize) - 1);
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000446
Misha Brukman81b06862003-05-21 18:48:06 +0000447 if (opSize > destSize ||
448 (opSize == destSize && !val->getType()->isSigned()))
449 // sign-extend from destSize to 64 bits
450 C = ((C & (1U << (8*destSize - 1)))
451 ? C | ~((1U << 8*destSize) - 1)
452 : C);
Vikram S. Adve6c0c3012002-08-13 18:04:08 +0000453
Misha Brukman81b06862003-05-21 18:48:06 +0000454 CreateIntSetInstruction(target, C, dest, mvec, mcfi);
Vikram S. Adve30764b82001-10-18 00:01:48 +0000455 }
Misha Brukman81b06862003-05-21 18:48:06 +0000456 } else {
457 // Make an instruction sequence to load the constant, viz:
458 // SETX <addr-of-constant>, tmpReg, addrReg
459 // LOAD /*addr*/ addrReg, /*offset*/ 0, dest
Vikram S. Adve30764b82001-10-18 00:01:48 +0000460
Misha Brukman81b06862003-05-21 18:48:06 +0000461 // First, create a tmp register to be used by the SETX sequence.
462 TmpInstruction* tmpReg =
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000463 new TmpInstruction(mcfi, PointerType::get(val->getType()), val);
Vikram S. Advea2a70942001-10-28 21:41:46 +0000464
Misha Brukman81b06862003-05-21 18:48:06 +0000465 // Create another TmpInstruction for the address register
466 TmpInstruction* addrReg =
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000467 new TmpInstruction(mcfi, PointerType::get(val->getType()), val);
Vikram S. Adve30764b82001-10-18 00:01:48 +0000468
Misha Brukman81b06862003-05-21 18:48:06 +0000469 // Put the address (a symbolic name) into a register
470 CreateSETXLabel(target, val, tmpReg, addrReg, mvec);
Vikram S. Adve30764b82001-10-18 00:01:48 +0000471
Misha Brukman81b06862003-05-21 18:48:06 +0000472 // Generate the load instruction
473 int64_t zeroOffset = 0; // to avoid ambiguity with (Value*) 0
474 unsigned Opcode = ChooseLoadInstruction(val->getType());
Misha Brukmanc559e052003-06-03 03:20:57 +0000475 Opcode = convertOpcodeFromRegToImm(Opcode);
Misha Brukman81b06862003-05-21 18:48:06 +0000476 mvec.push_back(BuildMI(Opcode, 3).addReg(addrReg).
477 addSImm(zeroOffset).addRegDef(dest));
Vikram S. Adve53fd4002002-07-10 21:39:50 +0000478
Misha Brukman81b06862003-05-21 18:48:06 +0000479 // Make sure constant is emitted to constant pool in assembly code.
480 MachineFunction::get(F).getInfo()->addToConstantPool(cast<Constant>(val));
481 }
Vikram S. Adve30764b82001-10-18 00:01:48 +0000482}
483
484
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000485// Create an instruction sequence to copy an integer register `val'
486// to a floating point register `dest' by copying to memory and back.
Vikram S. Adve5b6082e2001-11-09 02:16:40 +0000487// val must be an integral type. dest must be a Float or Double.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000488// The generated instructions are returned in `mvec'.
489// Any temp. registers (TmpInstruction) created are recorded in mcfi.
Misha Brukmanfce11432002-10-28 00:28:31 +0000490// Any stack space required is allocated via MachineFunction.
Vikram S. Adveb9c38632001-11-08 04:57:53 +0000491//
492void
Vikram S. Adve242a8082002-05-19 15:25:51 +0000493UltraSparcInstrInfo::CreateCodeToCopyIntToFloat(const TargetMachine& target,
494 Function* F,
495 Value* val,
496 Instruction* dest,
Misha Brukmana98cd452003-05-20 20:32:24 +0000497 std::vector<MachineInstr*>& mvec,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000498 MachineCodeForInstruction& mcfi) const
Vikram S. Adveb9c38632001-11-08 04:57:53 +0000499{
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000500 assert((val->getType()->isIntegral() || isa<PointerType>(val->getType()))
501 && "Source type must be integral (integer or bool) or pointer");
Chris Lattner9b625032002-05-06 16:15:30 +0000502 assert(dest->getType()->isFloatingPoint()
Vikram S. Adveb9c38632001-11-08 04:57:53 +0000503 && "Dest type must be float/double");
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000504
505 // Get a stack slot to use for the copy
Chris Lattner2ef9a6a2002-12-28 20:18:21 +0000506 int offset = MachineFunction::get(F).getInfo()->allocateLocalVar(val);
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000507
508 // Get the size of the source value being copied.
Chris Lattner2ef9a6a2002-12-28 20:18:21 +0000509 size_t srcSize = target.getTargetData().getTypeSize(val->getType());
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000510
Vikram S. Adveb9c38632001-11-08 04:57:53 +0000511 // Store instruction stores `val' to [%fp+offset].
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000512 // The store and load opCodes are based on the size of the source value.
513 // If the value is smaller than 32 bits, we must sign- or zero-extend it
514 // to 32 bits since the load-float will load 32 bits.
Vikram S. Advec190c012002-07-31 21:13:31 +0000515 // Note that the store instruction is the same for signed and unsigned ints.
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000516 const Type* storeType = (srcSize <= 4)? Type::IntTy : Type::LongTy;
517 Value* storeVal = val;
Misha Brukman81b06862003-05-21 18:48:06 +0000518 if (srcSize < target.getTargetData().getTypeSize(Type::FloatTy)) {
519 // sign- or zero-extend respectively
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000520 storeVal = new TmpInstruction(mcfi, storeType, val);
Misha Brukman81b06862003-05-21 18:48:06 +0000521 if (val->getType()->isSigned())
522 CreateSignExtensionInstructions(target, F, val, storeVal, 8*srcSize,
523 mvec, mcfi);
524 else
525 CreateZeroExtensionInstructions(target, F, val, storeVal, 8*srcSize,
526 mvec, mcfi);
527 }
Chris Lattner54e898e2003-01-15 19:23:34 +0000528
529 unsigned FPReg = target.getRegInfo().getFramePointer();
Misha Brukmanc559e052003-06-03 03:20:57 +0000530 unsigned StoreOpcode = ChooseStoreInstruction(storeType);
531 StoreOpcode = convertOpcodeFromRegToImm(StoreOpcode);
532 mvec.push_back(BuildMI(StoreOpcode, 3)
Chris Lattner54e898e2003-01-15 19:23:34 +0000533 .addReg(storeVal).addMReg(FPReg).addSImm(offset));
Vikram S. Adve30764b82001-10-18 00:01:48 +0000534
Vikram S. Adveb9c38632001-11-08 04:57:53 +0000535 // Load instruction loads [%fp+offset] to `dest'.
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000536 // The type of the load opCode is the floating point type that matches the
537 // stored type in size:
538 // On SparcV9: float for int or smaller, double for long.
Vikram S. Adve5b6082e2001-11-09 02:16:40 +0000539 //
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000540 const Type* loadType = (srcSize <= 4)? Type::FloatTy : Type::DoubleTy;
Misha Brukmanc559e052003-06-03 03:20:57 +0000541 unsigned LoadOpcode = ChooseLoadInstruction(loadType);
542 LoadOpcode = convertOpcodeFromRegToImm(LoadOpcode);
543 mvec.push_back(BuildMI(LoadOpcode, 3)
Chris Lattner54e898e2003-01-15 19:23:34 +0000544 .addMReg(FPReg).addSImm(offset).addRegDef(dest));
Vikram S. Adve5b6082e2001-11-09 02:16:40 +0000545}
546
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000547// Similarly, create an instruction sequence to copy an FP register
548// `val' to an integer register `dest' by copying to memory and back.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000549// The generated instructions are returned in `mvec'.
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000550// Any temp. virtual registers (TmpInstruction) created are recorded in mcfi.
551// Temporary stack space required is allocated via MachineFunction.
Vikram S. Adve5b6082e2001-11-09 02:16:40 +0000552//
553void
Vikram S. Adve242a8082002-05-19 15:25:51 +0000554UltraSparcInstrInfo::CreateCodeToCopyFloatToInt(const TargetMachine& target,
555 Function* F,
Chris Lattner697954c2002-01-20 22:54:45 +0000556 Value* val,
557 Instruction* dest,
Misha Brukmana98cd452003-05-20 20:32:24 +0000558 std::vector<MachineInstr*>& mvec,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000559 MachineCodeForInstruction& mcfi) const
Vikram S. Adve5b6082e2001-11-09 02:16:40 +0000560{
Vikram S. Advec190c012002-07-31 21:13:31 +0000561 const Type* opTy = val->getType();
562 const Type* destTy = dest->getType();
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000563
Vikram S. Advec190c012002-07-31 21:13:31 +0000564 assert(opTy->isFloatingPoint() && "Source type must be float/double");
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000565 assert((destTy->isIntegral() || isa<PointerType>(destTy))
566 && "Dest type must be integer, bool or pointer");
Vikram S. Advec190c012002-07-31 21:13:31 +0000567
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000568 // FIXME: For now, we allocate permanent space because the stack frame
569 // manager does not allow locals to be allocated (e.g., for alloca) after
570 // a temp is allocated!
571 //
Chris Lattner2ef9a6a2002-12-28 20:18:21 +0000572 int offset = MachineFunction::get(F).getInfo()->allocateLocalVar(val);
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000573
Chris Lattner54e898e2003-01-15 19:23:34 +0000574 unsigned FPReg = target.getRegInfo().getFramePointer();
575
Vikram S. Adve5b6082e2001-11-09 02:16:40 +0000576 // Store instruction stores `val' to [%fp+offset].
Vikram S. Advec190c012002-07-31 21:13:31 +0000577 // The store opCode is based only the source value being copied.
Vikram S. Adve5b6082e2001-11-09 02:16:40 +0000578 //
Misha Brukmanc559e052003-06-03 03:20:57 +0000579 unsigned StoreOpcode = ChooseStoreInstruction(opTy);
580 StoreOpcode = convertOpcodeFromRegToImm(StoreOpcode);
581 mvec.push_back(BuildMI(StoreOpcode, 3)
Chris Lattner54e898e2003-01-15 19:23:34 +0000582 .addReg(val).addMReg(FPReg).addSImm(offset));
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000583
Vikram S. Adve5b6082e2001-11-09 02:16:40 +0000584 // Load instruction loads [%fp+offset] to `dest'.
Vikram S. Advec190c012002-07-31 21:13:31 +0000585 // The type of the load opCode is the integer type that matches the
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000586 // source type in size:
Vikram S. Advec190c012002-07-31 21:13:31 +0000587 // On SparcV9: int for float, long for double.
588 // Note that we *must* use signed loads even for unsigned dest types, to
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000589 // ensure correct sign-extension for UByte, UShort or UInt:
590 //
591 const Type* loadTy = (opTy == Type::FloatTy)? Type::IntTy : Type::LongTy;
Misha Brukmanc559e052003-06-03 03:20:57 +0000592 unsigned LoadOpcode = ChooseLoadInstruction(loadTy);
593 LoadOpcode = convertOpcodeFromRegToImm(LoadOpcode);
594 mvec.push_back(BuildMI(LoadOpcode, 3).addMReg(FPReg)
Chris Lattner54e898e2003-01-15 19:23:34 +0000595 .addSImm(offset).addRegDef(dest));
Vikram S. Adve242a8082002-05-19 15:25:51 +0000596}
597
598
599// Create instruction(s) to copy src to dest, for arbitrary types
600// The generated instructions are returned in `mvec'.
601// Any temp. registers (TmpInstruction) created are recorded in mcfi.
Misha Brukmanfce11432002-10-28 00:28:31 +0000602// Any stack space required is allocated via MachineFunction.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000603//
604void
605UltraSparcInstrInfo::CreateCopyInstructionsByType(const TargetMachine& target,
606 Function *F,
607 Value* src,
608 Instruction* dest,
Misha Brukmana98cd452003-05-20 20:32:24 +0000609 std::vector<MachineInstr*>& mvec,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000610 MachineCodeForInstruction& mcfi) const
611{
612 bool loadConstantToReg = false;
613
614 const Type* resultType = dest->getType();
615
616 MachineOpCode opCode = ChooseAddInstructionByType(resultType);
Misha Brukman81b06862003-05-21 18:48:06 +0000617 if (opCode == V9::INVALID_OPCODE) {
Misha Brukmana98cd452003-05-20 20:32:24 +0000618 assert(0 && "Unsupported result type in CreateCopyInstructionsByType()");
619 return;
620 }
Vikram S. Adve242a8082002-05-19 15:25:51 +0000621
622 // if `src' is a constant that doesn't fit in the immed field or if it is
623 // a global variable (i.e., a constant address), generate a load
624 // instruction instead of an add
625 //
Misha Brukman81b06862003-05-21 18:48:06 +0000626 if (isa<Constant>(src)) {
Misha Brukmana98cd452003-05-20 20:32:24 +0000627 unsigned int machineRegNum;
628 int64_t immedValue;
629 MachineOperand::MachineOperandType opType =
630 ChooseRegOrImmed(src, opCode, target, /*canUseImmed*/ true,
631 machineRegNum, immedValue);
Vikram S. Adve242a8082002-05-19 15:25:51 +0000632
Misha Brukmana98cd452003-05-20 20:32:24 +0000633 if (opType == MachineOperand::MO_VirtualRegister)
634 loadConstantToReg = true;
635 }
Vikram S. Adve242a8082002-05-19 15:25:51 +0000636 else if (isa<GlobalValue>(src))
637 loadConstantToReg = true;
638
Misha Brukman81b06862003-05-21 18:48:06 +0000639 if (loadConstantToReg) {
640 // `src' is constant and cannot fit in immed field for the ADD
Misha Brukmana98cd452003-05-20 20:32:24 +0000641 // Insert instructions to "load" the constant into a register
642 target.getInstrInfo().CreateCodeToLoadConst(target, F, src, dest,
643 mvec, mcfi);
Misha Brukman81b06862003-05-21 18:48:06 +0000644 } else {
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000645 // Create a reg-to-reg copy instruction for the given type:
646 // -- For FP values, create a FMOVS or FMOVD instruction
647 // -- For non-FP values, create an add-with-0 instruction (opCode as above)
648 // Make `src' the second operand, in case it is a small constant!
Misha Brukmana98cd452003-05-20 20:32:24 +0000649 //
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000650 MachineInstr* MI;
651 if (resultType->isFloatingPoint())
652 MI = (BuildMI(resultType == Type::FloatTy? V9::FMOVS : V9::FMOVD, 2)
653 .addReg(src).addRegDef(dest));
654 else {
655 const Type* Ty =isa<PointerType>(resultType)? Type::ULongTy :resultType;
656 MI = (BuildMI(opCode, 3)
657 .addSImm((int64_t) 0).addReg(src).addRegDef(dest));
658 }
Misha Brukmana98cd452003-05-20 20:32:24 +0000659 mvec.push_back(MI);
660 }
Vikram S. Adve242a8082002-05-19 15:25:51 +0000661}
662
663
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000664// Helper function for sign-extension and zero-extension.
665// For SPARC v9, we sign-extend the given operand using SLL; SRA/SRL.
666inline void
667CreateBitExtensionInstructions(bool signExtend,
668 const TargetMachine& target,
669 Function* F,
670 Value* srcVal,
Vikram S. Adve5cedede2002-09-27 14:29:45 +0000671 Value* destVal,
672 unsigned int numLowBits,
Misha Brukmana98cd452003-05-20 20:32:24 +0000673 std::vector<MachineInstr*>& mvec,
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000674 MachineCodeForInstruction& mcfi)
675{
676 MachineInstr* M;
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000677
Vikram S. Adve5cedede2002-09-27 14:29:45 +0000678 assert(numLowBits <= 32 && "Otherwise, nothing should be done here!");
679
Misha Brukman81b06862003-05-21 18:48:06 +0000680 if (numLowBits < 32) {
681 // SLL is needed since operand size is < 32 bits.
Vikram S. Adved0d06ad2003-05-31 07:32:01 +0000682 TmpInstruction *tmpI = new TmpInstruction(mcfi, destVal->getType(),
Misha Brukmana98cd452003-05-20 20:32:24 +0000683 srcVal, destVal, "make32");
Misha Brukman71ed1c92003-05-27 22:35:43 +0000684 mvec.push_back(BuildMI(V9::SLLXi6, 3).addReg(srcVal)
Misha Brukmana98cd452003-05-20 20:32:24 +0000685 .addZImm(32-numLowBits).addRegDef(tmpI));
686 srcVal = tmpI;
687 }
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000688
Misha Brukmand36e30e2003-06-06 09:52:23 +0000689 mvec.push_back(BuildMI(signExtend? V9::SRAi5 : V9::SRLi5, 3)
Misha Brukmana98cd452003-05-20 20:32:24 +0000690 .addReg(srcVal).addZImm(32-numLowBits).addRegDef(destVal));
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000691}
692
693
Vikram S. Adve242a8082002-05-19 15:25:51 +0000694// Create instruction sequence to produce a sign-extended register value
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000695// from an arbitrary-sized integer value (sized in bits, not bytes).
Vikram S. Adve242a8082002-05-19 15:25:51 +0000696// The generated instructions are returned in `mvec'.
697// Any temp. registers (TmpInstruction) created are recorded in mcfi.
Misha Brukmanfce11432002-10-28 00:28:31 +0000698// Any stack space required is allocated via MachineFunction.
Vikram S. Adve242a8082002-05-19 15:25:51 +0000699//
700void
701UltraSparcInstrInfo::CreateSignExtensionInstructions(
702 const TargetMachine& target,
703 Function* F,
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000704 Value* srcVal,
Vikram S. Adve5cedede2002-09-27 14:29:45 +0000705 Value* destVal,
706 unsigned int numLowBits,
Misha Brukmana98cd452003-05-20 20:32:24 +0000707 std::vector<MachineInstr*>& mvec,
Vikram S. Adve242a8082002-05-19 15:25:51 +0000708 MachineCodeForInstruction& mcfi) const
709{
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000710 CreateBitExtensionInstructions(/*signExtend*/ true, target, F, srcVal,
Vikram S. Adve5cedede2002-09-27 14:29:45 +0000711 destVal, numLowBits, mvec, mcfi);
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000712}
713
714
715// Create instruction sequence to produce a zero-extended register value
716// from an arbitrary-sized integer value (sized in bits, not bytes).
717// For SPARC v9, we sign-extend the given operand using SLL; SRL.
718// The generated instructions are returned in `mvec'.
719// Any temp. registers (TmpInstruction) created are recorded in mcfi.
Misha Brukmanfce11432002-10-28 00:28:31 +0000720// Any stack space required is allocated via MachineFunction.
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000721//
722void
723UltraSparcInstrInfo::CreateZeroExtensionInstructions(
724 const TargetMachine& target,
725 Function* F,
726 Value* srcVal,
Vikram S. Adve5cedede2002-09-27 14:29:45 +0000727 Value* destVal,
728 unsigned int numLowBits,
Misha Brukmana98cd452003-05-20 20:32:24 +0000729 std::vector<MachineInstr*>& mvec,
Vikram S. Adve84c0fcb2002-09-05 18:33:59 +0000730 MachineCodeForInstruction& mcfi) const
731{
732 CreateBitExtensionInstructions(/*signExtend*/ false, target, F, srcVal,
Vikram S. Adve5cedede2002-09-27 14:29:45 +0000733 destVal, numLowBits, mvec, mcfi);
Vikram S. Adveb9c38632001-11-08 04:57:53 +0000734}