本文整理汇总了C++中LoadInst::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ LoadInst::getType方法的具体用法?C++ LoadInst::getType怎么用?C++ LoadInst::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoadInst
的用法示例。
在下文中一共展示了LoadInst::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
/// RewriteSingleStoreAlloca - If there is only a single store to this value,
/// replace any loads of it that are directly dominated by the definition with
/// the value stored.
void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
AllocaInfo &Info,
LargeBlockInfo &LBI) {
StoreInst *OnlyStore = Info.OnlyStore;
bool StoringGlobalVal = !isa<Instruction>(OnlyStore->getOperand(0));
BasicBlock *StoreBB = OnlyStore->getParent();
int StoreIndex = -1;
// Clear out UsingBlocks. We will reconstruct it here if needed.
Info.UsingBlocks.clear();
for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E; ) {
Instruction *UserInst = cast<Instruction>(*UI++);
if (!isa<LoadInst>(UserInst)) {
assert(UserInst == OnlyStore && "Should only have load/stores");
continue;
}
LoadInst *LI = cast<LoadInst>(UserInst);
// Okay, if we have a load from the alloca, we want to replace it with the
// only value stored to the alloca. We can do this if the value is
// dominated by the store. If not, we use the rest of the mem2reg machinery
// to insert the phi nodes as needed.
if (!StoringGlobalVal) { // Non-instructions are always dominated.
if (LI->getParent() == StoreBB) {
// If we have a use that is in the same block as the store, compare the
// indices of the two instructions to see which one came first. If the
// load came before the store, we can't handle it.
if (StoreIndex == -1)
StoreIndex = LBI.getInstructionIndex(OnlyStore);
if (unsigned(StoreIndex) > LBI.getInstructionIndex(LI)) {
// Can't handle this load, bail out.
Info.UsingBlocks.push_back(StoreBB);
continue;
}
} else if (LI->getParent() != StoreBB &&
!dominates(StoreBB, LI->getParent())) {
// If the load and store are in different blocks, use BB dominance to
// check their relationships. If the store doesn't dom the use, bail
// out.
Info.UsingBlocks.push_back(LI->getParent());
continue;
}
}
// Otherwise, we *can* safely rewrite this load.
Value *ReplVal = OnlyStore->getOperand(0);
// If the replacement value is the load, this must occur in unreachable
// code.
if (ReplVal == LI)
ReplVal = UndefValue::get(LI->getType());
LI->replaceAllUsesWith(ReplVal);
if (AST && LI->getType()->isPointerTy())
AST->deleteValue(LI);
LI->eraseFromParent();
LBI.deleteValue(LI);
}
}
示例2: MoveExtToFormExtLoad
/// MoveExtToFormExtLoad - Move a zext or sext fed by a load into the same
/// basic block as the load, unless conditions are unfavorable. This allows
/// SelectionDAG to fold the extend into the load.
///
bool CodeGenPrepare::MoveExtToFormExtLoad(Instruction *I) {
// Look for a load being extended.
LoadInst *LI = dyn_cast<LoadInst>(I->getOperand(0));
if (!LI) return false;
// If they're already in the same block, there's nothing to do.
if (LI->getParent() == I->getParent())
return false;
// If the load has other users and the truncate is not free, this probably
// isn't worthwhile.
if (!LI->hasOneUse() &&
TLI && (TLI->isTypeLegal(TLI->getValueType(LI->getType())) ||
!TLI->isTypeLegal(TLI->getValueType(I->getType()))) &&
!TLI->isTruncateFree(I->getType(), LI->getType()))
return false;
// Check whether the target supports casts folded into loads.
unsigned LType;
if (isa<ZExtInst>(I))
LType = ISD::ZEXTLOAD;
else {
assert(isa<SExtInst>(I) && "Unexpected ext type!");
LType = ISD::SEXTLOAD;
}
if (TLI && !TLI->isLoadExtLegal(LType, TLI->getValueType(LI->getType())))
return false;
// Move the extend into the same block as the load, so that SelectionDAG
// can fold it.
I->removeFromParent();
I->insertAfter(LI);
++NumExtsMoved;
return true;
}
示例3: visitLoadInst
void GraphBuilder::visitLoadInst(LoadInst &LI) {
//
// Create a DSNode for the pointer dereferenced by the load. If the DSNode
// is NULL, do nothing more (this can occur if the load is loading from a
// NULL pointer constant (bugpoint can generate such code).
//
DSNodeHandle Ptr = getValueDest(LI.getPointerOperand());
if (Ptr.isNull()) return; // Load from null
// Make that the node is read from...
Ptr.getNode()->setReadMarker();
// Ensure a typerecord exists...
Ptr.getNode()->growSizeForType(LI.getType(), Ptr.getOffset());
if (isa<PointerType>(LI.getType()))
setDestTo(LI, getLink(Ptr));
// check that it is the inserted value
if(TypeInferenceOptimize)
if(LI.hasOneUse())
if(StoreInst *SI = dyn_cast<StoreInst>(*(LI.use_begin())))
if(SI->getOperand(0) == &LI) {
++NumIgnoredInst;
return;
}
Ptr.getNode()->mergeTypeInfo(LI.getType(), Ptr.getOffset());
}
示例4: runOnModule
//
// Method: runOnModule()
//
// Description:
// Entry point for this LLVM pass. Search for insert/extractvalue instructions
// that can be simplified.
//
// 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 SimplifyLoad::runOnModule(Module& M) {
// Repeat till no change
bool changed;
do {
changed = false;
for (Module::iterator F = M.begin(); F != M.end(); ++F) {
for (Function::iterator B = F->begin(), FE = F->end(); B != FE; ++B) {
for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE;) {
LoadInst *LI = dyn_cast<LoadInst>(I++);
if(!LI)
continue;
if(LI->hasOneUse()) {
if(CastInst *CI = dyn_cast<CastInst>(*(LI->use_begin()))) {
if(LI->getType()->isPointerTy()) {
if(ConstantExpr *CE = dyn_cast<ConstantExpr>(LI->getOperand(0))) {
if(const PointerType *PTy = dyn_cast<PointerType>(CE->getOperand(0)->getType()))
if(PTy->getElementType() == CI->getType()) {
LoadInst *LINew = new LoadInst(CE->getOperand(0), "", LI);
CI->replaceAllUsesWith(LINew);
}
}
}
}
}
}
}
}
} while(changed);
return (numErased > 0);
}
示例5: visitLoadInst
void InstrumentMemoryAccesses::visitLoadInst(LoadInst &LI) {
// Instrument a load instruction with a load check.
Value *AccessSize = ConstantInt::get(SizeTy,
TD->getTypeStoreSize(LI.getType()));
instrument(LI.getPointerOperand(), AccessSize, LoadCheckFunction, LI);
++LoadsInstrumented;
}
示例6: visitLoadInst
void Interpreter::visitLoadInst(LoadInst &I) {
ExecutionContext &SF = ECStack.back();
GenericValue SRC = getOperandValue(I.getPointerOperand(), SF);
GenericValue *Ptr = (GenericValue*)GVTOP(SRC);
GenericValue Result = LoadValueFromMemory(Ptr, I.getType());
SetValue(&I, Result, SF);
}
示例7: unpack_struct
void Closure::unpack_struct(Scope<Value *> &dst,
llvm::Type *
#if LLVM_VERSION >= 37
type
#endif
,
Value *src,
IRBuilder<> *builder) {
// type, type of src should be a pointer to a struct of the type returned by build_type
int idx = 0;
LLVMContext &context = builder->getContext();
vector<string> nm = names();
for (size_t i = 0; i < nm.size(); i++) {
#if LLVM_VERSION >= 37
Value *ptr = builder->CreateConstInBoundsGEP2_32(type, src, 0, idx++);
#else
Value *ptr = builder->CreateConstInBoundsGEP2_32(src, 0, idx++);
#endif
LoadInst *load = builder->CreateLoad(ptr);
if (load->getType()->isPointerTy()) {
// Give it a unique type so that tbaa tells llvm that this can't alias anything
LLVMMDNodeArgumentType md_args[] = {MDString::get(context, nm[i])};
load->setMetadata("tbaa", MDNode::get(context, md_args));
}
dst.push(nm[i], load);
load->setName(nm[i]);
}
}
示例8: visitLoadInst
bool AMDGPUCodeGenPrepare::visitLoadInst(LoadInst &I) {
if (!WidenLoads)
return false;
if ((I.getPointerAddressSpace() == AMDGPUASI.CONSTANT_ADDRESS ||
I.getPointerAddressSpace() == AMDGPUASI.CONSTANT_ADDRESS_32BIT) &&
canWidenScalarExtLoad(I)) {
IRBuilder<> Builder(&I);
Builder.SetCurrentDebugLocation(I.getDebugLoc());
Type *I32Ty = Builder.getInt32Ty();
Type *PT = PointerType::get(I32Ty, I.getPointerAddressSpace());
Value *BitCast= Builder.CreateBitCast(I.getPointerOperand(), PT);
LoadInst *WidenLoad = Builder.CreateLoad(BitCast);
WidenLoad->copyMetadata(I);
// If we have range metadata, we need to convert the type, and not make
// assumptions about the high bits.
if (auto *Range = WidenLoad->getMetadata(LLVMContext::MD_range)) {
ConstantInt *Lower =
mdconst::extract<ConstantInt>(Range->getOperand(0));
if (Lower->getValue().isNullValue()) {
WidenLoad->setMetadata(LLVMContext::MD_range, nullptr);
} else {
Metadata *LowAndHigh[] = {
ConstantAsMetadata::get(ConstantInt::get(I32Ty, Lower->getValue().zext(32))),
// Don't make assumptions about the high bits.
ConstantAsMetadata::get(ConstantInt::get(I32Ty, 0))
};
WidenLoad->setMetadata(LLVMContext::MD_range,
MDNode::get(Mod->getContext(), LowAndHigh));
}
}
int TySize = Mod->getDataLayout().getTypeSizeInBits(I.getType());
Type *IntNTy = Builder.getIntNTy(TySize);
Value *ValTrunc = Builder.CreateTrunc(WidenLoad, IntNTy);
Value *ValOrig = Builder.CreateBitCast(ValTrunc, I.getType());
I.replaceAllUsesWith(ValOrig);
I.eraseFromParent();
return true;
}
return false;
}
示例9: visitLoadInst
void PropagateJuliaAddrspaces::visitLoadInst(LoadInst &LI) {
unsigned AS = LI.getPointerAddressSpace();
if (!isSpecialAS(AS))
return;
Value *Replacement = LiftPointer(LI.getPointerOperand(), LI.getType(), &LI);
if (!Replacement)
return;
LI.setOperand(LoadInst::getPointerOperandIndex(), Replacement);
}
示例10: canWidenScalarExtLoad
bool AMDGPUCodeGenPrepare::canWidenScalarExtLoad(LoadInst &I) const {
Type *Ty = I.getType();
const DataLayout &DL = Mod->getDataLayout();
int TySize = DL.getTypeSizeInBits(Ty);
unsigned Align = I.getAlignment() ?
I.getAlignment() : DL.getABITypeAlignment(Ty);
return I.isSimple() && TySize < 32 && Align >= 4 && DA->isUniform(&I);
}
示例11: insertLoadInstCheck
void LLSTDebuggingPass::insertLoadInstCheck(Function& F)
{
Value* BrokenPointerMessage = m_builder->CreateGlobalStringPtr("\npointer is broken\n");
InstructionVector Loads;
for (Function::iterator BB = F.begin(); BB != F.end(); ++BB)
{
for(BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II)
{
if (LoadInst* Load = dyn_cast<LoadInst>(II)) {
Loads.push_back(Load);
}
}
}
for(std::size_t i = 0; i < Loads.size(); i++)
{
LoadInst* Load = dyn_cast<LoadInst>(Loads[i]);
if (belongsToSmalltalkType( Load->getType() )) {
//split BB right after load inst. The new BB contains code that will be executed if pointer is OK
BasicBlock* PointerIsOkBB = Load->getParent()->splitBasicBlock(++( static_cast<BasicBlock::iterator>(Load) ));
BasicBlock* PointerIsBrokenBB = BasicBlock::Create(m_module->getContext(), "", &F, PointerIsOkBB);
BasicBlock* PointerIsNotSmallIntBB = BasicBlock::Create(m_module->getContext(), "", &F, PointerIsBrokenBB);
Instruction* branchToPointerIsOkBB = ++( static_cast<BasicBlock::iterator>(Load) );
//branchToPointerIsOkBB is created by splitBasicBlock() just after load inst
//We force builder to insert instructions before branchToPointerIsOkBB
m_builder->SetInsertPoint(branchToPointerIsOkBB);
//If pointer to class is null, jump to PointerIsBroken, otherwise to PointerIsOkBB
Value* objectPtr = m_builder->CreateBitCast( Load, m_baseTypes.object->getPointerTo());
Value* isSmallInt = m_builder->CreateCall(isSmallInteger, objectPtr);
m_builder->CreateCondBr(isSmallInt, PointerIsOkBB, PointerIsNotSmallIntBB);
m_builder->SetInsertPoint(PointerIsNotSmallIntBB);
Value* klassPtr = m_builder->CreateCall(getObjectClass, objectPtr);
Value* pointerIsNull = m_builder->CreateICmpEQ(klassPtr, ConstantPointerNull::get(m_baseTypes.klass->getPointerTo()) );
m_builder->CreateCondBr(pointerIsNull, PointerIsBrokenBB, PointerIsOkBB);
branchToPointerIsOkBB->eraseFromParent(); //We don't need it anymore
m_builder->SetInsertPoint(PointerIsBrokenBB);
m_builder->CreateCall(_printf, BrokenPointerMessage);
m_builder->CreateBr(PointerIsOkBB);
}
}
}
示例12: visitLoadInst
void GCInvariantVerifier::visitLoadInst(LoadInst &LI) {
Type *Ty = LI.getType();
if (Ty->isPointerTy()) {
unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
Check(AS != AddressSpace::CalleeRooted &&
AS != AddressSpace::Derived,
"Illegal load of gc relevant value", &LI);
}
Ty = LI.getPointerOperand()->getType();
if (Ty->isPointerTy()) {
unsigned AS = cast<PointerType>(Ty)->getAddressSpace();
Check(AS != AddressSpace::CalleeRooted,
"Illegal store of callee rooted value", &LI);
}
}
示例13: translateLoad
bool IRTranslator::translateLoad(const LoadInst &LI) {
assert(LI.isSimple() && "only simple loads are supported at the moment");
MachineFunction &MF = MIRBuilder.getMF();
unsigned Res = getOrCreateVReg(LI);
unsigned Addr = getOrCreateVReg(*LI.getPointerOperand());
LLT VTy{*LI.getType()}, PTy{*LI.getPointerOperand()->getType()};
MIRBuilder.buildLoad(
VTy, PTy, Res, Addr,
*MF.getMachineMemOperand(MachinePointerInfo(LI.getPointerOperand()),
MachineMemOperand::MOLoad,
VTy.getSizeInBits() / 8, getMemOpAlignment(LI)));
return true;
}
示例14: visitLoadInst
void ArrayIndexChecker::visitLoadInst(LoadInst& I) {
DEBUG(dbgs() << "ArrayIndexChecker: visiting load " << I << "\n");
visitValue(*I.getPointerOperand());
if (I.getType()->isPointerTy()) {
auto pos = std::find(ptr_value_vec_.begin(), ptr_value_vec_.end(), &I);
assert(pos != ptr_value_vec_.end());
index_t varIdx = pos - ptr_value_vec_.begin();
assert(idx2addr_.find(varIdx) != idx2addr_.end());
if (addr2version_[idx2addr_[varIdx]] != 0)
throw ArrayIndexIsNotConstant;
}
DEBUG(dbgs() << "ArrayIndexChecker: visited load\n");
}
示例15: visitLoadInst
void TracingNoGiri::visitLoadInst(LoadInst &LI) {
instrumentLock(&LI);
// Get the ID of the load instruction.
Value *LoadID = ConstantInt::get(Int32Type, lsNumPass->getID(&LI));
// Cast the pointer into a void pointer type.
Value *Pointer = LI.getPointerOperand();
Pointer = castTo(Pointer, VoidPtrType, Pointer->getName(), &LI);
// Get the size of the loaded data.
uint64_t size = TD->getTypeStoreSize(LI.getType());
Value *LoadSize = ConstantInt::get(Int64Type, size);
// Create the call to the run-time to record the load instruction.
std::vector<Value *> args=make_vector<Value *>(LoadID, Pointer, LoadSize, 0);
CallInst::Create(RecordLoad, args, "", &LI);
instrumentUnlock(&LI);
++NumLoads; // Update statistics
}