llvm.org GIT mirror llvm / 4188699
Foundation for call frame information. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@27491 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Laskey 14 years ago
21 changed file(s) with 363 addition(s) and 69 deletion(s). Raw diff Collapse all Expand all
4040 class DIEAbbrev;
4141 class GlobalVariableDesc;
4242 class MachineDebugInfo;
43 class MachineFunction;
4344 class MachineLocation;
44 class MachineFunction;
45 class MachineMove;
4546 class Module;
47 class MRegisterInfo;
4648 class SubprogramDesc;
49 class TargetData;
4750 class Type;
4851 class TypeDesc;
4952
7982 /// Asm - Target of Dwarf emission.
8083 ///
8184 AsmPrinter *Asm;
85
86 /// TD - Target data.
87 const TargetData &TD;
88
89 /// RI - Register Information.
90 const MRegisterInfo *RI;
8291
8392 /// M - Current module.
8493 ///
323332
324333 /// AddAddress - Add an address attribute to a die based on the location
325334 /// provided.
326 void AddAddress(DIE *Die, unsigned Attribute, MachineLocation &Location);
335 void AddAddress(DIE *Die, unsigned Attribute,
336 const MachineLocation &Location);
327337
328338 /// NewType - Create a new type DIE.
329339 ///
374384 ///
375385 void SizeAndOffsets();
376386
387 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
388 /// frame.
389 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
390 std::vector &Moves);
391
377392 /// EmitDebugInfo - Emit the debug info section.
378393 ///
379394 void EmitDebugInfo() const;
386401 ///
387402 void EmitDebugLines() const;
388403
389 /// EmitDebugFrame - Emit info into a debug frame section.
390 ///
391 void EmitDebugFrame();
392
404 /// EmitInitialDebugFrame - Emit common frame info into a debug frame section.
405 ///
406 void EmitInitialDebugFrame();
407
408 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
409 /// section.
410 void EmitFunctionDebugFrame();
411
393412 /// EmitDebugPubNames - Emit info into a debug pubnames section.
394413 ///
395414 void EmitDebugPubNames();
438457
439458 /// SetDebugInfo - Set DebugInfo when it's known that pass manager has
440459 /// created it. Set by the target AsmPrinter.
441 void SetDebugInfo(MachineDebugInfo *DI) { DebugInfo = DI; }
460 void SetDebugInfo(MachineDebugInfo *DI);
442461
443462 //===--------------------------------------------------------------------===//
444463 // Main entry points.
4646 class Constant;
4747 class DebugInfoDesc;
4848 class GlobalVariable;
49 class MachineFunction;
50 class MachineMove;
4951 class Module;
5052 class PointerType;
5153 class StructType;
573575 void setName(const std::string &N) { Name = N; }
574576 void setFile(CompileUnitDesc *U) { File = U; }
575577 void setLine(unsigned L) { Line = L; }
576 void setTypeDesc(TypeDesc *T) { TyDesc = T; }
578 void setType(TypeDesc *T) { TyDesc = T; }
577579 void setIsStatic(bool IS) { IsStatic = IS; }
578580 void setIsDefinition(bool ID) { IsDefinition = ID; }
579581
939941 // RootScope - Top level scope for the current function.
940942 //
941943 DebugScope *RootScope;
944
945 // FrameMoves - List of moves done by a function's prolog. Used to construct
946 // frame maps by debug consumers.
947 std::vector FrameMoves;
942948
943949 public:
944950 MachineDebugInfo();
952958 ///
953959 bool doFinalization();
954960
961 /// BeginFunction - Begin gathering function debug information.
962 ///
963 void BeginFunction(MachineFunction *MF);
964
965 /// EndFunction - Discard function debug information.
966 ///
967 void EndFunction();
968
955969 /// getDescFor - Convert a Value to a debug information descriptor.
956970 ///
957971 // FIXME - use new Value type when available.
10591073 /// getOrCreateScope - Returns the scope associated with the given descriptor.
10601074 ///
10611075 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1062
1063 /// ClearScopes - Delete the scope and variable info after a function is
1064 /// completed.
1065 void ClearScopes();
1076
1077 /// getFrameMoves - Returns a reference to a list of moves done in the current
1078 /// function's prologue. Used to construct frame maps for debug comsumers.
1079 std::vector &getFrameMoves() { return FrameMoves; }
10661080
10671081 }; // End class MachineDebugInfo
10681082
4343 class TargetData;
4444 class TargetRegisterClass;
4545 class Type;
46 class MachineDebugInfo;
4647 class MachineFunction;
4748
4849 class MachineFrameInfo {
105106 /// insertion.
106107 ///
107108 unsigned MaxCallFrameSize;
109
110 /// DebugInfo - This field is set (via setMachineDebugInfo) by a debug info
111 /// consumer (ex. DwarfWriter) to indicate that frame layout information
112 /// should be acquired. Typically, it's the responsibility of the target's
113 /// MRegisterInfo prologue/epilogue emitting code to inform MachineDebugInfo
114 /// of frame layouts.
115 MachineDebugInfo *DebugInfo;
116
108117 public:
109118 MachineFrameInfo() {
110119 NumFixedObjects = StackSize = MaxAlignment = 0;
111120 HasVarSizedObjects = false;
112121 HasCalls = false;
113122 MaxCallFrameSize = 0;
123 DebugInfo = 0;
114124 }
115125
116126 /// hasStackObjects - Return true if there are any stack objects in this
229239 return Objects.size()-NumFixedObjects-1;
230240 }
231241
242 /// getMachineDebugInfo - Used by a prologue/epilogue emitter (MRegisterInfo)
243 /// to provide frame layout information.
244 MachineDebugInfo *getMachineDebugInfo() const { return DebugInfo; }
245
246 /// setMachineDebugInfo - Used by a debug consumer (DwarfWriter) to indicate
247 /// that frame layout information should be gathered.
248 void setMachineDebugInfo(MachineDebugInfo *DI) { DebugInfo = DI; }
249
232250 /// print - Used by the MachineFunction printer to print information about
233251 /// stack objects. Implemented in MachineFunction.cpp
234252 ///
77 //===----------------------------------------------------------------------===//
88 // The MachineLocation class is used to represent a simple location in a machine
99 // frame. Locations will be one of two forms; a register or an address formed
10 // from a base address plus an offset.
10 // from a base address plus an offset. Register indirection can be specified by
11 // using an offset of zero.
12 //
13 // The MachineMove class is used to represent abstract move operations in the
14 // prolog/epilog of a compiled function. A collection of these objects can be
15 // used by a debug consumer to track the location of values when unwinding stack
16 // frames.
1117 //===----------------------------------------------------------------------===//
1218
1319
2329 int Offset; // Displacement if not register.
2430
2531 public:
32 enum {
33 // The target register number for an abstract frame pointer. The value is
34 // an arbitrary value greater than MRegisterInfo::FirstVirtualRegister.
35 VirtualFP = ~0U
36 };
2637 MachineLocation()
2738 : IsRegister(false)
2839 , Register(0)
3647 MachineLocation(unsigned R, int O)
3748 : IsRegister(false)
3849 , Register(R)
39 , Offset(0)
50 , Offset(O)
4051 {}
4152
4253 // Accessors
5667 Register = R;
5768 Offset = O;
5869 }
70
71 #ifndef NDEBUG
72 void dump();
73 #endif
74 };
75
76 class MachineMove {
77 private:
78 unsigned LabelID; // Label ID number for post-instruction
79 // address when result of move takes
80 // effect.
81 const MachineLocation Destination; // Move to location.
82 const MachineLocation Source; // Move from location.
83
84 public:
85 MachineMove(unsigned ID, MachineLocation &D, MachineLocation &S)
86 : LabelID(ID)
87 , Destination(D)
88 , Source(S)
89 {}
90
91 // Accessors
92 unsigned getLabelID() const { return LabelID; }
93 const MachineLocation &getDestination() const { return Destination; }
94 const MachineLocation &getSource() const { return Source; }
5995 };
6096
6197 } // End llvm namespace
2626 class MachineFunction;
2727 class MachineInstr;
2828 class MachineLocation;
29 class MachineMove;
2930 class TargetRegisterClass;
3031
3132 /// TargetRegisterDesc - This record contains all of the information known about
344345
345346 //===--------------------------------------------------------------------===//
346347 /// Debug information queries.
348
349 /// getDwarfRegNum - Map a target register to an equivalent dwarf register
350 /// number. Returns -1 if there is no equivalent value.
351 virtual int getDwarfRegNum(unsigned RegNum) const = 0;
347352
348353 /// getFrameRegister - This method should return the register used as a base
349 /// for values allocated in the current stack frame. This value should be
350 /// returned as a dwarf register number (getDwarfRegNum.)
354 /// for values allocated in the current stack frame.
351355 virtual unsigned getFrameRegister(MachineFunction &MF) const = 0;
356
357 /// getRARegister - This method should return the register where the return
358 /// address can be found.
359 virtual unsigned getRARegister() const = 0;
352360
361 /// getStackDirection - This method should return the factor by which stacks
362 /// grow. The tyical value is -4 which is the grows negatively in 4 byte
363 /// increments.
364 virtual int getStackDirection() const;
365
353366 /// getLocation - This method should return the actual location of a frame
354367 /// variable given the frame index. The location is returned in ML.
355368 /// Subclasses should override this method for special handling of frame
356369 /// variables and call MRegisterInfo::getLocation for the default action.
357370 virtual void getLocation(MachineFunction &MF, unsigned Index,
358371 MachineLocation &ML) const;
372
373 /// getInitialFrameState - Returns a list of machine moves that are assumed
374 /// on entry to all functions. Note that LabelID is ignored (assumed to be
375 /// the beginning of the function.)
376 virtual void getInitialFrameState(std::vector &Moves) const;
359377 };
360378
361379 // This is useful when building DenseMaps keyed on virtual registers
1717 #include "llvm/Type.h"
1818 #include "llvm/CodeGen/AsmPrinter.h"
1919 #include "llvm/CodeGen/MachineDebugInfo.h"
20 #include "llvm/CodeGen/MachineFrameInfo.h"
2021 #include "llvm/CodeGen/MachineLocation.h"
2122 #include "llvm/Support/Dwarf.h"
2223 #include "llvm/Support/CommandLine.h"
10721073 if (Asm->Data64bitsDirective) {
10731074 O << Asm->Data64bitsDirective << "0x" << std::hex << Value << std::dec;
10741075 } else {
1075 const TargetData &TD = Asm->TM.getTargetData();
1076
10771076 if (TD.isBigEndian()) {
10781077 EmitInt32(unsigned(Value >> 32)); O << "\n";
10791078 EmitInt32(unsigned(Value));
12151214 /// AddAddress - Add an address attribute to a die based on the location
12161215 /// provided.
12171216 void DwarfWriter::AddAddress(DIE *Die, unsigned Attribute,
1218 MachineLocation &Location) {
1217 const MachineLocation &Location) {
12191218 DIEBlock *Block = new DIEBlock();
12201219 if (Location.isRegister()) {
1221 Block->AddUInt(DW_FORM_data1, DW_OP_reg0 + Location.getRegister());
1220 Block->AddUInt(DW_FORM_data1,
1221 DW_OP_reg0 + RI->getDwarfRegNum(Location.getRegister()));
12221222 } else {
1223 Block->AddUInt(DW_FORM_data1, DW_OP_breg0 + Location.getRegister());
1223 Block->AddUInt(DW_FORM_data1,
1224 DW_OP_breg0 + RI->getDwarfRegNum(Location.getRegister()));
12241225 Block->AddUInt(DW_FORM_sdata, Location.getOffset());
12251226 }
12261227 Block->ComputeSize(*this);
13571358 // Now normalize offset to the field.
13581359 Offset -= FieldOffset;
13591360
1360 // Maybe we need to work from the other.
1361 const TargetData &TD = Asm->TM.getTargetData();
1361 // Maybe we need to work from the other end.
13621362 if (TD.isLittleEndian()) Offset = FieldSize - (Offset + Size);
13631363
13641364 Member->AddUInt(DW_AT_byte_size, 0, FieldSize >> 3);
15141514
15151515 DIE *SubprogramDie = new DIE(DW_TAG_subprogram);
15161516 SubprogramDie->AddString (DW_AT_name, DW_FORM_string, Name);
1517 SubprogramDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type);
1518 SubprogramDie->AddUInt (DW_AT_external, DW_FORM_flag, IsExternal);
1517 if (Type) {
1518 SubprogramDie->AddDIEntry (DW_AT_type, DW_FORM_ref4, Type);
1519 }
1520 SubprogramDie->AddUInt (DW_AT_external, DW_FORM_flag, IsExternal);
1521 SubprogramDie->AddUInt (DW_AT_prototyped, DW_FORM_flag, 1);
15191522
15201523 // Add source line info if available.
15211524 AddSourceLine(SubprogramDie, UnitDesc, SPD->getLine());
15601563
15611564 // Add variable address.
15621565 MachineLocation Location;
1563 Asm->TM.getRegisterInfo()->getLocation(*MF, DV->getFrameIndex(), Location);
1566 RI->getLocation(*MF, DV->getFrameIndex(), Location);
15641567 AddAddress(VariableDie, DW_AT_location, Location);
15651568
15661569 return VariableDie;
16201623
16211624 // Get the compile unit context.
16221625 CompileUnitDesc *UnitDesc = static_cast(SPD->getContext());
1623 CompileUnit *Unit = FindCompileUnit(UnitDesc);
1626 CompileUnit *Unit = FindCompileUnit(UnitDesc);
1627
1628 // Generate the mangled name.
1629 std::string MangledName = Asm->Mang->getValueName(MF->getFunction());
16241630
16251631 // Get the subprogram die.
16261632 DIE *SPDie = Unit->getDieMapSlotFor(SPD);
16271633 assert(SPDie && "Missing subprogram descriptor");
16281634
16291635 // Add the function bounds.
1630 SPDie->AddLabel(DW_AT_low_pc, DW_FORM_addr,
1631 DWLabel("func_begin", SubprogramCount));
1636 SPDie->AddObjectLabel(DW_AT_low_pc, DW_FORM_addr, MangledName);
16321637 SPDie->AddLabel(DW_AT_high_pc, DW_FORM_addr,
16331638 DWLabel("func_end", SubprogramCount));
1634 MachineLocation Location(Asm->TM.getRegisterInfo()->getFrameRegister(*MF));
1639 MachineLocation Location(RI->getFrameRegister(*MF));
16351640 AddAddress(SPDie, DW_AT_frame_base, Location);
16361641
16371642 ConstructScope(RootScope, SPDie, Unit);
17911796 }
17921797 }
17931798
1799 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
1800 /// frame.
1801 void DwarfWriter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
1802 std::vector &Moves) {
1803 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
1804 MachineMove *Move = Moves[i];
1805 unsigned LabelID = Move->getLabelID();
1806 const MachineLocation &Dst = Move->getDestination();
1807 const MachineLocation &Src = Move->getSource();
1808
1809 // Advance row if new location.
1810 if (BaseLabel && LabelID && BaseLabelID != LabelID) {
1811 EmitULEB128Bytes(DW_CFA_advance_loc4);
1812 EOL("DW_CFA_advance_loc4");
1813 EmitDifference("loc", LabelID, BaseLabel, BaseLabelID);
1814 EOL("");
1815
1816 BaseLabelID = LabelID;
1817 BaseLabel = "loc";
1818 }
1819
1820 // If advancing cfa.
1821 if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
1822 if (!Src.isRegister()) {
1823 if (Src.getRegister() == MachineLocation::VirtualFP) {
1824 EmitULEB128Bytes(DW_CFA_def_cfa_offset);
1825 EOL("DW_CFA_def_cfa_offset");
1826 } else {
1827 EmitULEB128Bytes(DW_CFA_def_cfa);
1828 EOL("DW_CFA_def_cfa");
1829
1830 EmitULEB128Bytes(RI->getDwarfRegNum(Src.getRegister()));
1831 EOL("Register");
1832 }
1833
1834 EmitULEB128Bytes(Src.getOffset() / RI->getStackDirection());
1835 EOL("Offset");
1836 } else {
1837 }
1838 } else {
1839 }
1840 }
1841 }
1842
17941843 /// EmitDebugInfo - Emit the debug info section.
17951844 ///
17961845 void DwarfWriter::EmitDebugInfo() const {
19982047 O << "\n";
19992048 }
20002049
2001 /// EmitDebugFrame - Emit visible names into a debug frame section.
2002 ///
2003 void DwarfWriter::EmitDebugFrame() {
2004 // Start the dwarf pubnames section.
2050 /// EmitInitialDebugFrame - Emit common frame info into a debug frame section.
2051 ///
2052 void DwarfWriter::EmitInitialDebugFrame() {
2053 // Start the dwarf frame section.
20052054 Asm->SwitchSection(DwarfFrameSection, 0);
20062055
20072056 EmitDifference("frame_common_end", 0,
20132062 EmitInt8(DW_CIE_VERSION); EOL("CIE Version");
20142063 EmitString(""); EOL("CIE Augmentation");
20152064 EmitULEB128Bytes(1); EOL("CIE Code Alignment Factor");
2016 // FIXME - needs to change based on stack direction.
2017 EmitSLEB128Bytes(-sizeof(int32_t)); EOL("CIE Data Alignment Factor");
2018 // FIXME - hard coded for PPC (LR).
2019 EmitInt8(0x41); EOL("CIE RA Column Hardcoded (PPC LR)");
2020 // FIXME - hard coded for PPC 0(SP).
2021 EmitULEB128Bytes(DW_CFA_def_cfa); EOL("DW_CFA_def_cfa");
2022 EmitULEB128Bytes(1); EOL("PPC Register SP");
2023 EmitULEB128Bytes(0); EOL("PPC offset 0 as in 0(SP)");
2065 EmitSLEB128Bytes(RI->getStackDirection()); EOL("CIE Data Alignment Factor");
2066 EmitInt8(RI->getDwarfRegNum(RI->getRARegister())); EOL("CIE RA Column");
2067
2068 std::vector Moves;
2069 RI->getInitialFrameState(Moves);
2070 EmitFrameMoves(NULL, 0, Moves);
2071 for (unsigned i = 0, N = Moves.size(); i < N; ++i) delete Moves[i];
2072
20242073 EmitAlign(2);
20252074 EmitLabel("frame_common_end", 0);
20262075
2076 O << "\n";
2077 }
2078
2079 /// EmitFunctionDebugFrame - Emit per function frame info into a debug frame
2080 /// section.
2081 void DwarfWriter::EmitFunctionDebugFrame() {
2082 // Start the dwarf frame section.
2083 Asm->SwitchSection(DwarfFrameSection, 0);
2084
2085 EmitDifference("frame_end", SubprogramCount,
2086 "frame_begin", SubprogramCount);
2087 EOL("Length of Frame Information Entry");
2088
2089 EmitLabel("frame_begin", SubprogramCount);
2090
2091 EmitReference("section_frame", 0); EOL("FDE CIE offset");
2092
2093 EmitReference("func_begin", SubprogramCount); EOL("FDE initial location");
2094 EmitDifference("func_end", SubprogramCount,
2095 "func_begin", SubprogramCount);
2096 EOL("FDE address range");
2097
2098 std::vector &Moves = DebugInfo->getFrameMoves();
2099
2100 EmitFrameMoves("func_begin", SubprogramCount, Moves);
2101
2102 EmitAlign(2);
2103 EmitLabel("frame_end", SubprogramCount);
2104
20272105 O << "\n";
20282106 }
20292107
22072285 if (!didInitial) {
22082286 EmitInitial();
22092287
2288 // Emit common frame information.
2289 EmitInitialDebugFrame();
2290
22102291 // Create all the compile unit DIEs.
22112292 ConstructCompileUnitDIEs();
22122293
22302311 DwarfWriter::DwarfWriter(std::ostream &OS, AsmPrinter *A)
22312312 : O(OS)
22322313 , Asm(A)
2314 , TD(Asm->TM.getTargetData())
2315 , RI(Asm->TM.getRegisterInfo())
22332316 , M(NULL)
22342317 , MF(NULL)
22352318 , DebugInfo(NULL)
22662349 }
22672350 }
22682351
2352 /// SetDebugInfo - Set DebugInfo when it's known that pass manager has
2353 /// created it. Set by the target AsmPrinter.
2354 void DwarfWriter::SetDebugInfo(MachineDebugInfo *DI) {
2355 DebugInfo = DI;
2356 }
2357
22692358 /// BeginModule - Emit all Dwarf sections that should come prior to the content.
22702359 ///
22712360 void DwarfWriter::BeginModule(Module *M) {
22992388 // Emit source line correspondence into a debug line section.
23002389 EmitDebugLines();
23012390
2302 // Emit info into a debug frame section.
2303 EmitDebugFrame();
2304
23052391 // Emit info into a debug pubnames section.
23062392 EmitDebugPubNames();
23072393
23252411 ///
23262412 void DwarfWriter::BeginFunction(MachineFunction *MF) {
23272413 this->MF = MF;
2414
2415 // Begin accumulating function debug information.
2416 DebugInfo->BeginFunction(MF);
23282417
23292418 if (!ShouldEmitDwarf()) return;
23302419 EOL("Dwarf Begin Function");
23342423 EmitLabel("func_begin", ++SubprogramCount);
23352424 }
23362425
2337
23382426 /// EndFunction - Gather and emit post-function debug information.
23392427 ///
23402428 void DwarfWriter::EndFunction() {
23472435
23482436 // Construct scopes for subprogram.
23492437 ConstructRootScope(DebugInfo->getRootScope());
2350 DebugInfo->ClearScopes();
2351 }
2438
2439 // Emit function frame information.
2440 EmitFunctionDebugFrame();
2441
2442 // Clear function debug information.
2443 DebugInfo->EndFunction();
2444 }
99 #include "llvm/CodeGen/MachineDebugInfo.h"
1010
1111 #include "llvm/Constants.h"
12 #include "llvm/CodeGen/MachineLocation.h"
1213 #include "llvm/DerivedTypes.h"
1314 #include "llvm/GlobalVariable.h"
1415 #include "llvm/Intrinsics.h"
14231424 , LabelID(0)
14241425 , ScopeMap()
14251426 , RootScope(NULL)
1426 {
1427
1428 }
1427 , FrameMoves()
1428 {}
14291429 MachineDebugInfo::~MachineDebugInfo() {
14301430
14311431 }
14401440 ///
14411441 bool MachineDebugInfo::doFinalization() {
14421442 return false;
1443 }
1444
1445 /// BeginFunction - Begin gathering function debug information.
1446 ///
1447 void MachineDebugInfo::BeginFunction(MachineFunction *MF) {
1448 // Coming soon.
1449 }
1450
1451 /// MachineDebugInfo::EndFunction - Discard function debug information.
1452 ///
1453 void MachineDebugInfo::EndFunction() {
1454 // Clean up scope information.
1455 if (RootScope) {
1456 delete RootScope;
1457 ScopeMap.clear();
1458 RootScope = NULL;
1459 }
1460
1461 // Clean up frame info.
1462 for (unsigned i = 0, N = FrameMoves.size(); i < N; ++i) delete FrameMoves[i];
1463 FrameMoves.clear();
14431464 }
14441465
14451466 /// getDescFor - Convert a Value to a debug information descriptor.
15641585 return Slot;
15651586 }
15661587
1567 /// ClearScopes - Delete the scope and variable info after a function is
1568 /// completed.
1569 void MachineDebugInfo::ClearScopes() {
1570 if (RootScope) {
1571 delete RootScope;
1572 ScopeMap.clear();
1573 RootScope = NULL;
1574 }
1575 }
1576
1577
1588
3535 /// frame indexes with appropriate references.
3636 ///
3737 bool runOnMachineFunction(MachineFunction &Fn) {
38 // Get MachineDebugInfo so that we can track the construction of the
39 // frame.
40 if (MachineDebugInfo *DI = getAnalysisToUpdate()) {
41 Fn.getFrameInfo()->setMachineDebugInfo(DI);
42 }
43
3844 // Scan the function for modified caller saved registers and insert spill
3945 // code for any caller saved registers that are modified. Also calculate
4046 // the MaxCallFrameSize and HasCalls variables for the function's frame
353353 }
354354 }
355355
356 unsigned AlphaRegisterInfo::getRARegister() const {
357 assert(0 && "What is the return address register");
358 return 0;
359 }
360
356361 unsigned AlphaRegisterInfo::getFrameRegister(MachineFunction &MF) const {
357 return getDwarfRegNum(hasFP(MF) ? Alpha::R15 : Alpha::R30);
362 return hasFP(MF) ? Alpha::R15 : Alpha::R30;
358363 }
359364
360365 #include "AlphaGenRegisterInfo.inc"
5252 void emitPrologue(MachineFunction &MF) const;
5353 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
5454
55 // Debug information queries.
55 // Debug information queries.
56 unsigned getRARegister() const;
5657 unsigned getFrameRegister(MachineFunction &MF) const;
5758
5859 static std::string getPrettyName(unsigned reg);
328328
329329 }
330330
331 unsigned IA64RegisterInfo::getRARegister() const {
332 assert(0 && "What is the return address register");
333 return 0;
334 }
335
331336 unsigned IA64RegisterInfo::getFrameRegister(MachineFunction &MF) const {
332 return getDwarfRegNum(hasFP(MF) ? IA64::r5 : IA64::r12);
337 return hasFP(MF) ? IA64::r5 : IA64::r12;
333338 }
334339
335340 #include "IA64GenRegisterInfo.inc"
4949 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
5050
5151 // Debug information queries.
52 unsigned getRARegister() const;
5253 unsigned getFrameRegister(MachineFunction &MF) const;
5354 };
5455
4343 return Allocatable;
4444 }
4545
46 /// getStackDirection - This method should return the factor by which stacks
47 /// grow. The tyical value is -4 which is the grows negatively in 4 byte
48 /// increments.
49 int MRegisterInfo::getStackDirection() const {
50 return -sizeof(int32_t);
51 }
52
4653 /// getLocation - This method should return the actual location of a frame
4754 /// variable given the frame index. The location is returned in ML.
4855 /// Subclasses should override this method for special handling of frame
5360 ML.set(getFrameRegister(MF),
5461 MFI->getObjectOffset(Index) + MFI->getStackSize());
5562 }
63
64 /// getInitialFrameState - Returns a list of machine moves that are assumed
65 /// on entry to a function.
66 void
67 MRegisterInfo::getInitialFrameState(std::vector &Moves) const {
68 // Default is to do nothing.
69 }
70
1818 #include "llvm/Type.h"
1919 #include "llvm/CodeGen/ValueTypes.h"
2020 #include "llvm/CodeGen/MachineInstrBuilder.h"
21 #include "llvm/CodeGen/MachineDebugInfo.h"
2122 #include "llvm/CodeGen/MachineFunction.h"
2223 #include "llvm/CodeGen/MachineFrameInfo.h"
2324 #include "llvm/CodeGen/MachineLocation.h"
25 #include "llvm/CodeGen/SelectionDAGNodes.h"
2426 #include "llvm/Target/TargetFrameInfo.h"
2527 #include "llvm/Target/TargetMachine.h"
2628 #include "llvm/Target/TargetOptions.h"
338340 MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
339341 MachineBasicBlock::iterator MBBI = MBB.begin();
340342 MachineFrameInfo *MFI = MF.getFrameInfo();
343 MachineDebugInfo *DebugInfo = MFI->getMachineDebugInfo();
341344
342345 // Do we have a frame pointer for this function?
343346 bool HasFP = hasFP(MF);
389392
390393 // Update frame info to pretend that this is part of the stack...
391394 MFI->setStackSize(NumBytes);
395 int NegNumbytes = -NumBytes;
392396
393397 // Adjust stack pointer: r1 -= numbytes.
394398 if (NumBytes <= 32768) {
395399 BuildMI(MBB, MBBI, PPC::STWU, 3)
396400 .addReg(PPC::R1).addSImm(-NumBytes).addReg(PPC::R1);
397401 } else {
398 int NegNumbytes = -NumBytes;
399402 BuildMI(MBB, MBBI, PPC::LIS, 1, PPC::R0).addSImm(NegNumbytes >> 16);
400403 BuildMI(MBB, MBBI, PPC::ORI, 2, PPC::R0)
401404 .addReg(PPC::R0).addImm(NegNumbytes & 0xFFFF);
402405 BuildMI(MBB, MBBI, PPC::STWUX, 3)
403406 .addReg(PPC::R1).addReg(PPC::R1).addReg(PPC::R0);
407 }
408
409 if (DebugInfo) {
410 std::vector &Moves = DebugInfo->getFrameMoves();
411 unsigned LabelID = DebugInfo->NextLabelID();
412
413 // Show update of SP.
414 MachineLocation Dst(MachineLocation::VirtualFP);
415 MachineLocation Src(MachineLocation::VirtualFP, NegNumbytes);
416 Moves.push_back(new MachineMove(LabelID, Dst, Src));
417
418 BuildMI(MBB, MBBI, PPC::DWARF_LABEL, 1).addSImm(LabelID);
404419 }
405420
406421 // If there is a preferred stack alignment, align R1 now
457472 }
458473 }
459474
475 unsigned PPCRegisterInfo::getRARegister() const {
476 return PPC::LR;
477 }
478
460479 unsigned PPCRegisterInfo::getFrameRegister(MachineFunction &MF) const {
461 return getDwarfRegNum(hasFP(MF) ? PPC::R31 : PPC::R1);
480 return hasFP(MF) ? PPC::R31 : PPC::R1;
481 }
482
483 void PPCRegisterInfo::getInitialFrameState(std::vector &Moves)
484 const {
485 // Initial state is the frame pointer is R1.
486 MachineLocation Dst(MachineLocation::VirtualFP);
487 MachineLocation Src(PPC::R1, 0);
488 Moves.push_back(new MachineMove(0, Dst, Src));
462489 }
463490
464491 #include "PPCGenRegisterInfo.inc"
5656 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
5757
5858 // Debug information queries.
59 unsigned getRARegister() const;
5960 unsigned getFrameRegister(MachineFunction &MF) const;
61 void getInitialFrameState(std::vector &Moves) const;
6062 };
6163
6264 } // end namespace llvm
199199 BuildMI(MBB, MBBI, SP::RESTORErr, 2, SP::G0).addReg(SP::G0).addReg(SP::G0);
200200 }
201201
202 unsigned SparcRegisterInfo::getRARegister() const {
203 assert(0 && "What is the return address register");
204 return 0;
205 }
206
202207 unsigned SparcRegisterInfo::getFrameRegister(MachineFunction &MF) const {
203 return getDwarfRegNum(SP::G1);
208 assert(0 && "What is the frame register");
209 return SP::G1;
204210 }
205211
206212 #include "SparcGenRegisterInfo.inc"
5757 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
5858
5959 // Debug information queries.
60 unsigned getRARegister() const;
6061 unsigned getFrameRegister(MachineFunction &MF) const;
6162 };
6263
316316 abort ();
317317 }
318318
319 int SparcV9RegisterInfo::getDwarfRegNum(unsigned RegNum) const {
320 abort ();
321 return 0;
322 }
323
324 unsigned SparcV9RegisterInfo::getRARegister() const {
325 abort ();
326 return 0;
327 }
319328
320329 unsigned SparcV9RegisterInfo::getFrameRegister(MachineFunction &MF) const {
321330 abort ();
4545 void emitEpilogue (MachineFunction &MF, MachineBasicBlock &MBB) const;
4646
4747 // Debug information queries.
48 int getDwarfRegNum(unsigned RegNum) const;
49 unsigned getRARegister() const;
4850 unsigned getFrameRegister(MachineFunction &MF) const;
4951 };
5052
685685 }
686686 }
687687
688 unsigned X86RegisterInfo::getRARegister() const {
689 return X86::ST0; // use a non-register register
690 }
691
688692 unsigned X86RegisterInfo::getFrameRegister(MachineFunction &MF) const {
689 return getDwarfRegNum(hasFP(MF) ? X86::EBP : X86::ESP);
693 return hasFP(MF) ? X86::EBP : X86::ESP;
690694 }
691695
692696 #include "X86GenRegisterInfo.inc"
6363 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
6464
6565 // Debug information queries.
66 unsigned getRARegister() const;
6667 unsigned getFrameRegister(MachineFunction &MF) const;
6768 };
6869