本文整理汇总了C++中GlobalAlias类的典型用法代码示例。如果您正苦于以下问题:C++ GlobalAlias类的具体用法?C++ GlobalAlias怎么用?C++ GlobalAlias使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GlobalAlias类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initOverload
static void initOverload(OverloadPtr x) {
EnvPtr env = overloadPatternEnv(x);
PatternPtr pattern = evaluateOnePattern(x->target, env);
ObjectPtr obj = derefDeep(pattern);
if (obj == NULL) {
x->nameIsPattern = true;
addPatternOverload(x);
}
else {
switch (obj->objKind) {
case PROCEDURE : {
Procedure *proc = (Procedure *)obj.ptr();
addProcedureOverload(proc, env, x);
break;
}
case RECORD_DECL : {
RecordDecl *r = (RecordDecl *)obj.ptr();
r->overloads.insert(r->overloads.begin(), x);
break;
}
case VARIANT_DECL : {
VariantDecl *v = (VariantDecl *)obj.ptr();
v->overloads.insert(v->overloads.begin(), x);
break;
}
case TYPE : {
Type *t = (Type *)obj.ptr();
t->overloads.insert(t->overloads.begin(), x);
break;
}
case PRIM_OP : {
if (isOverloadablePrimOp(obj))
addPrimOpOverload((PrimOp *)obj.ptr(), x);
else
error(x->target, "invalid overload target");
break;
}
case GLOBAL_ALIAS : {
GlobalAlias *a = (GlobalAlias*)obj.ptr();
if (!a->hasParams())
error(x->target, "invalid overload target");
a->overloads.insert(a->overloads.begin(), x);
break;
}
case INTRINSIC : {
error(x->target, "invalid overload target");
}
default : {
error(x->target, "invalid overload target");
}
}
}
}
示例2: AliasGToF
static void AliasGToF(Function *F, Function *G) {
if (!G->hasExternalLinkage() && !G->hasLocalLinkage() && !G->hasWeakLinkage())
return ThunkGToF(F, G);
GlobalAlias *GA = new GlobalAlias(
G->getType(), G->getLinkage(), "",
ConstantExpr::getBitCast(F, G->getType()), G->getParent());
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
GA->takeName(G);
GA->setVisibility(G->getVisibility());
G->replaceAllUsesWith(GA);
G->eraseFromParent();
}
示例3: llvmutil_extractmodule
Module * llvmutil_extractmodule(Module * OrigMod, TargetMachine * TM, std::vector<Function*> * livefns, std::vector<std::string> * symbolnames) {
assert(symbolnames == NULL || livefns->size() == symbolnames->size());
ValueToValueMapTy VMap;
Module * M = CloneModule(OrigMod, VMap);
PassManager * MPM = new PassManager();
llvmutil_addtargetspecificpasses(MPM, TM);
std::vector<const char *> names;
for(size_t i = 0; i < livefns->size(); i++) {
Function * fn = cast<Function>(VMap[(*livefns)[i]]);
const char * name;
if(symbolnames) {
GlobalAlias * ga = new GlobalAlias(fn->getType(), Function::ExternalLinkage, (*symbolnames)[i], fn, M);
name = copyName(ga->getName());
} else {
name = copyName(fn->getName());
}
names.push_back(name); //internalize pass has weird interface, so we need to copy the names here
}
//at this point we run optimizations on the module
//first internalize all functions not mentioned in "names" using an internalize pass and then perform
//standard optimizations
MPM->add(createVerifierPass()); //make sure we haven't messed stuff up yet
MPM->add(createInternalizePass(names));
MPM->add(createGlobalDCEPass()); //run this early since anything not in the table of exported functions is still in this module
//this will remove dead functions
//clean up the name list
for(size_t i = 0; i < names.size(); i++) {
free((char*)names[i]);
names[i] = NULL;
}
PassManagerBuilder PMB;
PMB.OptLevel = 3;
PMB.DisableUnrollLoops = true;
PMB.populateModulePassManager(*MPM);
//PMB.populateLTOPassManager(*MPM, false, false); //no need to re-internalize, we already did it
MPM->run(*M);
delete MPM;
MPM = NULL;
return M;
}
示例4: GlobalAlias
// Replace G with an alias to F and delete G.
void MergeFunctions::writeAlias(Function *F, Function *G) {
Constant *BitcastF = ConstantExpr::getBitCast(F, G->getType());
GlobalAlias *GA = new GlobalAlias(G->getType(), G->getLinkage(), "",
BitcastF, G->getParent());
F->setAlignment(std::max(F->getAlignment(), G->getAlignment()));
GA->takeName(G);
GA->setVisibility(G->getVisibility());
removeUsers(G);
G->replaceAllUsesWith(GA);
G->eraseFromParent();
DEBUG(dbgs() << "writeAlias: " << GA->getName() << '\n');
++NumAliasesWritten;
}
示例5: computeAliasSummary
static void
computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
DenseSet<GlobalValue::GUID> &CantBePromoted) {
bool NonRenamableLocal = isNonRenamableLocal(A);
GlobalValueSummary::GVFlags Flags(A.getLinkage(), NonRenamableLocal,
/* LiveRoot = */ false);
auto AS = llvm::make_unique<AliasSummary>(Flags, ArrayRef<ValueInfo>{});
auto *Aliasee = A.getBaseObject();
auto *AliaseeSummary = Index.getGlobalValueSummary(*Aliasee);
assert(AliaseeSummary && "Alias expects aliasee summary to be parsed");
AS->setAliasee(AliaseeSummary);
if (NonRenamableLocal)
CantBePromoted.insert(A.getGUID());
Index.addGlobalValueSummary(A.getName(), std::move(AS));
}
示例6: resolveFunction
static Function*
resolveFunction(Module& M, StringRef name)
{
Function* f = M.getFunction(name);
if (f != NULL)
return f;
GlobalAlias* ga = M.getNamedAlias(name);
if (ga != NULL) {
const GlobalValue* v = ga->resolveAliasedGlobal(true);
f = dyn_cast<Function>(const_cast<GlobalValue*>(v));
if (f != NULL) {
errs() << "Resolved alias " << name << " to " << f->getName() << "\n";
return f;
}
}
return NULL;
}
示例7: getLinkedToGlobal
/// LinkAliasProto - Set up prototypes for any aliases that come over from the
/// source module.
bool ModuleLinker::linkAliasProto(GlobalAlias *SGA) {
GlobalValue *DGV = getLinkedToGlobal(SGA);
llvm::Optional<GlobalValue::VisibilityTypes> NewVisibility;
if (DGV) {
GlobalValue::LinkageTypes NewLinkage = GlobalValue::InternalLinkage;
GlobalValue::VisibilityTypes NV;
bool LinkFromSrc = false;
if (getLinkageResult(DGV, SGA, NewLinkage, NV, LinkFromSrc))
return true;
NewVisibility = NV;
if (!LinkFromSrc) {
// Set calculated linkage.
DGV->setLinkage(NewLinkage);
DGV->setVisibility(*NewVisibility);
// Make sure to remember this mapping.
ValueMap[SGA] = ConstantExpr::getBitCast(DGV,TypeMap.get(SGA->getType()));
// Track the alias from the source module so we don't attempt to remap it.
DoNotLinkFromSource.insert(SGA);
return false;
}
}
// If there is no linkage to be performed or we're linking from the source,
// bring over SGA.
GlobalAlias *NewDA = new GlobalAlias(TypeMap.get(SGA->getType()),
SGA->getLinkage(), SGA->getName(),
/*aliasee*/0, DstM);
CopyGVAttributes(NewDA, SGA);
if (NewVisibility)
NewDA->setVisibility(*NewVisibility);
if (DGV) {
// Any uses of DGV need to change to NewDA, with cast.
DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDA, DGV->getType()));
DGV->eraseFromParent();
}
ValueMap[SGA] = NewDA;
return false;
}
示例8: while
//
// Method: runOnModule()
//
// Description:
// Entry point for this LLVM pass.
// Replace all internal aliases with the
// aliasee value
//
// Inputs:
// M - A reference to the LLVM module to transform
//
// Outputs:
// M - The transformed LLVM module.
//
// Return value:
// true - The module was modified.
// false - The module was not modified.
//
bool FuncSimplify::runOnModule(Module& M) {
std::vector<GlobalAlias*> toDelete;
for (Module::alias_iterator I = M.alias_begin(); I != M.alias_end(); ++I) {
if(!I->hasInternalLinkage())
continue;
I->replaceAllUsesWith(I->getAliasee());
toDelete.push_back(I);
}
numChanged += toDelete.size();
while(!toDelete.empty()) {
GlobalAlias *I = toDelete.back();
toDelete.pop_back();
I->eraseFromParent();
}
return true;
}
示例9: callableOverloads
static llvm::ArrayRef<OverloadPtr> callableOverloads(ObjectPtr x)
{
initCallable(x);
switch (x->objKind) {
case TYPE : {
Type *y = (Type *)x.ptr();
return y->overloads;
}
case RECORD_DECL : {
RecordDecl *y = (RecordDecl *)x.ptr();
return y->overloads;
}
case VARIANT_DECL : {
VariantDecl *y = (VariantDecl *)x.ptr();
return y->overloads;
}
case PROCEDURE : {
Procedure *y = (Procedure *)x.ptr();
return y->overloads;
}
case PRIM_OP : {
assert(isOverloadablePrimOp(x));
PrimOp *y = (PrimOp *)x.ptr();
return primOpOverloads(y);
}
case GLOBAL_ALIAS : {
GlobalAlias *a = (GlobalAlias *)x.ptr();
assert(a->hasParams());
return a->overloads;
}
default : {
assert(false);
const vector<OverloadPtr> *ptr = NULL;
return *ptr;
}
}
}
示例10: convertAliasToDeclaration
static void convertAliasToDeclaration(GlobalAlias &GA, Module &M) {
GlobalValue *GVal = GA.getBaseObject();
GlobalValue *NewGV;
if (auto *GVar = dyn_cast<GlobalVariable>(GVal)) {
GlobalVariable *NewGVar = new GlobalVariable(
M, GVar->getType()->getElementType(), GVar->isConstant(),
GVar->getLinkage(), /*init*/ nullptr, GA.getName(), GVar,
GVar->getThreadLocalMode(), GVar->getType()->getAddressSpace());
NewGV = NewGVar;
NewGV->copyAttributesFrom(GVar);
} else {
auto *F = dyn_cast<Function>(GVal);
assert(F);
Function *NewF = Function::Create(F->getFunctionType(), F->getLinkage(),
GA.getName(), &M);
NewGV = NewF;
NewGV->copyAttributesFrom(F);
}
GA.replaceAllUsesWith(ConstantExpr::getBitCast(NewGV, GA.getType()));
GA.eraseFromParent();
}
示例11: LLVM_General_GetNextAlias
LLVMValueRef LLVM_General_GetNextAlias(LLVMValueRef a) {
GlobalAlias *alias = unwrap<GlobalAlias>(a);
Module::alias_iterator i = alias;
if (++i == alias->getParent()->alias_end()) return 0;
return wrap(i);
}
示例12: handle_gep
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();
//.........这里部分代码省略.........
示例13: NextPowerOf2
/// Given a disjoint set of bitsets and globals, layout the globals, build the
/// bit sets and lower the llvm.bitset.test calls.
void LowerBitSets::buildBitSetsFromGlobalVariables(
ArrayRef<Metadata *> BitSets, ArrayRef<GlobalVariable *> Globals) {
// Build a new global with the combined contents of the referenced globals.
// This global is a struct whose even-indexed elements contain the original
// contents of the referenced globals and whose odd-indexed elements contain
// any padding required to align the next element to the next power of 2.
std::vector<Constant *> GlobalInits;
const DataLayout &DL = M->getDataLayout();
for (GlobalVariable *G : Globals) {
GlobalInits.push_back(G->getInitializer());
uint64_t InitSize = DL.getTypeAllocSize(G->getValueType());
// Compute the amount of padding required.
uint64_t Padding = NextPowerOf2(InitSize - 1) - InitSize;
// Cap at 128 was found experimentally to have a good data/instruction
// overhead tradeoff.
if (Padding > 128)
Padding = RoundUpToAlignment(InitSize, 128) - InitSize;
GlobalInits.push_back(
ConstantAggregateZero::get(ArrayType::get(Int8Ty, Padding)));
}
if (!GlobalInits.empty())
GlobalInits.pop_back();
Constant *NewInit = ConstantStruct::getAnon(M->getContext(), GlobalInits);
auto *CombinedGlobal =
new GlobalVariable(*M, NewInit->getType(), /*isConstant=*/true,
GlobalValue::PrivateLinkage, NewInit);
StructType *NewTy = cast<StructType>(NewInit->getType());
const StructLayout *CombinedGlobalLayout = DL.getStructLayout(NewTy);
// Compute the offsets of the original globals within the new global.
DenseMap<GlobalObject *, uint64_t> GlobalLayout;
for (unsigned I = 0; I != Globals.size(); ++I)
// Multiply by 2 to account for padding elements.
GlobalLayout[Globals[I]] = CombinedGlobalLayout->getElementOffset(I * 2);
lowerBitSetCalls(BitSets, CombinedGlobal, GlobalLayout);
// Build aliases pointing to offsets into the combined global for each
// global from which we built the combined global, and replace references
// to the original globals with references to the aliases.
for (unsigned I = 0; I != Globals.size(); ++I) {
// Multiply by 2 to account for padding elements.
Constant *CombinedGlobalIdxs[] = {ConstantInt::get(Int32Ty, 0),
ConstantInt::get(Int32Ty, I * 2)};
Constant *CombinedGlobalElemPtr = ConstantExpr::getGetElementPtr(
NewInit->getType(), CombinedGlobal, CombinedGlobalIdxs);
if (LinkerSubsectionsViaSymbols) {
Globals[I]->replaceAllUsesWith(CombinedGlobalElemPtr);
} else {
assert(Globals[I]->getType()->getAddressSpace() == 0);
GlobalAlias *GAlias = GlobalAlias::create(NewTy->getElementType(I * 2), 0,
Globals[I]->getLinkage(), "",
CombinedGlobalElemPtr, M);
GAlias->setVisibility(Globals[I]->getVisibility());
GAlias->takeName(Globals[I]);
Globals[I]->replaceAllUsesWith(GAlias);
}
Globals[I]->eraseFromParent();
}
}
示例14: visitGlobalAlias
SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalAlias(GlobalAlias &GA) {
if (GA.isInterposable())
return unknown();
return compute(GA.getAliasee());
}
示例15: isAliasToDeclaration
static bool isAliasToDeclaration(const GlobalAlias &V) {
return isDeclaration(*V.getAliasedGlobal());
}