<s>
void
ELFMBlazeAsmBackend
::
applyFixup
(
const
MCFixup
&
Fixup
,
char
*
Data
,
unsigned
DataSize
,
uint64_t
Value
)
const
{
unsigned
Size
=
getFixupKindSize
(
Fixup
.
getKind
(
)
)
;
assert
(
Fixup
.
getOffset
(
)
+
Size
<=
DataSize
&&
"Invalid fixup offset!"
)
;
char
*
data
=
Data
+
Fixup
.
getOffset
(
)
;
switch
(
Size
)
{
default
:
llvm_unreachable
(
"Cannot fixup unknown value."
)
;
case
1
:
llvm_unreachable
(
"Cannot fixup 1 byte value."
)
;
case
8
:
llvm_unreachable
(
"Cannot fixup 8 byte value."
)
;
case
4
:
*
(
data
+
7
)
=
uint8_t
(
Value
)
;
*
(
data
+
6
)
=
uint8_t
(
Value
>>
8
)
;
*
(
data
+
3
)
=
uint8_t
(
Value
>>
16
)
;
*
(
data
+
2
)
=
uint8_t
(
Value
>>
24
)
;
break
;
case
2
:
*
(
data
+
3
)
=
uint8_t
(
Value
>>
0
)
;
*
(
data
+
2
)
=
uint8_t
(
Value
>>
8
)
;
}
}
</s>

Apply the Value for given Fixup into the provided data fragment , at the offset specified by the fixup and following the fixup kind as appropriate .


<s> MCObjectWriter * createObjectWriter ( raw_ostream & OS ) const { return createMBlazeELFObjectWriter ( OS , OSABI ) ; } </s>

Create a new MCObjectWriter instance for use by the assembler backend to emit the final object file .


<s> bool MBlazeAsmBackend :: fixupNeedsRelaxation ( const MCFixup & Fixup , uint64_t Value , const MCInstFragment * DF , const MCAsmLayout & Layout ) const { return int64_t ( Value ) != int64_t ( int8_t ( Value ) ) ; } </s>

Simple predicate for targets where ! Resolved implies requiring relaxation .


<s> unsigned getNumFixupKinds ( ) const { return 2 ; } </s>

Get the number of target specific fixup kinds .


<s> unsigned getPointerSize ( ) const { return 4 ; } </s>

Layout pointer size in bytes , rounded up to a whole number of bytes .


<s> bool MBlazeAsmBackend :: mayNeedRelaxation ( const MCInst & Inst ) const { if ( getRelaxedOpcode ( Inst . getOpcode ( ) ) == Inst . getOpcode ( ) ) return false ; bool hasExprOrImm = false ; for ( unsigned i = 0 ; i < Inst . getNumOperands ( ) ; ++ i ) hasExprOrImm |= Inst . getOperand ( i ) . isExpr ( ) ; return hasExprOrImm ; } </s>

Check whether the given instruction may need relaxation .


<s> void MBlazeAsmBackend :: relaxInstruction ( const MCInst & Inst , MCInst & Res ) const { Res = Inst ; Res . setOpcode ( getRelaxedOpcode ( Inst . getOpcode ( ) ) ) ; } </s>

Relax the instruction in the given fragment to the next wider instruction .


<s> bool MBlazeAsmBackend :: writeNopData ( uint64_t Count , MCObjectWriter * OW ) const { if ( ( Count % 4 ) != 0 ) return false ; for ( uint64_t i = 0 ; i < Count ; i += 4 ) OW -> Write32 ( 0x00000000 ) ; return true ; } </s>

Write an ( optimal ) nop sequence of Count bytes to the given output .


<s> MCObjectWriter * createObjectWriter ( raw_ostream & OS ) const { return createELFObjectWriter ( new MBlazeELFObjectWriter ( OSType ) , OS , false ) ; } </s>


<s> MCObjectWriter * createObjectWriter ( raw_ostream & OS ) const { return createELFObjectWriter ( OS , false , OSType , ELF :: EM_MBLAZE , false , true ) ; } </s>


<s> virtual const MCObjectFormat & getObjectFormat ( ) const { return Format ; } </s>


<s>
AsmToken
LexToken
(
)
{
if
(
!
Lexer
)
{
SetError
(
SMLoc
(
)
,
"No MCAsmLexer installed"
)
;
return
AsmToken
(
AsmToken
::
Error
,
""
,
0
)
;
}
switch
(
AsmInfo
.
getAssemblerDialect
(
)
)
{
default
:
SetError
(
SMLoc
(
)
,
"Unhandled dialect"
)
;
return
AsmToken
(
AsmToken
::
Error
,
""
,
0
)
;
case
0
:
return
LexTokenUAL
(
)
;
}
}
</s>

LexToken - Read the next token and return its code .


"instruction use requires an option to be enabled"

"unable to convert operands to instruction"

MatchAndEmitInstruction - Recognize a series of operands of a parsed instruction as an actual MCInst and emit it to the specified MCStreamer .


<s> bool MBlazeAsmParser :: ParseInstruction ( StringRef Name , SMLoc NameLoc , SmallVectorImpl < MCParsedAsmOperand * > & Operands ) { size_t dotLoc = Name . find ( '.' ) ; Operands . push_back ( MBlazeOperand :: CreateToken ( Name . substr ( 0 , dotLoc ) , NameLoc ) ) ; if ( dotLoc < Name . size ( ) ) Operands . push_back ( MBlazeOperand :: CreateToken ( Name . substr ( dotLoc ) , NameLoc ) ) ; if ( getLexer ( ) . is ( AsmToken :: EndOfStatement ) ) return false ; if ( ! ParseOperand ( Operands ) ) return true ; while ( getLexer ( ) . isNot ( AsmToken :: EndOfStatement ) && getLexer ( ) . is ( AsmToken :: Comma ) ) { getLexer ( ) . Lex ( ) ; if ( ! ParseOperand ( Operands ) ) return true ; } if ( Name . startswith ( "lw" ) || Name . startswith ( "sw" ) || Name . startswith ( "lh" ) || Name . startswith ( "sh" ) || Name . startswith ( "lb" ) || Name . startswith ( "sb" ) ) return ( ParseMemory ( Operands ) == NULL ) ; return false ; } </s>

ParseInstruction - Parse one assembly instruction .

MBlaze MBlaze MBlaze 0 MBlaze "lw" "sw" "lh" "sh" "lb" "sb"


<s> void addExpr ( MCInst & Inst , const MCExpr * Expr ) const { if ( Expr == 0 ) Inst . addOperand ( MCOperand :: CreateImm ( 0 ) ) ; else if ( const MCConstantExpr * CE = dyn_cast < MCConstantExpr > ( Expr ) ) Inst . addOperand ( MCOperand :: CreateImm ( CE -> getValue ( ) ) ) ; else Inst . addOperand ( MCOperand :: CreateExpr ( Expr ) ) ; } </s>


<s> static MBlazeOperand * CreateMem ( unsigned Base , unsigned Off , SMLoc S , SMLoc E ) { MBlazeOperand * Op = new MBlazeOperand ( Memory ) ; Op -> Mem . Base = Base ; Op -> Mem . OffReg = Off ; Op -> Mem . Off = 0 ; Op -> StartLoc = S ; Op -> EndLoc = E ; return Op ; } </s>


<s> static MBlazeOperand * CreateReg ( unsigned RegNum , SMLoc S , SMLoc E ) { MBlazeOperand * Op = new MBlazeOperand ( Register ) ; Op -> Reg . RegNum = RegNum ; Op -> StartLoc = S ; Op -> EndLoc = E ; return Op ; } </s>

CreateReg - Allocate a single virtual register for the given type .


<s> bool Error ( SMLoc L , const Twine & Msg ) { return Parser . Error ( L , Msg ) ; } </s>

Return an error at the location L , with the message Msg .


<s> SMLoc getEndLoc ( ) const { return EndLoc ; } </s>

getEndLoc - Get the location of the last token of this operand .


<s>
unsigned
getReg
(
)
const
{
assert
(
Kind
==
Register
&&
"Invalid access!"
)
;
return
Reg
.
RegNum
;
}
</s>

Returns the register associated with this edge .


<s> SMLoc getStartLoc ( ) const { return StartLoc ; } </s>

getStartLoc - Get the location of the first token of this operand .


<s> bool isImm ( ) const { return Kind == Immediate ; } </s>


<s> bool isMem ( ) const { return Kind == Memory ; } </s>


<s> bool isReg ( ) const { return Kind == Register ; } </s>


<s> bool isToken ( ) const { return Kind == Token ; } </s>


<s> bool MBlazeAsmParser :: ParseDirective ( AsmToken DirectiveID ) { StringRef IDVal = DirectiveID . getIdentifier ( ) ; if ( IDVal == ".word" ) return ParseDirectiveWord ( 2 , DirectiveID . getLoc ( ) ) ; return true ; } </s>

ParseDirective - Parse a target specific assembler directive This method is deprecated , use 'parseDirective ' instead .


<s> bool MBlazeAsmParser :: ParseInstruction ( ParseInstructionInfo & Info , StringRef Name , SMLoc NameLoc , SmallVectorImpl < MCParsedAsmOperand * > & Operands ) { size_t dotLoc = Name . find ( '.' ) ; Operands . push_back ( MBlazeOperand :: CreateToken ( Name . substr ( 0 , dotLoc ) , NameLoc ) ) ; if ( dotLoc < Name . size ( ) ) Operands . push_back ( MBlazeOperand :: CreateToken ( Name . substr ( dotLoc ) , NameLoc ) ) ; if ( getLexer ( ) . is ( AsmToken :: EndOfStatement ) ) return false ; if ( ! ParseOperand ( Operands ) ) return true ; while ( getLexer ( ) . isNot ( AsmToken :: EndOfStatement ) && getLexer ( ) . is ( AsmToken :: Comma ) ) { getLexer ( ) . Lex ( ) ; if ( ! ParseOperand ( Operands ) ) return true ; } if ( Name . startswith ( "lw" ) || Name . startswith ( "sw" ) || Name . startswith ( "lh" ) || Name . startswith ( "sh" ) || Name . startswith ( "lb" ) || Name . startswith ( "sb" ) ) return ( ParseMemory ( Operands ) == NULL ) ; return false ; } </s>


<s>
void
MBlazeOperand
::
print
(
raw_ostream
&
OS
)
const
{
switch
(
Kind
)
{
case
Immediate
:
getImm
(
)
->
print
(
OS
)
;
break
;
case
Register
:
OS
<<
"<register R"
;
OS
<<
getMBlazeRegisterNumbering
(
getReg
(
)
)
<<
">"
;
break
;
case
Token
:
OS
<<
"'"
<<
getToken
(
)
<<
"'"
;
break
;
case
Memory
:
{
OS
<<
"<memory R"
;
OS
<<
getMBlazeRegisterNumbering
(
getMemBase
(
)
)
;
OS
<<
", "
;
unsigned
RegOff
=
getMemOffReg
(
)
;
if
(
RegOff
)
OS
<<
"R"
<<
getMBlazeRegisterNumbering
(
RegOff
)
;
else
OS
<<
getMemOff
(
)
;
OS
<<
">"
;
}
break
;
case
Fsl
:
getFslImm
(
)
->
print
(
OS
)
;
break
;
}
}
</s>

print - Print a debug representation of the operand to the given stream .

MBlaze
MBlaze
"<register R"
MBlaze
">"
"'"
"'"
"<memory R"
MBlaze
", "
"R"
MBlaze
">"


<s> void Warning ( SMLoc L , const Twine & Msg ) { Parser . Warning ( L , Msg ) ; } </s>

Emit a warning at the location L , with the message Msg .


<s>
void
MBlazeOperand
::
dump
(
raw_ostream
&
OS
)
const
{
switch
(
Kind
)
{
case
Immediate
:
getImm
(
)
->
print
(
OS
)
;
break
;
case
Register
:
OS
<<
"<register R"
;
OS
<<
MBlazeRegisterInfo
::
getRegisterNumbering
(
getReg
(
)
)
<<
">"
;
break
;
case
Token
:
OS
<<
"'"
<<
getToken
(
)
<<
"'"
;
break
;
case
Memory
:
{
OS
<<
"<memory R"
;
OS
<<
MBlazeRegisterInfo
::
getRegisterNumbering
(
getMemBase
(
)
)
;
OS
<<
", "
;
unsigned
RegOff
=
getMemOffReg
(
)
;
if
(
RegOff
)
OS
<<
"R"
<<
MBlazeRegisterInfo
::
getRegisterNumbering
(
RegOff
)
;
else
OS
<<
getMemOff
(
)
;
OS
<<
">"
;
}
break
;
case
Fsl
:
getFslImm
(
)
->
print
(
OS
)
;
break
;
}
}
</s>

Dump the plan to stderr ( for debugging ) .


"instruction use requires an option to be enabled"


<s> void MBlazeAsmPrinter :: EmitInstruction ( const MachineInstr * MI ) { MBlazeMCInstLower MCInstLowering ( OutContext , * this ) ; MCInst TmpInst ; MCInstLowering . Lower ( MI , TmpInst ) ; OutStreamer . EmitInstruction ( TmpInst ) ; } </s>

EmitInstruction - This callback is invoked when an instruction is emitted , to advance the hazard state .


<s> bool MBlazeAsmPrinter :: isBlockOnlyReachableByFallthrough ( const MachineBasicBlock * MBB ) const { if ( MBB -> isLandingPad ( ) || MBB -> pred_empty ( ) ) return false ; MachineBasicBlock :: const_pred_iterator PI = MBB -> pred_begin ( ) , PI2 = PI ; ++ PI2 ; if ( PI2 != MBB -> pred_end ( ) ) return false ; const MachineBasicBlock * Pred = * PI ; if ( ! Pred -> isLayoutSuccessor ( MBB ) ) return false ; if ( Pred -> empty ( ) ) return true ; MachineBasicBlock :: const_iterator I = Pred -> end ( ) ; while ( I != Pred -> begin ( ) && ! ( -- I ) -> isTerminator ( ) ) ; return I == Pred -> end ( ) || ! I -> isBarrier ( ) ; } </s>

isBlockOnlyReachableByFallthough - Return true if the basic block has exactly one predecessor and the control transfer mechanism between the predecessor and this block is a fall-through .


<s> bool MBlazeAsmPrinter :: PrintAsmOperand ( const MachineInstr * MI , unsigned OpNo , unsigned AsmVariant , const char * ExtraCode , raw_ostream & O ) { if ( ExtraCode && ExtraCode [ 0 ] ) if ( ExtraCode [ 1 ] != 0 ) return true ; switch ( ExtraCode [ 0 ] ) { default : return AsmPrinter :: PrintAsmOperand ( MI , OpNo , AsmVariant , ExtraCode , O ) ; } printOperand ( MI , OpNo , O ) ; return false ; } </s>

PrintAsmOperand - Print out an operand for an inline asm expression .


<s> void MBlazeAsmPrinter :: emitFrameDirective ( ) { const TargetRegisterInfo & RI = * TM . getRegisterInfo ( ) ; unsigned stackReg = RI . getFrameRegister ( * MF ) ; unsigned returnReg = RI . getRARegister ( ) ; unsigned stackSize = MF -> getFrameInfo ( ) -> getStackSize ( ) ; O << "\t.frame\t" << getRegisterName ( stackReg ) << ',' << stackSize << ',' << getRegisterName ( returnReg ) << '\n' ; } </s>


<s> void EmitInstruction ( const MachineInstr * MI ) { printInstruction ( MI ) ; O << '\n' ; } </s>


<s> bool MBlazeAsmPrinter :: PrintAsmOperand ( const MachineInstr * MI , unsigned OpNo , unsigned AsmVariant , const char * ExtraCode ) { if ( ExtraCode && ExtraCode [ 0 ] ) return true ; printOperand ( MI , OpNo ) ; return false ; } </s>


<s> void MBlazeAsmPrinter :: emitFrameDirective ( ) { const TargetRegisterInfo & RI = * TM . getRegisterInfo ( ) ; unsigned stackReg = RI . getFrameRegister ( * MF ) ; unsigned returnReg = RI . getRARegister ( ) ; unsigned stackSize = MF -> getFrameInfo ( ) -> getStackSize ( ) ; OutStreamer . EmitRawText ( "\t.frame\t" + Twine ( getRegisterName ( stackReg ) ) + "," + Twine ( stackSize ) + "," + Twine ( getRegisterName ( returnReg ) ) ) ; } </s>


<s> void EmitInstruction ( const MachineInstr * MI ) { SmallString < 128 > Str ; raw_svector_ostream OS ( Str ) ; printInstruction ( MI , OS ) ; OutStreamer . EmitRawText ( OS . str ( ) ) ; } </s>


<s> void MBlazeAsmPrinter :: emitFrameDirective ( ) { if ( ! OutStreamer . hasRawTextSupport ( ) ) return ; const TargetRegisterInfo & RI = * TM . getRegisterInfo ( ) ; unsigned stkReg = RI . getFrameRegister ( * MF ) ; unsigned retReg = RI . getRARegister ( ) ; unsigned stkSze = MF -> getFrameInfo ( ) -> getStackSize ( ) ; OutStreamer . EmitRawText ( "\t.frame\t" + Twine ( MBlazeInstPrinter :: getRegisterName ( stkReg ) ) + "," + Twine ( stkSze ) + "," + Twine ( MBlazeInstPrinter :: getRegisterName ( retReg ) ) ) ; } </s>

MBlaze MBlaze "\t.frame\t" MBlaze "," "," MBlaze


<s> void MBlazeAsmPrinter :: EmitInstruction ( const MachineInstr * MI ) { MBlazeMCInstLower MCInstLowering ( OutContext , * Mang , * this ) ; MCInst TmpInst ; MCInstLowering . Lower ( MI , TmpInst ) ; OutStreamer . EmitInstruction ( TmpInst ) ; } </s>


<s>
virtual
const
char
*
getPassName
(
)
const
{
return
"MBlaze Assembly Printer"
;
}
</s>

getPassName - Return a nice clean name for a pass .


<s> bool MBlazeAsmPrinter :: isBlockOnlyReachableByFallthrough ( const MachineBasicBlock * MBB ) const { if ( MBB -> isLandingPad ( ) || MBB -> pred_empty ( ) ) return false ; MachineBasicBlock :: const_pred_iterator PI = MBB -> pred_begin ( ) , PI2 = PI ; ++ PI2 ; if ( PI2 != MBB -> pred_end ( ) ) return false ; const MachineBasicBlock * Pred = * PI ; if ( ! Pred -> isLayoutSuccessor ( MBB ) ) return false ; if ( Pred -> empty ( ) ) return true ; MachineBasicBlock :: const_iterator I = Pred -> end ( ) ; while ( I != Pred -> begin ( ) && ! ( -- I ) -> getDesc ( ) . isTerminator ( ) ) ; return I == Pred -> end ( ) || ! I -> getDesc ( ) . isBarrier ( ) ; } </s>


<s> bool MBlazeAsmPrinter :: PrintAsmOperand ( const MachineInstr * MI , unsigned OpNo , unsigned AsmVariant , const char * ExtraCode , raw_ostream & O ) { if ( ExtraCode && ExtraCode [ 0 ] ) return true ; printOperand ( MI , OpNo , O ) ; return false ; } </s>


<s>
virtual
const
char
*
getPassName
(
)
const
{
return
"MBlaze Delay Slot Filler"
;
}
</s>


<s> bool runOnMachineFunction ( MachineFunction & F ) { bool Changed = false ; for ( MachineFunction :: iterator FI = F . begin ( ) , FE = F . end ( ) ; FI != FE ; ++ FI ) Changed |= runOnMachineBasicBlock ( * FI ) ; return Changed ; } </s>

runOnMachineFunction - Emit the function body .


<s> void MBlazeFrameInfo :: emitEpilogue ( MachineFunction & MF , MachineBasicBlock & MBB ) const { MachineBasicBlock :: iterator MBBI = prior ( MBB . end ( ) ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; const MBlazeInstrInfo & TII = * static_cast < const MBlazeInstrInfo * > ( MF . getTarget ( ) . getInstrInfo ( ) ) ; DebugLoc dl = MBBI -> getDebugLoc ( ) ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADD ) , MBlaze :: R1 ) . addReg ( MBlaze :: R19 ) . addReg ( MBlaze :: R0 ) ; BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addImm ( FPOffset ) ; } if ( MFI -> adjustsStack ( ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R15 ) . addReg ( MBlaze :: R1 ) . addImm ( RAOffset ) ; } int StackSize = ( int ) MFI -> getStackSize ( ) ; if ( StackSize ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( StackSize ) ; } } </s>


<s> void MBlazeFrameInfo :: emitPrologue ( MachineFunction & MF ) const { MachineBasicBlock & MBB = MF . front ( ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; const MBlazeInstrInfo & TII = * static_cast < const MBlazeInstrInfo * > ( MF . getTarget ( ) . getInstrInfo ( ) ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; MachineBasicBlock :: iterator MBBI = MBB . begin ( ) ; DebugLoc DL = MBBI != MBB . end ( ) ? MBBI -> getDebugLoc ( ) : DebugLoc ( ) ; MBlazeFI -> adjustLoadArgsFI ( MFI ) ; MBlazeFI -> adjustStoreVarArgsFI ( MFI ) ; unsigned StackSize = MFI -> getStackSize ( ) ; if ( StackSize == 0 && ! MFI -> adjustsStack ( ) ) return ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - StackSize ) ; if ( MFI -> adjustsStack ( ) ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R15 ) . addReg ( MBlaze :: R1 ) . addImm ( RAOffset ) ; } if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addImm ( FPOffset ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADD ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addReg ( MBlaze :: R0 ) ; } } </s>

emitProlog/emitEpilog - These methods insert prolog and epilog code into the function .


<s> bool MBlazeFrameInfo :: hasFP ( const MachineFunction & MF ) const { const MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; return DisableFramePointerElim ( MF ) || MFI -> hasVarSizedObjects ( ) ; } </s>

hasFP - Return true if the specified function should have a dedicated frame pointer register .


<s> bool targetHandlesStackFrameRounding ( ) const { return true ; } </s>

targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack frame ( probably at emitPrologue time ) .


<s> void MBlazeFrameLowering :: emitEpilogue ( MachineFunction & MF , MachineBasicBlock & MBB ) const { MachineBasicBlock :: iterator MBBI = MBB . getLastNonDebugInstr ( ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; const MBlazeInstrInfo & TII = * static_cast < const MBlazeInstrInfo * > ( MF . getTarget ( ) . getInstrInfo ( ) ) ; DebugLoc dl = MBBI -> getDebugLoc ( ) ; llvm :: CallingConv :: ID CallConv = MF . getFunction ( ) -> getCallingConv ( ) ; bool requiresRA = CallConv == llvm :: CallingConv :: MBLAZE_INTR ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADD ) , MBlaze :: R1 ) . addReg ( MBlaze :: R19 ) . addReg ( MBlaze :: R0 ) ; BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addImm ( FPOffset ) ; } if ( MFI -> adjustsStack ( ) || requiresRA ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R15 ) . addReg ( MBlaze :: R1 ) . addImm ( RAOffset ) ; } int StackSize = ( int ) MFI -> getStackSize ( ) ; if ( StackSize ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADDIK ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( StackSize ) ; } } </s>


<s> void MBlazeFrameLowering :: emitPrologue ( MachineFunction & MF ) const { MachineBasicBlock & MBB = MF . front ( ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; const MBlazeInstrInfo & TII = * static_cast < const MBlazeInstrInfo * > ( MF . getTarget ( ) . getInstrInfo ( ) ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; MachineBasicBlock :: iterator MBBI = MBB . begin ( ) ; DebugLoc DL = MBBI != MBB . end ( ) ? MBBI -> getDebugLoc ( ) : DebugLoc ( ) ; llvm :: CallingConv :: ID CallConv = MF . getFunction ( ) -> getCallingConv ( ) ; bool requiresRA = CallConv == llvm :: CallingConv :: MBLAZE_INTR ; determineFrameLayout ( MF ) ; unsigned StackSize = MFI -> getStackSize ( ) ; if ( StackSize == 0 && ! MFI -> adjustsStack ( ) && ! requiresRA ) return ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADDIK ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - StackSize ) ; if ( MFI -> adjustsStack ( ) || requiresRA ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R15 ) . addReg ( MBlaze :: R1 ) . addImm ( RAOffset ) ; } if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addImm ( FPOffset ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADD ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addReg ( MBlaze :: R0 ) ; } } </s>


<s> bool MBlazeFrameLowering :: hasFP ( const MachineFunction & MF ) const { const MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; return DisableFramePointerElim ( MF ) || MFI -> hasVarSizedObjects ( ) ; } </s>


<s>
static
void
determineFrameLayout
(
MachineFunction
&
MF
)
{
MachineFrameInfo
*
MFI
=
MF
.
getFrameInfo
(
)
;
MBlazeFunctionInfo
*
MBlazeFI
=
MF
.
getInfo
<
MBlazeFunctionInfo
>
(
)
;
MBlazeFI
->
adjustLoadArgsFI
(
MFI
)
;
MBlazeFI
->
adjustStoreVarArgsFI
(
MFI
)
;
unsigned
FrameSize
=
MFI
->
getStackSize
(
)
;
DEBUG
(
dbgs
(
)
<<
"Original Frame Size: "
<<
FrameSize
<<
"\n"
)
;
unsigned
TargetAlign
=
MF
.
getTarget
(
)
.
getFrameLowering
(
)
->
getStackAlignment
(
)
;
unsigned
AlignMask
=
TargetAlign
1
;
FrameSize
=
(
FrameSize
+
AlignMask
)
&
~
AlignMask
;
MFI
->
setStackSize
(
FrameSize
)
;
DEBUG
(
dbgs
(
)
<<
"Aligned Frame Size: "
<<
FrameSize
<<
"\n"
)
;
}
</s>

Determine the frame layout but do not update the machine function .

MBlaze
MBlaze
MBlaze
MBlaze
MBlaze
MBlaze
"Original Frame Size: "
"\n"
1
"Aligned Frame Size: "
"\n"


<s> void MBlazeFrameLowering :: eliminateCallFramePseudoInstr ( MachineFunction & MF , MachineBasicBlock & MBB , MachineBasicBlock :: iterator I ) const { const MBlazeInstrInfo & TII = * static_cast < const MBlazeInstrInfo * > ( MF . getTarget ( ) . getInstrInfo ( ) ) ; if ( ! hasReservedCallFrame ( MF ) ) { MachineInstr * Old = I ; int Amount = Old -> getOperand ( 0 ) . getImm ( ) + 4 ; if ( Amount != 0 ) { unsigned Align = getStackAlignment ( ) ; Amount = ( Amount + Align - 1 ) / Align * Align ; MachineInstr * New ; if ( Old -> getOpcode ( ) == MBlaze :: ADJCALLSTACKDOWN ) { New = BuildMI ( MF , Old -> getDebugLoc ( ) , TII . get ( MBlaze :: ADDIK ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - Amount ) ; } else { assert ( Old -> getOpcode ( ) == MBlaze :: ADJCALLSTACKUP ) ; New = BuildMI ( MF , Old -> getDebugLoc ( ) , TII . get ( MBlaze :: ADDIK ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( Amount ) ; } MBB . insert ( I , New ) ; } } MBB . erase ( I ) ; } </s>

This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy pseudo instructions ( but only if the Target is using them ) .


<s> void MBlazeFrameLowering :: emitEpilogue ( MachineFunction & MF , MachineBasicBlock & MBB ) const { MachineBasicBlock :: iterator MBBI = MBB . getLastNonDebugInstr ( ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; const MBlazeInstrInfo & TII = * static_cast < const MBlazeInstrInfo * > ( MF . getTarget ( ) . getInstrInfo ( ) ) ; DebugLoc dl = MBBI -> getDebugLoc ( ) ; CallingConv :: ID CallConv = MF . getFunction ( ) -> getCallingConv ( ) ; bool requiresRA = CallConv == CallingConv :: MBLAZE_INTR ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADD ) , MBlaze :: R1 ) . addReg ( MBlaze :: R19 ) . addReg ( MBlaze :: R0 ) ; BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addImm ( FPOffset ) ; } if ( MFI -> adjustsStack ( ) || requiresRA ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R15 ) . addReg ( MBlaze :: R1 ) . addImm ( RAOffset ) ; } int StackSize = ( int ) MFI -> getStackSize ( ) ; if ( StackSize ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADDIK ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( StackSize ) ; } } </s>


<s> void MBlazeFrameLowering :: emitPrologue ( MachineFunction & MF ) const { MachineBasicBlock & MBB = MF . front ( ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; const MBlazeInstrInfo & TII = * static_cast < const MBlazeInstrInfo * > ( MF . getTarget ( ) . getInstrInfo ( ) ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; MachineBasicBlock :: iterator MBBI = MBB . begin ( ) ; DebugLoc DL = MBBI != MBB . end ( ) ? MBBI -> getDebugLoc ( ) : DebugLoc ( ) ; CallingConv :: ID CallConv = MF . getFunction ( ) -> getCallingConv ( ) ; bool requiresRA = CallConv == CallingConv :: MBLAZE_INTR ; determineFrameLayout ( MF ) ; unsigned StackSize = MFI -> getStackSize ( ) ; if ( StackSize == 0 && ! MFI -> adjustsStack ( ) && ! requiresRA ) return ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADDIK ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - StackSize ) ; if ( MFI -> adjustsStack ( ) || requiresRA ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R15 ) . addReg ( MBlaze :: R1 ) . addImm ( RAOffset ) ; } if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addImm ( FPOffset ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADD ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addReg ( MBlaze :: R0 ) ; } } </s>


<s> bool MBlazeFrameLowering :: hasFP ( const MachineFunction & MF ) const { const MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; return MF . getTarget ( ) . Options . DisableFramePointerElim ( MF ) || MFI -> hasVarSizedObjects ( ) ; } </s>


<s> void MBlazeInstPrinter :: printInst ( const MCInst * MI , raw_ostream & O , StringRef Annot ) { printInstruction ( MI , O ) ; printAnnotation ( O , Annot ) ; } </s>

Print the specified MCInst to the specified raw_ostream .


<s> unsigned MBlazeInstrInfo :: getGlobalBaseReg ( MachineFunction * MF ) const { MBlazeFunctionInfo * MBlazeFI = MF -> getInfo < MBlazeFunctionInfo > ( ) ; unsigned GlobalBaseReg = MBlazeFI -> getGlobalBaseReg ( ) ; if ( GlobalBaseReg != 0 ) return GlobalBaseReg ; MachineBasicBlock & FirstMBB = MF -> front ( ) ; MachineBasicBlock :: iterator MBBI = FirstMBB . begin ( ) ; MachineRegisterInfo & RegInfo = MF -> getRegInfo ( ) ; const TargetInstrInfo * TII = MF -> getTarget ( ) . getInstrInfo ( ) ; GlobalBaseReg = RegInfo . createVirtualRegister ( & MBlaze :: GPRRegClass ) ; BuildMI ( FirstMBB , MBBI , DebugLoc ( ) , TII -> get ( TargetOpcode :: COPY ) , GlobalBaseReg ) . addReg ( MBlaze :: R20 ) ; RegInfo . addLiveIn ( MBlaze :: R20 ) ; MBlazeFI -> setGlobalBaseReg ( GlobalBaseReg ) ; return GlobalBaseReg ; } </s>

getGlobalBaseReg - Return a virtual register initialized with the the global base register value .

MBlaze MBlaze MBlaze MBlaze MBlaze MBlaze 0 MBlaze::GPRRegClass MBlaze::R20 MBlaze::R20 MBlaze


<s> void MBlazeInstrInfo :: copyPhysReg ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , DebugLoc DL , unsigned DestReg , unsigned SrcReg , bool KillSrc ) const { llvm :: BuildMI ( MBB , I , DL , get ( MBlaze :: ADDK ) , DestReg ) . addReg ( SrcReg , getKillRegState ( KillSrc ) ) . addReg ( MBlaze :: R0 ) ; } </s>


<s> unsigned MBlazeInstrInfo :: getGlobalBaseReg ( MachineFunction * MF ) const { MBlazeFunctionInfo * MBlazeFI = MF -> getInfo < MBlazeFunctionInfo > ( ) ; unsigned GlobalBaseReg = MBlazeFI -> getGlobalBaseReg ( ) ; if ( GlobalBaseReg != 0 ) return GlobalBaseReg ; MachineBasicBlock & FirstMBB = MF -> front ( ) ; MachineBasicBlock :: iterator MBBI = FirstMBB . begin ( ) ; MachineRegisterInfo & RegInfo = MF -> getRegInfo ( ) ; const TargetInstrInfo * TII = MF -> getTarget ( ) . getInstrInfo ( ) ; GlobalBaseReg = RegInfo . createVirtualRegister ( MBlaze :: GPRRegisterClass ) ; BuildMI ( FirstMBB , MBBI , DebugLoc ( ) , TII -> get ( TargetOpcode :: COPY ) , GlobalBaseReg ) . addReg ( MBlaze :: R20 ) ; RegInfo . addLiveIn ( MBlaze :: R20 ) ; MBlazeFI -> setGlobalBaseReg ( GlobalBaseReg ) ; return GlobalBaseReg ; } </s>

MBlaze MBlaze MBlaze MBlaze MBlaze MBlaze 0 MBlaze::GPRRegisterClass MBlaze::R20 MBlaze::R20 MBlaze


<s> void MBlazeInstrInfo :: insertNoop ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator MI ) const { DebugLoc DL ; BuildMI ( MBB , MI , DL , get ( MBlaze :: NOP ) ) ; } </s>

Insert a noop into the instruction stream at the specified point .


<s> unsigned MBlazeInstrInfo :: isLoadFromStackSlot ( const MachineInstr * MI , int & FrameIndex ) const { if ( MI -> getOpcode ( ) == MBlaze :: LWI ) { if ( ( MI -> getOperand ( 1 ) . isFI ( ) ) && ( MI -> getOperand ( 2 ) . isImm ( ) ) && ( isZeroImm ( MI -> getOperand ( 2 ) ) ) ) { FrameIndex = MI -> getOperand ( 1 ) . getIndex ( ) ; return MI -> getOperand ( 0 ) . getReg ( ) ; } } return 0 ; } </s>

isLoadFromStackSlot - If the specified machine instruction is a direct load from a stack slot , return the virtual or physical register number of the destination along with the FrameIndex of the loaded stack slot .


<s> unsigned MBlazeInstrInfo :: isStoreToStackSlot ( const MachineInstr * MI , int & FrameIndex ) const { if ( MI -> getOpcode ( ) == MBlaze :: SWI ) { if ( ( MI -> getOperand ( 1 ) . isFI ( ) ) && ( MI -> getOperand ( 2 ) . isImm ( ) ) && ( isZeroImm ( MI -> getOperand ( 2 ) ) ) ) { FrameIndex = MI -> getOperand ( 1 ) . getIndex ( ) ; return MI -> getOperand ( 0 ) . getReg ( ) ; } } return 0 ; } </s>

isStoreToStackSlot - If the specified machine instruction is a direct store to a stack slot , return the virtual or physical register number of the source reg along with the FrameIndex of the loaded stack slot .


<s> void MBlazeInstrInfo :: loadRegFromStackSlot ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , unsigned DestReg , int FI , const TargetRegisterClass * RC , const TargetRegisterInfo * TRI ) const { DebugLoc DL ; BuildMI ( MBB , I , DL , get ( MBlaze :: LWI ) , DestReg ) . addFrameIndex ( FI ) . addImm ( 0 ) ; } </s>

Load the specified register of the given register class from the specified stack frame index .


<s> void MBlazeInstrInfo :: storeRegToStackSlot ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , unsigned SrcReg , bool isKill , int FI , const TargetRegisterClass * RC , const TargetRegisterInfo * TRI ) const { DebugLoc DL ; BuildMI ( MBB , I , DL , get ( MBlaze :: SWI ) ) . addReg ( SrcReg , getKillRegState ( isKill ) ) . addFrameIndex ( FI ) . addImm ( 0 ) ; } </s>

Store the specified register of the given register class to the specified stack frame index .


<s> void MBlazeInstrInfo :: copyPhysReg ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , DebugLoc DL , unsigned DestReg , unsigned SrcReg , bool KillSrc ) const { llvm :: BuildMI ( MBB , I , DL , get ( MBlaze :: ADD ) , DestReg ) . addReg ( SrcReg , getKillRegState ( KillSrc ) ) . addReg ( MBlaze :: R0 ) ; } </s>


<s> unsigned MBlazeInstrInfo :: getGlobalBaseReg ( MachineFunction * MF ) const { MBlazeFunctionInfo * MBlazeFI = MF -> getInfo < MBlazeFunctionInfo > ( ) ; unsigned GlobalBaseReg = MBlazeFI -> getGlobalBaseReg ( ) ; if ( GlobalBaseReg != 0 ) return GlobalBaseReg ; MachineBasicBlock & FirstMBB = MF -> front ( ) ; MachineBasicBlock :: iterator MBBI = FirstMBB . begin ( ) ; MachineRegisterInfo & RegInfo = MF -> getRegInfo ( ) ; const TargetInstrInfo * TII = MF -> getTarget ( ) . getInstrInfo ( ) ; GlobalBaseReg = RegInfo . createVirtualRegister ( MBlaze :: CPURegsRegisterClass ) ; BuildMI ( FirstMBB , MBBI , DebugLoc ( ) , TII -> get ( TargetOpcode :: COPY ) , GlobalBaseReg ) . addReg ( MBlaze :: R20 ) ; RegInfo . addLiveIn ( MBlaze :: R20 ) ; MBlazeFI -> setGlobalBaseReg ( GlobalBaseReg ) ; return GlobalBaseReg ; } </s>

MBlaze MBlaze MBlaze MBlaze MBlaze MBlaze 0 MBlaze::CPURegsRegisterClass MBlaze::R20 MBlaze::R20 MBlaze


<s> void MBlazeInstrInfo :: loadRegFromStackSlot ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , unsigned DestReg , int FI , const TargetRegisterClass * RC , const TargetRegisterInfo * TRI ) const { DebugLoc DL ; BuildMI ( MBB , I , DL , get ( MBlaze :: LWI ) , DestReg ) . addImm ( 0 ) . addFrameIndex ( FI ) ; } </s>


<s> void MBlazeInstrInfo :: storeRegToStackSlot ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , unsigned SrcReg , bool isKill , int FI , const TargetRegisterClass * RC , const TargetRegisterInfo * TRI ) const { DebugLoc DL ; BuildMI ( MBB , I , DL , get ( MBlaze :: SWI ) ) . addReg ( SrcReg , getKillRegState ( isKill ) ) . addImm ( 0 ) . addFrameIndex ( FI ) ; } </s>


<s> virtual MachineInstr * foldMemoryOperandImpl ( MachineFunction & MF , MachineInstr * MI , const SmallVectorImpl < unsigned > & Ops , MachineInstr * LoadMI ) const { return 0 ; } </s>

foldMemoryOperand - Same as the previous version except it allows folding of any load and store from / to any address , not just from a specific stack slot .


<s> void MBlazeInstrInfo :: insertNoop ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator MI ) const { DebugLoc DL = DebugLoc :: getUnknownLoc ( ) ; if ( MI != MBB . end ( ) ) DL = MI -> getDebugLoc ( ) ; BuildMI ( MBB , MI , DL , get ( MBlaze :: NOP ) ) ; } </s>


<s> void MBlazeInstrInfo :: loadRegFromStackSlot ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , unsigned DestReg , int FI , const TargetRegisterClass * RC ) const { DebugLoc dl = DebugLoc :: getUnknownLoc ( ) ; BuildMI ( MBB , I , dl , get ( MBlaze :: LWI ) , DestReg ) . addImm ( 0 ) . addFrameIndex ( FI ) ; } </s>


<s> void MBlazeInstrInfo :: storeRegToStackSlot ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , unsigned SrcReg , bool isKill , int FI , const TargetRegisterClass * RC ) const { DebugLoc dl = DebugLoc :: getUnknownLoc ( ) ; BuildMI ( MBB , I , dl , get ( MBlaze :: SWI ) ) . addReg ( SrcReg , getKillRegState ( isKill ) ) . addImm ( 0 ) . addFrameIndex ( FI ) ; } </s>


<s> MachineInstr * MBlazeInstrInfo :: foldMemoryOperandImpl ( MachineFunction & MF , MachineInstr * MI , const SmallVectorImpl < unsigned > & Ops , int FI ) const { if ( Ops . size ( ) != 1 ) return NULL ; MachineInstr * NewMI = NULL ; switch ( MI -> getOpcode ( ) ) { case MBlaze :: OR : case MBlaze :: ADD : if ( ( MI -> getOperand ( 0 ) . isReg ( ) ) && ( MI -> getOperand ( 2 ) . isReg ( ) ) && ( MI -> getOperand ( 2 ) . getReg ( ) == MBlaze :: R0 ) && ( MI -> getOperand ( 1 ) . isReg ( ) ) ) { if ( Ops [ 0 ] == 0 ) { unsigned SrcReg = MI -> getOperand ( 1 ) . getReg ( ) ; bool isKill = MI -> getOperand ( 1 ) . isKill ( ) ; bool isUndef = MI -> getOperand ( 1 ) . isUndef ( ) ; NewMI = BuildMI ( MF , MI -> getDebugLoc ( ) , get ( MBlaze :: SW ) ) . addReg ( SrcReg , getKillRegState ( isKill ) | getUndefRegState ( isUndef ) ) . addImm ( 0 ) . addFrameIndex ( FI ) ; } else { unsigned DstReg = MI -> getOperand ( 0 ) . getReg ( ) ; bool isDead = MI -> getOperand ( 0 ) . isDead ( ) ; bool isUndef = MI -> getOperand ( 0 ) . isUndef ( ) ; NewMI = BuildMI ( MF , MI -> getDebugLoc ( ) , get ( MBlaze :: LW ) ) . addReg ( DstReg , RegState :: Define | getDeadRegState ( isDead ) | getUndefRegState ( isUndef ) ) . addImm ( 0 ) . addFrameIndex ( FI ) ; } } break ; } return NewMI ; } </s>


"Couldn't assign to global base register!"


<s> virtual const MBlazeRegisterInfo & getRegisterInfo ( ) const { return RI ; } </s>

getRegisterInfo - TargetInstrInfo is a superset of MRegister info .


<s> void MBlazeInstrInfo :: insertNoop ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator MI ) const { DebugLoc DL ; if ( MI != MBB . end ( ) ) DL = MI -> getDebugLoc ( ) ; BuildMI ( MBB , MI , DL , get ( MBlaze :: NOP ) ) ; } </s>


<s> unsigned MBlazeInstrInfo :: isLoadFromStackSlot ( const MachineInstr * MI , int & FrameIndex ) const { if ( MI -> getOpcode ( ) == MBlaze :: LWI ) { if ( ( MI -> getOperand ( 2 ) . isFI ( ) ) && ( MI -> getOperand ( 1 ) . isImm ( ) ) && ( isZeroImm ( MI -> getOperand ( 1 ) ) ) ) { FrameIndex = MI -> getOperand ( 2 ) . getIndex ( ) ; return MI -> getOperand ( 0 ) . getReg ( ) ; } } return 0 ; } </s>


<s> unsigned MBlazeInstrInfo :: isStoreToStackSlot ( const MachineInstr * MI , int & FrameIndex ) const { if ( MI -> getOpcode ( ) == MBlaze :: SWI ) { if ( ( MI -> getOperand ( 2 ) . isFI ( ) ) && ( MI -> getOperand ( 1 ) . isImm ( ) ) && ( isZeroImm ( MI -> getOperand ( 1 ) ) ) ) { FrameIndex = MI -> getOperand ( 2 ) . getIndex ( ) ; return MI -> getOperand ( 0 ) . getReg ( ) ; } } return 0 ; } </s>


<s> void MBlazeInstrInfo :: loadRegFromStackSlot ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , unsigned DestReg , int FI , const TargetRegisterClass * RC ) const { DebugLoc DL ; BuildMI ( MBB , I , DL , get ( MBlaze :: LWI ) , DestReg ) . addImm ( 0 ) . addFrameIndex ( FI ) ; } </s>


<s> void MBlazeInstrInfo :: storeRegToStackSlot ( MachineBasicBlock & MBB , MachineBasicBlock :: iterator I , unsigned SrcReg , bool isKill , int FI , const TargetRegisterClass * RC ) const { DebugLoc DL ; BuildMI ( MBB , I , DL , get ( MBlaze :: SWI ) ) . addReg ( SrcReg , getKillRegState ( isKill ) ) . addImm ( 0 ) . addFrameIndex ( FI ) ; } </s>


<s>
Function
*
MBlazeIntrinsicInfo
::
getDeclaration
(
Module
*
M
,
unsigned
IntrID
,
Type
*
*
Tys
,
unsigned
numTy
)
const
{
assert
(
!
isOverloaded
(
IntrID
)
&&
"MBlaze intrinsics are not overloaded"
)
;
AttributeSet
AList
=
getAttributes
(
M
->
getContext
(
)
,
(
mblazeIntrinsic
::
ID
)
IntrID
)
;
return
cast
<
Function
>
(
M
->
getOrInsertFunction
(
getName
(
IntrID
)
,
getType
(
M
->
getContext
(
)
,
IntrID
)
,
AList
)
)
;
}
</s>

Create or insert an LLVM Function declaration for an intrinsic , and return it .

MBlaze
MBlaze
"MBlaze intrinsics are not overloaded"
mblazeIntrinsic::ID


<s>
std
::
string
MBlazeIntrinsicInfo
::
getName
(
unsigned
IntrID
,
Type
*
*
Tys
,
unsigned
numTys
)
const
{
static
const
char
*
const
names
[
]
=
{
}
;
assert
(
!
isOverloaded
(
IntrID
)
&&
"MBlaze intrinsics are not overloaded"
)
;
if
(
IntrID
<
Intrinsic
::
num_intrinsics
)
return
0
;
assert
(
IntrID
<
mblazeIntrinsic
::
num_mblaze_intrinsics
&&
"Invalid intrinsic ID"
)
;
std
::
string
Result
(
names
[
IntrID
Intrinsic
::
num_intrinsics
]
)
;
return
Result
;
}
</s>

Return a string with the name of the plan and the applicable VFs and UFs .


<s> static FunctionType * getType ( LLVMContext & Context , unsigned id ) { Type * ResultTy = NULL ; SmallVector < Type * , 8 > ArgTys ; bool IsVarArg = false ; return FunctionType :: get ( ResultTy , ArgTys , IsVarArg ) ; } </s>

Overload to return most specific vector type .


<s> bool MBlazeIntrinsicInfo :: isOverloaded ( unsigned IntrID ) const { if ( IntrID == 0 ) return false ; unsigned id = IntrID - Intrinsic :: num_intrinsics + 1 ; } </s>

Returns true if the intrinsic can be overloaded .


<s> unsigned MBlazeIntrinsicInfo :: lookupName ( const char * Name , unsigned Len ) const { if ( ! StringRef ( Name , Len ) . startswith ( "llvm." ) ) return 0 ; return 0 ; } </s>


<s>
Function
*
MBlazeIntrinsicInfo
::
getDeclaration
(
Module
*
M
,
unsigned
IntrID
,
Type
*
*
Tys
,
unsigned
numTy
)
const
{
assert
(
!
isOverloaded
(
IntrID
)
&&
"MBlaze intrinsics are not overloaded"
)
;
AttrListPtr
AList
=
getAttributes
(
M
->
getContext
(
)
,
(
mblazeIntrinsic
::
ID
)
IntrID
)
;
return
cast
<
Function
>
(
M
->
getOrInsertFunction
(
getName
(
IntrID
)
,
getType
(
M
->
getContext
(
)
,
IntrID
)
,
AList
)
)
;
}
</s>


<s> unsigned MBlazeIntrinsicInfo :: lookupName ( const char * Name , unsigned Len ) const { return 0 ; } </s>


<s>
Function
*
MBlazeIntrinsicInfo
::
getDeclaration
(
Module
*
M
,
unsigned
IntrID
,
Type
*
*
Tys
,
unsigned
numTy
)
const
{
assert
(
!
isOverloaded
(
IntrID
)
&&
"MBlaze intrinsics are not overloaded"
)
;
AttrListPtr
AList
=
getAttributes
(
(
mblazeIntrinsic
::
ID
)
IntrID
)
;
return
cast
<
Function
>
(
M
->
getOrInsertFunction
(
getName
(
IntrID
)
,
getType
(
M
->
getContext
(
)
,
IntrID
)
,
AList
)
)
;
}
</s>


<s> static FunctionType * getType ( LLVMContext & Context , unsigned id ) { Type * ResultTy = NULL ; std :: vector < Type * > ArgTys ; bool IsVarArg = false ; return FunctionType :: get ( ResultTy , ArgTys , IsVarArg ) ; } </s>


<s>
Function
*
MBlazeIntrinsicInfo
::
getDeclaration
(
Module
*
M
,
unsigned
IntrID
,
const
Type
*
*
Tys
,
unsigned
numTy
)
const
{
assert
(
!
isOverloaded
(
IntrID
)
&&
"MBlaze intrinsics are not overloaded"
)
;
AttrListPtr
AList
=
getAttributes
(
(
mblazeIntrinsic
::
ID
)
IntrID
)
;
return
cast
<
Function
>
(
M
->
getOrInsertFunction
(
getName
(
IntrID
)
,
getType
(
M
->
getContext
(
)
,
IntrID
)
,
AList
)
)
;
}
</s>


<s>
std
::
string
MBlazeIntrinsicInfo
::
getName
(
unsigned
IntrID
,
const
Type
*
*
Tys
,
unsigned
numTys
)
const
{
static
const
char
*
const
names
[
]
=
{
}
;
assert
(
!
isOverloaded
(
IntrID
)
&&
"MBlaze intrinsics are not overloaded"
)
;
if
(
IntrID
<
Intrinsic
::
num_intrinsics
)
return
0
;
assert
(
IntrID
<
mblazeIntrinsic
::
num_mblaze_intrinsics
&&
"Invalid intrinsic ID"
)
;
std
::
string
Result
(
names
[
IntrID
Intrinsic
::
num_intrinsics
]
)
;
return
Result
;
}
</s>


<s> static const FunctionType * getType ( LLVMContext & Context , unsigned id ) { const Type * ResultTy = NULL ; std :: vector < const Type * > ArgTys ; bool IsVarArg = false ; return FunctionType :: get ( ResultTy , ArgTys , IsVarArg ) ; } </s>


<s> bool MBlazeIntrinsicInfo :: isOverloaded ( unsigned IntrID ) const { const bool OTable [ ] = { } ; if ( IntrID == 0 ) return false ; else return OTable [ IntrID - Intrinsic :: num_intrinsics ] ; } </s>


<s> unsigned MBlazeIntrinsicInfo :: lookupName ( const char * Name , unsigned Len ) const { if ( Len < 5 || Name [ 4 ] != '.' || Name [ 0 ] != 'l' || Name [ 1 ] != 'l' || Name [ 2 ] != 'v' || Name [ 3 ] != 'm' ) return 0 ; return 0 ; } </s>


<s> SDNode * MBlazeDAGToDAGISel :: getGlobalBaseReg ( ) { unsigned GlobalBaseReg = getInstrInfo ( ) -> getGlobalBaseReg ( MF ) ; return CurDAG -> getRegister ( GlobalBaseReg , TLI . getPointerTy ( ) ) . getNode ( ) ; } </s>


<s>
SDNode
*
MBlazeDAGToDAGISel
::
Select
(
SDNode
*
Node
)
{
unsigned
Opcode
=
Node
->
getOpcode
(
)
;
DebugLoc
dl
=
Node
->
getDebugLoc
(
)
;
if
(
Node
->
isMachineOpcode
(
)
)
return
;
switch
(
Opcode
)
{
default
:
break
;
case
ISD
::
GLOBAL_OFFSET_TABLE
:
return
getGlobalBaseReg
(
)
;
case
ISD
::
FrameIndex
:
{
SDValue
imm
=
CurDAG
->
getTargetConstant
(
0
,
MVT
::
i32
)
;
int
FI
=
dyn_cast
<
FrameIndexSDNode
>
(
Node
)
->
getIndex
(
)
;
EVT
VT
=
Node
->
getValueType
(
0
)
;
SDValue
TFI
=
CurDAG
->
getTargetFrameIndex
(
FI
,
VT
)
;
unsigned
Opc
=
MBlaze
::
ADDI
;
if
(
Node
->
hasOneUse
(
)
)
return
CurDAG
->
SelectNodeTo
(
Node
,
Opc
,
VT
,
TFI
,
imm
)
;
return
CurDAG
->
getMachineNode
(
Opc
,
dl
,
VT
,
TFI
,
imm
)
;
}
case
MBlazeISD
::
JmpLink
:
{
if
(
TM
.
getRelocationModel
(
)
==
Reloc
::
PIC_
)
{
SDValue
Chain
=
Node
->
getOperand
(
0
)
;
SDValue
Callee
=
Node
->
getOperand
(
1
)
;
SDValue
R20Reg
=
CurDAG
->
getRegister
(
MBlaze
::
R20
,
MVT
::
i32
)
;
SDValue
InFlag
(
0
,
0
)
;
if
(
(
isa
<
GlobalAddressSDNode
>
(
Callee
)
)
||
(
isa
<
ExternalSymbolSDNode
>
(
Callee
)
)
)
{
SDValue
GPReg
=
CurDAG
->
getRegister
(
MBlaze
::
R15
,
MVT
::
i32
)
;
SDValue
Ops
[
]
=
{
Callee
,
GPReg
,
Chain
}
;
SDValue
Load
=
SDValue
(
CurDAG
->
getMachineNode
(
MBlaze
::
LW
,
dl
,
MVT
::
i32
,
MVT
::
Other
,
Ops
,
3
)
,
0
)
;
Chain
=
Load
.
getValue
(
1
)
;
Chain
=
CurDAG
->
getCopyToReg
(
Chain
,
dl
,
R20Reg
,
Load
,
InFlag
)
;
}
else
Chain
=
CurDAG
->
getCopyToReg
(
Chain
,
dl
,
R20Reg
,
Callee
,
InFlag
)
;
SDNode
*
ResNode
=
CurDAG
->
getMachineNode
(
MBlaze
::
BRLID
,
dl
,
MVT
::
Other
,
MVT
::
Flag
,
R20Reg
,
Chain
)
;
Chain
=
SDValue
(
ResNode
,
0
)
;
InFlag
=
SDValue
(
ResNode
,
1
)
;
ReplaceUses
(
SDValue
(
Node
,
0
)
,
Chain
)
;
ReplaceUses
(
SDValue
(
Node
,
1
)
,
InFlag
)
;
return
ResNode
;
}
}
}
SDNode
*
ResNode
=
SelectCode
(
Node
)
;
DEBUG
(
errs
(
)
<<
"=> "
)
;
if
(
ResNode
==
||
ResNode
==
Node
)
DEBUG
(
Node
->
dump
(
CurDAG
)
)
;
else
DEBUG
(
ResNode
->
dump
(
CurDAG
)
)
;
DEBUG
(
errs
(
)
<<
"\n"
)
;
return
ResNode
;
}
</s>

Main hook for targets to transform nodes into machine nodes .


<s>
SDNode
*
MBlazeDAGToDAGISel
::
Select
(
SDNode
*
Node
)
{
unsigned
Opcode
=
Node
->
getOpcode
(
)
;
DebugLoc
dl
=
Node
->
getDebugLoc
(
)
;
if
(
Node
->
isMachineOpcode
(
)
)
return
;
switch
(
Opcode
)
{
default
:
break
;
case
ISD
::
GLOBAL_OFFSET_TABLE
:
return
getGlobalBaseReg
(
)
;
case
ISD
::
FrameIndex
:
{
SDValue
imm
=
CurDAG
->
getTargetConstant
(
0
,
MVT
::
i32
)
;
int
FI
=
dyn_cast
<
FrameIndexSDNode
>
(
Node
)
->
getIndex
(
)
;
EVT
VT
=
Node
->
getValueType
(
0
)
;
SDValue
TFI
=
CurDAG
->
getTargetFrameIndex
(
FI
,
VT
)
;
unsigned
Opc
=
MBlaze
::
ADDIK
;
if
(
Node
->
hasOneUse
(
)
)
return
CurDAG
->
SelectNodeTo
(
Node
,
Opc
,
VT
,
TFI
,
imm
)
;
return
CurDAG
->
getMachineNode
(
Opc
,
dl
,
VT
,
TFI
,
imm
)
;
}
case
MBlazeISD
::
JmpLink
:
{
if
(
TM
.
getRelocationModel
(
)
==
Reloc
::
PIC_
)
{
SDValue
Chain
=
Node
->
getOperand
(
0
)
;
SDValue
Callee
=
Node
->
getOperand
(
1
)
;
SDValue
R20Reg
=
CurDAG
->
getRegister
(
MBlaze
::
R20
,
MVT
::
i32
)
;
SDValue
InFlag
(
0
,
0
)
;
if
(
(
isa
<
GlobalAddressSDNode
>
(
Callee
)
)
||
(
isa
<
ExternalSymbolSDNode
>
(
Callee
)
)
)
{
SDValue
GPReg
=
CurDAG
->
getRegister
(
MBlaze
::
R15
,
MVT
::
i32
)
;
SDValue
Ops
[
]
=
{
Callee
,
GPReg
,
Chain
}
;
SDValue
Load
=
SDValue
(
CurDAG
->
getMachineNode
(
MBlaze
::
LW
,
dl
,
MVT
::
i32
,
MVT
::
Other
,
Ops
,
3
)
,
0
)
;
Chain
=
Load
.
getValue
(
1
)
;
Chain
=
CurDAG
->
getCopyToReg
(
Chain
,
dl
,
R20Reg
,
Load
,
InFlag
)
;
}
else
Chain
=
CurDAG
->
getCopyToReg
(
Chain
,
dl
,
R20Reg
,
Callee
,
InFlag
)
;
SDNode
*
ResNode
=
CurDAG
->
getMachineNode
(
MBlaze
::
BRLID
,
dl
,
MVT
::
Other
,
MVT
::
Glue
,
R20Reg
,
Chain
)
;
Chain
=
SDValue
(
ResNode
,
0
)
;
InFlag
=
SDValue
(
ResNode
,
1
)
;
ReplaceUses
(
SDValue
(
Node
,
0
)
,
Chain
)
;
ReplaceUses
(
SDValue
(
Node
,
1
)
,
InFlag
)
;
return
ResNode
;
}
}
}
SDNode
*
ResNode
=
SelectCode
(
Node
)
;
DEBUG
(
errs
(
)
<<
"=> "
)
;
if
(
ResNode
==
||
ResNode
==
Node
)
DEBUG
(
Node
->
dump
(
CurDAG
)
)
;
else
DEBUG
(
ResNode
->
dump
(
CurDAG
)
)
;
DEBUG
(
errs
(
)
<<
"\n"
)
;
return
ResNode
;
}
</s>


<s>
SDNode
*
MBlazeDAGToDAGISel
::
Select
(
SDNode
*
Node
)
{
unsigned
Opcode
=
Node
->
getOpcode
(
)
;
DebugLoc
dl
=
Node
->
getDebugLoc
(
)
;
if
(
Node
->
isMachineOpcode
(
)
)
return
;
switch
(
Opcode
)
{
default
:
break
;
case
ISD
::
GLOBAL_OFFSET_TABLE
:
return
getGlobalBaseReg
(
)
;
case
ISD
::
FrameIndex
:
{
SDValue
imm
=
CurDAG
->
getTargetConstant
(
0
,
MVT
::
i32
)
;
int
FI
=
dyn_cast
<
FrameIndexSDNode
>
(
Node
)
->
getIndex
(
)
;
EVT
VT
=
Node
->
getValueType
(
0
)
;
SDValue
TFI
=
CurDAG
->
getTargetFrameIndex
(
FI
,
VT
)
;
unsigned
Opc
=
MBlaze
::
ADDIK
;
if
(
Node
->
hasOneUse
(
)
)
return
CurDAG
->
SelectNodeTo
(
Node
,
Opc
,
VT
,
TFI
,
imm
)
;
return
CurDAG
->
getMachineNode
(
Opc
,
dl
,
VT
,
TFI
,
imm
)
;
}
case
MBlazeISD
::
JmpLink
:
{
if
(
TM
.
getRelocationModel
(
)
==
Reloc
::
PIC_
)
{
SDValue
Chain
=
Node
->
getOperand
(
0
)
;
SDValue
Callee
=
Node
->
getOperand
(
1
)
;
SDValue
R20Reg
=
CurDAG
->
getRegister
(
MBlaze
::
R20
,
MVT
::
i32
)
;
SDValue
InFlag
(
0
,
0
)
;
if
(
(
isa
<
GlobalAddressSDNode
>
(
Callee
)
)
||
(
isa
<
ExternalSymbolSDNode
>
(
Callee
)
)
)
{
SDValue
GPReg
=
CurDAG
->
getRegister
(
MBlaze
::
R15
,
MVT
::
i32
)
;
SDValue
Ops
[
]
=
{
Callee
,
GPReg
,
Chain
}
;
SDValue
Load
=
SDValue
(
CurDAG
->
getMachineNode
(
MBlaze
::
LW
,
dl
,
MVT
::
i32
,
MVT
::
Other
,
Ops
)
,
0
)
;
Chain
=
Load
.
getValue
(
1
)
;
Chain
=
CurDAG
->
getCopyToReg
(
Chain
,
dl
,
R20Reg
,
Load
,
InFlag
)
;
}
else
Chain
=
CurDAG
->
getCopyToReg
(
Chain
,
dl
,
R20Reg
,
Callee
,
InFlag
)
;
SDNode
*
ResNode
=
CurDAG
->
getMachineNode
(
MBlaze
::
BRLID
,
dl
,
MVT
::
Other
,
MVT
::
Glue
,
R20Reg
,
Chain
)
;
Chain
=
SDValue
(
ResNode
,
0
)
;
InFlag
=
SDValue
(
ResNode
,
1
)
;
ReplaceUses
(
SDValue
(
Node
,
0
)
,
Chain
)
;
ReplaceUses
(
SDValue
(
Node
,
1
)
,
InFlag
)
;
return
ResNode
;
}
}
}
SDNode
*
ResNode
=
SelectCode
(
Node
)
;
DEBUG
(
errs
(
)
<<
"=> "
)
;
if
(
ResNode
==
||
ResNode
==
Node
)
DEBUG
(
Node
->
dump
(
CurDAG
)
)
;
else
DEBUG
(
ResNode
->
dump
(
CurDAG
)
)
;
DEBUG
(
errs
(
)
<<
"\n"
)
;
return
ResNode
;
}
</s>


<s> SDNode * MBlazeDAGToDAGISel :: getGlobalBaseReg ( ) { unsigned GlobalBaseReg = getInstrInfo ( ) -> getGlobalBaseReg ( MF ) ; return CurDAG -> getRegister ( GlobalBaseReg , TLI -> getPointerTy ( ) ) . getNode ( ) ; } </s>


<s> SDNode * MBlazeDAGToDAGISel :: getGlobalBaseReg ( ) { unsigned GlobalBaseReg = getInstrInfo ( ) -> getGlobalBaseReg ( MF ) ; return CurDAG -> getRegister ( GlobalBaseReg , getTargetLowering ( ) -> getPointerTy ( ) ) . getNode ( ) ; } </s>


<s> const MBlazeInstrInfo * getInstrInfo ( ) { return getTargetMachine ( ) . getInstrInfo ( ) ; } </s>


"MBlaze DAG->DAG Pattern Instruction Selection"

getPassName - Return a nice clean name for a pass .


<s> const MBlazeTargetMachine & getTargetMachine ( ) { return static_cast < const MBlazeTargetMachine & > ( TM ) ; } </s>

Return the target machine ( if available ) .


<s>
SDNode
*
MBlazeDAGToDAGISel
::
Select
(
SDNode
*
Node
)
{
unsigned
Opcode
=
Node
->
getOpcode
(
)
;
SDLoc
dl
(
Node
)
;
if
(
Node
->
isMachineOpcode
(
)
)
return
;
switch
(
Opcode
)
{
default
:
break
;
case
ISD
::
GLOBAL_OFFSET_TABLE
:
return
getGlobalBaseReg
(
)
;
case
ISD
::
FrameIndex
:
{
SDValue
imm
=
CurDAG
->
getTargetConstant
(
0
,
MVT
::
i32
)
;
int
FI
=
dyn_cast
<
FrameIndexSDNode
>
(
Node
)
->
getIndex
(
)
;
EVT
VT
=
Node
->
getValueType
(
0
)
;
SDValue
TFI
=
CurDAG
->
getTargetFrameIndex
(
FI
,
VT
)
;
unsigned
Opc
=
MBlaze
::
ADDIK
;
if
(
Node
->
hasOneUse
(
)
)
return
CurDAG
->
SelectNodeTo
(
Node
,
Opc
,
VT
,
TFI
,
imm
)
;
return
CurDAG
->
getMachineNode
(
Opc
,
dl
,
VT
,
TFI
,
imm
)
;
}
case
MBlazeISD
::
JmpLink
:
{
if
(
TM
.
getRelocationModel
(
)
==
Reloc
::
PIC_
)
{
SDValue
Chain
=
Node
->
getOperand
(
0
)
;
SDValue
Callee
=
Node
->
getOperand
(
1
)
;
SDValue
R20Reg
=
CurDAG
->
getRegister
(
MBlaze
::
R20
,
MVT
::
i32
)
;
SDValue
InFlag
(
0
,
0
)
;
if
(
(
isa
<
GlobalAddressSDNode
>
(
Callee
)
)
||
(
isa
<
ExternalSymbolSDNode
>
(
Callee
)
)
)
{
SDValue
GPReg
=
CurDAG
->
getRegister
(
MBlaze
::
R15
,
MVT
::
i32
)
;
SDValue
Ops
[
]
=
{
Callee
,
GPReg
,
Chain
}
;
SDValue
Load
=
SDValue
(
CurDAG
->
getMachineNode
(
MBlaze
::
LW
,
dl
,
MVT
::
i32
,
MVT
::
Other
,
Ops
)
,
0
)
;
Chain
=
Load
.
getValue
(
1
)
;
Chain
=
CurDAG
->
getCopyToReg
(
Chain
,
dl
,
R20Reg
,
Load
,
InFlag
)
;
}
else
Chain
=
CurDAG
->
getCopyToReg
(
Chain
,
dl
,
R20Reg
,
Callee
,
InFlag
)
;
SDNode
*
ResNode
=
CurDAG
->
getMachineNode
(
MBlaze
::
BRLID
,
dl
,
MVT
::
Other
,
MVT
::
Glue
,
R20Reg
,
Chain
)
;
Chain
=
SDValue
(
ResNode
,
0
)
;
InFlag
=
SDValue
(
ResNode
,
1
)
;
ReplaceUses
(
SDValue
(
Node
,
0
)
,
Chain
)
;
ReplaceUses
(
SDValue
(
Node
,
1
)
,
InFlag
)
;
return
ResNode
;
}
}
}
SDNode
*
ResNode
=
SelectCode
(
Node
)
;
DEBUG
(
errs
(
)
<<
"=> "
)
;
if
(
ResNode
==
||
ResNode
==
Node
)
DEBUG
(
Node
->
dump
(
CurDAG
)
)
;
else
DEBUG
(
ResNode
->
dump
(
CurDAG
)
)
;
DEBUG
(
errs
(
)
<<
"\n"
)
;
return
ResNode
;
}
</s>


<s> std :: pair < unsigned , const TargetRegisterClass * > MBlazeTargetLowering :: getRegForInlineAsmConstraint ( const std :: string & Constraint , EVT VT ) const { if ( Constraint . size ( ) == 1 ) { switch ( Constraint [ 0 ] ) { case 'r' : return std :: make_pair ( 0U , & MBlaze :: GPRRegClass ) ; case 'd' : case 'y' : case 'f' : if ( VT == MVT :: f32 ) return std :: make_pair ( 0U , & MBlaze :: GPRRegClass ) ; } } return TargetLowering :: getRegForInlineAsmConstraint ( Constraint , VT ) ; } </s>

