Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
llvm-epi-0.8
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Roger Ferrer
llvm-epi-0.8
Commits
2a6cc830
Commit
2a6cc830
authored
23 years ago
by
Ruchira Sasanka
Browse files
Options
Downloads
Patches
Plain Diff
updated suggesting/coloring of call & return args & implicit operands.
Changed added instr to a deque (from a vector) llvm-svn: 831
parent
086bf0fe
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llvm/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp
+43
-52
43 additions, 52 deletions
llvm/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp
llvm/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
+104
-18
104 additions, 18 deletions
llvm/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
with
147 additions
and
70 deletions
llvm/lib/CodeGen/RegAlloc/LiveRangeInfo.cpp
+
43
−
52
View file @
2a6cc830
...
@@ -108,30 +108,27 @@ void LiveRangeInfo::constructLiveRanges()
...
@@ -108,30 +108,27 @@ void LiveRangeInfo::constructLiveRanges()
const
MachineInstr
*
MInst
=
*
MInstIterator
;
const
MachineInstr
*
MInst
=
*
MInstIterator
;
// Now if the machine instruction has special operands that must be
// Now if the machine instruction is a call/return instruction,
// set with a "suggested color", do it here.
// add it to CallRetInstrList for processing its implicit operands
// This will be true for call/return instructions
if
(
(
TM
.
getInstrInfo
()).
isReturn
(
MInst
->
getOpCode
())
||
if
(
MRI
.
handleSpecialMInstr
(
MInst
,
*
this
,
RegClassList
)
)
(
TM
.
getInstrInfo
()).
isCall
(
MInst
->
getOpCode
()
)
)
continue
;
CallRetInstrList
.
push_back
(
MInst
);
// iterate over MI operands to find defs
// iterate over MI operands to find defs
for
(
MachineInstr
::
val_op_const_iterator
OpI
(
MInst
);
!
OpI
.
done
();
++
OpI
)
{
for
(
MachineInstr
::
val_op_const_iterator
OpI
(
MInst
);
!
OpI
.
done
();
++
OpI
)
{
if
(
DEBUG_RA
)
{
// delete later from here ************
MachineOperand
::
MachineOperandType
OpTyp
=
MachineOperand
::
Machine
OperandType
OpTyp
=
OpI
.
get
MachineOperand
().
get
OperandType
();
OpI
.
getMachineOperand
().
getOperandType
();
if
(
OpTyp
==
MachineOperand
::
MO_CCRegister
)
{
if
(
DEBUG_RA
&&
OpTyp
==
MachineOperand
::
MO_CCRegister
)
{
cout
<<
"
\n
**CC reg found. Is Def="
<<
OpI
.
isDef
()
<<
" Val:"
;
cout
<<
"
\n
**CC reg found. Is Def="
<<
OpI
.
isDef
()
<<
" Val:"
;
printValue
(
OpI
.
getMachineOperand
().
getVRegValue
()
)
;
printValue
(
OpI
.
getMachineOperand
().
getVRegValue
()
)
;
cout
<<
endl
;
cout
<<
endl
;
}
}
}
// ************* to here
// create a new LR iff this operand is a def
// create a new LR iff this operand is a def
if
(
OpI
.
isDef
()
)
{
if
(
OpI
.
isDef
()
)
{
...
@@ -193,60 +190,56 @@ void LiveRangeInfo::constructLiveRanges()
...
@@ -193,60 +190,56 @@ void LiveRangeInfo::constructLiveRanges()
}
}
}
}
}
// if isDef()
}
// if isDef()
}
// for all opereands in machine instructions
}
// for all opereands in machine instructions
}
// for all machine instructions in the BB
}
// for all machine instructions in the BB
}
// for all BBs in method
}
// for all BBs in method
// go thru LLVM instructions in the basic block and suggest colors
// for their args. Also record all CALL
// instructions and Return instructions in the CallRetInstrList
// This is done because since there are no reverse pointers in machine
// instructions to find the llvm instruction, when we encounter a call
// or a return whose args must be specailly colored (e.g., %o's for args)
// We have to makes sure that all LRs of call/ret args are added before
// doing this. But return value of call will not have a LR.
BBI
=
Meth
->
begin
();
// random iterator for BBs
// Now we have to suggest clors for call and return arg live ranges.
// Also, if there are implicit defs (e.g., retun value of a call inst)
// they must be added to the live range list
for
(
;
BBI
!=
Meth
->
end
();
++
BBI
)
{
// go thru BBs in random order
suggestRegs4CallRets
();
BasicBlock
::
const_iterator
InstIt
=
(
*
BBI
)
->
begin
();
if
(
DEBUG_RA
)
cout
<<
"Initial Live Ranges constructed!"
<<
endl
;
for
(
;
InstIt
!=
(
*
BBI
)
->
end
()
;
++
InstIt
)
{
}
const
Instruction
*
const
CallRetI
=
*
InstIt
;
unsigned
OpCode
=
(
CallRetI
)
->
getOpcode
();
if
(
(
OpCode
==
Instruction
::
Call
)
)
{
CallRetInstrList
.
push_back
(
CallRetI
);
MRI
.
suggestRegs4CallArgs
(
(
CallInst
*
)
CallRetI
,
*
this
,
RegClassList
);
}
else
if
(
OpCode
==
Instruction
::
Ret
)
{
CallRetInstrList
.
push_back
(
CallRetI
);
MRI
.
suggestReg4RetValue
(
(
ReturnInst
*
)
CallRetI
,
*
this
);
}
// Suggest colors for call and return args.
// Also create new LRs for implicit defs
}
// for each llvm instr in BB
void
LiveRangeInfo
::
suggestRegs4CallRets
()
{
}
// for all BBs in method
CallRetInstrListType
::
const_iterator
It
=
CallRetInstrList
.
begin
();
if
(
DEBUG_RA
)
for
(
;
It
!=
CallRetInstrList
.
end
();
++
It
)
{
cout
<<
"Initial Live Ranges constructed!"
<<
endl
;
const
MachineInstr
*
MInst
=
*
It
;
MachineOpCode
OpCode
=
MInst
->
getOpCode
();
if
(
(
TM
.
getInstrInfo
()).
isReturn
(
OpCode
)
)
MRI
.
suggestReg4RetValue
(
MInst
,
*
this
);
else
if
(
(
TM
.
getInstrInfo
()).
isCall
(
OpCode
)
)
MRI
.
suggestRegs4CallArgs
(
MInst
,
*
this
,
RegClassList
);
else
assert
(
0
&&
"Non call/ret instr in CallRetInstrList"
);
}
}
}
void
LiveRangeInfo
::
coalesceLRs
()
void
LiveRangeInfo
::
coalesceLRs
()
{
{
...
@@ -318,8 +311,6 @@ void LiveRangeInfo::coalesceLRs()
...
@@ -318,8 +311,6 @@ void LiveRangeInfo::coalesceLRs()
if
(
RCOfDef
==
RCOfUse
)
{
// if the reg classes are the same
if
(
RCOfDef
==
RCOfUse
)
{
// if the reg classes are the same
// if( LROfUse->getTypeID() == LROfDef->getTypeID() ) {
if
(
!
RCOfDef
->
getInterference
(
LROfDef
,
LROfUse
)
)
{
if
(
!
RCOfDef
->
getInterference
(
LROfDef
,
LROfUse
)
)
{
unsigned
CombinedDegree
=
unsigned
CombinedDegree
=
...
...
This diff is collapsed.
Click to expand it.
llvm/lib/CodeGen/RegAlloc/PhyRegAlloc.cpp
+
104
−
18
View file @
2a6cc830
...
@@ -248,6 +248,100 @@ void PhyRegAlloc::addInterferencesForArgs()
...
@@ -248,6 +248,100 @@ void PhyRegAlloc::addInterferencesForArgs()
}
}
#if 0
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void PhyRegAlloc::insertCallerSavingCode(const MachineInstr *MInst,
const BasicBlock *BB )
{
assert( (TM.getInstrInfo()).isCall( MInst->getOpCode() ) );
int StackOff = 10; // ****TODO : Change
set<unsigned> PushedRegSet();
// Now find the LR of the return value of the call
// The last *implicit operand* is the return value of a call
// Insert it to to he PushedRegSet since we must not save that register
// and restore it after the call.
// We do this because, we look at the LV set *after* the instruction
// to determine, which LRs must be saved across calls. The return value
// of the call is live in this set - but we must not save/restore it.
unsigned NumOfImpRefs = MInst->getNumImplicitRefs();
if( NumOfImpRefs > 0 ) {
if( MInst->implicitRefIsDefined(NumOfImpRefs-1) ) {
const Value *RetVal = CallMI->getImplicitRef(NumOfImpRefs-1);
LiveRange *RetValLR = LRI.getLiveRangeForValue( RetVal );
assert( RetValLR && "No LR for RetValue of call");
PushedRegSet.insert(
MRI.getUnifiedRegNum((RetValLR->getRegClass())->getID(),
RetValLR->getColor() ) );
}
}
LiveVarSet *LVSetAft = LVI->getLiveVarSetAfterMInst(MInst, BB);
LiveVarSet::const_iterator LIt = LVSetAft->begin();
// for each live var in live variable set after machine inst
for( ; LIt != LVSetAft->end(); ++LIt) {
// get the live range corresponding to live var
LiveRange *const LR = LRI.getLiveRangeForValue(*LIt );
// LROfVar can be null if it is a const since a const
// doesn't have a dominating def - see Assumptions above
if( LR ) {
if( LR->hasColor() ) {
unsigned RCID = (LR->getRegClass())->getID();
unsigned Color = LR->getColor();
if ( MRI.isRegVolatile(RCID, Color) ) {
// if the value is in both LV sets (i.e., live before and after
// the call machine instruction)
unsigned Reg = MRI.getUnifiedRegNum(RCID, Color);
if( PuhsedRegSet.find(Reg) == PhusedRegSet.end() ) {
// if we haven't already pushed that register
MachineInstr *AdI =
MRI.saveRegOnStackMI(Reg, MRI.getFPReg(), StackOff );
((AddedInstrMap[MInst])->InstrnsBefore).push_front(AdI);
((AddedInstrMap[MInst])->InstrnsAfter).push_back(AdI);
PushedRegSet.insert( Reg );
StackOff += 4; // ****TODO: Correct ??????
cout << "Inserted caller saving instr");
} // if not already pushed
} // if LR has a volatile color
} // if LR has color
} // if there is a LR for Var
} // for each value in the LV set after instruction
}
#endif
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// This method is called after register allocation is complete to set the
// This method is called after register allocation is complete to set the
// allocated reisters in the machine code. This code will add register numbers
// allocated reisters in the machine code. This code will add register numbers
...
@@ -275,12 +369,12 @@ void PhyRegAlloc::updateMachineCode()
...
@@ -275,12 +369,12 @@ void PhyRegAlloc::updateMachineCode()
// ***TODO: Add InstrnsAfter as well
// ***TODO: Add InstrnsAfter as well
if
(
AddedInstrMap
[
MInst
]
)
{
if
(
AddedInstrMap
[
MInst
]
)
{
vector
<
MachineInstr
*>
&
IBef
=
deque
<
MachineInstr
*>
&
IBef
=
(
AddedInstrMap
[
MInst
])
->
InstrnsBefore
;
(
AddedInstrMap
[
MInst
])
->
InstrnsBefore
;
if
(
!
IBef
.
empty
()
)
{
if
(
!
IBef
.
empty
()
)
{
vector
<
MachineInstr
*>::
iterator
AdIt
;
deque
<
MachineInstr
*>::
iterator
AdIt
;
for
(
AdIt
=
IBef
.
begin
();
AdIt
!=
IBef
.
end
()
;
++
AdIt
)
{
for
(
AdIt
=
IBef
.
begin
();
AdIt
!=
IBef
.
end
()
;
++
AdIt
)
{
...
@@ -331,7 +425,8 @@ void PhyRegAlloc::updateMachineCode()
...
@@ -331,7 +425,8 @@ void PhyRegAlloc::updateMachineCode()
cout
<<
TargetInstrDescriptors
[
MInst
->
getOpCode
()].
opCodeString
;
cout
<<
TargetInstrDescriptors
[
MInst
->
getOpCode
()].
opCodeString
;
}
}
Op
.
setRegForValue
(
1000
);
// mark register as invalid
if
(
Op
.
getAllocatedRegNum
()
==
-
1
)
Op
.
setRegForValue
(
1000
);
// mark register as invalid
#if 0
#if 0
if( ((Val->getType())->isLabelType()) ||
if( ((Val->getType())->isLabelType()) ||
...
@@ -475,16 +570,9 @@ void PhyRegAlloc::colorCallRetArgs()
...
@@ -475,16 +570,9 @@ void PhyRegAlloc::colorCallRetArgs()
for
(
;
It
!=
CallRetInstList
.
end
();
++
It
)
{
for
(
;
It
!=
CallRetInstList
.
end
();
++
It
)
{
const
Instruction
*
const
C
allRet
I
=
*
It
;
const
MachineInstr
*
const
C
RM
I
=
*
It
;
unsigned
OpCode
=
(
CallRetI
)
->
getOp
c
ode
();
unsigned
OpCode
=
CRMI
->
getOp
C
ode
();
const
MachineInstr
*
CRMI
=
*
((
CallRetI
->
getMachineInstrVec
()).
begin
());
assert
(
(
TM
.
getInstrInfo
().
isReturn
(
CRMI
->
getOpCode
())
||
TM
.
getInstrInfo
().
isCall
(
CRMI
->
getOpCode
())
)
&&
"First Machine Instruction is not a Call/Retrunr"
);
// get the added instructions for this Call/Ret instruciton
// get the added instructions for this Call/Ret instruciton
AddedInstrns
*
AI
=
AddedInstrMap
[
CRMI
];
AddedInstrns
*
AI
=
AddedInstrMap
[
CRMI
];
if
(
!
AI
)
{
if
(
!
AI
)
{
...
@@ -492,14 +580,12 @@ void PhyRegAlloc::colorCallRetArgs()
...
@@ -492,14 +580,12 @@ void PhyRegAlloc::colorCallRetArgs()
AddedInstrMap
[
CRMI
]
=
AI
;
AddedInstrMap
[
CRMI
]
=
AI
;
}
}
if
(
(
OpCode
==
Instruction
::
Call
)
)
if
(
(
TM
.
getInstrInfo
()).
isCall
(
OpCode
)
)
MRI
.
colorCallArgs
(
(
CallInst
*
)
CallRet
I
,
LRI
,
AI
);
MRI
.
colorCallArgs
(
CRM
I
,
LRI
,
AI
);
else
if
(
(
TM
.
getInstrInfo
()).
isReturn
(
OpCode
)
)
else
if
(
OpCode
==
Instruction
::
Ret
)
MRI
.
colorRetValue
(
CRMI
,
LRI
,
AI
);
MRI
.
colorRetValue
(
(
ReturnInst
*
)
CallRetI
,
LRI
,
AI
);
else
assert
(
0
&&
"Non Call/Ret instrn in CallRetInstrList
\n
"
);
else
assert
(
0
&&
"Non Call/Ret instrn in CallRetInstrList
\n
"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment