1 //===-- SparcInternals.h - Header file for Sparc backend ---------*- C++ -*--=//
3 // This file defines stuff that is to be private to the Sparc backend, but is
4 // shared among different portions of the backend.
6 //===----------------------------------------------------------------------===//
8 #ifndef SPARC_INTERNALS_H
9 #define SPARC_INTERNALS_H
12 #include "SparcRegClassInfo.h"
13 #include "llvm/Target/TargetMachine.h"
14 #include "llvm/Target/MachineInstrInfo.h"
16 #include "llvm/Target/MachineSchedInfo.h"
17 #include "llvm/CodeGen/RegClass.h"
18 #include "llvm/Type.h"
20 #include <sys/types.h>
24 // OpCodeMask definitions for the Sparc V9
26 const OpCodeMask Immed = 0x00002000; // immed or reg operand?
27 const OpCodeMask Annul = 0x20000000; // annul delay instr?
28 const OpCodeMask PredictTaken = 0x00080000; // predict branch taken?
31 enum SparcInstrSchedClass {
32 SPARC_NONE, /* Instructions with no scheduling restrictions */
33 SPARC_IEUN, /* Integer class that can use IEU0 or IEU1 */
34 SPARC_IEU0, /* Integer class IEU0 */
35 SPARC_IEU1, /* Integer class IEU1 */
36 SPARC_FPM, /* FP Multiply or Divide instructions */
37 SPARC_FPA, /* All other FP instructions */
38 SPARC_CTI, /* Control-transfer instructions */
39 SPARC_LD, /* Load instructions */
40 SPARC_ST, /* Store instructions */
41 SPARC_SINGLE, /* Instructions that must issue by themselves */
43 SPARC_INV, /* This should stay at the end for the next value */
44 SPARC_NUM_SCHED_CLASSES = SPARC_INV
48 //---------------------------------------------------------------------------
49 // enum SparcMachineOpCode.
50 // const MachineInstrDescriptor SparcMachineInstrDesc[]
53 // Description of UltraSparc machine instructions.
55 //---------------------------------------------------------------------------
57 enum SparcMachineOpCode {
58 #define I(ENUM, OPCODESTRING, NUMOPERANDS, RESULTPOS, MAXIMM, IMMSE, \
59 NUMDELAYSLOTS, LATENCY, SCHEDCLASS, INSTFLAGS) \
61 #include "SparcInstr.def"
63 // End-of-array marker
65 NUM_REAL_OPCODES = PHI, // number of valid opcodes
66 NUM_TOTAL_OPCODES = INVALID_OPCODE
70 // Array of machine instruction descriptions...
71 extern const MachineInstrDescriptor SparcMachineInstrDesc[];
74 //---------------------------------------------------------------------------
75 // class UltraSparcInstrInfo
78 // Information about individual instructions.
79 // Most information is stored in the SparcMachineInstrDesc array above.
80 // Other information is computed on demand, and most such functions
81 // default to member functions in base class MachineInstrInfo.
82 //---------------------------------------------------------------------------
84 class UltraSparcInstrInfo : public MachineInstrInfo {
86 /*ctor*/ UltraSparcInstrInfo();
88 virtual bool hasResultInterlock (MachineOpCode opCode) const
90 // All UltraSPARC instructions have interlocks (note that delay slots
91 // are not considered here).
92 // However, instructions that use the result of an FCMP produce a
93 // 9-cycle stall if they are issued less than 3 cycles after the FCMP.
94 // Force the compiler to insert a software interlock (i.e., gap of
95 // 2 other groups, including NOPs if necessary).
96 return (opCode == FCMPS || opCode == FCMPD || opCode == FCMPQ);
99 //-------------------------------------------------------------------------
100 // Code generation support for creating individual machine instructions
101 //-------------------------------------------------------------------------
103 // Create an instruction sequence to put the constant `val' into
104 // the virtual register `dest'. The generated instructions are
105 // returned in `minstrVec'. Any temporary registers (TmpInstruction)
106 // created are returned in `tempVec'.
108 virtual void CreateCodeToLoadConst(Value* val,
110 vector<MachineInstr*>& minstrVec,
111 vector<TmpInstruction*>& tempVec) const;
118 //----------------------------------------------------------------------------
119 // class UltraSparcRegInfo
121 //----------------------------------------------------------------------------
129 class UltraSparcRegInfo : public MachineRegInfo
134 // The actual register classes in the Sparc
144 // Type of registers available in Sparc. There can be several reg types
145 // in the same class. For instace, the float reg class has Single/Double
155 // the size of a value (int, float, etc..) stored in the stack frame
159 // WARNING: If the above enum order must be changed, also modify
160 // getRegisterClassOfValue method below since it assumes this particular
161 // order for efficiency.
164 // reverse pointer to get info about the ultra sparc machine
165 const UltraSparc *const UltraSparcInfo;
167 // Both int and float rguments can be passed in 6 int regs -
168 // %o0 to %o5 (cannot be changed)
169 unsigned const NumOfIntArgRegs;
170 unsigned const NumOfFloatArgRegs;
171 int const InvalidRegNum;
172 int SizeOfOperandOnStack;
176 //void setCallArgColor(LiveRange *const LR, const unsigned RegNo) const;
178 void setCallOrRetArgCol(LiveRange *const LR, const unsigned RegNo,
179 const MachineInstr *MI,AddedInstrMapType &AIMap)const;
181 MachineInstr * getCopy2RegMI(const Value *SrcVal, const unsigned Reg,
182 unsigned RegClassID) const ;
185 void suggestReg4RetAddr(const MachineInstr * RetMI,
186 LiveRangeInfo& LRI) const;
188 void suggestReg4CallAddr(const MachineInstr * CallMI, LiveRangeInfo& LRI,
189 vector<RegClass *> RCList) const;
192 Value *getValue4ReturnAddr( const MachineInstr * MInst ) const ;
194 int getRegType(const LiveRange *const LR) const {
198 switch( (LR->getRegClass())->getID() ) {
200 case IntRegClassID: return IntRegType;
202 case FloatRegClassID:
203 Typ = LR->getTypeID();
204 if( Typ == Type::FloatTyID )
205 return FPSingleRegType;
206 else if( Typ == Type::DoubleTyID )
207 return FPDoubleRegType;
208 else assert(0 && "Unknown type in FloatRegClass");
210 case IntCCRegClassID: return IntCCRegType;
212 case FloatCCRegClassID: return FloatCCRegType ;
214 default: assert( 0 && "Unknown reg class ID");
220 int getRegType(const Value *const Val) const {
224 switch( getRegClassIDOfValue(Val) ) {
226 case IntRegClassID: return IntRegType;
228 case FloatRegClassID:
229 Typ = (Val->getType())->getPrimitiveID();
230 if( Typ == Type::FloatTyID )
231 return FPSingleRegType;
232 else if( Typ == Type::DoubleTyID )
233 return FPDoubleRegType;
234 else assert(0 && "Unknown type in FloatRegClass");
236 case IntCCRegClassID: return IntCCRegType;
238 case FloatCCRegClassID: return FloatCCRegType ;
240 default: assert( 0 && "Unknown reg class ID");
248 // ***TODO: See this method is necessary
250 MachineInstr * cpValue2RegMI(Value * Val, const unsigned DestReg,
251 const int RegType) const;
253 const Value *getCallInstRetAddr(const MachineInstr *CallMI) const;
254 const unsigned getCallInstNumArgs(const MachineInstr *CallMI) const;
257 MachineInstr * cpCCR2IntMI(const unsigned IntReg) const;
258 MachineInstr * cpInt2CCRMI(const unsigned IntReg) const;
263 UltraSparcRegInfo(const UltraSparc *const USI ) : UltraSparcInfo(USI),
265 NumOfFloatArgRegs(32),
267 SizeOfOperandOnStack(8)
269 MachineRegClassArr.push_back( new SparcIntRegClass(IntRegClassID) );
270 MachineRegClassArr.push_back( new SparcFloatRegClass(FloatRegClassID) );
271 MachineRegClassArr.push_back( new SparcIntCCRegClass(IntCCRegClassID) );
272 MachineRegClassArr.push_back( new SparcFloatCCRegClass(FloatCCRegClassID));
274 assert( SparcFloatRegOrder::StartOfNonVolatileRegs == 32 &&
275 "32 Float regs are used for float arg passing");
280 ~UltraSparcRegInfo(void) { } // empty destructor
283 inline const UltraSparc & getUltraSparcInfo() const {
284 return *UltraSparcInfo;
289 inline unsigned getRegClassIDOfValue (const Value *const Val,
290 bool isCCReg = false) const {
292 Type::PrimitiveID ty = (Val->getType())->getPrimitiveID();
296 if( (ty && ty <= Type::LongTyID) || (ty == Type::LabelTyID) ||
297 (ty == Type::MethodTyID) || (ty == Type::PointerTyID) )
298 res = IntRegClassID; // sparc int reg (ty=0: void)
299 else if( ty <= Type::DoubleTyID)
300 res = FloatRegClassID; // sparc float reg class
302 cerr << "TypeID: " << ty << endl;
303 assert(0 && "Cannot resolve register class for type");
307 return res + 2; // corresponidng condition code regiser
312 // returns the register tha contains always zero
313 // this is the unified register number
314 inline int getZeroRegNum() const { return SparcIntRegOrder::g0; }
316 // returns the reg used for pushing the address when a method is called.
317 // This can be used for other purposes between calls
318 unsigned getCallAddressReg() const { return SparcIntRegOrder::o7; }
321 // and when we return from a method. It should be made sure that this
322 // register contains the return value when a return instruction is reached.
323 unsigned getReturnAddressReg() const { return SparcIntRegOrder::i7; }
325 void suggestRegs4MethodArgs(const Method *const Meth,
326 LiveRangeInfo& LRI) const;
328 void suggestRegs4CallArgs(const MachineInstr *const CallMI,
329 LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
331 void suggestReg4RetValue(const MachineInstr *const RetMI,
332 LiveRangeInfo& LRI ) const;
335 void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI,
336 AddedInstrns *const FirstAI) const;
338 void colorCallArgs(const MachineInstr *const CallMI, LiveRangeInfo& LRI,
339 AddedInstrns *const CallAI, PhyRegAlloc &PRA) const;
341 void colorRetValue(const MachineInstr *const RetI, LiveRangeInfo& LRI,
342 AddedInstrns *const RetAI) const;
345 // bool handleSpecialMInstr(const MachineInstr * MInst,
346 // LiveRangeInfo& LRI, vector<RegClass *> RCL) const;
349 static void printReg(const LiveRange *const LR) ;
351 // this method provides a unique number for each register
352 inline int getUnifiedRegNum(int RegClassID, int reg) const {
354 if( RegClassID == IntRegClassID && reg < 32 )
356 else if ( RegClassID == FloatRegClassID && reg < 64)
357 return reg + 32; // we have 32 int regs
358 else if( RegClassID == FloatCCRegClassID && reg < 4)
359 return reg + 32 + 64; // 32 int, 64 float
360 else if( RegClassID == IntCCRegClassID )
361 return 4+ 32 + 64; // only int cc reg
362 else if (reg==InvalidRegNum)
363 return InvalidRegNum;
365 assert(0 && "Invalid register class or reg number");
369 // given the unified register number, this gives the name
370 inline const string getUnifiedRegName(int reg) const {
372 return SparcIntRegOrder::getRegName(reg);
373 else if ( reg < (64 + 32) )
374 return SparcFloatRegOrder::getRegName( reg - 32);
375 else if( reg < (64+32+4) )
376 return SparcFloatCCRegOrder::getRegName( reg -32 - 64);
377 else if( reg < (64+32+4+2) ) // two names: %xcc and %ccr
378 return SparcIntCCRegOrder::getRegName( reg -32 - 64 - 4);
379 else if (reg== InvalidRegNum) //****** TODO: Remove */
382 assert(0 && "Invalid register number");
385 inline unsigned int getRegNumInCallersWindow(int reg) {
386 if (reg == InvalidRegNum || reg >= 32)
388 return SparcIntRegOrder::getRegNumInCallersWindow(reg);
391 inline bool mustBeRemappedInCallersWindow(int reg) {
392 return (reg != InvalidRegNum && reg < 32);
395 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
397 MachineInstr * cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
398 const int RegType) const;
400 MachineInstr * cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
401 const int Offset, const int RegType) const;
403 MachineInstr * cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
404 const unsigned DestReg, const int RegType) const;
406 MachineInstr* cpValue2Value(Value *Src, Value *Dest) const;
409 inline bool isRegVolatile(const int RegClassID, const int Reg) const {
410 return (MachineRegClassArr[RegClassID])->isRegVolatile(Reg);
414 inline unsigned getFramePointer() const {
415 return SparcIntRegOrder::i6;
418 inline unsigned getStackPointer() const {
419 return SparcIntRegOrder::o6;
422 inline int getInvalidRegNum() const {
423 return InvalidRegNum;
427 void insertCallerSavingCode(const MachineInstr *MInst,
428 const BasicBlock *BB, PhyRegAlloc &PRA ) const;
435 /*---------------------------------------------------------------------------
436 Scheduling guidelines for SPARC IIi:
438 I-Cache alignment rules (pg 326)
439 -- Align a branch target instruction so that it's entire group is within
440 the same cache line (may be 1-4 instructions).
441 ** Don't let a branch that is predicted taken be the last instruction
442 on an I-cache line: delay slot will need an entire line to be fetched
443 -- Make a FP instruction or a branch be the 4th instruction in a group.
444 For branches, there are tradeoffs in reordering to make this happen
446 ** Don't put a branch in a group that crosses a 32-byte boundary!
447 An artificial branch is inserted after every 32 bytes, and having
448 another branch will force the group to be broken into 2 groups.
451 -- Don't let a loop span two memory pages, if possible
453 Branch prediction performance:
454 -- Don't make the branch in a delay slot the target of a branch
455 -- Try not to have 2 predicted branches within a group of 4 instructions
456 (because each such group has a single branch target field).
457 -- Try to align branches in slots 0, 2, 4 or 6 of a cache line (to avoid
458 the wrong prediction bits being used in some cases).
460 D-Cache timing constraints:
461 -- Signed int loads of less than 64 bits have 3 cycle latency, not 2
462 -- All other loads that hit in D-Cache have 2 cycle latency
463 -- All loads are returned IN ORDER, so a D-Cache miss will delay a later hit
464 -- Mis-aligned loads or stores cause a trap. In particular, replace
465 mis-aligned FP double precision l/s with 2 single-precision l/s.
466 -- Simulations of integer codes show increase in avg. group size of
467 33% when code (including esp. non-faulting loads) is moved across
468 one branch, and 50% across 2 branches.
470 E-Cache timing constraints:
471 -- Scheduling for E-cache (D-Cache misses) is effective (due to load buffering)
473 Store buffer timing constraints:
474 -- Stores can be executed in same cycle as instruction producing the value
475 -- Stores are buffered and have lower priority for E-cache until
476 highwater mark is reached in the store buffer (5 stores)
478 Pipeline constraints:
479 -- Shifts can only use IEU0.
480 -- CC setting instructions can only use IEU1.
481 -- Several other instructions must only use IEU1:
482 EDGE(?), ARRAY(?), CALL, JMPL, BPr, PST, and FCMP.
483 -- Two instructions cannot store to the same register file in a single cycle
484 (single write port per file).
486 Issue and grouping constraints:
487 -- FP and branch instructions must use slot 4.
488 -- Shift instructions cannot be grouped with other IEU0-specific instructions.
489 -- CC setting instructions cannot be grouped with other IEU1-specific instrs.
490 -- Several instructions must be issued in a single-instruction group:
491 MOVcc or MOVr, MULs/x and DIVs/x, SAVE/RESTORE, many others
492 -- A CALL or JMPL breaks a group, ie, is not combined with subsequent instrs.
496 Branch delay slot scheduling rules:
497 -- A CTI couple (two back-to-back CTI instructions in the dynamic stream)
498 has a 9-instruction penalty: the entire pipeline is flushed when the
499 second instruction reaches stage 9 (W-Writeback).
500 -- Avoid putting multicycle instructions, and instructions that may cause
501 load misses, in the delay slot of an annulling branch.
502 -- Avoid putting WR, SAVE..., RESTORE and RETURN instructions in the
503 delay slot of an annulling branch.
505 *--------------------------------------------------------------------------- */
507 //---------------------------------------------------------------------------
508 // List of CPUResources for UltraSPARC IIi.
509 //---------------------------------------------------------------------------
511 const CPUResource AllIssueSlots( "All Instr Slots", 4);
512 const CPUResource IntIssueSlots( "Int Instr Slots", 3);
513 const CPUResource First3IssueSlots("Instr Slots 0-3", 3);
514 const CPUResource LSIssueSlots( "Load-Store Instr Slot", 1);
515 const CPUResource CTIIssueSlots( "Ctrl Transfer Instr Slot", 1);
516 const CPUResource FPAIssueSlots( "Int Instr Slot 1", 1);
517 const CPUResource FPMIssueSlots( "Int Instr Slot 1", 1);
519 // IEUN instructions can use either Alu and should use IAluN.
520 // IEU0 instructions must use Alu 1 and should use both IAluN and IAlu0.
521 // IEU1 instructions must use Alu 2 and should use both IAluN and IAlu1.
522 const CPUResource IAluN("Int ALU 1or2", 2);
523 const CPUResource IAlu0("Int ALU 1", 1);
524 const CPUResource IAlu1("Int ALU 2", 1);
526 const CPUResource LSAluC1("Load/Store Unit Addr Cycle", 1);
527 const CPUResource LSAluC2("Load/Store Unit Issue Cycle", 1);
528 const CPUResource LdReturn("Load Return Unit", 1);
530 const CPUResource FPMAluC1("FP Mul/Div Alu Cycle 1", 1);
531 const CPUResource FPMAluC2("FP Mul/Div Alu Cycle 2", 1);
532 const CPUResource FPMAluC3("FP Mul/Div Alu Cycle 3", 1);
534 const CPUResource FPAAluC1("FP Other Alu Cycle 1", 1);
535 const CPUResource FPAAluC2("FP Other Alu Cycle 2", 1);
536 const CPUResource FPAAluC3("FP Other Alu Cycle 3", 1);
538 const CPUResource IRegReadPorts("Int Reg ReadPorts", INT_MAX); // CHECK
539 const CPUResource IRegWritePorts("Int Reg WritePorts", 2); // CHECK
540 const CPUResource FPRegReadPorts("FP Reg Read Ports", INT_MAX); // CHECK
541 const CPUResource FPRegWritePorts("FP Reg Write Ports", 1); // CHECK
543 const CPUResource CTIDelayCycle( "CTI delay cycle", 1);
544 const CPUResource FCMPDelayCycle("FCMP delay cycle", 1);
547 //---------------------------------------------------------------------------
548 // const InstrClassRUsage SparcRUsageDesc[]
551 // Resource usage information for instruction in each scheduling class.
552 // The InstrRUsage Objects for individual classes are specified first.
553 // Note that fetch and decode are decoupled from the execution pipelines
554 // via an instr buffer, so they are not included in the cycles below.
555 //---------------------------------------------------------------------------
557 const InstrClassRUsage NoneClassRUsage = {
562 /* isSingleIssue */ false,
563 /* breaksGroup */ false,
567 /* feasibleSlots[] */ { 0, 1, 2, 3 },
581 const InstrClassRUsage IEUNClassRUsage = {
586 /* isSingleIssue */ false,
587 /* breaksGroup */ false,
591 /* feasibleSlots[] */ { 0, 1, 2 },
595 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
596 { IntIssueSlots.rid, 0, 1 },
597 /*Cycle E */ { IAluN.rid, 1, 1 },
602 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
606 const InstrClassRUsage IEU0ClassRUsage = {
611 /* isSingleIssue */ false,
612 /* breaksGroup */ false,
616 /* feasibleSlots[] */ { 0, 1, 2 },
620 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
621 { IntIssueSlots.rid, 0, 1 },
622 /*Cycle E */ { IAluN.rid, 1, 1 },
628 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
632 const InstrClassRUsage IEU1ClassRUsage = {
637 /* isSingleIssue */ false,
638 /* breaksGroup */ false,
642 /* feasibleSlots[] */ { 0, 1, 2 },
646 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
647 { IntIssueSlots.rid, 0, 1 },
648 /*Cycle E */ { IAluN.rid, 1, 1 },
654 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
658 const InstrClassRUsage FPMClassRUsage = {
663 /* isSingleIssue */ false,
664 /* breaksGroup */ false,
668 /* feasibleSlots[] */ { 0, 1, 2, 3 },
672 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
673 { FPMIssueSlots.rid, 0, 1 },
674 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
675 /*Cycle C */ { FPMAluC1.rid, 2, 1 },
676 /*Cycle N1*/ { FPMAluC2.rid, 3, 1 },
677 /*Cycle N1*/ { FPMAluC3.rid, 4, 1 },
679 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
683 const InstrClassRUsage FPAClassRUsage = {
688 /* isSingleIssue */ false,
689 /* breaksGroup */ false,
693 /* feasibleSlots[] */ { 0, 1, 2, 3 },
697 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
698 { FPAIssueSlots.rid, 0, 1 },
699 /*Cycle E */ { FPRegReadPorts.rid, 1, 1 },
700 /*Cycle C */ { FPAAluC1.rid, 2, 1 },
701 /*Cycle N1*/ { FPAAluC2.rid, 3, 1 },
702 /*Cycle N1*/ { FPAAluC3.rid, 4, 1 },
704 /*Cycle W */ { FPRegWritePorts.rid, 6, 1 }
708 const InstrClassRUsage LDClassRUsage = {
713 /* isSingleIssue */ false,
714 /* breaksGroup */ false,
718 /* feasibleSlots[] */ { 0, 1, 2, },
722 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
723 { First3IssueSlots.rid, 0, 1 },
724 { LSIssueSlots.rid, 0, 1 },
725 /*Cycle E */ { LSAluC1.rid, 1, 1 },
726 /*Cycle C */ { LSAluC2.rid, 2, 1 },
727 { LdReturn.rid, 2, 1 },
731 /*Cycle W */ { IRegWritePorts.rid, 6, 1 }
735 const InstrClassRUsage STClassRUsage = {
740 /* isSingleIssue */ false,
741 /* breaksGroup */ false,
745 /* feasibleSlots[] */ { 0, 1, 2 },
749 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
750 { First3IssueSlots.rid, 0, 1 },
751 { LSIssueSlots.rid, 0, 1 },
752 /*Cycle E */ { LSAluC1.rid, 1, 1 },
753 /*Cycle C */ { LSAluC2.rid, 2, 1 }
761 const InstrClassRUsage CTIClassRUsage = {
766 /* isSingleIssue */ false,
767 /* breaksGroup */ false,
771 /* feasibleSlots[] */ { 0, 1, 2, 3 },
775 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
776 { CTIIssueSlots.rid, 0, 1 },
777 /*Cycle E */ { IAlu0.rid, 1, 1 },
778 /*Cycles E-C */ { CTIDelayCycle.rid, 1, 2 }
787 const InstrClassRUsage SingleClassRUsage = {
792 /* isSingleIssue */ true,
793 /* breaksGroup */ false,
797 /* feasibleSlots[] */ { 0 },
801 /*Cycle G */ { AllIssueSlots.rid, 0, 1 },
802 { AllIssueSlots.rid, 0, 1 },
803 { AllIssueSlots.rid, 0, 1 },
804 { AllIssueSlots.rid, 0, 1 },
805 /*Cycle E */ { IAlu0.rid, 1, 1 }
815 const InstrClassRUsage SparcRUsageDesc[] = {
829 //---------------------------------------------------------------------------
830 // const InstrIssueDelta SparcInstrIssueDeltas[]
833 // Changes to issue restrictions information in InstrClassRUsage for
834 // instructions that differ from other instructions in their class.
835 //---------------------------------------------------------------------------
837 const InstrIssueDelta SparcInstrIssueDeltas[] = {
839 // opCode, isSingleIssue, breaksGroup, numBubbles
841 // Special cases for single-issue only
842 // Other single issue cases are below.
843 //{ LDDA, true, true, 0 },
844 //{ STDA, true, true, 0 },
845 //{ LDDF, true, true, 0 },
846 //{ LDDFA, true, true, 0 },
847 { ADDC, true, true, 0 },
848 { ADDCcc, true, true, 0 },
849 { SUBC, true, true, 0 },
850 { SUBCcc, true, true, 0 },
851 //{ LDSTUB, true, true, 0 },
852 //{ SWAP, true, true, 0 },
853 //{ SWAPA, true, true, 0 },
854 //{ CAS, true, true, 0 },
855 //{ CASA, true, true, 0 },
856 //{ CASX, true, true, 0 },
857 //{ CASXA, true, true, 0 },
858 //{ LDFSR, true, true, 0 },
859 //{ LDFSRA, true, true, 0 },
860 //{ LDXFSR, true, true, 0 },
861 //{ LDXFSRA, true, true, 0 },
862 //{ STFSR, true, true, 0 },
863 //{ STFSRA, true, true, 0 },
864 //{ STXFSR, true, true, 0 },
865 //{ STXFSRA, true, true, 0 },
866 //{ SAVED, true, true, 0 },
867 //{ RESTORED, true, true, 0 },
868 //{ FLUSH, true, true, 9 },
869 //{ FLUSHW, true, true, 9 },
870 //{ ALIGNADDR, true, true, 0 },
871 { RETURN, true, true, 0 },
872 //{ DONE, true, true, 0 },
873 //{ RETRY, true, true, 0 },
874 //{ WR, true, true, 0 },
875 //{ WRPR, true, true, 4 },
876 //{ RD, true, true, 0 },
877 //{ RDPR, true, true, 0 },
878 //{ TCC, true, true, 0 },
879 //{ SHUTDOWN, true, true, 0 },
881 // Special cases for breaking group *before*
882 // CURRENTLY NOT SUPPORTED!
883 { CALL, false, false, 0 },
884 { JMPLCALL, false, false, 0 },
885 { JMPLRET, false, false, 0 },
887 // Special cases for breaking the group *after*
888 { MULX, true, true, (4+34)/2 },
889 { FDIVS, false, true, 0 },
890 { FDIVD, false, true, 0 },
891 { FDIVQ, false, true, 0 },
892 { FSQRTS, false, true, 0 },
893 { FSQRTD, false, true, 0 },
894 { FSQRTQ, false, true, 0 },
895 //{ FCMP{LE,GT,NE,EQ}, false, true, 0 },
897 // Instructions that introduce bubbles
898 //{ MULScc, true, true, 2 },
899 //{ SMULcc, true, true, (4+18)/2 },
900 //{ UMULcc, true, true, (4+19)/2 },
901 { SDIVX, true, true, 68 },
902 { UDIVX, true, true, 68 },
903 //{ SDIVcc, true, true, 36 },
904 //{ UDIVcc, true, true, 37 },
905 //{ WR, false, false, 4 },
906 //{ WRPR, false, false, 4 },
910 //---------------------------------------------------------------------------
911 // const InstrRUsageDelta SparcInstrUsageDeltas[]
914 // Changes to resource usage information in InstrClassRUsage for
915 // instructions that differ from other instructions in their class.
916 //---------------------------------------------------------------------------
918 const InstrRUsageDelta SparcInstrUsageDeltas[] = {
920 // MachineOpCode, Resource, Start cycle, Num cycles
923 // JMPL counts as a load/store instruction for issue!
925 { JMPLCALL, LSIssueSlots.rid, 0, 1 },
926 { JMPLRET, LSIssueSlots.rid, 0, 1 },
929 // Many instructions cannot issue for the next 2 cycles after an FCMP
930 // We model that with a fake resource FCMPDelayCycle.
932 { FCMPS, FCMPDelayCycle.rid, 1, 3 },
933 { FCMPD, FCMPDelayCycle.rid, 1, 3 },
934 { FCMPQ, FCMPDelayCycle.rid, 1, 3 },
936 { MULX, FCMPDelayCycle.rid, 1, 1 },
937 { SDIVX, FCMPDelayCycle.rid, 1, 1 },
938 { UDIVX, FCMPDelayCycle.rid, 1, 1 },
939 //{ SMULcc, FCMPDelayCycle.rid, 1, 1 },
940 //{ UMULcc, FCMPDelayCycle.rid, 1, 1 },
941 //{ SDIVcc, FCMPDelayCycle.rid, 1, 1 },
942 //{ UDIVcc, FCMPDelayCycle.rid, 1, 1 },
943 { STD, FCMPDelayCycle.rid, 1, 1 },
944 { FMOVRSZ, FCMPDelayCycle.rid, 1, 1 },
945 { FMOVRSLEZ,FCMPDelayCycle.rid, 1, 1 },
946 { FMOVRSLZ, FCMPDelayCycle.rid, 1, 1 },
947 { FMOVRSNZ, FCMPDelayCycle.rid, 1, 1 },
948 { FMOVRSGZ, FCMPDelayCycle.rid, 1, 1 },
949 { FMOVRSGEZ,FCMPDelayCycle.rid, 1, 1 },
952 // Some instructions are stalled in the GROUP stage if a CTI is in
955 { LDD, CTIDelayCycle.rid, 1, 1 },
956 //{ LDDA, CTIDelayCycle.rid, 1, 1 },
957 //{ LDDSTUB, CTIDelayCycle.rid, 1, 1 },
958 //{ LDDSTUBA, CTIDelayCycle.rid, 1, 1 },
959 //{ SWAP, CTIDelayCycle.rid, 1, 1 },
960 //{ SWAPA, CTIDelayCycle.rid, 1, 1 },
961 //{ CAS, CTIDelayCycle.rid, 1, 1 },
962 //{ CASA, CTIDelayCycle.rid, 1, 1 },
963 //{ CASX, CTIDelayCycle.rid, 1, 1 },
964 //{ CASXA, CTIDelayCycle.rid, 1, 1 },
967 // Signed int loads of less than dword size return data in cycle N1 (not C)
968 // and put all loads in consecutive cycles into delayed load return mode.
970 { LDSB, LdReturn.rid, 2, -1 },
971 { LDSB, LdReturn.rid, 3, 1 },
973 { LDSH, LdReturn.rid, 2, -1 },
974 { LDSH, LdReturn.rid, 3, 1 },
976 { LDSW, LdReturn.rid, 2, -1 },
977 { LDSW, LdReturn.rid, 3, 1 },
980 #undef EXPLICIT_BUBBLES_NEEDED
981 #ifdef EXPLICIT_BUBBLES_NEEDED
983 // MULScc inserts one bubble.
984 // This means it breaks the current group (captured in UltraSparcSchedInfo)
985 // *and occupies all issue slots for the next cycle
987 //{ MULScc, AllIssueSlots.rid, 2, 2-1 },
988 //{ MULScc, AllIssueSlots.rid, 2, 2-1 },
989 //{ MULScc, AllIssueSlots.rid, 2, 2-1 },
990 //{ MULScc, AllIssueSlots.rid, 2, 2-1 },
993 // SMULcc inserts between 4 and 18 bubbles, depending on #leading 0s in rs1.
994 // We just model this with a simple average.
996 //{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
997 //{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
998 //{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
999 //{ SMULcc, AllIssueSlots.rid, 2, ((4+18)/2)-1 },
1001 // SMULcc inserts between 4 and 19 bubbles, depending on #leading 0s in rs1.
1002 //{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1003 //{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1004 //{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1005 //{ UMULcc, AllIssueSlots.rid, 2, ((4+19)/2)-1 },
1008 // MULX inserts between 4 and 34 bubbles, depending on #leading 0s in rs1.
1010 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1011 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1012 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1013 { MULX, AllIssueSlots.rid, 2, ((4+34)/2)-1 },
1016 // SDIVcc inserts 36 bubbles.
1018 //{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1019 //{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1020 //{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1021 //{ SDIVcc, AllIssueSlots.rid, 2, 36-1 },
1023 // UDIVcc inserts 37 bubbles.
1024 //{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1025 //{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1026 //{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1027 //{ UDIVcc, AllIssueSlots.rid, 2, 37-1 },
1030 // SDIVX inserts 68 bubbles.
1032 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1033 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1034 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1035 { SDIVX, AllIssueSlots.rid, 2, 68-1 },
1038 // UDIVX inserts 68 bubbles.
1040 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1041 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1042 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1043 { UDIVX, AllIssueSlots.rid, 2, 68-1 },
1046 // WR inserts 4 bubbles.
1048 //{ WR, AllIssueSlots.rid, 2, 68-1 },
1049 //{ WR, AllIssueSlots.rid, 2, 68-1 },
1050 //{ WR, AllIssueSlots.rid, 2, 68-1 },
1051 //{ WR, AllIssueSlots.rid, 2, 68-1 },
1054 // WRPR inserts 4 bubbles.
1056 //{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1057 //{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1058 //{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1059 //{ WRPR, AllIssueSlots.rid, 2, 68-1 },
1062 // DONE inserts 9 bubbles.
1064 //{ DONE, AllIssueSlots.rid, 2, 9-1 },
1065 //{ DONE, AllIssueSlots.rid, 2, 9-1 },
1066 //{ DONE, AllIssueSlots.rid, 2, 9-1 },
1067 //{ DONE, AllIssueSlots.rid, 2, 9-1 },
1070 // RETRY inserts 9 bubbles.
1072 //{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1073 //{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1074 //{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1075 //{ RETRY, AllIssueSlots.rid, 2, 9-1 },
1077 #endif /*EXPLICIT_BUBBLES_NEEDED */
1082 // Additional delays to be captured in code:
1083 // 1. RDPR from several state registers (page 349)
1084 // 2. RD from *any* register (page 349)
1085 // 3. Writes to TICK, PSTATE, TL registers and FLUSH{W} instr (page 349)
1086 // 4. Integer store can be in same group as instr producing value to store.
1087 // 5. BICC and BPICC can be in the same group as instr producing CC (pg 350)
1088 // 6. FMOVr cannot be in the same or next group as an IEU instr (pg 351).
1089 // 7. The second instr. of a CTI group inserts 9 bubbles (pg 351)
1090 // 8. WR{PR}, SVAE, SAVED, RESTORE, RESTORED, RETURN, RETRY, and DONE that
1091 // follow an annulling branch cannot be issued in the same group or in
1092 // the 3 groups following the branch.
1093 // 9. A predicted annulled load does not stall dependent instructions.
1094 // Other annulled delay slot instructions *do* stall dependents, so
1095 // nothing special needs to be done for them during scheduling.
1096 //10. Do not put a load use that may be annulled in the same group as the
1097 // branch. The group will stall until the load returns.
1098 //11. Single-prec. FP loads lock 2 registers, for dependency checking.
1101 // Additional delays we cannot or will not capture:
1102 // 1. If DCTI is last word of cache line, it is delayed until next line can be
1103 // fetched. Also, other DCTI alignment-related delays (pg 352)
1104 // 2. Load-after-store is delayed by 7 extra cycles if load hits in D-Cache.
1105 // Also, several other store-load and load-store conflicts (pg 358)
1106 // 3. MEMBAR, LD{X}FSR, LDD{A} and a bunch of other load stalls (pg 358)
1107 // 4. There can be at most 8 outstanding buffered store instructions
1108 // (including some others like MEMBAR, LDSTUB, CAS{AX}, and FLUSH)
1112 //---------------------------------------------------------------------------
1113 // class UltraSparcSchedInfo
1116 // Interface to instruction scheduling information for UltraSPARC.
1117 // The parameter values above are based on UltraSPARC IIi.
1118 //---------------------------------------------------------------------------
1121 class UltraSparcSchedInfo: public MachineSchedInfo {
1123 /*ctor*/ UltraSparcSchedInfo (const MachineInstrInfo* mii);
1124 /*dtor*/ virtual ~UltraSparcSchedInfo () {}
1126 virtual void initializeResources ();
1130 //---------------------------------------------------------------------------
1131 // class UltraSparcFrameInfo
1134 // Interface to stack frame layout info for the UltraSPARC.
1135 // Note that there is no machine-independent interface to this information
1136 //---------------------------------------------------------------------------
1138 class UltraSparcFrameInfo: public NonCopyable {
1140 static const int MinStackFrameSize = 176;
1141 static const int FirstOutgoingArgOffsetFromSP = 128;
1142 static const int FirstOptionalOutgoingArgOffsetFromSP = 176;
1143 static const int StaticStackAreaOffsetFromFP = -1;
1145 static const int FirstIncomingArgOffsetFromFP = 126;
1147 static int getFirstAutomaticVarOffsetFromFP (const Method* method);
1148 static int getRegSpillAreaOffsetFromFP (const Method* method);
1149 static int getFrameSizeBelowDynamicArea (const Method* method);
1154 //---------------------------------------------------------------------------
1155 // class UltraSparcMachine
1158 // Primary interface to machine description for the UltraSPARC.
1159 // Primarily just initializes machine-dependent parameters in
1160 // class TargetMachine, and creates machine-dependent subclasses
1161 // for classes such as InstrInfo, SchedInfo and RegInfo.
1162 //---------------------------------------------------------------------------
1164 class UltraSparc : public TargetMachine {
1166 UltraSparcInstrInfo instrInfo;
1167 UltraSparcSchedInfo schedInfo;
1168 UltraSparcRegInfo regInfo;
1169 UltraSparcFrameInfo frameInfo;
1172 virtual ~UltraSparc() {}
1174 virtual const MachineInstrInfo &getInstrInfo() const { return instrInfo; }
1175 virtual const MachineSchedInfo &getSchedInfo() const { return schedInfo; }
1176 virtual const MachineRegInfo &getRegInfo() const { return regInfo; }
1177 const UltraSparcFrameInfo &getFrameInfo() const { return frameInfo; }
1180 // compileMethod - For the sparc, we do instruction selection, followed by
1181 // delay slot scheduling, then register allocation.
1183 virtual bool compileMethod(Method *M);
1186 // emitAssembly - Output assembly language code (a .s file) for the specified
1187 // module. The specified module must have been compiled before this may be
1190 virtual void emitAssembly(const Module *M, ostream &OutStr) const;