Given a physical register constraint ( e.g .


<s> EVT MBlazeTargetLowering :: getSetCCResultType ( EVT VT ) const { return MVT :: i32 ; } </s>

Return the value type to use for ISD : :SETCC .


<s> SDValue MBlazeTargetLowering :: LowerCallResult ( SDValue Chain , SDValue InFlag , CallingConv :: ID CallConv , bool isVarArg , const SmallVectorImpl < ISD :: InputArg > & Ins , DebugLoc dl , SelectionDAG & DAG , SmallVectorImpl < SDValue > & InVals ) const { SmallVector < CCValAssign , 16 > RVLocs ; CCState CCInfo ( CallConv , isVarArg , DAG . getMachineFunction ( ) , getTargetMachine ( ) , RVLocs , * DAG . getContext ( ) ) ; CCInfo . AnalyzeCallResult ( Ins , RetCC_MBlaze ) ; for ( unsigned i = 0 ; i != RVLocs . size ( ) ; ++ i ) { Chain = DAG . getCopyFromReg ( Chain , dl , RVLocs [ i ] . getLocReg ( ) , RVLocs [ i ] . getValVT ( ) , InFlag ) . getValue ( 1 ) ; InFlag = Chain . getValue ( 2 ) ; InVals . push_back ( Chain . getValue ( 0 ) ) ; } return Chain ; } </s>

LowerCallResult - Lower the result values of an ISD : :CALL into the appropriate copies out of appropriate physical registers .


<s>
SDValue
MBlazeTargetLowering
::
LowerReturn
(
SDValue
Chain
,
CallingConv
::
ID
CallConv
,
bool
isVarArg
,
const
SmallVectorImpl
<
ISD
::
OutputArg
>
&
Outs
,
const
SmallVectorImpl
<
SDValue
>
&
OutVals
,
DebugLoc
dl
,
SelectionDAG
&
DAG
)
const
{
SmallVector
<
CCValAssign
,
16
>
RVLocs
;
CCState
CCInfo
(
CallConv
,
isVarArg
,
DAG
.
getMachineFunction
(
)
,
getTargetMachine
(
)
,
RVLocs
,
*
DAG
.
getContext
(
)
)
;
CCInfo
.
AnalyzeReturn
(
Outs
,
RetCC_MBlaze
)
;
if
(
DAG
.
getMachineFunction
(
)
.
getRegInfo
(
)
.
liveout_empty
(
)
)
{
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
if
(
RVLocs
[
i
]
.
isRegLoc
(
)
)
DAG
.
getMachineFunction
(
)
.
getRegInfo
(
)
.
addLiveOut
(
RVLocs
[
i
]
.
getLocReg
(
)
)
;
}
SDValue
Flag
;
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
{
CCValAssign
&
VA
=
RVLocs
[
i
]
;
assert
(
VA
.
isRegLoc
(
)
&&
"Can only return in registers!"
)
;
Chain
=
DAG
.
getCopyToReg
(
Chain
,
dl
,
VA
.
getLocReg
(
)
,
OutVals
[
i
]
,
Flag
)
;
Flag
=
Chain
.
getValue
(
1
)
;
}
unsigned
Ret
=
(
CallConv
==
CallingConv
::
MBLAZE_INTR
)
MBlazeISD
::
IRet
:
MBlazeISD
::
Ret
;
unsigned
Reg
=
(
CallConv
==
CallingConv
::
MBLAZE_INTR
)
MBlaze
::
R14
:
MBlaze
::
R15
;
SDValue
DReg
=
DAG
.
getRegister
(
Reg
,
MVT
::
i32
)
;
if
(
Flag
.
getNode
(
)
)
return
DAG
.
getNode
(
Ret
,
dl
,
MVT
::
Other
,
Chain
,
DReg
,
Flag
)
;
return
DAG
.
getNode
(
Ret
,
dl
,
MVT
::
Other
,
Chain
,
DReg
)
;
}
</s>

This hook must be implemented to lower outgoing return values , described by the Outs array , into the specified DAG .


<s>
SDValue
MBlazeTargetLowering
::
LowerReturn
(
SDValue
Chain
,
CallingConv
::
ID
CallConv
,
bool
isVarArg
,
const
SmallVectorImpl
<
ISD
::
OutputArg
>
&
Outs
,
const
SmallVectorImpl
<
SDValue
>
&
OutVals
,
DebugLoc
dl
,
SelectionDAG
&
DAG
)
const
{
SmallVector
<
CCValAssign
,
16
>
RVLocs
;
CCState
CCInfo
(
CallConv
,
isVarArg
,
DAG
.
getMachineFunction
(
)
,
getTargetMachine
(
)
,
RVLocs
,
*
DAG
.
getContext
(
)
)
;
CCInfo
.
AnalyzeReturn
(
Outs
,
RetCC_MBlaze
)
;
SDValue
Flag
;
SmallVector
<
SDValue
,
4
>
RetOps
(
1
,
Chain
)
;
unsigned
Ret
=
(
CallConv
==
CallingConv
::
MBLAZE_INTR
)
MBlazeISD
::
IRet
:
MBlazeISD
::
Ret
;
unsigned
Reg
=
(
CallConv
==
CallingConv
::
MBLAZE_INTR
)
MBlaze
::
R14
:
MBlaze
::
R15
;
RetOps
.
push_back
(
DAG
.
getRegister
(
Reg
,
MVT
::
i32
)
)
;
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
{
CCValAssign
&
VA
=
RVLocs
[
i
]
;
assert
(
VA
.
isRegLoc
(
)
&&
"Can only return in registers!"
)
;
Chain
=
DAG
.
getCopyToReg
(
Chain
,
dl
,
VA
.
getLocReg
(
)
,
OutVals
[
i
]
,
Flag
)
;
Flag
=
Chain
.
getValue
(
1
)
;
RetOps
.
push_back
(
DAG
.
getRegister
(
VA
.
getLocReg
(
)
,
VA
.
getLocVT
(
)
)
)
;
}
RetOps
[
0
]
=
Chain
;
if
(
Flag
.
getNode
(
)
)
RetOps
.
push_back
(
Flag
)
;
return
DAG
.
getNode
(
Ret
,
dl
,
MVT
::
Other
,
&
RetOps
[
0
]
,
RetOps
.
size
(
)
)
;
}
</s>


<s>
MachineBasicBlock
*
MBlazeTargetLowering
::
EmitInstrWithCustomInserter
(
MachineInstr
*
MI
,
MachineBasicBlock
*
MBB
)
const
{
switch
(
MI
->
getOpcode
(
)
)
{
default
:
assert
(
false
&&
"Unexpected instr type to insert"
)
;
case
MBlaze
::
ShiftRL
:
case
MBlaze
::
ShiftRA
:
case
MBlaze
::
ShiftL
:
return
EmitCustomShift
(
MI
,
MBB
)
;
case
MBlaze
::
Select_FCC
:
case
MBlaze
::
Select_CC
:
return
EmitCustomSelect
(
MI
,
MBB
)
;
case
MBlaze
::
CAS32
:
case
MBlaze
::
SWP32
:
case
MBlaze
::
LAA32
:
case
MBlaze
::
LAS32
:
case
MBlaze
::
LAD32
:
case
MBlaze
::
LAO32
:
case
MBlaze
::
LAX32
:
case
MBlaze
::
LAN32
:
return
EmitCustomAtomic
(
MI
,
MBB
)
;
case
MBlaze
::
MEMBARRIER
:
MI
->
eraseFromParent
(
)
;
return
MBB
;
}
}
</s>

This method should be implemented by targets that mark instructions with the 'usesCustomInserter ' flag .


<s> std :: pair < unsigned , const TargetRegisterClass * > MBlazeTargetLowering :: getRegForInlineAsmConstraint ( const std :: string & Constraint , EVT VT ) const { if ( Constraint . size ( ) == 1 ) { switch ( Constraint [ 0 ] ) { case 'r' : return std :: make_pair ( 0U , MBlaze :: GPRRegisterClass ) ; case 'd' : case 'y' : case 'f' : if ( VT == MVT :: f32 ) return std :: make_pair ( 0U , MBlaze :: GPRRegisterClass ) ; } } return TargetLowering :: getRegForInlineAsmConstraint ( Constraint , VT ) ; } </s>


<s>
SDValue
MBlazeTargetLowering
::
LowerReturn
(
SDValue
Chain
,
CallingConv
::
ID
CallConv
,
bool
isVarArg
,
const
SmallVectorImpl
<
ISD
::
OutputArg
>
&
Outs
,
const
SmallVectorImpl
<
SDValue
>
&
OutVals
,
DebugLoc
dl
,
SelectionDAG
&
DAG
)
const
{
SmallVector
<
CCValAssign
,
16
>
RVLocs
;
CCState
CCInfo
(
CallConv
,
isVarArg
,
DAG
.
getMachineFunction
(
)
,
getTargetMachine
(
)
,
RVLocs
,
*
DAG
.
getContext
(
)
)
;
CCInfo
.
AnalyzeReturn
(
Outs
,
RetCC_MBlaze
)
;
if
(
DAG
.
getMachineFunction
(
)
.
getRegInfo
(
)
.
liveout_empty
(
)
)
{
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
if
(
RVLocs
[
i
]
.
isRegLoc
(
)
)
DAG
.
getMachineFunction
(
)
.
getRegInfo
(
)
.
addLiveOut
(
RVLocs
[
i
]
.
getLocReg
(
)
)
;
}
SDValue
Flag
;
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
{
CCValAssign
&
VA
=
RVLocs
[
i
]
;
assert
(
VA
.
isRegLoc
(
)
&&
"Can only return in registers!"
)
;
Chain
=
DAG
.
getCopyToReg
(
Chain
,
dl
,
VA
.
getLocReg
(
)
,
OutVals
[
i
]
,
Flag
)
;
Flag
=
Chain
.
getValue
(
1
)
;
}
unsigned
Ret
=
(
CallConv
==
llvm
::
CallingConv
::
MBLAZE_INTR
)
MBlazeISD
::
IRet
:
MBlazeISD
::
Ret
;
unsigned
Reg
=
(
CallConv
==
llvm
::
CallingConv
::
MBLAZE_INTR
)
MBlaze
::
R14
:
MBlaze
::
R15
;
SDValue
DReg
=
DAG
.
getRegister
(
Reg
,
MVT
::
i32
)
;
if
(
Flag
.
getNode
(
)
)
return
DAG
.
getNode
(
Ret
,
dl
,
MVT
::
Other
,
Chain
,
DReg
,
Flag
)
;
return
DAG
.
getNode
(
Ret
,
dl
,
MVT
::
Other
,
Chain
,
DReg
)
;
}
</s>


<s> MBlazeTargetLowering :: ConstraintType MBlazeTargetLowering :: getConstraintType ( const std :: string & Constraint ) const { if ( Constraint . size ( ) == 1 ) { switch ( Constraint [ 0 ] ) { default : break ; case 'd' : case 'y' : case 'f' : return C_RegisterClass ; break ; } } return TargetLowering :: getConstraintType ( Constraint ) ; } </s>

Given a constraint letter , return the type of constraint for this target .


<s> std :: pair < unsigned , const TargetRegisterClass * > MBlazeTargetLowering :: getRegForInlineAsmConstraint ( const std :: string & Constraint , EVT VT ) const { if ( Constraint . size ( ) == 1 ) { switch ( Constraint [ 0 ] ) { case 'r' : return std :: make_pair ( 0U , MBlaze :: CPURegsRegisterClass ) ; case 'f' : if ( VT == MVT :: f32 ) return std :: make_pair ( 0U , MBlaze :: FGR32RegisterClass ) ; } } return TargetLowering :: getRegForInlineAsmConstraint ( Constraint , VT ) ; } </s>


<s> MVT :: SimpleValueType MBlazeTargetLowering :: getSetCCResultType ( EVT VT ) const { return MVT :: i32 ; } </s>

MBlaze MVT::SimpleValueType MBlaze MVT::i32


<s> SDValue MBlazeTargetLowering :: LowerCallResult ( SDValue Chain , SDValue InFlag , CallingConv :: ID CallConv , bool isVarArg , const SmallVectorImpl < ISD :: InputArg > & Ins , DebugLoc dl , SelectionDAG & DAG , SmallVectorImpl < SDValue > & InVals ) { SmallVector < CCValAssign , 16 > RVLocs ; CCState CCInfo ( CallConv , isVarArg , getTargetMachine ( ) , RVLocs , * DAG . getContext ( ) ) ; CCInfo . AnalyzeCallResult ( Ins , RetCC_MBlaze ) ; for ( unsigned i = 0 ; i != RVLocs . size ( ) ; ++ i ) { Chain = DAG . getCopyFromReg ( Chain , dl , RVLocs [ i ] . getLocReg ( ) , RVLocs [ i ] . getValVT ( ) , InFlag ) . getValue ( 1 ) ; InFlag = Chain . getValue ( 2 ) ; InVals . push_back ( Chain . getValue ( 0 ) ) ; } return Chain ; } </s>


<s> SDValue MBlazeTargetLowering :: LowerOperation ( SDValue Op , SelectionDAG & DAG ) { switch ( Op . getOpcode ( ) ) { case ISD :: ConstantPool : return LowerConstantPool ( Op , DAG ) ; case ISD :: GlobalAddress : return LowerGlobalAddress ( Op , DAG ) ; case ISD :: GlobalTLSAddress : return LowerGlobalTLSAddress ( Op , DAG ) ; case ISD :: JumpTable : return LowerJumpTable ( Op , DAG ) ; case ISD :: SELECT_CC : return LowerSELECT_CC ( Op , DAG ) ; case ISD :: VASTART : return LowerVASTART ( Op , DAG ) ; } return SDValue ( ) ; } </s>

LowerOperation - Provide custom lowering hooks for some operations .

MBlaze MBlaze ISD::ConstantPool ISD::GlobalAddress ISD::GlobalTLSAddress ISD::JumpTable ISD::SELECT_CC ISD::VASTART


<s>
SDValue
MBlazeTargetLowering
::
LowerReturn
(
SDValue
Chain
,
CallingConv
::
ID
CallConv
,
bool
isVarArg
,
const
SmallVectorImpl
<
ISD
::
OutputArg
>
&
Outs
,
DebugLoc
dl
,
SelectionDAG
&
DAG
)
{
SmallVector
<
CCValAssign
,
16
>
RVLocs
;
CCState
CCInfo
(
CallConv
,
isVarArg
,
getTargetMachine
(
)
,
RVLocs
,
*
DAG
.
getContext
(
)
)
;
CCInfo
.
AnalyzeReturn
(
Outs
,
RetCC_MBlaze
)
;
if
(
DAG
.
getMachineFunction
(
)
.
getRegInfo
(
)
.
liveout_empty
(
)
)
{
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
if
(
RVLocs
[
i
]
.
isRegLoc
(
)
)
DAG
.
getMachineFunction
(
)
.
getRegInfo
(
)
.
addLiveOut
(
RVLocs
[
i
]
.
getLocReg
(
)
)
;
}
SDValue
Flag
;
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
{
CCValAssign
&
VA
=
RVLocs
[
i
]
;
assert
(
VA
.
isRegLoc
(
)
&&
"Can only return in registers!"
)
;
Chain
=
DAG
.
getCopyToReg
(
Chain
,
dl
,
VA
.
getLocReg
(
)
,
Outs
[
i
]
.
Val
,
Flag
)
;
Flag
=
Chain
.
getValue
(
1
)
;
}
if
(
Flag
.
getNode
(
)
)
return
DAG
.
getNode
(
MBlazeISD
::
Ret
,
dl
,
MVT
::
Other
,
Chain
,
DAG
.
getRegister
(
MBlaze
::
R15
,
MVT
::
i32
)
,
Flag
)
;
else
return
DAG
.
getNode
(
MBlazeISD
::
Ret
,
dl
,
MVT
::
Other
,
Chain
,
DAG
.
getRegister
(
MBlaze
::
R15
,
MVT
::
i32
)
)
;
}
</s>


<s> SDValue MBlazeTargetLowering :: LowerCallResult ( SDValue Chain , SDValue InFlag , CallingConv :: ID CallConv , bool isVarArg , const SmallVectorImpl < ISD :: InputArg > & Ins , DebugLoc dl , SelectionDAG & DAG , SmallVectorImpl < SDValue > & InVals ) const { SmallVector < CCValAssign , 16 > RVLocs ; CCState CCInfo ( CallConv , isVarArg , getTargetMachine ( ) , RVLocs , * DAG . getContext ( ) ) ; CCInfo . AnalyzeCallResult ( Ins , RetCC_MBlaze ) ; for ( unsigned i = 0 ; i != RVLocs . size ( ) ; ++ i ) { Chain = DAG . getCopyFromReg ( Chain , dl , RVLocs [ i ] . getLocReg ( ) , RVLocs [ i ] . getValVT ( ) , InFlag ) . getValue ( 1 ) ; InFlag = Chain . getValue ( 2 ) ; InVals . push_back ( Chain . getValue ( 0 ) ) ; } return Chain ; } </s>


<s>
SDValue
MBlazeTargetLowering
::
LowerReturn
(
SDValue
Chain
,
CallingConv
::
ID
CallConv
,
bool
isVarArg
,
const
SmallVectorImpl
<
ISD
::
OutputArg
>
&
Outs
,
const
SmallVectorImpl
<
SDValue
>
&
OutVals
,
DebugLoc
dl
,
SelectionDAG
&
DAG
)
const
{
SmallVector
<
CCValAssign
,
16
>
RVLocs
;
CCState
CCInfo
(
CallConv
,
isVarArg
,
getTargetMachine
(
)
,
RVLocs
,
*
DAG
.
getContext
(
)
)
;
CCInfo
.
AnalyzeReturn
(
Outs
,
RetCC_MBlaze
)
;
if
(
DAG
.
getMachineFunction
(
)
.
getRegInfo
(
)
.
liveout_empty
(
)
)
{
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
if
(
RVLocs
[
i
]
.
isRegLoc
(
)
)
DAG
.
getMachineFunction
(
)
.
getRegInfo
(
)
.
addLiveOut
(
RVLocs
[
i
]
.
getLocReg
(
)
)
;
}
SDValue
Flag
;
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
{
CCValAssign
&
VA
=
RVLocs
[
i
]
;
assert
(
VA
.
isRegLoc
(
)
&&
"Can only return in registers!"
)
;
Chain
=
DAG
.
getCopyToReg
(
Chain
,
dl
,
VA
.
getLocReg
(
)
,
OutVals
[
i
]
,
Flag
)
;
Flag
=
Chain
.
getValue
(
1
)
;
}
if
(
Flag
.
getNode
(
)
)
return
DAG
.
getNode
(
MBlazeISD
::
Ret
,
dl
,
MVT
::
Other
,
Chain
,
DAG
.
getRegister
(
MBlaze
::
R15
,
MVT
::
i32
)
,
Flag
)
;
else
return
DAG
.
getNode
(
MBlazeISD
::
Ret
,
dl
,
MVT
::
Other
,
Chain
,
DAG
.
getRegister
(
MBlaze
::
R15
,
MVT
::
i32
)
)
;
}
</s>


<s> std :: pair < unsigned , const TargetRegisterClass * > MBlazeTargetLowering :: getRegForInlineAsmConstraint ( const std :: string & Constraint , EVT VT ) const { if ( Constraint . size ( ) == 1 ) { switch ( Constraint [ 0 ] ) { case 'r' : return std :: make_pair ( 0U , MBlaze :: GPRRegisterClass ) ; case 'f' : if ( VT == MVT :: f32 ) return std :: make_pair ( 0U , MBlaze :: GPRRegisterClass ) ; } } return TargetLowering :: getRegForInlineAsmConstraint ( Constraint , VT ) ; } </s>


<s> TargetLowering :: ConstraintWeight MBlazeTargetLowering :: getSingleConstraintMatchWeight ( AsmOperandInfo & info , const char * constraint ) const { ConstraintWeight weight = CW_Invalid ; Value * CallOperandVal = info . CallOperandVal ; if ( CallOperandVal == NULL ) return CW_Default ; const Type * type = CallOperandVal -> getType ( ) ; switch ( * constraint ) { default : weight = TargetLowering :: getSingleConstraintMatchWeight ( info , constraint ) ; break ; case 'd' : case 'y' : if ( type -> isIntegerTy ( ) ) weight = CW_Register ; break ; case 'f' : if ( type -> isFloatTy ( ) ) weight = CW_Register ; break ; } return weight ; } </s>

Examine constraint string and operand type and determine a weight value .


<s>
MachineBasicBlock
*
MBlazeTargetLowering
::
EmitInstrWithCustomInserter
(
MachineInstr
*
MI
,
MachineBasicBlock
*
MBB
)
const
{
switch
(
MI
->
getOpcode
(
)
)
{
default
:
llvm_unreachable
(
"Unexpected instr type to insert"
)
;
case
MBlaze
::
ShiftRL
:
case
MBlaze
::
ShiftRA
:
case
MBlaze
::
ShiftL
:
return
EmitCustomShift
(
MI
,
MBB
)
;
case
MBlaze
::
Select_FCC
:
case
MBlaze
::
Select_CC
:
return
EmitCustomSelect
(
MI
,
MBB
)
;
case
MBlaze
::
CAS32
:
case
MBlaze
::
SWP32
:
case
MBlaze
::
LAA32
:
case
MBlaze
::
LAS32
:
case
MBlaze
::
LAD32
:
case
MBlaze
::
LAO32
:
case
MBlaze
::
LAX32
:
case
MBlaze
::
LAN32
:
return
EmitCustomAtomic
(
MI
,
MBB
)
;
case
MBlaze
::
MEMBARRIER
:
MI
->
eraseFromParent
(
)
;
return
MBB
;
}
}
</s>


<s> MBlazeTargetLowering :: ConstraintType MBlazeTargetLowering :: getConstraintType ( const std :: string & Constraint ) const { if ( Constraint . size ( ) == 1 ) { switch ( Constraint [ 0 ] ) { default : break ; case 'd' : case 'y' : case 'f' : return C_RegisterClass ; } } return TargetLowering :: getConstraintType ( Constraint ) ; } </s>


<s> std :: pair < unsigned , const TargetRegisterClass * > MBlazeTargetLowering :: getRegForInlineAsmConstraint ( const std :: string & Constraint , MVT VT ) const { if ( Constraint . size ( ) == 1 ) { switch ( Constraint [ 0 ] ) { case 'r' : return std :: make_pair ( 0U , & MBlaze :: GPRRegClass ) ; case 'd' : case 'y' : case 'f' : if ( VT == MVT :: f32 ) return std :: make_pair ( 0U , & MBlaze :: GPRRegClass ) ; } } return TargetLowering :: getRegForInlineAsmConstraint ( Constraint , VT ) ; } </s>


<s> EVT MBlazeTargetLowering :: getSetCCResultType ( LLVMContext & , EVT ) const { return MVT :: i32 ; } </s>


<s> TargetLowering :: ConstraintWeight MBlazeTargetLowering :: getSingleConstraintMatchWeight ( AsmOperandInfo & info , const char * constraint ) const { ConstraintWeight weight = CW_Invalid ; Value * CallOperandVal = info . CallOperandVal ; if ( CallOperandVal == NULL ) return CW_Default ; Type * type = CallOperandVal -> getType ( ) ; switch ( * constraint ) { default : weight = TargetLowering :: getSingleConstraintMatchWeight ( info , constraint ) ; break ; case 'd' : case 'y' : if ( type -> isIntegerTy ( ) ) weight = CW_Register ; break ; case 'f' : if ( type -> isFloatTy ( ) ) weight = CW_Register ; break ; } return weight ; } </s>


<s> const char * MBlazeTargetLowering :: getTargetNodeName ( unsigned Opcode ) const { switch ( Opcode ) { case MBlazeISD :: JmpLink : return "MBlazeISD::JmpLink" ; case MBlazeISD :: GPRel : return "MBlazeISD::GPRel" ; case MBlazeISD :: Wrap : return "MBlazeISD::Wrap" ; case MBlazeISD :: ICmp : return "MBlazeISD::ICmp" ; case MBlazeISD :: Ret : return "MBlazeISD::Ret" ; case MBlazeISD :: Select_CC : return "MBlazeISD::Select_CC" ; default : return NULL ; } } </s>

getTargetNodeName - This method returns the name of a target specific

MBlaze MBlaze MBlazeISD::JmpLink "MBlazeISD::JmpLink" MBlazeISD::GPRel "MBlazeISD::GPRel" MBlazeISD::Wrap "MBlazeISD::Wrap" MBlazeISD::ICmp "MBlazeISD::ICmp" MBlazeISD::Ret "MBlazeISD::Ret" MBlazeISD::Select_CC "MBlazeISD::Select_CC"


<s> bool MBlazeTargetLowering :: isFPImmLegal ( const APFloat & Imm , EVT VT ) const { return VT != MVT :: f32 ; } </s>

Returns true if the target can instruction select the specified FP immediate natively .


<s> bool MBlazeTargetLowering :: isOffsetFoldingLegal ( const GlobalAddressSDNode * GA ) const { return false ; } </s>

Return true if folding a constant offset with the given GlobalAddress is legal .


<s> SDValue MBlazeTargetLowering :: LowerCallResult ( SDValue Chain , SDValue InFlag , CallingConv :: ID CallConv , bool isVarArg , const SmallVectorImpl < ISD :: InputArg > & Ins , SDLoc dl , SelectionDAG & DAG , SmallVectorImpl < SDValue > & InVals ) const { SmallVector < CCValAssign , 16 > RVLocs ; CCState CCInfo ( CallConv , isVarArg , DAG . getMachineFunction ( ) , getTargetMachine ( ) , RVLocs , * DAG . getContext ( ) ) ; CCInfo . AnalyzeCallResult ( Ins , RetCC_MBlaze ) ; for ( unsigned i = 0 ; i != RVLocs . size ( ) ; ++ i ) { Chain = DAG . getCopyFromReg ( Chain , dl , RVLocs [ i ] . getLocReg ( ) , RVLocs [ i ] . getValVT ( ) , InFlag ) . getValue ( 1 ) ; InFlag = Chain . getValue ( 2 ) ; InVals . push_back ( Chain . getValue ( 0 ) ) ; } return Chain ; } </s>


<s> SDValue MBlazeTargetLowering :: LowerOperation ( SDValue Op , SelectionDAG & DAG ) const { switch ( Op . getOpcode ( ) ) { case ISD :: ConstantPool : return LowerConstantPool ( Op , DAG ) ; case ISD :: GlobalAddress : return LowerGlobalAddress ( Op , DAG ) ; case ISD :: GlobalTLSAddress : return LowerGlobalTLSAddress ( Op , DAG ) ; case ISD :: JumpTable : return LowerJumpTable ( Op , DAG ) ; case ISD :: SELECT_CC : return LowerSELECT_CC ( Op , DAG ) ; case ISD :: VASTART : return LowerVASTART ( Op , DAG ) ; } return SDValue ( ) ; } </s>


<s>
SDValue
MBlazeTargetLowering
::
LowerReturn
(
SDValue
Chain
,
CallingConv
::
ID
CallConv
,
bool
isVarArg
,
const
SmallVectorImpl
<
ISD
::
OutputArg
>
&
Outs
,
const
SmallVectorImpl
<
SDValue
>
&
OutVals
,
SDLoc
dl
,
SelectionDAG
&
DAG
)
const
{
SmallVector
<
CCValAssign
,
16
>
RVLocs
;
CCState
CCInfo
(
CallConv
,
isVarArg
,
DAG
.
getMachineFunction
(
)
,
getTargetMachine
(
)
,
RVLocs
,
*
DAG
.
getContext
(
)
)
;
CCInfo
.
AnalyzeReturn
(
Outs
,
RetCC_MBlaze
)
;
SDValue
Flag
;
SmallVector
<
SDValue
,
4
>
RetOps
(
1
,
Chain
)
;
unsigned
Ret
=
(
CallConv
==
CallingConv
::
MBLAZE_INTR
)
MBlazeISD
::
IRet
:
MBlazeISD
::
Ret
;
unsigned
Reg
=
(
CallConv
==
CallingConv
::
MBLAZE_INTR
)
MBlaze
::
R14
:
MBlaze
::
R15
;
RetOps
.
push_back
(
DAG
.
getRegister
(
Reg
,
MVT
::
i32
)
)
;
for
(
unsigned
i
=
0
;
i
!=
RVLocs
.
size
(
)
;
++
i
)
{
CCValAssign
&
VA
=
RVLocs
[
i
]
;
assert
(
VA
.
isRegLoc
(
)
&&
"Can only return in registers!"
)
;
Chain
=
DAG
.
getCopyToReg
(
Chain
,
dl
,
VA
.
getLocReg
(
)
,
OutVals
[
i
]
,
Flag
)
;
Flag
=
Chain
.
getValue
(
1
)
;
RetOps
.
push_back
(
DAG
.
getRegister
(
VA
.
getLocReg
(
)
,
VA
.
getLocVT
(
)
)
)
;
}
RetOps
[
0
]
=
Chain
;
if
(
Flag
.
getNode
(
)
)
RetOps
.
push_back
(
Flag
)
;
return
DAG
.
getNode
(
Ret
,
dl
,
MVT
::
Other
,
&
RetOps
[
0
]
,
RetOps
.
size
(
)
)
;
}
</s>


<s> unsigned getGlobalBaseReg ( ) const { return GlobalBaseReg ; } </s>

getGlobalBaseReg - Return a virtual register initialized with the the global base register value .


<s> bool isLiveIn ( int FI ) { for ( unsigned i = 0 , e = LiveInFI . size ( ) ; i < e ; ++ i ) if ( FI == LiveInFI [ i ] ) return true ; return false ; } </s>

Returns true if this VPValue is a live-in , i.e . defined outside the VPlan .


<s> unsigned MBlazeMCCodeEmitter :: getMachineOpValue ( const MCInst & MI , const MCOperand & MO ) const { if ( MO . isReg ( ) ) return getMBlazeRegisterNumbering ( MO . getReg ( ) ) ; if ( MO . isImm ( ) ) return static_cast < unsigned > ( MO . getImm ( ) ) ; if ( MO . isExpr ( ) ) return 0 ; errs ( ) << MO ; llvm_unreachable ( 0 ) ; } </s>

getMachineOpValue - Return binary encoding of operand .


<s> unsigned MBlazeMCCodeEmitter :: getMachineOpValue ( const MCInst & MI , const MCOperand & MO ) const { if ( MO . isReg ( ) ) return getMBlazeRegisterNumbering ( MO . getReg ( ) ) ; else if ( MO . isImm ( ) ) return static_cast < unsigned > ( MO . getImm ( ) ) ; else if ( MO . isExpr ( ) ) return 0 ; else { errs ( ) << MO ; llvm_unreachable ( 0 ) ; } return 0 ; } </s>


<s> unsigned MBlazeMCCodeEmitter :: getMachineOpValue ( const MCInst & MI , const MCOperand & MO ) const { if ( MO . isReg ( ) ) return MBlazeRegisterInfo :: getRegisterNumbering ( MO . getReg ( ) ) ; else if ( MO . isImm ( ) ) return static_cast < unsigned > ( MO . getImm ( ) ) ; else if ( MO . isExpr ( ) ) return 0 ; else { errs ( ) << MO ; llvm_unreachable ( 0 ) ; } return 0 ; } </s>


<s>
MCSymbol
*
MBlazeMCInstLower
::
GetBlockAddressSymbol
(
const
MachineOperand
&
MO
)
const
{
switch
(
MO
.
getTargetFlags
(
)
)
{
default
:
assert
(
0
&&
"Unknown target flag on GV operand"
)
;
case
0
:
break
;
}
return
Printer
.
GetBlockAddressSymbol
(
MO
.
getBlockAddress
(
)
)
;
}
</s>

Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block .


<s>
MCSymbol
*
MBlazeMCInstLower
::
GetBlockAddressSymbol
(
const
MachineOperand
&
MO
)
const
{
switch
(
MO
.
getTargetFlags
(
)
)
{
default
:
llvm_unreachable
(
"Unknown target flag on GV operand"
)
;
case
0
:
break
;
}
return
Printer
.
GetBlockAddressSymbol
(
MO
.
getBlockAddress
(
)
)
;
}
</s>

MBlaze
MBlaze
"Unknown target flag on GV operand"
0


<s>
MCSymbol
*
MBlazeMCInstLower
::
GetExternalSymbolSymbol
(
const
MachineOperand
&
MO
)
const
{
switch
(
MO
.
getTargetFlags
(
)
)
{
default
:
llvm_unreachable
(
"Unknown target flag on GV operand"
)
;
case
0
:
break
;
}
return
Printer
.
GetExternalSymbolSymbol
(
MO
.
getSymbolName
(
)
)
;
}
</s>

Return the MCSymbol for the specified ExternalSymbol .


<s> static MCAsmInfo * createMCAsmInfo ( const Target & T , StringRef TT ) { Triple TheTriple ( TT ) ; switch ( TheTriple . getOS ( ) ) { default : return new MBlazeMCAsmInfo ( ) ; } } </s>

createMCAsmInfo - Create a MCAsmInfo implementation for the specified target triple .


<s> static MCAsmInfo * createMCAsmInfo ( const MCRegisterInfo & MRI , StringRef TT ) { return new MBlazeMCAsmInfo ( ) ; } </s>


<s> static MCAsmInfo * createMCAsmInfo ( const MCRegisterInfo & MRI , StringRef TT ) { Triple TheTriple ( TT ) ; switch ( TheTriple . getOS ( ) ) { default : return new MBlazeMCAsmInfo ( ) ; } } </s>


<s> void MBlazeRegisterInfo :: eliminateCallFramePseudoInstr ( MachineFunction & MF , MachineBasicBlock & MBB , MachineBasicBlock :: iterator I ) const { MBB . erase ( I ) ; } </s>

This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy pseudo instructions ( but only if the Target is using them ) .


"Instr doesn't have FrameIndex operand!"

This method must be overriden to eliminate abstract frame indices from instructions which may use them .


<s> void MBlazeRegisterInfo :: emitEpilogue ( MachineFunction & MF , MachineBasicBlock & MBB ) const { MachineBasicBlock :: iterator MBBI = prior ( MBB . end ( ) ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; DebugLoc dl = MBBI -> getDebugLoc ( ) ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADD ) , MBlaze :: R1 ) . addReg ( MBlaze :: R19 ) . addReg ( MBlaze :: R0 ) ; BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R19 ) . addImm ( FPOffset ) . addReg ( MBlaze :: R1 ) ; } if ( MFI -> hasCalls ( ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R15 ) . addImm ( RAOffset ) . addReg ( MBlaze :: R1 ) ; } int StackSize = ( int ) MFI -> getStackSize ( ) ; if ( StackSize < 28 && MFI -> hasCalls ( ) ) StackSize = 28 ; if ( StackSize ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( StackSize ) ; } } </s>


