void Rationalizer::RewriteAssignment(LIR::Use& use) { assert(use.IsInitialized()); GenTreeOp* assignment = use.Def()->AsOp(); assert(assignment->OperGet() == GT_ASG); GenTree* location = assignment->gtGetOp1(); GenTree* value = assignment->gtGetOp2(); genTreeOps locationOp = location->OperGet(); switch (locationOp) { case GT_LCL_VAR: case GT_LCL_FLD: case GT_REG_VAR: case GT_PHI_ARG: RewriteAssignmentIntoStoreLclCore(assignment, location, value, locationOp); BlockRange().Remove(location); break; case GT_IND: { GenTreeStoreInd* store = new (comp, GT_STOREIND) GenTreeStoreInd(location->TypeGet(), location->gtGetOp1(), value); copyFlags(store, assignment, GTF_ALL_EFFECT); copyFlags(store, location, GTF_IND_FLAGS); if (assignment->IsReverseOp()) { store->gtFlags |= GTF_REVERSE_OPS; } // TODO: JIT dump // Remove the GT_IND node and replace the assignment node with the store BlockRange().Remove(location); BlockRange().InsertBefore(assignment, store); use.ReplaceWith(comp, store); BlockRange().Remove(assignment); } break; case GT_CLS_VAR: { location->SetOper(GT_CLS_VAR_ADDR); location->gtType = TYP_BYREF; assignment->SetOper(GT_STOREIND); // TODO: JIT dump } break; default: unreached(); break; } }
void Rationalizer::RewriteAddress(LIR::Use& use) { assert(use.IsInitialized()); GenTreeUnOp* address = use.Def()->AsUnOp(); assert(address->OperGet() == GT_ADDR); GenTree* location = address->gtGetOp1(); genTreeOps locationOp = location->OperGet(); if (location->IsLocal()) { // We are changing the child from GT_LCL_VAR TO GT_LCL_VAR_ADDR. // Therefore gtType of the child needs to be changed to a TYP_BYREF #ifdef DEBUG if (locationOp == GT_LCL_VAR) { JITDUMP("Rewriting GT_ADDR(GT_LCL_VAR) to GT_LCL_VAR_ADDR:\n"); } else { assert(locationOp == GT_LCL_FLD); JITDUMP("Rewriting GT_ADDR(GT_LCL_FLD) to GT_LCL_FLD_ADDR:\n"); } #endif // DEBUG location->SetOper(addrForm(locationOp)); location->gtType = TYP_BYREF; copyFlags(location, address, GTF_ALL_EFFECT); use.ReplaceWith(comp, location); BlockRange().Remove(address); } else if (locationOp == GT_CLS_VAR) { location->SetOper(GT_CLS_VAR_ADDR); location->gtType = TYP_BYREF; copyFlags(location, address, GTF_ALL_EFFECT); use.ReplaceWith(comp, location); BlockRange().Remove(address); JITDUMP("Rewriting GT_ADDR(GT_CLS_VAR) to GT_CLS_VAR_ADDR:\n"); } else if (location->OperIsIndir()) { use.ReplaceWith(comp, location->gtGetOp1()); BlockRange().Remove(location); BlockRange().Remove(address); JITDUMP("Rewriting GT_ADDR(GT_IND(X)) to X:\n"); } DISPTREERANGE(BlockRange(), use.Def()); JITDUMP("\n"); }
void TriObject::CopyValidity(TriObject *fromOb, ChannelMask channels) { if (channels&GEOM_CHANNEL) geomValid = fromOb->geomValid; if (channels&VERTCOLOR_CHANNEL) vcolorValid = fromOb->vcolorValid; if (channels&TOPO_CHANNEL) topoValid = fromOb->topoValid; if (channels&TEXMAP_CHANNEL) texmapValid = fromOb->texmapValid; if (channels&SELECT_CHANNEL) selectValid = fromOb->selectValid; if (channels&GFX_DATA_CHANNEL) gfxdataValid = fromOb->gfxdataValid; copyFlags(validBits, fromOb->validBits,channels); }
static void RewriteAssignmentIntoStoreLclCore(GenTreeOp* assignment, GenTree* location, GenTree* value, genTreeOps locationOp) { assert(assignment != nullptr); assert(assignment->OperGet() == GT_ASG); assert(location != nullptr); assert(value != nullptr); genTreeOps storeOp = storeForm(locationOp); #ifdef DEBUG JITDUMP("rewriting asg(%s, X) to %s(X)\n", GenTree::NodeName(locationOp), GenTree::NodeName(storeOp)); #endif // DEBUG assignment->SetOper(storeOp); GenTreeLclVarCommon* store = assignment->AsLclVarCommon(); GenTreeLclVarCommon* var = location->AsLclVarCommon(); store->SetLclNum(var->gtLclNum); store->SetSsaNum(var->gtSsaNum); if (locationOp == GT_LCL_FLD) { store->gtLclFld.gtLclOffs = var->gtLclFld.gtLclOffs; store->gtLclFld.gtFieldSeq = var->gtLclFld.gtFieldSeq; } copyFlags(store, var, GTF_LIVENESS_MASK); store->gtFlags &= ~GTF_REVERSE_OPS; store->gtType = var->TypeGet(); store->gtOp1 = value; DISPNODE(store); JITDUMP("\n"); }
MStatus atomExport::writer( const MFileObject& file, const MString& options, FileAccessMode mode) { MStatus status = MS::kFailure; MString fileName = file.fullName(); #if defined (OSMac_) char fname[MAXPATHLEN]; strcpy (fname, fileName.asChar()); ofstream animFile(fname); #else ofstream animFile(fileName.asChar()); #endif // Defaults. // MString copyFlags("copyKey -cb api -fea 1 "); int precision = kDefaultPrecision; bool statics = false; bool includeChildren = false; std::set<std::string> attrStrings; // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // bool useSpecifiedRange = false; bool useTemplate = false; bool cached = false; bool constraint = false; bool sdk = false; bool animLayers = true; MString templateName; MString viewName; MTime startTime = MAnimControl::animationStartTime(); MTime endTime = MAnimControl::animationEndTime(); MString exportEditsFile; MString exportFlags; if (options.length() > 0) { const MString flagPrecision("precision"); const MString flagStatics("statics"); const MString flagConstraint("constraint"); const MString flagSDK("sdk"); const MString flagAnimLayers("animLayers"); const MString flagCopyKeyCmd("copyKeyCmd"); const MString flagSelected("selected"); const MString flagTemplate("template"); const MString flagView("view"); const MString optionChildrenToo("childrenToo"); const MString optionTemplate("template"); const MString flagAttr("at"); const MString flagWhichRange("whichRange"); const MString flagRange("range"); const MString flagExportEdits("exportEdits"); const MString flagCached("baked"); // Start parsing. // MStringArray optionList; MStringArray theOption; options.split(';', optionList); unsigned nOptions = optionList.length(); for (unsigned i = 0; i < nOptions; i++) { theOption.clear(); optionList[i].split('=', theOption); if (theOption.length() < 1) { continue; } if (theOption[0] == flagPrecision && theOption.length() > 1) { if (theOption[1].isInt()) { precision = theOption[1].asInt(); } } else if( theOption[0] == flagTemplate && theOption.length() > 1) { templateName = theOption[1]; } else if( theOption[0] == flagView && theOption.length() > 1) { viewName = theOption[1]; } else if ( theOption[0] == flagWhichRange && theOption.length() > 1) { if (theOption[1].isInt()) useSpecifiedRange = (theOption[1].asInt() ==1) ? false : true; } else if ( theOption[0] == flagRange && theOption.length() > 1) { MStringArray rangeArray; theOption[1].split(':',rangeArray); if(rangeArray.length()==2) { if(rangeArray[0].isDouble()) { double val = rangeArray[0].asDouble(); startTime = MTime(val,MTime::uiUnit()); } else if(rangeArray[0].isInt()) { double val = (double)rangeArray[0].asInt(); startTime = MTime(val,MTime::uiUnit()); } if(rangeArray[1].isDouble()) { double val = rangeArray[1].asDouble(); endTime = MTime(val,MTime::uiUnit()); } else if(rangeArray[1].isInt()) { double val = (double)rangeArray[1].asInt(); endTime = MTime(val,MTime::uiUnit()); } } } else if ( theOption[0] == flagStatics && theOption.length() > 1) { if (theOption[1].isInt()) { statics = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagSDK && theOption.length() > 1) { if (theOption[1].isInt()) { sdk = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagConstraint && theOption.length() > 1) { if (theOption[1].isInt()) { constraint = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagAnimLayers && theOption.length() > 1) { if (theOption[1].isInt()) { animLayers = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagCached && theOption.length() > 1) { if (theOption[1].isInt()) { cached = (theOption[1].asInt()) ? true : false; } } else if (theOption[0] == flagSelected && theOption.length() > 1) { includeChildren = (theOption[1] == optionChildrenToo) ? true : false; if(theOption[1] == optionTemplate) useTemplate = true; } else if (theOption[0] == flagAttr && theOption.length() > 1) { std::string str(theOption[1].asChar()); attrStrings.insert(str); } else if ( theOption[0] == flagCopyKeyCmd && theOption.length() > 1) { // Replace any '>' characters with '"'. This is needed // since the file translator option boxes do not handle // escaped quotation marks. // const char *optStr = theOption[1].asChar(); size_t nChars = strlen(optStr); char *copyStr = new char[nChars+1]; copyStr = strcpy(copyStr, optStr); for (size_t j = 0; j < nChars; j++) { if (copyStr[j] == '>') { copyStr[j] = '"'; } } copyFlags += copyStr; delete [] copyStr; } else if (theOption[0] == flagExportEdits && theOption.length() > 1) { exportEditsFile = theOption[1]; } } } // Set the precision of the ofstream. // animFile.precision(precision); atomTemplateReader templateReader; if(useTemplate == true) { includeChildren = false; templateReader.setTemplate(templateName,viewName); templateReader.selectNodes(); //make the template nodes be the selection } status = exportSelected(animFile, copyFlags, attrStrings, includeChildren, useSpecifiedRange, startTime, endTime, statics, cached,sdk,constraint, animLayers, exportEditsFile,templateReader); animFile.flush(); animFile.close(); return status; }
void Rationalizer::RewriteAssignment(LIR::Use& use) { assert(use.IsInitialized()); GenTreeOp* assignment = use.Def()->AsOp(); assert(assignment->OperGet() == GT_ASG); GenTree* location = assignment->gtGetOp1(); GenTree* value = assignment->gtGetOp2(); genTreeOps locationOp = location->OperGet(); if (assignment->OperIsBlkOp()) { #ifdef FEATURE_SIMD if (varTypeIsSIMD(location) && assignment->OperIsInitBlkOp()) { if (location->OperGet() == GT_LCL_VAR) { var_types simdType = location->TypeGet(); GenTree* initVal = assignment->gtOp.gtOp2; var_types baseType = comp->getBaseTypeOfSIMDLocal(location); if (baseType != TYP_UNKNOWN) { GenTreeSIMD* simdTree = new (comp, GT_SIMD) GenTreeSIMD(simdType, initVal, SIMDIntrinsicInit, baseType, genTypeSize(simdType)); assignment->gtOp.gtOp2 = simdTree; value = simdTree; initVal->gtNext = simdTree; simdTree->gtPrev = initVal; simdTree->gtNext = location; location->gtPrev = simdTree; } } } #endif // FEATURE_SIMD if ((location->TypeGet() == TYP_STRUCT) && !assignment->IsPhiDefn() && !value->IsMultiRegCall()) { if ((location->OperGet() == GT_LCL_VAR)) { // We need to construct a block node for the location. // Modify lcl to be the address form. location->SetOper(addrForm(locationOp)); LclVarDsc* varDsc = &(comp->lvaTable[location->AsLclVarCommon()->gtLclNum]); location->gtType = TYP_BYREF; GenTreeBlk* storeBlk = nullptr; unsigned int size = varDsc->lvExactSize; if (varDsc->lvStructGcCount != 0) { CORINFO_CLASS_HANDLE structHnd = varDsc->lvVerTypeInfo.GetClassHandle(); GenTreeObj* objNode = comp->gtNewObjNode(structHnd, location)->AsObj(); unsigned int slots = (unsigned)(roundUp(size, TARGET_POINTER_SIZE) / TARGET_POINTER_SIZE); objNode->SetGCInfo(varDsc->lvGcLayout, varDsc->lvStructGcCount, slots); objNode->ChangeOper(GT_STORE_OBJ); objNode->SetData(value); comp->fgMorphUnsafeBlk(objNode); storeBlk = objNode; } else { storeBlk = new (comp, GT_STORE_BLK) GenTreeBlk(GT_STORE_BLK, TYP_STRUCT, location, value, size); } storeBlk->gtFlags |= (GTF_REVERSE_OPS | GTF_ASG); storeBlk->gtFlags |= ((location->gtFlags | value->gtFlags) & GTF_ALL_EFFECT); GenTree* insertionPoint = location->gtNext; BlockRange().InsertBefore(insertionPoint, storeBlk); use.ReplaceWith(comp, storeBlk); BlockRange().Remove(assignment); JITDUMP("After transforming local struct assignment into a block op:\n"); DISPTREERANGE(BlockRange(), use.Def()); JITDUMP("\n"); return; } else { assert(location->OperIsBlk()); } } } switch (locationOp) { case GT_LCL_VAR: case GT_LCL_FLD: case GT_REG_VAR: case GT_PHI_ARG: RewriteAssignmentIntoStoreLclCore(assignment, location, value, locationOp); BlockRange().Remove(location); break; case GT_IND: { GenTreeStoreInd* store = new (comp, GT_STOREIND) GenTreeStoreInd(location->TypeGet(), location->gtGetOp1(), value); copyFlags(store, assignment, GTF_ALL_EFFECT); copyFlags(store, location, GTF_IND_FLAGS); if (assignment->IsReverseOp()) { store->gtFlags |= GTF_REVERSE_OPS; } // TODO: JIT dump // Remove the GT_IND node and replace the assignment node with the store BlockRange().Remove(location); BlockRange().InsertBefore(assignment, store); use.ReplaceWith(comp, store); BlockRange().Remove(assignment); } break; case GT_CLS_VAR: { location->SetOper(GT_CLS_VAR_ADDR); location->gtType = TYP_BYREF; assignment->SetOper(GT_STOREIND); // TODO: JIT dump } break; case GT_BLK: case GT_OBJ: case GT_DYN_BLK: { assert(varTypeIsStruct(location)); GenTreeBlk* storeBlk = location->AsBlk(); genTreeOps storeOper; switch (location->gtOper) { case GT_BLK: storeOper = GT_STORE_BLK; break; case GT_OBJ: storeOper = GT_STORE_OBJ; break; case GT_DYN_BLK: storeOper = GT_STORE_DYN_BLK; break; default: unreached(); } JITDUMP("Rewriting GT_ASG(%s(X), Y) to %s(X,Y):\n", GenTree::NodeName(location->gtOper), GenTree::NodeName(storeOper)); storeBlk->SetOperRaw(storeOper); storeBlk->gtFlags &= ~GTF_DONT_CSE; storeBlk->gtFlags |= (assignment->gtFlags & (GTF_ALL_EFFECT | GTF_REVERSE_OPS | GTF_BLK_VOLATILE | GTF_BLK_UNALIGNED | GTF_DONT_CSE)); storeBlk->gtBlk.Data() = value; // Replace the assignment node with the store use.ReplaceWith(comp, storeBlk); BlockRange().Remove(assignment); DISPTREERANGE(BlockRange(), use.Def()); JITDUMP("\n"); } break; default: unreached(); break; } }
void Rationalizer::RewriteAssignment(LIR::Use& use) { assert(use.IsInitialized()); GenTreeOp* assignment = use.Def()->AsOp(); assert(assignment->OperGet() == GT_ASG); GenTree* location = assignment->gtGetOp1(); GenTree* value = assignment->gtGetOp2(); genTreeOps locationOp = location->OperGet(); #ifdef FEATURE_SIMD if (varTypeIsSIMD(location) && assignment->OperIsInitBlkOp()) { if (location->OperGet() == GT_LCL_VAR) { var_types simdType = location->TypeGet(); GenTree* initVal = assignment->gtOp.gtOp2; var_types baseType = comp->getBaseTypeOfSIMDLocal(location); if (baseType != TYP_UNKNOWN) { GenTreeSIMD* simdTree = new (comp, GT_SIMD) GenTreeSIMD(simdType, initVal, SIMDIntrinsicInit, baseType, genTypeSize(simdType)); assignment->gtOp.gtOp2 = simdTree; value = simdTree; initVal->gtNext = simdTree; simdTree->gtPrev = initVal; simdTree->gtNext = location; location->gtPrev = simdTree; } } else { assert(location->OperIsBlk()); } } #endif // FEATURE_SIMD switch (locationOp) { case GT_LCL_VAR: case GT_LCL_FLD: case GT_REG_VAR: case GT_PHI_ARG: RewriteAssignmentIntoStoreLclCore(assignment, location, value, locationOp); BlockRange().Remove(location); break; case GT_IND: { GenTreeStoreInd* store = new (comp, GT_STOREIND) GenTreeStoreInd(location->TypeGet(), location->gtGetOp1(), value); copyFlags(store, assignment, GTF_ALL_EFFECT); copyFlags(store, location, GTF_IND_FLAGS); if (assignment->IsReverseOp()) { store->gtFlags |= GTF_REVERSE_OPS; } // TODO: JIT dump // Remove the GT_IND node and replace the assignment node with the store BlockRange().Remove(location); BlockRange().InsertBefore(assignment, store); use.ReplaceWith(comp, store); BlockRange().Remove(assignment); } break; case GT_CLS_VAR: { location->SetOper(GT_CLS_VAR_ADDR); location->gtType = TYP_BYREF; assignment->SetOper(GT_STOREIND); // TODO: JIT dump } break; case GT_BLK: case GT_OBJ: case GT_DYN_BLK: { assert(varTypeIsStruct(location)); GenTreeBlk* storeBlk = location->AsBlk(); genTreeOps storeOper; switch (location->gtOper) { case GT_BLK: storeOper = GT_STORE_BLK; break; case GT_OBJ: storeOper = GT_STORE_OBJ; break; case GT_DYN_BLK: storeOper = GT_STORE_DYN_BLK; break; default: unreached(); } JITDUMP("Rewriting GT_ASG(%s(X), Y) to %s(X,Y):\n", GenTree::NodeName(location->gtOper), GenTree::NodeName(storeOper)); storeBlk->SetOperRaw(storeOper); storeBlk->gtFlags &= ~GTF_DONT_CSE; storeBlk->gtFlags |= (assignment->gtFlags & (GTF_ALL_EFFECT | GTF_REVERSE_OPS | GTF_BLK_VOLATILE | GTF_BLK_UNALIGNED | GTF_BLK_INIT | GTF_DONT_CSE)); storeBlk->gtBlk.Data() = value; // Replace the assignment node with the store use.ReplaceWith(comp, storeBlk); BlockRange().Remove(assignment); DISPTREERANGE(BlockRange(), use.Def()); JITDUMP("\n"); } break; default: unreached(); break; } }
MStatus animExport::writer( const MFileObject& file, const MString& options, FileAccessMode mode) { MStatus status = MS::kFailure; MString fileName = file.fullName(); #if defined (OSMac_) char fname[MAXPATHLEN]; strcpy (fname, fileName.asChar()); ofstream animFile(fname); #else ofstream animFile(fileName.asChar()); #endif // Defaults. // MString copyFlags("copyKey -cb api -fea 1 "); int precision = kDefaultPrecision; bool nodeNames = true; bool verboseUnits = false; // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // MString exportFlags; if (options.length() > 0) { const MString flagPrecision("precision"); const MString flagNodeNames("nodeNames"); const MString flagVerboseUnits("verboseUnits"); const MString flagCopyKeyCmd("copyKeyCmd"); // Start parsing. // MStringArray optionList; MStringArray theOption; options.split(';', optionList); unsigned nOptions = optionList.length(); for (unsigned i = 0; i < nOptions; i++) { theOption.clear(); optionList[i].split('=', theOption); if (theOption.length() < 1) { continue; } if (theOption[0] == flagPrecision && theOption.length() > 1) { if (theOption[1].isInt()) { precision = theOption[1].asInt(); } } else if ( theOption[0] == flagNodeNames && theOption.length() > 1) { if (theOption[1].isInt()) { nodeNames = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagVerboseUnits && theOption.length() > 1) { if (theOption[1].isInt()) { verboseUnits = (theOption[1].asInt()) ? true : false; } } else if ( theOption[0] == flagCopyKeyCmd && theOption.length() > 1) { // Replace any '>' characters with '"'. This is needed // since the file translator option boxes do not handle // escaped quotation marks. // const char *optStr = theOption[1].asChar(); size_t nChars = strlen(optStr); char *copyStr = new char[nChars+1]; copyStr = strcpy(copyStr, optStr); for (size_t j = 0; j < nChars; j++) { if (copyStr[j] == '>') { copyStr[j] = '"'; } } copyFlags += copyStr; delete [] copyStr; } } } // Set the precision of the ofstream. // animFile.precision(precision); status = exportSelected(animFile, copyFlags, nodeNames, verboseUnits); animFile.flush(); animFile.close(); return status; }
int main(int argc, char *argv[]) { int realWorld[NOCOLS][NOROWS]; // Array of ints holding real world map int agentWorld[NOCOLS][NOROWS]; // Array of ints holding agents world map int x, y; // Counters struct coord currentCoord; // Current position coordinates struct coord start = {0, 0}; // Starting position // Initialize random number generator seed srand((unsigned int)time(0)); // Initialize both worlds to zero. for(y=0; y<NOROWS; y++){ for(x=0; x<NOCOLS; x++){ realWorld[x][y] = 0; agentWorld[x][y] = 0; } } // Generate realWorld. generateRealWorld(realWorld); // Generate agentWorld setFlag(agentWorld, start, CURRENT); // Initialy player is at (0,0) // Set current coordinates currentCoord = start; // Display real world puts("R E A L W O R L D"); displayWorldAll(realWorld); int count = 0; while(1){ printf("\n============================================================\n"); count++; // Update current coordinates currentCoord = getCurrentCoord(agentWorld); // If current field isn't visited, process sensor data if(testFlag(agentWorld, currentCoord, VISITED) == 0){ // Read sensors and update agents map of the world copyFlags(realWorld,agentWorld,currentCoord); // Check is cave or wumpus here, if it is then game over, else process sensors if(testFlag(agentWorld, currentCoord, CAVE)){ // Display agent world printf("\nA G E N T W O R L D (Step %d)\n",count); printf("Current position (%d,%d):\n", currentCoord.x, currentCoord.y); displayWorldAll(agentWorld); puts("\nWent down the cave. GAME OVER!"); break; } else if(testFlag(agentWorld,currentCoord,WUMPUS)){ // Display agent world printf("\nA G E N T W O R L D (Step %d)\n",count); printf("Current position (%d,%d):\n", currentCoord.x, currentCoord.y); displayWorldAll(agentWorld); puts("\nWumpus had a good meal. GAME OVER!"); break; } else if(testFlag(agentWorld,currentCoord,GLOW)){ // Display agent world printf("\nA G E N T W O R L D (Step %d)\n",count); printf("Current position (%d,%d):\n", currentCoord.x, currentCoord.y); displayWorldAll(agentWorld); puts("\nCongratulate! You have found gold! Nice!"); break; } else{ // Mark current coordinates as visited and remove safe setFlag(agentWorld, currentCoord, VISITED); // Evaluate neighbors and set appropriate flags evaluateNeighbors(agentWorld,currentCoord); } } // Display agent world printf("\nA G E N T W O R L D (Step %d)\n",count); printf("Current position (%d,%d):\n", currentCoord.x, currentCoord.y); displayWorldAll(agentWorld); if(takeGlowAction(agentWorld, currentCoord)){ printf("This move is recommended by takeGlowAction method!\n"); } else if(takeSafeAction(agentWorld, currentCoord)){ printf("This move is recommended by takeSafeAction method!\n"); } else if(takeRollTheDiceAction(agentWorld, currentCoord)){ printf("This move is recommended by takeRollTheDiceAction method!\n"); } else if(takeSuicideAction(agentWorld, currentCoord)){ printf("This move is recommended by takeSuicideAction method, situation was hopeless!\n"); } // sleep(2); myPause(); } myPause(); return EXIT_SUCCESS; }