Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM 11 rebase #5

Open
wants to merge 14 commits into
base: upstream-llvm11-snapshot
Choose a base branch
from
103 changes: 52 additions & 51 deletions llvm/lib/Target/RISCV/ISPMetadataPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,59 +54,60 @@ static void setMIFlags(MachineInstr *MI) {

bool RISCVISPMetadata::runOnMachineFunction(MachineFunction &MF) {

for (auto &MBB : MF) {

// check first instruction
auto MI = MBB.getFirstNonDebugInstr();
setMIFlags(&*MI);
if ( MI == MBB.end() )
continue;

MBB.getSymbol()->modifyFlags((&MBB == &*MF.begin() ?
MachineInstr::CallTarget :
MachineInstr::BranchTarget),
0);

for(auto &pred : MBB.predecessors()){
const auto &last = pred->getLastNonDebugInstr();
if(last != pred->end()) {
if(last->isCall()) {
MI->setFlag(MachineInstr::ReturnTarget);
}
if(last->isBranch())
MI->setFlag(MachineInstr::BranchTarget);
}
for (auto &MBB : MF) {

// check first instruction
auto MI = MBB.getFirstNonDebugInstr();
if ( MI == MBB.end() )
continue;

MBB.getSymbol()->modifyFlags((&MBB == &*MF.begin() ?
MachineInstr::CallTarget :
MachineInstr::BranchTarget),
0);

setMIFlags(&*MI);

for(auto &pred : MBB.predecessors()){
const auto &last = pred->getLastNonDebugInstr();
if(last != pred->end()) {
if(last->isCall()) {
MI->setFlag(MachineInstr::ReturnTarget);
}
if(last->isBranch())
MI->setFlag(MachineInstr::BranchTarget);
}
}

// check all other instructions

auto last = MI;
for( auto MI = std::next(MBB.instr_begin()); MI != MBB.instr_end(); MI++ ) {

setMIFlags(&*MI);

//The zero size instructions from RISCVInstrInfo.cpp - getInstSizeInBytes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

//wasn't obvious how to call it, so here's this unmaintable approach
switch(MI->getOpcode()){
case TargetOpcode::EH_LABEL:
case TargetOpcode::IMPLICIT_DEF:
case TargetOpcode::KILL:
case TargetOpcode::DBG_VALUE:
continue;
default: //do nothing
break; //breaks the switch not the loop
}

if(last->isCall())
MI->setFlag(MachineInstr::ReturnTarget);

if(last->isBranch())
MI->setFlag(MachineInstr::BranchTarget);

last = MI;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit seems to be doing more than a re-ordering since it pulls the code section into the for loop.

}

// check all other instructions

auto last = MI;
for( auto MI = std::next(MBB.instr_begin()); MI != MBB.instr_end(); MI++ ) {

setMIFlags(&*MI);

//The zero size instructions from RISCVInstrInfo.cpp - getInstSizeInBytes
//wasn't obvious how to call it, so here's this unmaintable approach
switch(MI->getOpcode()){
case TargetOpcode::EH_LABEL:
case TargetOpcode::IMPLICIT_DEF:
case TargetOpcode::KILL:
case TargetOpcode::DBG_VALUE:
continue;
default: //do nothing
break; //breaks the switch not the loop
}

if(last->isCall())
MI->setFlag(MachineInstr::ReturnTarget);

if(last->isBranch())
MI->setFlag(MachineInstr::BranchTarget);

last = MI;
}
}

return false;
}

Expand Down