<s> void MBlazeRegisterInfo :: emitPrologue ( MachineFunction & MF ) const { MachineBasicBlock & MBB = MF . front ( ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; MachineBasicBlock :: iterator MBBI = MBB . begin ( ) ; DebugLoc dl = ( MBBI != MBB . end ( ) ? MBBI -> getDebugLoc ( ) : DebugLoc :: getUnknownLoc ( ) ) ; adjustMBlazeStackFrame ( MF ) ; unsigned StackSize = MFI -> getStackSize ( ) ; if ( StackSize == 0 && ! MFI -> hasCalls ( ) ) return ; if ( StackSize < 28 && MFI -> hasCalls ( ) ) StackSize = 28 ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - StackSize ) ; if ( MFI -> hasCalls ( ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R15 ) . addImm ( RAOffset ) . addReg ( MBlaze :: R1 ) ; } if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R19 ) . addImm ( FPOffset ) . addReg ( MBlaze :: R1 ) ; BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADD ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addReg ( MBlaze :: R0 ) ; } } </s>

emitProlog/emitEpilog - These methods insert prolog and epilog code into the function .


<s>
int
MBlazeRegisterInfo
::
getDwarfRegNum
(
unsigned
RegNum
,
bool
isEH
)
const
{
llvm_unreachable
(
"What is the dwarf register number"
)
;
return
1
;
}
</s>

Map a target register to an equivalent dwarf register number .

MBlaze
MBlaze
"What is the dwarf register number"
1


<s> unsigned MBlazeRegisterInfo :: getFrameRegister ( const MachineFunction & MF ) const { return hasFP ( MF ) ? MBlaze :: R19 : MBlaze :: R1 ; } </s>


<s> unsigned MBlazeRegisterInfo :: getRARegister ( ) const { return MBlaze :: R15 ; } </s>

This method should return the register where the return address can be found .


<s> bool MBlazeRegisterInfo :: hasFP ( const MachineFunction & MF ) const { const MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; return NoFramePointerElim || MFI -> hasVarSizedObjects ( ) ; } </s>

hasFP - Return true if the specified function should have a dedicated frame pointer register .


<s> void MBlazeRegisterInfo :: processFunctionBeforeFrameFinalized ( MachineFunction & MF ) const { MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; if ( MBlazeFI -> needGPSaveRestore ( ) ) MFI -> setObjectOffset ( MBlazeFI -> getGPFI ( ) , MBlazeFI -> getGPStackOffset ( ) ) ; } </s>

processFunctionBeforeFrameFinalized - This method is called immediately before the specified function 's frame layout ( MF.getFrameInfo ( ) ) is finalized .

MBlaze MBlaze MBlaze MBlaze MBlaze MBlaze MBlaze MBlaze


<s> void MBlazeRegisterInfo :: eliminateCallFramePseudoInstr ( MachineFunction & MF , MachineBasicBlock & MBB , MachineBasicBlock :: iterator I ) const { const TargetFrameLowering * TFI = MF . getTarget ( ) . getFrameLowering ( ) ; if ( ! TFI -> hasReservedCallFrame ( MF ) ) { MachineInstr * Old = I ; int Amount = Old -> getOperand ( 0 ) . getImm ( ) + 4 ; if ( Amount != 0 ) { unsigned Align = TFI -> getStackAlignment ( ) ; Amount = ( Amount + Align - 1 ) / Align * Align ; MachineInstr * New ; if ( Old -> getOpcode ( ) == MBlaze :: ADJCALLSTACKDOWN ) { New = BuildMI ( MF , Old -> getDebugLoc ( ) , TII . get ( MBlaze :: ADDIK ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - Amount ) ; } else { assert ( Old -> getOpcode ( ) == MBlaze :: ADJCALLSTACKUP ) ; New = BuildMI ( MF , Old -> getDebugLoc ( ) , TII . get ( MBlaze :: ADDIK ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( Amount ) ; } MBB . insert ( I , New ) ; } } MBB . erase ( I ) ; } </s>


<s> const unsigned * MBlazeRegisterInfo :: getCalleeSavedRegs ( const MachineFunction * MF ) const { static const unsigned CalleeSavedRegs [ ] = { MBlaze :: R20 , MBlaze :: R21 , MBlaze :: R22 , MBlaze :: R23 , MBlaze :: R24 , MBlaze :: R25 , MBlaze :: R26 , MBlaze :: R27 , MBlaze :: R28 , MBlaze :: R29 , MBlaze :: R30 , MBlaze :: R31 , 0 } ; return CalleeSavedRegs ; } </s>


<s> void MBlazeRegisterInfo :: emitPrologue ( MachineFunction & MF ) const { MachineBasicBlock & MBB = MF . front ( ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; MachineBasicBlock :: iterator MBBI = MBB . begin ( ) ; DebugLoc DL = MBBI != MBB . end ( ) ? MBBI -> getDebugLoc ( ) : DebugLoc ( ) ; adjustMBlazeStackFrame ( MF ) ; unsigned StackSize = MFI -> getStackSize ( ) ; if ( StackSize == 0 && ! MFI -> hasCalls ( ) ) return ; if ( StackSize < 28 && MFI -> hasCalls ( ) ) StackSize = 28 ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - StackSize ) ; if ( MFI -> hasCalls ( ) ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R15 ) . addImm ( RAOffset ) . addReg ( MBlaze :: R1 ) ; } if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R19 ) . addImm ( FPOffset ) . addReg ( MBlaze :: R1 ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADD ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addReg ( MBlaze :: R0 ) ; } } </s>


<s> void MBlazeRegisterInfo :: emitEpilogue ( MachineFunction & MF , MachineBasicBlock & MBB ) const { MachineBasicBlock :: iterator MBBI = prior ( MBB . end ( ) ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; DebugLoc dl = MBBI -> getDebugLoc ( ) ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADD ) , MBlaze :: R1 ) . addReg ( MBlaze :: R19 ) . addReg ( MBlaze :: R0 ) ; BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R19 ) . addImm ( FPOffset ) . addReg ( MBlaze :: R1 ) ; } if ( MFI -> adjustsStack ( ) ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: LWI ) , MBlaze :: R15 ) . addImm ( RAOffset ) . addReg ( MBlaze :: R1 ) ; } int StackSize = ( int ) MFI -> getStackSize ( ) ; if ( StackSize < 28 && MFI -> adjustsStack ( ) ) StackSize = 28 ; if ( StackSize ) { BuildMI ( MBB , MBBI , dl , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( StackSize ) ; } } </s>


