/*addAlias * * * */ void addAlias(commandT* cmd){ if(cmd->argc <=1){ printAliasList(); return; } aliasL* current = aliasList; //printf("added job\n"); if (current == NULL){ aliasList = makeAlias(cmd); //printf("aliasList->alias is %s\n", aliasList->alias); //printAliasList(); return; } else{ while (current->next != NULL){ current = current->next; } current->next = makeAlias(cmd); //printAliasList(); return; } //printAliasList(); }//addAlias
void AAAnalyzer::handle_instrinsic(Instruction *inst) { IntrinsicInst * call = (IntrinsicInst*) inst; switch (call->getIntrinsicID()) { // Variable Argument Handling Intrinsics case Intrinsic::vastart: { Value * va_list_ptr = call->getArgOperand(0); wrapValue(va_list_ptr); } break; case Intrinsic::vaend: { } break; case Intrinsic::vacopy: // the same with memmove/memcpy //Standard C Library Intrinsics case Intrinsic::memmove: case Intrinsic::memcpy: { Value * src_ptr = call->getArgOperand(0); Value * dst_ptr = call->getArgOperand(1); DyckVertex* src_ptr_ver = wrapValue(src_ptr); DyckVertex* dst_ptr_ver = wrapValue(dst_ptr); DyckVertex* src_ver = addPtrTo(src_ptr_ver, NULL); DyckVertex* dst_ver = addPtrTo(dst_ptr_ver, NULL); makeAlias(src_ver, dst_ver); } break; case Intrinsic::memset: { Value * ptr = call->getArgOperand(0); Value * val = call->getArgOperand(1); addPtrTo(wrapValue(ptr), wrapValue(val)); } break; /// @todo other C lib intrinsics //Accurate Garbage Collection Intrinsics //Code Generator Intrinsics //Bit Manipulation Intrinsics //Exception Handling Intrinsics //Trampoline Intrinsics //Memory Use Markers //General Intrinsics //Arithmetic with Overflow Intrinsics //Specialised Arithmetic Intrinsics //Half Precision Floating Point Intrinsics //Debugger Intrinsics default:break; } }
/* * RebuildQueryStrings deparses the job query for each task to * include execution-time changes such as function evaluation. */ void RebuildQueryStrings(Query *originalQuery, List *taskList) { ListCell *taskCell = NULL; Oid relationId = ((RangeTblEntry *) linitial(originalQuery->rtable))->relid; foreach(taskCell, taskList) { Task *task = (Task *) lfirst(taskCell); StringInfo newQueryString = makeStringInfo(); Query *query = originalQuery; if (task->insertSelectQuery) { /* for INSERT..SELECT, adjust shard names in SELECT part */ RangeTblEntry *copiedInsertRte = NULL; RangeTblEntry *copiedSubqueryRte = NULL; Query *copiedSubquery = NULL; List *relationShardList = task->relationShardList; ShardInterval *shardInterval = LoadShardInterval(task->anchorShardId); query = copyObject(originalQuery); copiedInsertRte = ExtractInsertRangeTableEntry(query); copiedSubqueryRte = ExtractSelectRangeTableEntry(query); copiedSubquery = copiedSubqueryRte->subquery; AddShardIntervalRestrictionToSelect(copiedSubquery, shardInterval); ReorderInsertSelectTargetLists(query, copiedInsertRte, copiedSubqueryRte); /* setting an alias simplifies deparsing of RETURNING */ if (copiedInsertRte->alias == NULL) { Alias *alias = makeAlias(CITUS_TABLE_ALIAS, NIL); copiedInsertRte->alias = alias; } UpdateRelationToShardNames((Node *) copiedSubquery, relationShardList); } deparse_shard_query(query, relationId, task->anchorShardId, newQueryString); ereport(DEBUG4, (errmsg("query before rebuilding: %s", task->queryString))); ereport(DEBUG4, (errmsg("query after rebuilding: %s", newQueryString->data))); task->queryString = newQueryString->data; }
void AAAnalyzer::handle_inst(Instruction *inst, FunctionWrapper * parent_func) { //outs()<<*inst<<"\n"; outs().flush(); switch (inst->getOpcode()) { // common/bitwise binary operations // Terminator instructions case Instruction::Ret: { ReturnInst* retInst = ((ReturnInst*) inst); if (retInst->getNumOperands() > 0 && !retInst->getOperandUse(0)->getType()->isVoidTy()) { parent_func->addRet(retInst->getOperandUse(0)); } } break; case Instruction::Resume: { Value* resume = ((ResumeInst*) inst)->getOperand(0); parent_func->addResume(resume); } break; case Instruction::Switch: case Instruction::Br: case Instruction::IndirectBr: case Instruction::Unreachable: break; // vector operations case Instruction::ExtractElement: { } break; case Instruction::InsertElement: { } break; case Instruction::ShuffleVector: { } break; // aggregate operations case Instruction::ExtractValue: { Value * agg = ((ExtractValueInst*) inst)->getAggregateOperand(); DyckVertex* aggV = wrapValue(agg); Type* aggTy = agg->getType(); ArrayRef<unsigned> indices = ((ExtractValueInst*) inst)->getIndices(); DyckVertex* currentStruct = aggV; for (unsigned int i = 0; i < indices.size(); i++) { if (isa<CompositeType>(aggTy) && aggTy->isSized()) { if (!aggTy->isStructTy()) { aggTy = ((CompositeType*) aggTy)->getTypeAtIndex(indices[i]); #ifndef ARRAY_SIMPLIFIED current = addPtrOffset(current, (int) indices[i] * dl.getTypeAllocSize(aggTy), dgraph); #endif if (i == indices.size() - 1) { this->makeAlias(currentStruct, wrapValue(inst)); } } else { aggTy = ((CompositeType*) aggTy)->getTypeAtIndex(indices[i]); if (i != indices.size() - 1) { currentStruct = this->addField(currentStruct, -2 - (int) indices[i], NULL); } else { currentStruct = this->addField(currentStruct, -2 - (int) indices[i], wrapValue(inst)); } } } else { break; } } } break; case Instruction::InsertValue: { DyckVertex* resultV = wrapValue(inst); Value * agg = ((InsertValueInst*) inst)->getAggregateOperand(); if (!isa<UndefValue>(agg)) { makeAlias(resultV, wrapValue(agg)); } Value * val = ((InsertValueInst*) inst)->getInsertedValueOperand(); DyckVertex* insertedVal = wrapValue(val); Type *aggTy = inst->getType(); ArrayRef<unsigned> indices = ((InsertValueInst*) inst)->getIndices(); DyckVertex* currentStruct = resultV; for (unsigned int i = 0; i < indices.size(); i++) { if (isa<CompositeType>(aggTy) && aggTy->isSized()) { if (!aggTy->isStructTy()) { aggTy = ((CompositeType*) aggTy)->getTypeAtIndex(indices[i]); #ifndef ARRAY_SIMPLIFIED current = addPtrOffset(current, (int) indices[i] * dl.getTypeAllocSize(aggTy), dgraph); #endif if (i == indices.size() - 1) { this->makeAlias(currentStruct, insertedVal); } } else { aggTy = ((CompositeType*) aggTy)->getTypeAtIndex(indices[i]); if (i != indices.size() - 1) { currentStruct = this->addField(currentStruct, -2 - (int) indices[i], NULL); } else { currentStruct = this->addField(currentStruct, -2 - (int) indices[i], insertedVal); } } } else { break; } } } break; // memory accessing and addressing operations case Instruction::Alloca: { } break; case Instruction::Fence: { } break; case Instruction::AtomicCmpXchg: { Value * retXchg = inst; Value * ptrXchg = inst->getOperand(0); Value * newXchg = inst->getOperand(2); addPtrTo(wrapValue(ptrXchg), wrapValue(retXchg)); addPtrTo(wrapValue(ptrXchg), wrapValue(newXchg)); } break; case Instruction::AtomicRMW: { Value * retRmw = inst; Value * ptrRmw = ((AtomicRMWInst*) inst)->getPointerOperand(); addPtrTo(wrapValue(ptrRmw), wrapValue(retRmw)); switch (((AtomicRMWInst*) inst)->getOperation()) { case AtomicRMWInst::Max: case AtomicRMWInst::Min: case AtomicRMWInst::UMax: case AtomicRMWInst::UMin: case AtomicRMWInst::Xchg: { Value * newRmw = ((AtomicRMWInst*) inst)->getValOperand(); addPtrTo(wrapValue(ptrRmw), wrapValue(newRmw)); } break; default: //others are binary ops like add/sub/... ///@TODO break; } } break; case Instruction::Load: { Value *lval = inst; Value *ladd = inst->getOperand(0); addPtrTo(wrapValue(ladd), wrapValue(lval)); } break; case Instruction::Store: { Value * sval = inst->getOperand(0); Value * sadd = inst->getOperand(1); addPtrTo(wrapValue(sadd), wrapValue(sval)); } break; case Instruction::GetElementPtr: { makeAlias(wrapValue(inst), handle_gep((GEPOperator*) inst)); } break; // conversion operations case Instruction::Trunc: case Instruction::ZExt: case Instruction::SExt: case Instruction::FPTrunc: case Instruction::FPExt: case Instruction::FPToUI: case Instruction::FPToSI: case Instruction::UIToFP: case Instruction::SIToFP: case Instruction::BitCast: case Instruction::PtrToInt: case Instruction::IntToPtr: { Value * itpv = inst->getOperand(0); makeAlias(wrapValue(inst), wrapValue(itpv)); } break; // other operations case Instruction::Invoke: // invoke is a terminal operation { InvokeInst * invoke = (InvokeInst*) inst; LandingPadInst* lpd = invoke->getLandingPadInst(); parent_func->addLandingPad(invoke, lpd); Value * cv = invoke->getCalledValue(); vector<Value*> args; for (unsigned i = 0; i < invoke->getNumArgOperands(); i++) { args.push_back(invoke->getArgOperand(i)); } this->handle_invoke_call_inst(invoke, cv, &args, parent_func); } break; case Instruction::Call: { CallInst * callinst = (CallInst*) inst; if (callinst->isInlineAsm()) { break; } Value * cv = callinst->getCalledValue(); vector<Value*> args; for (unsigned i = 0; i < callinst->getNumArgOperands(); i++) { args.push_back(callinst->getArgOperand(i)); } this->handle_invoke_call_inst(callinst, cv, &args, parent_func); } break; case Instruction::PHI: { PHINode *phi = (PHINode *) inst; int nums = phi->getNumIncomingValues(); for (int i = 0; i < nums; i++) { Value * p = phi->getIncomingValue(i); makeAlias(wrapValue(inst), wrapValue(p)); } } break; case Instruction::Select: { Value *first = ((SelectInst*) inst)->getTrueValue(); Value *second = ((SelectInst*) inst)->getFalseValue(); makeAlias(wrapValue(inst), wrapValue(first)); makeAlias(wrapValue(inst), wrapValue(second)); } break; case Instruction::VAArg: { parent_func->addVAArg(inst); DyckVertex* vaarg = wrapValue(inst); Value * ptrVaarg = inst->getOperand(0); addPtrTo(wrapValue(ptrVaarg), vaarg); } break; case Instruction::LandingPad: // handled with invoke inst case Instruction::ICmp: case Instruction::FCmp: default: break; } }
DyckVertex* AAAnalyzer::wrapValue(Value * v) { // if the vertex of v exists, return it, otherwise create one pair < DyckVertex*, bool> retpair = dgraph->retrieveDyckVertex(v); if (retpair.second) { return retpair.first; } DyckVertex* vdv = retpair.first; // constantTy are handled as below. if (isa<ConstantExpr>(v)) { // constant expr should be handled like a assignment instruction if (isa<GEPOperator>(v)) { DyckVertex * got = handle_gep((GEPOperator*) v); makeAlias(vdv, got); } else if (((ConstantExpr*) v)->isCast()) { // errs() << *v << "\n"; DyckVertex * got = wrapValue(((ConstantExpr*) v)->getOperand(0)); makeAlias(vdv, got); } else { unsigned opcode = ((ConstantExpr*) v)->getOpcode(); switch (opcode) { case 23: // BinaryConstantExpr "and" case 24: // BinaryConstantExpr "or" { // do nothing } break; default: { errs() << "ERROR when handle the following constant expression\n"; errs() << *v << "\n"; errs() << ((ConstantExpr*) v)->getOpcode() << "\n"; errs() << ((ConstantExpr*) v)->getOpcodeName() << "\n"; errs().flush(); exit(-1); } break; } } } else if (isa<ConstantArray>(v)) { #ifndef ARRAY_SIMPLIFIED DyckVertex* ptr = addPtrTo(NULL, vdv, dgraph); DyckVertex* current = ptr; Constant * vAgg = (Constant*) v; int numElmt = vAgg->getNumOperands(); for (int i = 0; i < numElmt; i++) { Value * vi = vAgg->getOperand(i); DyckVertex* viptr = addPtrOffset(current, i * dl.getTypeAllocSize(vi->getType()), dgraph); addPtrTo(viptr, wrapValue(vi, dgraph, dl), dgraph); } #else Constant * vAgg = (Constant*) v; int numElmt = vAgg->getNumOperands(); for (int i = 0; i < numElmt; i++) { Value * vi = vAgg->getOperand(i); makeAlias(vdv, wrapValue(vi)); } #endif } else if (isa<ConstantStruct>(v)) { //DyckVertex* ptr = addPtrTo(NULL, vdv); //DyckVertex* current = ptr; Constant * vAgg = (Constant*) v; int numElmt = vAgg->getNumOperands(); for (int i = 0; i < numElmt; i++) { Value * vi = vAgg->getOperand(i); addField(vdv, -2 - i, wrapValue(vi)); } } else if (isa<GlobalValue>(v)) { if (isa<GlobalVariable>(v)) { GlobalVariable * global = (GlobalVariable *) v; if (global->hasInitializer()) { Value * initializer = global->getInitializer(); if (!isa<UndefValue>(initializer)) { DyckVertex * initVer = wrapValue(initializer); addPtrTo(vdv, initVer); } } } else if (isa<GlobalAlias>(v)) { GlobalAlias * global = (GlobalAlias *) v; Value * aliasee = global->getAliasee(); makeAlias(vdv, wrapValue(aliasee)); } else if (isa<Function>(v)) { // do nothing } // no else } else if (isa<ConstantInt>(v) || isa<ConstantFP>(v) || isa<ConstantPointerNull>(v) || isa<UndefValue>(v)) { // do nothing } else if (isa<ConstantDataArray>(v) || isa<ConstantAggregateZero>(v)) { // do nothing } else if (isa<BlockAddress>(v)) { // do nothing } else if (isa<ConstantDataVector>(v)) { errs() << "ERROR when handle the following ConstantDataSequential, ConstantDataVector\n"; errs() << *v << "\n"; errs().flush(); exit(-1); } else if (isa<ConstantVector>(v)) { errs() << "ERROR when handle the following ConstantVector\n"; errs() << *v << "\n"; errs().flush(); exit(-1); } else if (isa<Constant>(v)) { errs() << "ERROR when handle the following constant value\n"; errs() << *v << "\n"; errs().flush(); exit(-1); } return vdv; }
void AAAnalyzer::handle_common_function_call(Call* c, FunctionWrapper* caller, FunctionWrapper* callee) { //landingpad<->resume if (c->ret != NULL) { Value* lpd = caller->getLandingPad(c->ret); if (lpd != NULL) { DyckVertex* lpdVertex = wrapValue(lpd); set<Value*>& res = callee->getResumes(); set<Value*>::iterator resIt = res.begin(); while (resIt != res.end()) { makeAlias(wrapValue(*resIt), lpdVertex); resIt++; } } } //return<->call set<Value*>& rets = callee->getReturns(); if (c->ret != NULL) { set<Value*>::iterator retIt = rets.begin(); while (retIt != rets.end()) { makeAlias(wrapValue(*retIt), wrapValue(c->ret)); retIt++; } } // parameter<->arg unsigned int numOfArgOp = c->args.size(); unsigned argIdx = 0; Function * func = callee->getLLVMFunction(); if (!func->isIntrinsic()) { vector<Value*>& parameters = callee->getArgs(); vector<Value*>::iterator pit = parameters.begin(); while (pit != parameters.end()) { if (numOfArgOp <= argIdx) { errs() << "Warning the number of args is less than that of parameters\n"; errs() << func->getName() << "\n"; errs() << *(c->ret) << "\n"; break; //exit(-1); } Value * arg = c->args[argIdx]; Value * par = *pit; makeAlias(wrapValue(par), wrapValue(arg)); argIdx++; pit++; } if (func->isVarArg()) { vector<Value*>& va_parameters = callee->getVAArgs(); for (unsigned int i = argIdx; i < numOfArgOp; i++) { Value * arg = c->args[i]; DyckVertex* arg_v = wrapValue(arg); vector<Value*>::iterator va_par_it = va_parameters.begin(); while (va_par_it != va_parameters.end()) { Value* va_par = *va_par_it; makeAlias(arg_v, wrapValue(va_par)); va_par_it++; } } } } else { errs() << "ERROR in handle_common_function_call(...):\n"; errs() << func->getName() << " can not be an intrinsic.\n"; exit(-1); } }