本文整理汇总了C++中GlobalVariable::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ GlobalVariable::getType方法的具体用法?C++ GlobalVariable::getType怎么用?C++ GlobalVariable::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlobalVariable
的用法示例。
在下文中一共展示了GlobalVariable::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runOnFunction
virtual bool runOnFunction(Function &F) {
//F.dump();
bool changed = false;
for (inst_iterator inst_it = inst_begin(F), _inst_end = inst_end(F); inst_it != _inst_end; ++inst_it) {
LoadInst *li = dyn_cast<LoadInst>(&*inst_it);
if (!li) continue;
ConstantExpr *ce = dyn_cast<ConstantExpr>(li->getOperand(0));
// Not 100% sure what the isGEPWithNoNotionalOverIndexing() means, but
// at least it checks if it's a gep:
if (ce && ce->isGEPWithNoNotionalOverIndexing() && ce->getOperand(0)->getType() == g.llvm_flavor_type_ptr) {
changed = handleFlavor(li, ce);
}
GlobalVariable *gv = dyn_cast<GlobalVariable>(li->getOperand(0));
if (!gv) continue;
llvm::Type* gv_t = gv->getType();
if (gv_t == g.llvm_bool_type_ptr->getPointerTo()) {
changed = handleBool(li, gv) || changed;
continue;
}
if (gv_t == g.llvm_class_type_ptr->getPointerTo()) {
changed = handleCls(li, gv) || changed;
continue;
}
}
return changed;
}
示例2: visitGlobalVariable
SizeOffsetType ObjectSizeOffsetVisitor::visitGlobalVariable(GlobalVariable &GV){
if (!GV.hasDefinitiveInitializer())
return unknown();
APInt Size(IntTyBits, TD->getTypeAllocSize(GV.getType()->getElementType()));
return std::make_pair(align(Size, GV.getAlignment()), Zero);
}
示例3: CU
Function *GCOVProfiler::insertCounterWriteout(
ArrayRef<std::pair<GlobalVariable *, MDNode *> > CountersBySP) {
FunctionType *WriteoutFTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
Function *WriteoutF = M->getFunction("__llvm_gcov_writeout");
if (!WriteoutF)
WriteoutF = Function::Create(WriteoutFTy, GlobalValue::InternalLinkage,
"__llvm_gcov_writeout", M);
WriteoutF->setUnnamedAddr(true);
WriteoutF->addFnAttr(Attribute::NoInline);
if (Options.NoRedZone)
WriteoutF->addFnAttr(Attribute::NoRedZone);
BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", WriteoutF);
IRBuilder<> Builder(BB);
Constant *StartFile = getStartFileFunc();
Constant *EmitFunction = getEmitFunctionFunc();
Constant *EmitArcs = getEmitArcsFunc();
Constant *SummaryInfo = getSummaryInfoFunc();
Constant *EndFile = getEndFileFunc();
NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
if (CU_Nodes) {
for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
DICompileUnit CU(CU_Nodes->getOperand(i));
std::string FilenameGcda = mangleName(CU, "gcda");
uint32_t CfgChecksum = FileChecksums.empty() ? 0 : FileChecksums[i];
Builder.CreateCall3(StartFile,
Builder.CreateGlobalStringPtr(FilenameGcda),
Builder.CreateGlobalStringPtr(ReversedVersion),
Builder.getInt32(CfgChecksum));
for (unsigned j = 0, e = CountersBySP.size(); j != e; ++j) {
DISubprogram SP(CountersBySP[j].second);
uint32_t FuncChecksum = Funcs.empty() ? 0 : Funcs[j]->getFuncChecksum();
Builder.CreateCall5(
EmitFunction, Builder.getInt32(j),
Options.FunctionNamesInData ?
Builder.CreateGlobalStringPtr(getFunctionName(SP)) :
Constant::getNullValue(Builder.getInt8PtrTy()),
Builder.getInt32(FuncChecksum),
Builder.getInt8(Options.UseCfgChecksum),
Builder.getInt32(CfgChecksum));
GlobalVariable *GV = CountersBySP[j].first;
unsigned Arcs =
cast<ArrayType>(GV->getType()->getElementType())->getNumElements();
Builder.CreateCall2(EmitArcs,
Builder.getInt32(Arcs),
Builder.CreateConstGEP2_64(GV, 0, 0));
}
Builder.CreateCall(SummaryInfo);
Builder.CreateCall(EndFile);
}
}
Builder.CreateRetVoid();
return WriteoutF;
}
示例4: GetGVTypeString
static StringRef GetGVTypeString(const GlobalVariable &G) {
// Types of GlobalVariables are always pointer types.
Type *GType = G.getType()->getElementType();
// For now we support blacklisting struct types only.
if (StructType *SGType = dyn_cast<StructType>(GType)) {
if (!SGType->isLiteral())
return SGType->getName();
}
return "<unknown type>";
}
示例5: diCu
static std::unique_ptr<StructInfo> getCpuArchStructInfo(Module *module)
{
GlobalVariable *env = module->getGlobalVariable("cpuarchstruct_type_anchor", false);
assert(env);
assert(env->getType() && env->getType()->isPointerTy());
assert(env->getType()->getElementType() && env->getType()->getElementType()->isPointerTy());
PointerType *envDeref = dyn_cast<PointerType>(env->getType()->getElementType());
assert(envDeref && envDeref->getElementType() && envDeref->getElementType()->isStructTy());
StructType *structType = dyn_cast<StructType>(envDeref->getElementType());
assert(structType);
NamedMDNode *mdCuNodes = module->getNamedMetadata("llvm.dbg.cu");
if (!mdCuNodes) {
return nullptr;
}
std::shared_ptr<DITypeIdentifierMap> typeIdentifierMap(new DITypeIdentifierMap(generateDITypeIdentifierMap(mdCuNodes)));
DICompositeType *diStructType = nullptr;
for ( unsigned i = 0; i < mdCuNodes->getNumOperands() && !diStructType; ++i )
{
DICompileUnit diCu(mdCuNodes->getOperand(i));
for ( unsigned j = 0; j < diCu.getGlobalVariables().getNumElements(); ++j )
{
DIGlobalVariable diGlobalVar(diCu.getGlobalVariables().getElement(j));
if (diGlobalVar.getName() != "cpuarchstruct_type_anchor") {
continue;
}
assert(diGlobalVar.getType().isDerivedType());
DIDerivedType diEnvPtrType(diGlobalVar.getType());
assert(diEnvPtrType.getTypeDerivedFrom().resolve(*typeIdentifierMap).isCompositeType());
return std::unique_ptr<StructInfo>(new StructInfo(module, structType, new DICompositeType(diEnvPtrType.getTypeDerivedFrom().resolve(*typeIdentifierMap)), typeIdentifierMap));
}
}
llvm::errs() << "WARNING: Debug information for struct CPUArchState not found" << '\n';
return nullptr;
}
示例6: getIndexOfMember
// Retourne un objet value contenant un entier
Value* GlobalVariableGenerator::getIndexOfMember(Module *module, std::string name) {
LLVMContext &c = module->getContext();
Type *t;
GlobalVariable *g = module->getGlobalVariable(name);
t = Type::getInt32Ty(c)->getPointerTo();
if(g->getType() != t)
KawaUtilitary::stopGenerationIR(ERROR_UNKNOW_INDEX);
Value *v = new LoadInst(g);
return v;
}
示例7: runOnFunction
bool AMDGPUPromoteAlloca::runOnFunction(Function &F) {
const FunctionType *FTy = F.getFunctionType();
LocalMemAvailable = ST.getLocalMemorySize();
// If the function has any arguments in the local address space, then it's
// possible these arguments require the entire local memory space, so
// we cannot use local memory in the pass.
for (unsigned i = 0, e = FTy->getNumParams(); i != e; ++i) {
const Type *ParamTy = FTy->getParamType(i);
if (ParamTy->isPointerTy() &&
ParamTy->getPointerAddressSpace() == AMDGPUAS::LOCAL_ADDRESS) {
LocalMemAvailable = 0;
DEBUG(dbgs() << "Function has local memory argument. Promoting to "
"local memory disabled.\n");
break;
}
}
if (LocalMemAvailable > 0) {
// Check how much local memory is being used by global objects
for (Module::global_iterator I = Mod->global_begin(),
E = Mod->global_end(); I != E; ++I) {
GlobalVariable *GV = I;
PointerType *GVTy = GV->getType();
if (GVTy->getAddressSpace() != AMDGPUAS::LOCAL_ADDRESS)
continue;
for (Value::use_iterator U = GV->use_begin(),
UE = GV->use_end(); U != UE; ++U) {
Instruction *Use = dyn_cast<Instruction>(*U);
if (!Use)
continue;
if (Use->getParent()->getParent() == &F)
LocalMemAvailable -=
Mod->getDataLayout()->getTypeAllocSize(GVTy->getElementType());
}
}
}
LocalMemAvailable = std::max(0, LocalMemAvailable);
DEBUG(dbgs() << LocalMemAvailable << "bytes free in local memory.\n");
visit(F);
return false;
}
示例8: setGlobalVariableValue
static void setGlobalVariableValue(Module &M, const char *Name,
Constant *Value) {
GlobalVariable *Var = M.getNamedGlobal(Name);
if (!Var) {
// This warning can happen in a program that does not use a libc
// and does not initialize TLS variables. Such a program might be
// linked with "-nostdlib".
errs() << "Warning: Variable " << Name << " not referenced\n";
} else {
if (Var->hasInitializer()) {
report_fatal_error(std::string("Variable ") + Name +
" already has an initializer");
}
Var->replaceAllUsesWith(ConstantExpr::getBitCast(Value, Var->getType()));
Var->eraseFromParent();
}
}
示例9: runOnModule
bool RegisterGlobals::runOnModule(Module &M) {
TD = &getAnalysis<TargetData>();
VoidTy = Type::getVoidTy(M.getContext());
VoidPtrTy = Type::getInt8PtrTy(M.getContext());
SizeTy = IntegerType::getInt64Ty(M.getContext());
// Create the function prototype
M.getOrInsertFunction("__pool_register_global", VoidTy, VoidPtrTy, SizeTy,
NULL);
RegisterGlobalPoolFunction = M.getFunction("__pool_register_global");
// Create the function that will contain the registration calls
createRegistrationFunction(M);
Module::global_iterator GI = M.global_begin(), GE = M.global_end();
for ( ; GI != GE; ++GI) {
GlobalVariable *GV = GI;
// Skip globals without a size
if (!GV->getType()->getElementType()->isSized())
continue;
// Optionally avoid registering globals with uncertain size.
if (!RegUncertain) {
// Linking can change the size of declarations
if (GV->isDeclaration())
continue;
// Linking can't change the size of defined globals with eternal linkage.
// Linking can't change the size of globals with local linkage.
if (!GV->hasExternalLinkage() && !GV->hasLocalLinkage())
continue;
}
// Thread-local globals would have to be registered for each thread.
// FIXME: add support for thread-local globals
if (GV->isThreadLocal())
continue;
registerGlobal(GV);
}
return true;
}
示例10: if
Function *GCOVProfiler::
insertFlush(ArrayRef<std::pair<GlobalVariable*, MDNode*> > CountersBySP) {
FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
Function *FlushF = M->getFunction("__llvm_gcov_flush");
if (!FlushF)
FlushF = Function::Create(FTy, GlobalValue::InternalLinkage,
"__llvm_gcov_flush", M);
else
FlushF->setLinkage(GlobalValue::InternalLinkage);
FlushF->setUnnamedAddr(true);
FlushF->addFnAttr(Attribute::NoInline);
if (Options.NoRedZone)
FlushF->addFnAttr(Attribute::NoRedZone);
BasicBlock *Entry = BasicBlock::Create(*Ctx, "entry", FlushF);
// Write out the current counters.
Constant *WriteoutF = M->getFunction("__llvm_gcov_writeout");
assert(WriteoutF && "Need to create the writeout function first!");
IRBuilder<> Builder(Entry);
Builder.CreateCall(WriteoutF);
// Zero out the counters.
for (ArrayRef<std::pair<GlobalVariable *, MDNode *> >::iterator
I = CountersBySP.begin(), E = CountersBySP.end();
I != E; ++I) {
GlobalVariable *GV = I->first;
Constant *Null = Constant::getNullValue(GV->getType()->getElementType());
Builder.CreateStore(Null, GV);
}
Type *RetTy = FlushF->getReturnType();
if (RetTy == Type::getVoidTy(*Ctx))
Builder.CreateRetVoid();
else if (RetTy->isIntegerTy())
// Used if __llvm_gcov_flush was implicitly declared.
Builder.CreateRet(ConstantInt::get(RetTy, 0));
else
report_fatal_error("invalid return type for __llvm_gcov_flush");
return FlushF;
}
示例11: GlobalVariable
/// getOrInsertGlobal - Look up the specified global in the module symbol table.
/// 1. If it does not exist, add a declaration of the global and return it.
/// 2. Else, the global exists but has the wrong type: return the function
/// with a constantexpr cast to the right type.
/// 3. Finally, if the existing global is the correct delclaration, return the
/// existing global.
Constant *Module::getOrInsertGlobal(StringRef Name, Type *Ty) {
// See if we have a definition for the specified global already.
GlobalVariable *GV = dyn_cast_or_null<GlobalVariable>(getNamedValue(Name));
if (GV == 0) {
// Nope, add it
GlobalVariable *New =
new GlobalVariable(*this, Ty, false, GlobalVariable::ExternalLinkage,
0, Name);
return New; // Return the new declaration.
}
// If the variable exists but has the wrong type, return a bitcast to the
// right type.
if (GV->getType() != PointerType::getUnqual(Ty))
return ConstantExpr::getBitCast(GV, PointerType::getUnqual(Ty));
// Otherwise, we just found the existing function or a prototype.
return GV;
}
示例12: if
void GCOVProfiler::
insertFlush(ArrayRef<std::pair<GlobalVariable*, MDNode*> > CountersBySP) {
FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
Function *FlushF = M->getFunction("__llvm_gcov_flush");
if (!FlushF)
FlushF = Function::Create(FTy, GlobalValue::InternalLinkage,
"__llvm_gcov_flush", M);
else
FlushF->setLinkage(GlobalValue::InternalLinkage);
FlushF->setUnnamedAddr(true);
Type *Int8Ty = Type::getInt8Ty(*Ctx);
Type *Int64Ty = Type::getInt64Ty(*Ctx);
BasicBlock *Entry = BasicBlock::Create(*Ctx, "entry", FlushF);
// Write out the current counters.
Constant *WriteoutF = M->getFunction("__llvm_gcov_writeout");
assert(WriteoutF && "Need to create the writeout function first!");
IRBuilder<> Builder(Entry);
Builder.CreateCall(WriteoutF);
if (TD)
// Zero out the counters.
for (ArrayRef<std::pair<GlobalVariable *, MDNode *> >::iterator
I = CountersBySP.begin(), E = CountersBySP.end();
I != E; ++I) {
GlobalVariable *GV = I->first;
uint64_t NumBytes = TD->getTypeAllocSize(GV->getType()->getElementType());
Builder.CreateMemSet(Builder.CreateConstGEP2_64(GV, 0, 0),
ConstantInt::get(Int8Ty, 0),
ConstantInt::get(Int64Ty, NumBytes), false);
}
Type *RetTy = FlushF->getReturnType();
if (RetTy == Type::getVoidTy(*Ctx))
Builder.CreateRetVoid();
else if (RetTy->isIntegerTy())
// Used if __llvm_gcov_flush was implicitly declared.
Builder.CreateRet(ConstantInt::get(RetTy, 0));
else
report_fatal_error("invalid return type for __llvm_gcov_flush");
}
示例13: mapAppendingVariable
void Mapper::mapAppendingVariable(GlobalVariable &GV, Constant *InitPrefix,
bool IsOldCtorDtor,
ArrayRef<Constant *> NewMembers) {
SmallVector<Constant *, 16> Elements;
if (InitPrefix) {
unsigned NumElements =
cast<ArrayType>(InitPrefix->getType())->getNumElements();
for (unsigned I = 0; I != NumElements; ++I)
Elements.push_back(InitPrefix->getAggregateElement(I));
}
PointerType *VoidPtrTy;
Type *EltTy;
if (IsOldCtorDtor) {
// FIXME: This upgrade is done during linking to support the C API. See
// also IRLinker::linkAppendingVarProto() in IRMover.cpp.
VoidPtrTy = Type::getInt8Ty(GV.getContext())->getPointerTo();
auto &ST = *cast<StructType>(NewMembers.front()->getType());
Type *Tys[3] = {ST.getElementType(0), ST.getElementType(1), VoidPtrTy};
EltTy = StructType::get(GV.getContext(), Tys, false);
}
for (auto *V : NewMembers) {
Constant *NewV;
if (IsOldCtorDtor) {
auto *S = cast<ConstantStruct>(V);
auto *E1 = cast<Constant>(mapValue(S->getOperand(0)));
auto *E2 = cast<Constant>(mapValue(S->getOperand(1)));
Constant *Null = Constant::getNullValue(VoidPtrTy);
NewV = ConstantStruct::get(cast<StructType>(EltTy), E1, E2, Null);
} else {
NewV = cast_or_null<Constant>(mapValue(V));
}
Elements.push_back(NewV);
}
GV.setInitializer(ConstantArray::get(
cast<ArrayType>(GV.getType()->getElementType()), Elements));
}
示例14: InsertProfilingShutdownCall
void llvm::InsertProfilingShutdownCall(Function *Callee, Module *Mod) {
// llvm.global_dtors is an array of type { i32, void ()* }. Prepare those
// types.
Type *GlobalDtorElems[2] = {
Type::getInt32Ty(Mod->getContext()),
FunctionType::get(Type::getVoidTy(Mod->getContext()), false)->getPointerTo()
};
StructType *GlobalDtorElemTy =
StructType::get(Mod->getContext(), GlobalDtorElems, false);
// Construct the new element we'll be adding.
Constant *Elem[2] = {
ConstantInt::get(Type::getInt32Ty(Mod->getContext()), 65535),
ConstantExpr::getBitCast(Callee, GlobalDtorElems[1])
};
// If llvm.global_dtors exists, make a copy of the things in its list and
// delete it, to replace it with one that has a larger array type.
std::vector<Constant *> dtors;
if (GlobalVariable *GlobalDtors = Mod->getNamedGlobal("llvm.global_dtors")) {
if (ConstantArray *InitList =
dyn_cast<ConstantArray>(GlobalDtors->getInitializer())) {
for (unsigned i = 0, e = InitList->getType()->getNumElements();
i != e; ++i)
dtors.push_back(cast<Constant>(InitList->getOperand(i)));
}
GlobalDtors->eraseFromParent();
}
// Build up llvm.global_dtors with our new item in it.
GlobalVariable *GlobalDtors = new GlobalVariable(
*Mod, ArrayType::get(GlobalDtorElemTy, 1), false,
GlobalValue::AppendingLinkage, NULL, "llvm.global_dtors");
dtors.push_back(ConstantStruct::get(GlobalDtorElemTy, Elem));
GlobalDtors->setInitializer(ConstantArray::get(
cast<ArrayType>(GlobalDtors->getType()->getElementType()), dtors));
}
示例15: objectAnalysis
void PointerAnalysis::objectAnalysis()
{
llvm::DataLayout DL(module);
for (auto &globalVal: module->globals()) {
GlobalVariable *gv = dyn_cast<GlobalVariable>(&globalVal);
Type *gvt = gv->getType();
assert(gvt->isPointerTy());
globals.insert(gv);
globalBounds[gv] = sizeOf(gvt->getContainedType(0), DL);
}
Function *mainfp = module->getFunction("main");
if (mainfp == nullptr)
return;
ArgumentAttributes args( mainfp->arg_size() );
for (size_t i = 0; i < mainfp->arg_size(); i++) {
args[i] = UNBOUND_ATTR;
}
objectPass(mainfp, args);
}
开发者ID:cwz920716,项目名称:Combining-Static-and-Dynamic-Bound-Checking-Using-LLVM-Framework-and-SoftBound,代码行数:23,代码来源:PointerAnalysis.cpp