#define DEBUG_TYPE "structcfg"
#include "AMDIL.h"
+#include "AMDILInstrInfo.h"
#include "AMDILRegisterInfo.h"
#include "AMDILUtilityFunctions.h"
#include "llvm/ADT/SCCIterator.h"
~CFGStructurizer();
/// Perform the CFG structurization
- bool run(FuncT &Func, PassT &Pass);
+ bool run(FuncT &Func, PassT &Pass, const AMDILRegisterInfo *tri);
/// Perform the CFG preparation
- bool prepare(FuncT &Func, PassT &Pass);
+ bool prepare(FuncT &Func, PassT &Pass, const AMDILRegisterInfo *tri);
private:
void orderBlocks();
BlockInfoMap blockInfoMap;
LoopLandInfoMap loopLandInfoMap;
SmallVector<BlockT *, DEFAULT_VEC_SLOTS> orderedBlks;
+ const AMDILRegisterInfo *TRI;
}; //template class CFGStructurizer
}
template<class PassT>
-bool CFGStructurizer<PassT>::prepare(FuncT &func, PassT &pass) {
+bool CFGStructurizer<PassT>::prepare(FuncT &func, PassT &pass,
+ const AMDILRegisterInfo * tri) {
passRep = &pass;
funcRep = &func;
+ TRI = tri;
bool changed = false;
//func.RenumberBlocks();
} //CFGStructurizer::prepare
template<class PassT>
-bool CFGStructurizer<PassT>::run(FuncT &func, PassT &pass) {
+bool CFGStructurizer<PassT>::run(FuncT &func, PassT &pass,
+ const AMDILRegisterInfo * tri) {
passRep = &pass;
funcRep = &func;
+ TRI = tri;
//func.RenumberBlocks();
// if (initReg !=2) {...}
//
// add initReg = initVal to headBlk
+
+ const TargetRegisterClass * I32RC = TRI->getCFGStructurizerRegClass(MVT::i32);
unsigned initReg =
- funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass);
+ funcRep->getRegInfo().createVirtualRegister(I32RC);
if (!migrateTrue || !migrateFalse) {
int initVal = migrateTrue ? 0 : 1;
CFGTraits::insertAssignInstrBefore(headBlk, passRep, initReg, initVal);
if (landBlkHasOtherPred) {
unsigned immReg =
- funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass);
+ funcRep->getRegInfo().createVirtualRegister(I32RC);
CFGTraits::insertAssignInstrBefore(insertPos, passRep, immReg, 2);
unsigned cmpResReg =
- funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass);
+ funcRep->getRegInfo().createVirtualRegister(I32RC);
CFGTraits::insertCompareInstrBefore(landBlk, insertPos, passRep, cmpResReg,
initReg, immReg);
errs() << "Trying to break loop-depth = " << getLoopDepth(exitLoop)
<< " from loop-depth = " << getLoopDepth(exitingLoop) << "\n";
}
+ const TargetRegisterClass * I32RC = TRI->getCFGStructurizerRegClass(MVT::i32);
RegiT initReg = INVALIDREGNUM;
if (exitingLoop != exitLoop) {
initReg = static_cast<int>
- (funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass));
+ (funcRep->getRegInfo().createVirtualRegister(I32RC));
assert(initReg != INVALIDREGNUM);
addLoopBreakInitReg(exitLoop, initReg);
while (exitingLoop != exitLoop && exitingLoop) {
}
RegiT initReg = INVALIDREGNUM;
+ const TargetRegisterClass * I32RC = TRI->getCFGStructurizerRegClass(MVT::i32);
if (contingLoop != contLoop) {
initReg = static_cast<int>
- (funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass));
+ (funcRep->getRegInfo().createVirtualRegister(I32RC));
assert(initReg != INVALIDREGNUM);
addLoopContInitReg(contLoop, initReg);
while (contingLoop && contingLoop->getParentLoop() != contLoop) {
CFGStructurizer<PassT>::addLoopEndbranchBlock(LoopT *loopRep,
BlockTSmallerVector &exitingBlks,
BlockTSmallerVector &exitBlks) {
- const TargetInstrInfo *tii = passRep->getTargetInstrInfo();
+ const AMDILInstrInfo *tii =
+ static_cast<const AMDILInstrInfo *>(passRep->getTargetInstrInfo());
+ const TargetRegisterClass * I32RC = TRI->getCFGStructurizerRegClass(MVT::i32);
RegiT endBranchReg = static_cast<int>
- (funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass));
+ (funcRep->getRegInfo().createVirtualRegister(I32RC));
assert(endBranchReg >= 0);
// reg = 0 before entering the loop
DebugLoc DL;
RegiT preValReg = static_cast<int>
- (funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass));
- BuildMI(preBranchBlk, DL, tii->get(AMDIL::LOADCONST_i32), preValReg)
- .addImm(i - 1); //preVal
+ (funcRep->getRegInfo().createVirtualRegister(I32RC));
+
+ preBranchBlk->insert(preBranchBlk->begin(),
+ tii->getMovImmInstr(preBranchBlk->getParent(), preValReg,
+ i - 1));
// condResReg = (endBranchReg == preValReg)
RegiT condResReg = static_cast<int>
- (funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass));
- BuildMI(preBranchBlk, DL, tii->get(AMDIL::IEQ), condResReg)
+ (funcRep->getRegInfo().createVirtualRegister(I32RC));
+ BuildMI(preBranchBlk, DL, tii->get(tii->getIEQOpcode()), condResReg)
.addReg(endBranchReg).addReg(preValReg);
BuildMI(preBranchBlk, DL, tii->get(AMDIL::BRANCH_COND_i32))
loopHeader = LoopRep->getHeader();
loopLatch = LoopRep->getLoopLatch();
BlockT *dummyExitBlk = NULL;
+ const TargetRegisterClass * I32RC = TRI->getCFGStructurizerRegClass(MVT::i32);
if (loopHeader!=NULL && loopLatch!=NULL) {
InstrT *branchInstr = CFGTraits::getLoopendBlockBranchInstr(loopLatch);
if (branchInstr!=NULL && CFGTraits::isUncondBranch(branchInstr)) {
typename BlockT::iterator insertPos =
CFGTraits::getInstrPos(loopLatch, branchInstr);
unsigned immReg =
- funcRep->getRegInfo().createVirtualRegister(&AMDIL::GPRI32RegClass);
+ funcRep->getRegInfo().createVirtualRegister(I32RC);
CFGTraits::insertAssignInstrBefore(insertPos, passRep, immReg, 1);
InstrT *newInstr =
CFGTraits::insertInstrBefore(insertPos, AMDIL::BRANCH_COND_i32, passRep);
typedef MachinePostDominatorTree PostDominatortreeType;
typedef MachineDomTreeNode DomTreeNodeType;
typedef MachineLoop LoopType;
-//private:
+
+protected:
TargetMachine &TM;
const TargetInstrInfo *TII;
-
-//public:
-// static char ID;
+ const AMDILRegisterInfo *TRI;
public:
AMDILCFGStructurizer(char &pid, TargetMachine &tm AMDIL_OPT_LEVEL_DECL);
} //end of namespace llvm
AMDILCFGStructurizer::AMDILCFGStructurizer(char &pid, TargetMachine &tm
AMDIL_OPT_LEVEL_DECL)
-: MachineFunctionPass(pid), TM(tm), TII(tm.getInstrInfo()) {
+: MachineFunctionPass(pid), TM(tm), TII(tm.getInstrInfo()),
+ TRI(static_cast<const AMDILRegisterInfo *>(tm.getRegisterInfo())
+ ) {
}
const TargetInstrInfo *AMDILCFGStructurizer::getTargetInstrInfo() const {
AMDILCFGStructurizer *passRep,
RegiT regNum, int regVal) {
MachineInstr *oldInstr = &(*instrPos);
- const TargetInstrInfo *tii = passRep->getTargetInstrInfo();
+ const AMDILInstrInfo *tii =
+ static_cast<const AMDILInstrInfo *>(passRep->getTargetInstrInfo());
MachineBasicBlock *blk = oldInstr->getParent();
- MachineInstr *newInstr =
- blk->getParent()->CreateMachineInstr(tii->get(AMDIL::LOADCONST_i32),
- DebugLoc());
- MachineInstrBuilder(newInstr).addReg(regNum, RegState::Define); //set target
- MachineInstrBuilder(newInstr).addImm(regVal); //set src value
-
+ MachineInstr *newInstr = tii->getMovImmInstr(blk->getParent(), regNum,
+ regVal);
blk->insert(instrPos, newInstr);
SHOWNEWINSTR(newInstr);
static void insertAssignInstrBefore(MachineBasicBlock *blk,
AMDILCFGStructurizer *passRep,
RegiT regNum, int regVal) {
- const TargetInstrInfo *tii = passRep->getTargetInstrInfo();
-
- MachineInstr *newInstr =
- blk->getParent()->CreateMachineInstr(tii->get(AMDIL::LOADCONST_i32),
- DebugLoc());
- MachineInstrBuilder(newInstr).addReg(regNum, RegState::Define); //set target
- MachineInstrBuilder(newInstr).addImm(regVal); //set src value
+ const AMDILInstrInfo *tii =
+ static_cast<const AMDILInstrInfo *>(passRep->getTargetInstrInfo());
+ MachineInstr *newInstr = tii->getMovImmInstr(blk->getParent(), regNum,
+ regVal);
if (blk->begin() != blk->end()) {
blk->insert(blk->begin(), newInstr);
} else {
AMDILCFGStructurizer *passRep,
RegiT dstReg, RegiT src1Reg,
RegiT src2Reg) {
- const TargetInstrInfo *tii = passRep->getTargetInstrInfo();
+ const AMDILInstrInfo *tii =
+ static_cast<const AMDILInstrInfo *>(passRep->getTargetInstrInfo());
MachineInstr *newInstr =
- blk->getParent()->CreateMachineInstr(tii->get(AMDIL::IEQ), DebugLoc());
+ blk->getParent()->CreateMachineInstr(tii->get(tii->getIEQOpcode()), DebugLoc());
MachineInstrBuilder(newInstr).addReg(dstReg, RegState::Define); //set target
MachineInstrBuilder(newInstr).addReg(src1Reg); //set src value
bool AMDILCFGPrepare::runOnMachineFunction(MachineFunction &func) {
return llvmCFGStruct::CFGStructurizer<AMDILCFGStructurizer>().prepare(func,
- *this);
+ *this,
+ TRI);
}
// createAMDILCFGStructurizerPass- Returns a pass
bool AMDILCFGPerform::runOnMachineFunction(MachineFunction &func) {
return llvmCFGStruct::CFGStructurizer<AMDILCFGStructurizer>().run(func,
- *this);
+ *this,
+ TRI);
}
//end of file newline goes below