40 #include <llvm/CodeGen/MachineInstr.h>
41 #include <llvm/CodeGen/MachineMemOperand.h>
119 interPassData_(NULL), cfg_(NULL), rvIsParamReg_(
false) {
134 if (llvmOptions != NULL && llvmOptions->
disableLLVMAA() ==
false) {
147 interPassData_(&ipd), cfg_(NULL), rvIsParamReg_(true) {
154 static const TCEString SP_DATUM =
"STACK_POINTER";
155 static const TCEString FP_DATUM =
"FRAME_POINTER";
156 static const TCEString RV_DATUM =
"RV_REGISTER";
158 static const TCEString RV_HIGH_DATUM =
"RV_HIGH_REGISTER";
160 static const TCEString IPARAM_DATUM_PREFIX =
"IPARAM";
161 static const TCEString VECTOR_RV_PREFIX=
"VRV_REGISTER";
187 <<
"Warning: Stack pointer datum not found "
188 <<
"in interpassdata given to ddg builder. "
189 <<
"May generate invalid code if stack used."
206 <<
"Warning: Return value register datum not found "
207 <<
"in interpassdata given to ddg builder. "
208 <<
"May generate invalid code if return values used."
213 for(
int i = 2;;i++) {
214 TCEString datum = IPARAM_DATUM_PREFIX; datum << i;
224 for (
int i = 0;;i++) {
225 TCEString datum = VECTOR_RV_PREFIX; datum << i;
244 <<
"Warning: Frame Pointer Register datum not found "
245 <<
"in interpassdata given to ddg builder. "
246 <<
"May generate invalid code."
263 if (llvmOptions != NULL && llvmOptions->
disableLLVMAA() ==
false) {
274 !
options->noaliasFunctions()->empty())) {
308 std::map<int,TCEString>& registers) {
326 std::map<int,TCEString>& registers) {
327 for (
int i = 0; i < cfg.
nodeCount(); i++) {
346 std::map<int,TCEString>& registers) {
349 for (
int i = 0; i < ins.
moveCount(); i++) {
354 case ProgramAnnotation::ANN_REGISTER_RV_READ: {
359 case ProgramAnnotation::ANN_REGISTER_RV_SAVE: {
364 case ProgramAnnotation::ANN_REGISTER_SP_READ: {
369 case ProgramAnnotation::ANN_REGISTER_SP_SAVE: {
374 case ProgramAnnotation::ANN_REGISTER_IPARAM_READ: {
390 case ProgramAnnotation::ANN_REGISTER_IPARAM_SAVE: {
405 }
catch (std::bad_cast& e) {
425 for (
int i = 0; i < 6; i++) {
462 bool createMemAndFUDeps,
470 if (llvmaa != NULL) {
496 if (createMemAndFUDeps) {
566 for (
int i = 0; i < ins.
moveCount(); i++) {
568 Move& move = *movePtr;
581 hasProgramOperation()) {
585 if (po->hasMoveNodeForMove(move)) {
586 moveNode = &po->moveNode(move);
593 hasProgramOperation()) {
597 if (po->hasMoveNodeForMove(move)) {
598 moveNode = &po->moveNode(move);
639 +
TCEString(
" handled but we have unready PO at: ")
641 +
TCEString(
", probably an operation without result move?");
644 msg +=
"\n\tmissing read: " +
649 msg +=
"\n\tmissing dest: " +
677 for (
int ia = 0; ia < bb.instructionCount(); ia++) {
679 for (
int i = 0; i < ins.
moveCount(); i++) {
686 assert(bb.liveRangeData_);
688 std::set<TCEString> actualRegUses;
689 std::set<TCEString> actualRegDefs;
690 for (
int i = 0; i < bb.instructionCount(); i++) {
691 auto& ins = bb.instructionAtIndex(i);
692 for (
int m = 0; m < ins.moveCount(); m++) {
693 auto& move = ins.move(m);
695 auto rdReg = move.source().isGPR() ? move.source().toString()
697 if (!rdReg.empty()) actualRegUses.insert(rdReg);
699 if (move.isConditional()) {
700 const Guard& grd = move.guard().guard();
706 actualRegUses.insert(regName);
710 auto wrReg = move.destination().isGPR()
711 ? move.destination().toString()
713 if (!wrReg.empty()) actualRegDefs.insert(wrReg);
719 for (
auto reg : effectiveRegUses) {
728 for (
auto reg : effectiveRegDefs) {
733 liveRangeData.
regKills_[reg] = std::make_pair(mnd, mnd);
741 liveRangeData.
regKills_[reg] = std::make_pair(mnd, mnd);
772 "Analysis for port guards not supported! used in: "
801 if (source.
isGPR()) {
814 switch (triggerIndex) {
816 TCEString msg =
"Trigger index ambiguous for operation: ";
817 msg << op.
name() <<
" in the machine.";
823 msg << op.
name() <<
" Not found from the machine";
828 return triggerIndex == destIndex;
885 "Move has illegal destination" +
900 BasicBlock& bb,
bool interBBInformationNeeded) {
902 if (!interBBInformationNeeded) {
953 if (&dop != &po->operation()) {
954 std::cerr <<
"pending po: " << po->toString() << std::endl;
955 std::cerr <<
"current dop: " << dop.
name() << std::endl;
958 assert(&dop == &po->operation());
959 if (!po->isComplete()) {
960 po->addInputNode(moveNode);
975 "Trigger before all operands.");
989 po->addInputNode(moveNode);
1002 TCEString(
"Trigger without operand in ") + moveDisasm);
1070 assert(&dop == &po->operation());
1072 if (!po->isComplete()) {
1073 po->addInputNode(moveNode);
1091 po->addInputNode(moveNode);
1113 if (!po->isComplete()) {
1114 po->addOutputNode(moveNode);
1120 po->operation().numberOfOutputs()) {
1130 (boost::format(
"Result move '%s' without operands") %
1147 for (
int i = 0; i < po->inputMoveCount(); i++) {
1148 MoveNode& inputNode = po->inputMove(i);
1150 for (
int j = 0; j < po->outputMoveCount(); j++) {
1151 MoveNode& outputNode = po->outputMove(j);
1163 inputNode, outputNode, dde);
1184 MoveNodeUse& mnd, std::set<MoveNodeUse>& defines) {
1187 for (std::set<MoveNodeUse>::iterator i = defines.begin();
1188 i != defines.end(); i++) {
1191 !i->mn()->move().isUnconditional() &&
1199 std::set<MoveNodeUse>
1201 MoveNodeUse& mnd, std::set<MoveNodeUse>& defines) {
1203 std::set<MoveNodeUse> results;
1205 for (std::set<MoveNodeUse>::iterator i = defines.begin();
1206 i != defines.end(); i++) {
1209 !i->mn()->move().isUnconditional() &&
1236 std::set<MoveNodeUse>& defines =
1242 bool guardedKillFound = !sameGuardDefines.empty();
1246 for (std::set<MoveNodeUse>::iterator i = defines.begin();
1247 i != defines.end(); i++) {
1252 if (!guardedKillFound || (!i->mn()->move().isUnconditional() &&
1260 i->pseudo(), mnd.
pseudo(), i->loop());
1272 if (!guardedKillFound) {
1287 std::map<TCEString, std::pair<MoveNodeUse, bool> >::iterator iter =
1290 iter->second.second =
true;
1307 bool guardedKillFound) {
1310 for (std::set<MoveNodeUse>::iterator i = predecessorNodes.begin();
1311 i != predecessorNodes.end();) {
1318 if (guardedKillFound && i->mn()->move().isUnconditional()) {
1325 if (i->mn() == mnd.
mn()) {
1342 depType, reg, i->guard(),
false,
1343 i->pseudo(), mnd.
pseudo(), i->loop());
1351 predecessorNodes.erase(i++);
1376 std::set<MoveNodeUse>& defines =
1380 std::set<MoveNodeUse>& lastUses =
1399 std::map<TCEString, std::pair<MoveNodeUse, bool> >::iterator
1404 *(iter->second.first.mn()), *(mnd.
mn()))) {
1410 if (!guardedKillFound) {
1448 std::map<TCEString, std::pair<MoveNodeUse, bool> >::iterator iter =
1452 *(iter->second.first.mn()), *(mnd.
mn()))) {
1465 defines.insert(iter->second.first);
1467 if (!iter->second.second) {
1473 std::pair<MoveNodeUse, bool>(mnd,
false);
1475 defines.insert(mnd);
1506 MoveNodeUse(moveNode,
false,
false,
true),vrvIt->second);
1573 for (
int i = 0; i < 4;i++) {
1575 if (paramReg !=
"") {
1617 for (MoveNodeUseSet::iterator iter =
1622 iter->mn()->destinationOperation().operation();
1651 for (MoveNodeUseSet::iterator i = prevMoves.begin();
1652 i != prevMoves.end(); i++) {
1653 const Operation& o = i->mn()->destinationOperation().operation();
1667 false,
static_cast<int>(i->loop()));
1669 *(i->mn()), mn, dde);
1689 MoveNodeUse& mnd, std::set<MoveNodeUse>& defines) {
1692 for (std::set<MoveNodeUse>::iterator i = defines.begin();
1693 i != defines.end(); i++) {
1719 MoveNodeUse& mnd, std::set<MoveNodeUse>& prevNodes,
1723 for (MoveNodeUseSet::iterator iter =
1724 prevNodes.begin(); iter != prevNodes.end();) {
1729 prevNodes.erase(iter++);
1748 std::set<MoveNodeUse>& defines =
1751 std::set<MoveNodeUse>& lastUses =
1764 bool guardedKillFound =
1767 if (!guardedKillFound) {
1789 defines.insert(mnd);
1805 std::set<MoveNodeUse>& defines =
1812 bool guardedKillFound =
1815 if (!guardedKillFound) {
1823 for (MoveNodeUseSet::iterator iter =
1824 defines.begin(); iter != defines.end(); iter++) {
1859 const llvm::MachineInstr* instr1 = currPop.
machineInstr();
1860 const llvm::MachineInstr* instr2 = prevPop.
machineInstr();
1865 if (instr1 != NULL && instr2 != NULL) {
1866 llvm::MachineInstr::mmo_iterator begin1 =
1867 instr1->memoperands_begin();
1870 while (begin1 != instr1->memoperands_end()) {
1871 llvm::MachineInstr::mmo_iterator begin2 =
1872 instr2->memoperands_begin();
1874 while (begin2 != instr2->memoperands_end()) {
1876 if ((*begin1)->isVolatile() && (*begin2)->isVolatile()) {
1881 (*begin1)->getValue()->dump();
1882 (*begin2)->getValue()->dump();
1910 static_cast<int>(prev.
loop()));
2042 ProgramAnnotation::ANN_POINTER_ADDR_SPACE)) {
2044 0, ProgramAnnotation::ANN_POINTER_ADDR_SPACE).
stringValue()
2049 0, ProgramAnnotation::ANN_POINTER_ADDR_SPACE)
2062 ProgramAnnotation::ANN_POINTER_NAME) &&
2064 ProgramAnnotation::ANN_POINTER_NOALIAS)) {
2067 0, ProgramAnnotation::ANN_POINTER_NAME).
stringValue();
2068 category +=
"_RESTRICT:" + pointerName;
2084 if (m.
hasAnnotations(ProgramAnnotation::ANN_OPENCL_WORK_ITEM_ID)) {
2089 0, ProgramAnnotation::ANN_OPENCL_WORK_ITEM_ID).
2125 bool createMemAndFUDeps,
bool createDeathInformation,
2133 if (llvmaa != NULL) {
2159 if (createMemAndFUDeps) {
2166 if (createDeathInformation) {
2221 if (newState != oldState) {
2241 assert(firstBBs.size() == 1);
2349 std::list<BBData*>::iterator bbIter =
2391 BBData& bbd,
bool firstTime) {
2395 for (BasicBlockNodeSet::iterator predIter = predecessors.begin();
2396 predIter != predecessors.end(); predIter++) {
2425 BBData& bbd,
bool queueAll,
2431 for (BasicBlockNodeSet::iterator succIter = forwardSuccessors.begin();
2432 succIter != forwardSuccessors.end(); succIter++) {
2434 bb, **succIter, queueAll,
false, phase);
2439 for (BasicBlockNodeSet::iterator succIter = backwardSuccessors.begin();
2440 succIter != backwardSuccessors.end(); succIter++) {
2442 bb, **succIter, queueAll,
true, phase);
2466 bool changed =
false;
2501 if (changed || queueAll) {
2522 bool changed =
false;
2525 for (MoveNodeUseMapSet::iterator iter =
2530 std::set<MoveNodeUse>& preDefs = iter->second;
2533 size_t size = defAfter.size();
2537 for (std::set<MoveNodeUse>::iterator i = preDefs.begin();
2538 i != preDefs.end(); i++ ) {
2539 defAfter.insert(*i);
2543 if (size < defAfter.size()) {
2554 for (MoveNodeUseMapSet::iterator iter =
2558 std::set<MoveNodeUse>& preUses = iter->second;
2560 size_t size = useAfter.size();
2562 for (std::set<MoveNodeUse>::iterator i = preUses.begin();
2563 i != preUses.end(); i++ ) {
2564 useAfter.insert(*i);
2568 if (size < useAfter.size()) {
2594 bool changed =
false;
2601 std::set<MoveNodeUse>& preDefs = iter->second;
2604 size_t size = defAfter.size();
2608 for (std::set<MoveNodeUse>::iterator i = preDefs.begin();
2609 i != preDefs.end(); i++ ) {
2613 bool overWritten =
false;
2614 for (std::set<MoveNodeUse>::iterator j = ownDefines.begin();
2615 j != ownDefines.end(); j++) {
2616 if (j->mn()->move().isUnconditional()) {
2627 defAfter.insert(*i);
2632 if (size < defAfter.size()) {
2646 std::set<MoveNodeUse>& preUses = iter->second;
2650 size_t size = useAfter.size();
2652 for (std::set<MoveNodeUse>::iterator i = preUses.begin();
2653 i != preUses.end(); i++ ) {
2656 bool overWritten =
false;
2657 for (std::set<MoveNodeUse>::iterator j =
2658 ownDefines.begin(); j != ownDefines.end(); j++) {
2659 if (j->mn()->move().isUnconditional()) {
2669 useAfter.insert(*i);
2674 if (size < useAfter.size()) {
2716 for (
int i = 0;;i++) {
2718 if(paramReg !=
"") {
2752 for (MoveNodeUseMapSet::iterator firstUseIter =
2757 std::set<MoveNodeUse>& firstUseSet = firstUseIter->second;
2758 for (std::set<MoveNodeUse>::iterator iter2 = firstUseSet.begin();
2759 iter2 != firstUseSet.end(); iter2++) {
2767 for (MoveNodeUseMapSet::iterator firstDefineIter =
2770 firstDefineIter++) {
2772 std::set<MoveNodeUse>& firstDefineSet =
2773 firstDefineIter->second;
2774 for (std::set<MoveNodeUse>::iterator iter2=
2775 firstDefineSet.begin();
2776 iter2 != firstDefineSet.end(); iter2++) {
2786 for (MoveNodeUseMapSet::iterator firstUseIter =
2790 TCEString category = firstUseIter->first;
2791 std::set<MoveNodeUse>& firstUseSet = firstUseIter->second;
2792 for (std::set<MoveNodeUse>::iterator iter2 = firstUseSet.begin();
2793 iter2 != firstUseSet.end(); iter2++) {
2799 for (MoveNodeUseMapSet::iterator firstDefineIter =
2802 firstDefineIter++) {
2803 TCEString category = firstDefineIter->first;
2804 std::set<MoveNodeUse>& firstDefineSet = firstDefineIter->second;
2805 for (std::set<MoveNodeUse>::iterator iter2=firstDefineSet.begin();
2806 iter2 != firstDefineSet.end(); iter2++) {
2812 for (MoveNodeUseSet::iterator iter =
2815 Terminal& dest = iter->mn()->move().destination();
2837 for (MoveNodeUseSet::iterator iter =
2845 memUseReaches_[category].begin();
2862 for (MoveNodeUseSet::iterator iter =
2889 for (ControlFlowGraph::NodeSet::iterator iter =
2890 lastBBs.begin(); iter != lastBBs.end(); iter++) {
2928 std::list<BBData*>::iterator bbIter =
3000 bool alwaysDifferentFUs =
true;
3002 idx < srcMN->
move().annotationCount(
3010 ANN_ALLOWED_UNIT_DST)
3012 alwaysDifferentFUs =
false;
3016 return alwaysDifferentFUs;
3036 state_(BB_UNREACHED), constructed_(
false), bblock_(&bb) {