bool ResolveAliases::runOnModule(Module &M) { bool Modified = false; for (auto I = M.alias_begin(), E = M.alias_end(); I != E;) { GlobalAlias *Alias = &*I++; Alias->replaceAllUsesWith(Alias->getAliasee()); Alias->eraseFromParent(); Modified = true; } return Modified; }
SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalAlias(GlobalAlias &GA) { if (GA.mayBeOverridden()) return unknown(); return compute(GA.getAliasee()); }
SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalAlias(GlobalAlias &GA) { if (GA.isInterposable()) return unknown(); return compute(GA.getAliasee()); }
void IRLinker::linkAliasBody(GlobalAlias &Dst, GlobalAlias &Src) { Mapper.scheduleMapGlobalAliasee(Dst, *Src.getAliasee(), AliasMCID); }
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 IRLinker::linkAliasBody(GlobalAlias &Dst, GlobalAlias &Src) { Constant *Aliasee = Src.getAliasee(); Constant *Val = MapValue(Aliasee, AliasValueMap, RF_MoveDistinctMDs, &TypeMap, &LValMaterializer); Dst.setAliasee(Val); }