void DeadVariableElimination::DeleteVariable(uint32_t result_id) { ir::Instruction* inst = get_def_use_mgr()->GetDef(result_id); assert(inst->opcode() == SpvOpVariable && "Should not be trying to delete anything other than an OpVariable."); // Look for an initializer that references another variable. We need to know // if that variable can be deleted after the reference is removed. if (inst->NumOperands() == 4) { ir::Instruction* initializer = get_def_use_mgr()->GetDef(inst->GetSingleWordOperand(3)); // TODO: Handle OpSpecConstantOP which might be defined in terms of other // variables. Will probably require a unified dead code pass that does all // instruction types. (Issue 906) if (initializer->opcode() == SpvOpVariable) { uint32_t initializer_id = initializer->result_id(); size_t& count = reference_count_[initializer_id]; if (count != kMustKeep) { --count; } if (count == 0) { DeleteVariable(initializer_id); } } } context()->KillDef(result_id); }
// This optimization removes global variables that are not needed because they // are definitely not accessed. Pass::Status DeadVariableElimination::Process(ir::IRContext* c) { // The algorithm will compute the reference count for every global variable. // Anything with a reference count of 0 will then be deleted. For variables // that might have references that are not explicit in this context, we use // the // value kMustKeep as the reference count. InitializeProcessing(c); std::vector<uint32_t> ids_to_remove; // Get the reference count for all of the global OpVariable instructions. for (auto& inst : context()->types_values()) { if (inst.opcode() != SpvOp::SpvOpVariable) { continue; } size_t count = 0; uint32_t result_id = inst.result_id(); // Check the linkage. If it is exported, it could be reference somewhere // else, so we must keep the variable around. get_decoration_mgr()->ForEachDecoration( result_id, SpvDecorationLinkageAttributes, [&count](const ir::Instruction& linkage_instruction) { uint32_t last_operand = linkage_instruction.NumOperands() - 1; if (linkage_instruction.GetSingleWordOperand(last_operand) == SpvLinkageTypeExport) { count = kMustKeep; } }); if (count != kMustKeep) { // If we don't have to keep the instruction for other reasons, then look // at the uses and count the number of real references. count = 0; get_def_use_mgr()->ForEachUser( result_id, [&count](ir::Instruction* user) { if (!ir::IsAnnotationInst(user->opcode()) && user->opcode() != SpvOpName) { ++count; } }); } reference_count_[result_id] = count; if (count == 0) { ids_to_remove.push_back(result_id); } } // Remove all of the variables that have a reference count of 0. bool modified = false; if (!ids_to_remove.empty()) { modified = true; for (auto result_id : ids_to_remove) { DeleteVariable(result_id); } } return (modified ? Status::SuccessWithChange : Status::SuccessWithoutChange); }
void _KillDataFilterParameters (_String const & filter_name) { _List kill_these_arguments; kill_these_arguments < "species" < "sites" < "site_map" < "site_freqs" < "sequence_map"; for (unsigned long i = 0; i < kill_these_arguments.countitems(); i++) { DeleteVariable(WrapInNamespace(*(_String*)kill_these_arguments.GetItem(i), &filter_name)); } }
void NewList(char *scope, char *lval, void *rval, enum cfdatatype dt) { Rval rvald; if (GetVariable(scope, lval, &rvald) != cf_notype) { DeleteVariable(scope, lval); } AddVariableHash(scope, lval, (Rval) {rval, CF_LIST}, dt, NULL, 0); }
int CVariable::DeleteVariable_all() { DebugText("AllDeleteVariable..."); for(int i=0;i<=Max;i++) { DeleteVariable(i); } Max=-1; DebugText("OK!\n"); return 0; }
void NewList(char *scope,char *lval,void *rval,enum cfdatatype dt) { char *sp1; struct Rval rvald; if (GetVariable(scope,lval,&rvald.item,&rvald.rtype) != cf_notype) { DeleteVariable(scope,lval); } sp1 = strdup(lval); AddVariableHash(scope,sp1,rval,CF_LIST,dt,NULL,0); }
void ForceScalar(char *lval, char *rval) { Rval retval; if (THIS_AGENT_TYPE != cf_agent && THIS_AGENT_TYPE != cf_know) { return; } if (GetVariable("match", lval, &retval) != cf_notype) { DeleteVariable("match", lval); } NewScalar("match", lval, rval, cf_str); CfDebug("Setting local variable \"match.%s\" context; $(%s) = %s\n", lval, lval, rval); }
bool SetVariable(VariableSpace space, const char *name, const char *value) { struct _variable *current, *previous; if (!space) return false; if (strspn(name, VALID_VARIABLE_CHARS) != strlen(name)) return false; if (!value) return DeleteVariable(space, name); for (previous = space, current = space->next; current; previous = current, current = current->next) { if (strcmp(current->name, name) == 0) { /* found entry, so update */ if (current->value) free(current->value); current->value = pg_strdup(value); if (current->assign_hook) (*current->assign_hook) (current->value); return true; } } /* not present, make new entry */ current = pg_malloc(sizeof *current); current->name = pg_strdup(name); current->value = pg_strdup(value); current->assign_hook = NULL; current->next = NULL; previous->next = current; return true; }
static void parse_psql_options(int argc, char *argv[], struct adhoc_opts * options) { static struct option long_options[] = { {"echo-all", no_argument, NULL, 'a'}, {"no-align", no_argument, NULL, 'A'}, {"command", required_argument, NULL, 'c'}, {"dbname", required_argument, NULL, 'd'}, {"echo-queries", no_argument, NULL, 'e'}, {"echo-errors", no_argument, NULL, 'b'}, {"echo-hidden", no_argument, NULL, 'E'}, {"file", required_argument, NULL, 'f'}, {"field-separator", required_argument, NULL, 'F'}, {"field-separator-zero", no_argument, NULL, 'z'}, {"host", required_argument, NULL, 'h'}, {"html", no_argument, NULL, 'H'}, {"list", no_argument, NULL, 'l'}, {"log-file", required_argument, NULL, 'L'}, {"no-readline", no_argument, NULL, 'n'}, {"single-transaction", no_argument, NULL, '1'}, {"output", required_argument, NULL, 'o'}, {"port", required_argument, NULL, 'p'}, {"pset", required_argument, NULL, 'P'}, {"quiet", no_argument, NULL, 'q'}, {"record-separator", required_argument, NULL, 'R'}, {"record-separator-zero", no_argument, NULL, '0'}, {"single-step", no_argument, NULL, 's'}, {"single-line", no_argument, NULL, 'S'}, {"tuples-only", no_argument, NULL, 't'}, {"table-attr", required_argument, NULL, 'T'}, {"username", required_argument, NULL, 'U'}, {"set", required_argument, NULL, 'v'}, {"variable", required_argument, NULL, 'v'}, {"version", no_argument, NULL, 'V'}, {"no-password", no_argument, NULL, 'w'}, {"password", no_argument, NULL, 'W'}, {"expanded", no_argument, NULL, 'x'}, {"no-psqlrc", no_argument, NULL, 'X'}, {"help", optional_argument, NULL, 1}, {NULL, 0, NULL, 0} }; int optindex; int c; memset(options, 0, sizeof *options); while ((c = getopt_long(argc, argv, "aAbc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?01", long_options, &optindex)) != -1) { switch (c) { case 'a': SetVariable(pset.vars, "ECHO", "all"); break; case 'A': pset.popt.topt.format = PRINT_UNALIGNED; break; case 'b': SetVariable(pset.vars, "ECHO", "errors"); break; case 'c': options->action_string = pg_strdup(optarg); if (optarg[0] == '\\') { options->action = ACT_SINGLE_SLASH; options->action_string++; } else options->action = ACT_SINGLE_QUERY; break; case 'd': options->dbname = pg_strdup(optarg); break; case 'e': SetVariable(pset.vars, "ECHO", "queries"); break; case 'E': SetVariableBool(pset.vars, "ECHO_HIDDEN"); break; case 'f': options->action = ACT_FILE; options->action_string = pg_strdup(optarg); break; case 'F': pset.popt.topt.fieldSep.separator = pg_strdup(optarg); pset.popt.topt.fieldSep.separator_zero = false; break; case 'h': options->host = pg_strdup(optarg); break; case 'H': pset.popt.topt.format = PRINT_HTML; break; case 'l': options->action = ACT_LIST_DB; break; case 'L': options->logfilename = pg_strdup(optarg); break; case 'n': options->no_readline = true; break; case 'o': if (!setQFout(optarg)) exit(EXIT_FAILURE); break; case 'p': options->port = pg_strdup(optarg); break; case 'P': { char *value; char *equal_loc; bool result; value = pg_strdup(optarg); equal_loc = strchr(value, '='); if (!equal_loc) result = do_pset(value, NULL, &pset.popt, true); else { *equal_loc = '\0'; result = do_pset(value, equal_loc + 1, &pset.popt, true); } if (!result) { fprintf(stderr, _("%s: could not set printing parameter \"%s\"\n"), pset.progname, value); exit(EXIT_FAILURE); } free(value); break; } case 'q': SetVariableBool(pset.vars, "QUIET"); break; case 'R': pset.popt.topt.recordSep.separator = pg_strdup(optarg); pset.popt.topt.recordSep.separator_zero = false; break; case 's': SetVariableBool(pset.vars, "SINGLESTEP"); break; case 'S': SetVariableBool(pset.vars, "SINGLELINE"); break; case 't': pset.popt.topt.tuples_only = true; break; case 'T': pset.popt.topt.tableAttr = pg_strdup(optarg); break; case 'U': options->username = pg_strdup(optarg); break; case 'v': { char *value; char *equal_loc; value = pg_strdup(optarg); equal_loc = strchr(value, '='); if (!equal_loc) { if (!DeleteVariable(pset.vars, value)) { fprintf(stderr, _("%s: could not delete variable \"%s\"\n"), pset.progname, value); exit(EXIT_FAILURE); } } else { *equal_loc = '\0'; if (!SetVariable(pset.vars, value, equal_loc + 1)) { fprintf(stderr, _("%s: could not set variable \"%s\"\n"), pset.progname, value); exit(EXIT_FAILURE); } } free(value); break; } case 'V': showVersion(); exit(EXIT_SUCCESS); case 'w': pset.getPassword = TRI_NO; break; case 'W': pset.getPassword = TRI_YES; break; case 'x': pset.popt.topt.expanded = true; break; case 'X': options->no_psqlrc = true; break; case 'z': pset.popt.topt.fieldSep.separator_zero = true; break; case '0': pset.popt.topt.recordSep.separator_zero = true; break; case '1': options->single_txn = true; break; case '?': /* Actual help option given */ if (strcmp(argv[optind - 1], "-?") == 0) { usage(NOPAGER); exit(EXIT_SUCCESS); } /* unknown option reported by getopt */ else goto unknown_option; break; case 1: { if (!optarg || strcmp(optarg, "options") == 0) usage(NOPAGER); else if (optarg && strcmp(optarg, "commands") == 0) slashUsage(NOPAGER); else if (optarg && strcmp(optarg, "variables") == 0) helpVariables(NOPAGER); else goto unknown_option; exit(EXIT_SUCCESS); } break; default: unknown_option: fprintf(stderr, _("Try \"%s --help\" for more information.\n"), pset.progname); exit(EXIT_FAILURE); break; } } /* * if we still have arguments, use it as the database name and username */ while (argc - optind >= 1) { if (!options->dbname) options->dbname = argv[optind]; else if (!options->username) options->username = argv[optind]; else if (!pset.quiet) fprintf(stderr, _("%s: warning: extra command-line argument \"%s\" ignored\n"), pset.progname, argv[optind]); optind++; } }
static void CheckControlPromises(char *scope,char *agent,struct Constraint *controllist) { struct Constraint *cp; struct BodySyntax *bp = NULL; struct Rlist *rp; int i = 0; struct Rval returnval; char rettype; void *retval; Debug("CheckControlPromises(%s)\n",agent); for (i = 0; CF_ALL_BODIES[i].bs != NULL; i++) { bp = CF_ALL_BODIES[i].bs; if (strcmp(agent,CF_ALL_BODIES[i].btype) == 0) { break; } } if (bp == NULL) { FatalError("Unknown agent"); } for (cp = controllist; cp != NULL; cp=cp->next) { if (IsExcluded(cp->classes)) { continue; } if (strcmp(cp->lval,CFG_CONTROLBODY[cfg_bundlesequence].lval) == 0) { returnval = ExpandPrivateRval(CONTEXTID,cp->rval,cp->type); } else { returnval = EvaluateFinalRval(CONTEXTID,cp->rval,cp->type,true,NULL); } DeleteVariable(scope,cp->lval); if (!AddVariableHash(scope,cp->lval,returnval.item,returnval.rtype,GetControlDatatype(cp->lval,bp),cp->audit->filename,cp->lineno)) { CfOut(cf_error,""," !! Rule from %s at/before line %d\n",cp->audit->filename,cp->lineno); } if (strcmp(cp->lval,CFG_CONTROLBODY[cfg_output_prefix].lval) == 0) { strncpy(VPREFIX,returnval.item,CF_MAXVARSIZE); } if (strcmp(cp->lval,CFG_CONTROLBODY[cfg_domain].lval) == 0) { strcpy(VDOMAIN,cp->rval); CfOut(cf_verbose,"","SET domain = %s\n",VDOMAIN); DeleteScalar("sys","domain"); DeleteScalar("sys","fqhost"); snprintf(VFQNAME,CF_MAXVARSIZE,"%s.%s",VUQNAME,VDOMAIN); NewScalar("sys","fqhost",VFQNAME,cf_str); NewScalar("sys","domain",VDOMAIN,cf_str); DeleteClass("undefined_domain"); NewClass(VDOMAIN); } if (strcmp(cp->lval,CFG_CONTROLBODY[cfg_ignore_missing_inputs].lval) == 0) { CfOut(cf_verbose,"","SET ignore_missing_inputs %s\n",cp->rval); IGNORE_MISSING_INPUTS = GetBoolean(cp->rval); } if (strcmp(cp->lval,CFG_CONTROLBODY[cfg_ignore_missing_bundles].lval) == 0) { CfOut(cf_verbose,"","SET ignore_missing_bundles %s\n",cp->rval); IGNORE_MISSING_BUNDLES = GetBoolean(cp->rval); } if (strcmp(cp->lval,CFG_CONTROLBODY[cfg_goalpatterns].lval) == 0) { GOALS = NULL; for (rp = (struct Rlist *)returnval.item; rp != NULL; rp=rp->next) { PrependRScalar(&GOALS,rp->item,CF_SCALAR); } CfOut(cf_verbose,"","SET goal_patterns list\n"); continue; } if (strcmp(cp->lval,CFG_CONTROLBODY[cfg_goalcategories].lval) == 0) { GOALCATEGORIES = NULL; for (rp = (struct Rlist *)returnval.item; rp != NULL; rp=rp->next) { PrependRScalar(&GOALCATEGORIES,rp->item,CF_SCALAR); } CfOut(cf_verbose,"","SET goal_categories list\n"); continue; } DeleteRvalItem(returnval.item,returnval.rtype); } }
bool _HYObjectInspector::ProcessGEvent (_HYEvent* e) { _String firstArg; long k,f; bool done = false; lastKillID++; _HYPullDown* p1 = (_HYPullDown*)GetCellObject (0,2); if (e->EventClass()==_hyGlobalTreeKillEvent) { firstArg = e->EventCode().Cut (0,(f=e->EventCode().Find(','))-1); k = firstArg.toNum(); if (MatchID(k)) { k = e->EventCode().Cut (f+1,-1).toNum(); _Variable* theV = LocateVar(k); if (theV->ObjectClass()==TREE) { _SimpleList lfIDs; TreeDependencies (lfIDs, theV->GetAVariable()); for (k=0; k<lfIDs.lLength; k++) { postLFKillEvent (GetID(), lfIDs.lData[k]); } if (lfIDs.lLength == 0) { DeleteVariable (*theV->GetName(),true); } else if (lastKillID<=2) { postTreeKillEvent (GetID(), theV->GetAVariable()); } BuildListOfObjects (p1->GetSelection()); } } done = true; } else if (e->EventClass()==_hyGlobalLFKillEvent) { firstArg = e->EventCode().Cut (0,(f=e->EventCode().Find(','))-1); k = firstArg.toNum(); if (MatchID(k)) { k = e->EventCode().Cut (f+1,-1).toNum(); KillLFRecord (k); } done = true; } else if (e->EventClass()==_hyGlobalDSKillEvent) { firstArg = e->EventCode().Cut (0,(f=e->EventCode().Find(','))-1); k = firstArg.toNum(); if (MatchID(k)) { k = e->EventCode().Cut (f+1,-1).toNum(); _SimpleList lfIDs; DSDependencies (lfIDs, k); for (f=0; f<lfIDs.lLength; f++) { postLFKillEvent (GetID(), lfIDs.lData[f]); } if (lfIDs.lLength == 0) { KillDataSetRecord (k); } else if (lastKillID<=2) { postDSKillEvent (GetID(), k); } BuildListOfObjects (p1->GetSelection()); done = true; } } lastKillID --; if (!done) { return _HYWindow::ProcessGEvent (e); } return true; }
//__________________________________________________________________________________ void DeleteVariable (_String&name, bool deleteself) { DeleteVariable(LocateVarByName (name), deleteself); }
//__________________________________________________________________________________ void DeleteVariable (long dv, bool deleteself) { if (dv>=0) { _String *name = (_String*)variableNames.Retrieve (dv); _String myName = *name&'.'; long vidx = variableNames.GetXtra (dv); UpdateChangingFlas (vidx); _SimpleList recCache; variableNames.Find (name,recCache); _String nextVarID;// = *(_String*)variableNames.Retrieve(variableNames.Next (dv,recCache)); long nvid; if ((nvid = variableNames.Next (dv,recCache))>=0) { nextVarID = *(_String*)variableNames.Retrieve(nvid); } if (deleteself) { _SimpleList tcache; long iv, k = variableNames.Traverser (tcache, iv, variableNames.GetRoot()); for (; k>=0; k = variableNames.Traverser (tcache, iv)) { _Variable * thisVar = FetchVar(k); if (thisVar->CheckFForDependence (vidx,false)) { _PMathObj curValue = thisVar->Compute(); curValue->nInstances++; // this could be a leak 01/05/2004. thisVar->SetValue (curValue); DeleteObject (curValue); } } _Variable* delvar = (FetchVar(dv)); DeleteObject (delvar); variableNames.Delete (variableNames.Retrieve(dv),true); (*((_SimpleList*)&variablePtrs))[vidx]=0; freeSlots<<vidx; } else { _Variable* delvar = (FetchVar(dv)); if (delvar->IsContainer()) { _VariableContainer* dc = (_VariableContainer*)delvar; dc->Clear(); } } _List toDelete; recCache.Clear(); long nextVar = variableNames.Find (&nextVarID,recCache); for (; nextVar>=0; nextVar = variableNames.Next (nextVar, recCache)) { _String dependent = *(_String*)variableNames.Retrieve (nextVar); if (dependent.startswith(myName)) { toDelete && & dependent; } else { break; } } for (long k=0; k< toDelete.lLength; k++) { DeleteVariable (*(_String*)toDelete(k)); } } }