<s> void MBlazeRegisterInfo :: emitPrologue ( MachineFunction & MF ) const { MachineBasicBlock & MBB = MF . front ( ) ; MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; MBlazeFunctionInfo * MBlazeFI = MF . getInfo < MBlazeFunctionInfo > ( ) ; MachineBasicBlock :: iterator MBBI = MBB . begin ( ) ; DebugLoc DL = MBBI != MBB . end ( ) ? MBBI -> getDebugLoc ( ) : DebugLoc ( ) ; adjustMBlazeStackFrame ( MF ) ; unsigned StackSize = MFI -> getStackSize ( ) ; if ( StackSize == 0 && ! MFI -> adjustsStack ( ) ) return ; if ( StackSize < 28 && MFI -> adjustsStack ( ) ) StackSize = 28 ; int FPOffset = MBlazeFI -> getFPStackOffset ( ) ; int RAOffset = MBlazeFI -> getRAStackOffset ( ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - StackSize ) ; if ( MFI -> adjustsStack ( ) ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R15 ) . addImm ( RAOffset ) . addReg ( MBlaze :: R1 ) ; } if ( hasFP ( MF ) ) { BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: SWI ) ) . addReg ( MBlaze :: R19 ) . addImm ( FPOffset ) . addReg ( MBlaze :: R1 ) ; BuildMI ( MBB , MBBI , DL , TII . get ( MBlaze :: ADD ) , MBlaze :: R19 ) . addReg ( MBlaze :: R1 ) . addReg ( MBlaze :: R0 ) ; } } </s>


<s> bool MBlazeRegisterInfo :: hasFP ( const MachineFunction & MF ) const { const MachineFrameInfo * MFI = MF . getFrameInfo ( ) ; return DisableFramePointerElim ( MF ) || MFI -> hasVarSizedObjects ( ) ; } </s>


<s> void MBlazeRegisterInfo :: eliminateCallFramePseudoInstr ( MachineFunction & MF , MachineBasicBlock & MBB , MachineBasicBlock :: iterator I ) const { const TargetFrameInfo * TFI = MF . getTarget ( ) . getFrameInfo ( ) ; if ( ! TFI -> hasReservedCallFrame ( MF ) ) { MachineInstr * Old = I ; int Amount = Old -> getOperand ( 0 ) . getImm ( ) + 4 ; if ( Amount != 0 ) { unsigned Align = MF . getTarget ( ) . getFrameInfo ( ) -> getStackAlignment ( ) ; Amount = ( Amount + Align - 1 ) / Align * Align ; MachineInstr * New ; if ( Old -> getOpcode ( ) == MBlaze :: ADJCALLSTACKDOWN ) { New = BuildMI ( MF , Old -> getDebugLoc ( ) , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( - Amount ) ; } else { assert ( Old -> getOpcode ( ) == MBlaze :: ADJCALLSTACKUP ) ; New = BuildMI ( MF , Old -> getDebugLoc ( ) , TII . get ( MBlaze :: ADDI ) , MBlaze :: R1 ) . addReg ( MBlaze :: R1 ) . addImm ( Amount ) ; } MBB . insert ( I , New ) ; } } MBB . erase ( I ) ; } </s>


<s> int MBlazeRegisterInfo :: getDwarfRegNum ( unsigned RegNo , bool isEH ) const { return MBlazeGenRegisterInfo :: getDwarfRegNumFull ( RegNo , 0 ) ; } </s>


<s> unsigned MBlazeRegisterInfo :: getFrameRegister ( const MachineFunction & MF ) const { const TargetFrameInfo * TFI = MF . getTarget ( ) . getFrameInfo ( ) ; return TFI -> hasFP ( MF ) ? MBlaze :: R19 : MBlaze :: R1 ; } </s>


"Instr doesn't have FrameIndex operand!"


<s> const uint16_t * MBlazeRegisterInfo :: getCalleeSavedRegs ( const MachineFunction * MF ) const { static const uint16_t CalleeSavedRegs [ ] = { MBlaze :: R20 , MBlaze :: R21 , MBlaze :: R22 , MBlaze :: R23 , MBlaze :: R24 , MBlaze :: R25 , MBlaze :: R26 , MBlaze :: R27 , MBlaze :: R28 , MBlaze :: R29 , MBlaze :: R30 , MBlaze :: R31 , 0 } ; return CalleeSavedRegs ; } </s>


<s> unsigned MBlazeRegisterInfo :: getPICCallReg ( ) { return MBlaze :: R20 ; } </s>


<s> BitVector MBlazeRegisterInfo :: getReservedRegs ( const MachineFunction & MF ) const { BitVector Reserved ( getNumRegs ( ) ) ; Reserved . set ( MBlaze :: R0 ) ; Reserved . set ( MBlaze :: R1 ) ; Reserved . set ( MBlaze :: R2 ) ; Reserved . set ( MBlaze :: R13 ) ; Reserved . set ( MBlaze :: R14 ) ; Reserved . set ( MBlaze :: R15 ) ; Reserved . set ( MBlaze :: R16 ) ; Reserved . set ( MBlaze :: R17 ) ; Reserved . set ( MBlaze :: R18 ) ; Reserved . set ( MBlaze :: R19 ) ; return Reserved ; } </s>

getReservedRegs - Returns a bitset indexed by physical register number indicating if a register is a special register that has particular uses and should be considered unavailable at all times , e.g .


<s> bool MBlazeSubtarget :: enablePostRAScheduler ( CodeGenOpt :: Level OptLevel , TargetSubtargetInfo :: AntiDepBreakMode & Mode , RegClassVector & CriticalPathRCs ) const { Mode = TargetSubtargetInfo :: ANTIDEP_CRITICAL ; CriticalPathRCs . clear ( ) ; CriticalPathRCs . push_back ( & MBlaze :: GPRRegClass ) ; return HasItin && OptLevel >= CodeGenOpt :: Default ; } </s>

True if the subtarget should run a scheduler after register allocation .


<s> const InstrItineraryData & getInstrItineraryData ( ) const { return InstrItins ; } </s>

getInstrItineraryData - Returns instruction itinerary data for the target or specific subtarget .


<s> bool hasFPU ( ) const { return HasFPU ; } </s>


<s> virtual const DataLayout * getDataLayout ( ) const { return & DL ; } </s>

Return the DataLayout associated with the module this SCEV instance is operating on .


<s> bool MBlazeTargetMachine :: addInstSelector ( PassManagerBase & PM ) { PM . add ( createMBlazeISelDag ( * this ) ) ; return false ; } </s>

addInstSelector - This method should install an instruction selector pass , which converts from LLVM code to machine instructions .


<s> bool MBlazeTargetMachine :: addPreEmitPass ( PassManagerBase & PM ) { PM . add ( createMBlazeDelaySlotFillerPass ( * this ) ) ; return true ; } </s>

This pass may be implemented by targets that want to run passes immediately before machine code is emitted .


<s> bool MBlazeTargetMachine :: addInstSelector ( PassManagerBase & PM , CodeGenOpt :: Level OptLevel ) { PM . add ( createMBlazeISelDag ( * this ) ) ; return false ; } </s>


<s> bool MBlazeTargetMachine :: addPreEmitPass ( PassManagerBase & PM , CodeGenOpt :: Level OptLevel ) { PM . add ( createMBlazeDelaySlotFillerPass ( * this ) ) ; return true ; } </s>


<s> virtual const InstrItineraryData * getInstrItineraryData ( ) const { return & InstrItins ; } </s>


<s> bool MBlazePassConfig :: addInstSelector ( ) { PM . add ( createMBlazeISelDag ( getMBlazeTargetMachine ( ) ) ) ; return false ; } </s>


<s> bool MBlazePassConfig :: addPreEmitPass ( ) { PM . add ( createMBlazeDelaySlotFillerPass ( getMBlazeTargetMachine ( ) ) ) ; return true ; } </s>


<s> bool MBlazePassConfig :: addInstSelector ( ) { PM -> add ( createMBlazeISelDag ( getMBlazeTargetMachine ( ) ) ) ; return false ; } </s>


<s> bool MBlazePassConfig :: addPreEmitPass ( ) { PM -> add ( createMBlazeDelaySlotFillerPass ( getMBlazeTargetMachine ( ) ) ) ; return true ; } </s>


<s> bool MBlazePassConfig :: addInstSelector ( ) { addPass ( createMBlazeISelDag ( getMBlazeTargetMachine ( ) ) ) ; return false ; } </s>


<s> bool MBlazePassConfig :: addPreEmitPass ( ) { addPass ( createMBlazeDelaySlotFillerPass ( getMBlazeTargetMachine ( ) ) ) ; return true ; } </s>


<s> TargetPassConfig * MBlazeTargetMachine :: createPassConfig ( PassManagerBase & PM ) { return new MBlazePassConfig ( this , PM ) ; } </s>

Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of CodeGen passes .


<s> virtual const TargetFrameInfo * getFrameInfo ( ) const { return & FrameInfo ; } </s>

getFrameInfo - Return the frame info object for the current function .


<s> virtual const MBlazeInstrInfo * getInstrInfo ( ) const { return & InstrInfo ; } </s>


<s> const TargetIntrinsicInfo * getIntrinsicInfo ( ) const { return & IntrinsicInfo ; } </s>

If intrinsic information is available , return it . If not , return null .


<s> virtual const MBlazeRegisterInfo * getRegisterInfo ( ) const { return & InstrInfo . getRegisterInfo ( ) ; } </s>

getRegisterInfo - TargetInstrInfo is a superset of MRegister info .


<s> virtual const MBlazeSubtarget * getSubtargetImpl ( ) const { return & Subtarget ; } </s>

Virtual method implemented by subclasses that returns a reference to that target 's TargetSubtargetInfo-derived member variable .


<s> void MBlazeTargetObjectFile :: Initialize ( MCContext & Ctx , const TargetMachine & TM ) { TargetLoweringObjectFileELF :: Initialize ( Ctx , TM ) ; SmallDataSection = getContext ( ) . getELFSection ( ".sdata" , ELF :: SHT_PROGBITS , ELF :: SHF_WRITE | ELF :: SHF_ALLOC , SectionKind :: getDataRel ( ) ) ; SmallBSSSection = getContext ( ) . getELFSection ( ".sbss" , ELF :: SHT_NOBITS , ELF :: SHF_WRITE | ELF :: SHF_ALLOC , SectionKind :: getBSS ( ) ) ; } </s>

This method must be called before any actual lowering is done .


<s> bool MBlazeTargetObjectFile :: IsGlobalInSmallSection ( const GlobalValue * GV , const TargetMachine & TM , SectionKind Kind ) const { const GlobalVariable * GVA = dyn_cast < GlobalVariable > ( GV ) ; if ( ! GVA ) return false ; if ( ! Kind . isBSS ( ) && ! Kind . isDataRel ( ) ) return false ; if ( Kind . isMergeable1ByteCString ( ) ) return false ; Type * Ty = GV -> getType ( ) -> getElementType ( ) ; return IsInSmallSection ( TM . getDataLayout ( ) -> getTypeAllocSize ( Ty ) ) ; } </s>

Return true if this global address should be placed into small data/bss section .


<s> void MBlazeTargetObjectFile :: Initialize ( MCContext & Ctx , const TargetMachine & TM ) { TargetLoweringObjectFileELF :: Initialize ( Ctx , TM ) ; SmallDataSection = getContext ( ) . getELFSection ( ".sdata" , MCSectionELF :: SHT_PROGBITS , MCSectionELF :: SHF_WRITE | MCSectionELF :: SHF_ALLOC , SectionKind :: getDataRel ( ) ) ; SmallBSSSection = getContext ( ) . getELFSection ( ".sbss" , MCSectionELF :: SHT_NOBITS , MCSectionELF :: SHF_WRITE | MCSectionELF :: SHF_ALLOC , SectionKind :: getBSS ( ) ) ; } </s>


<s> bool MBlazeTargetObjectFile :: IsGlobalInSmallSection ( const GlobalValue * GV , const TargetMachine & TM , SectionKind Kind ) const { const GlobalVariable * GVA = dyn_cast < GlobalVariable > ( GV ) ; if ( ! GVA ) return false ; if ( ! Kind . isBSS ( ) && ! Kind . isDataRel ( ) ) return false ; if ( Kind . isMergeable1ByteCString ( ) ) return false ; const Type * Ty = GV -> getType ( ) -> getElementType ( ) ; return IsInSmallSection ( TM . getTargetData ( ) -> getTypeAllocSize ( Ty ) ) ; } </s>


<s> void MBlazeTargetObjectFile :: Initialize ( MCContext & Ctx , const TargetMachine & TM ) { TargetLoweringObjectFileELF :: Initialize ( Ctx , TM ) ; SmallDataSection = getELFSection ( ".sdata" , MCSectionELF :: SHT_PROGBITS , MCSectionELF :: SHF_WRITE | MCSectionELF :: SHF_ALLOC , SectionKind :: getDataRel ( ) ) ; SmallBSSSection = getELFSection ( ".sbss" , MCSectionELF :: SHT_NOBITS , MCSectionELF :: SHF_WRITE | MCSectionELF :: SHF_ALLOC , SectionKind :: getBSS ( ) ) ; } </s>


<s> bool MBlazeTargetObjectFile :: IsGlobalInSmallSection ( const GlobalValue * GV , const TargetMachine & TM , SectionKind Kind ) const { const GlobalVariable * GVA = dyn_cast < GlobalVariable > ( GV ) ; if ( ! GVA ) return false ; if ( ! Kind . isBSS ( ) && ! Kind . isDataRel ( ) ) return false ; if ( Kind . isMergeable1ByteCString ( ) ) return false ; Type * Ty = GV -> getType ( ) -> getElementType ( ) ; return IsInSmallSection ( TM . getTargetData ( ) -> getTypeAllocSize ( Ty ) ) ; } </s>