本文整理汇总了C++中ExtractValueInst::getNumIndices方法的典型用法代码示例。如果您正苦于以下问题:C++ ExtractValueInst::getNumIndices方法的具体用法?C++ ExtractValueInst::getNumIndices怎么用?C++ ExtractValueInst::getNumIndices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExtractValueInst
的用法示例。
在下文中一共展示了ExtractValueInst::getNumIndices方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: substituteLPadValues
/// substituteLPadValues - Substitute the values returned by the landingpad
/// instruction with those returned by the personality function.
void SjLjEHPrepare::substituteLPadValues(LandingPadInst *LPI, Value *ExnVal,
Value *SelVal) {
SmallVector<Value *, 8> UseWorkList(LPI->user_begin(), LPI->user_end());
while (!UseWorkList.empty()) {
Value *Val = UseWorkList.pop_back_val();
ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(Val);
if (!EVI)
continue;
if (EVI->getNumIndices() != 1)
continue;
if (*EVI->idx_begin() == 0)
EVI->replaceAllUsesWith(ExnVal);
else if (*EVI->idx_begin() == 1)
EVI->replaceAllUsesWith(SelVal);
if (EVI->getNumUses() == 0)
EVI->eraseFromParent();
}
if (LPI->getNumUses() == 0)
return;
// There are still some uses of LPI. Construct an aggregate with the exception
// values and replace the LPI with that aggregate.
Type *LPadType = LPI->getType();
Value *LPadVal = UndefValue::get(LPadType);
auto *SelI = cast<Instruction>(SelVal);
IRBuilder<> Builder(SelI->getParent(), std::next(SelI->getIterator()));
LPadVal = Builder.CreateInsertValue(LPadVal, ExnVal, 0, "lpad.val");
LPadVal = Builder.CreateInsertValue(LPadVal, SelVal, 1, "lpad.val");
LPI->replaceAllUsesWith(LPadVal);
}
示例2: expandAtomicCmpXchg
//.........这里部分代码省略.........
auto FailureBB = BasicBlock::Create(Ctx, "cmpxchg.failure", F, ExitBB);
auto NoStoreBB = BasicBlock::Create(Ctx, "cmpxchg.nostore", F, FailureBB);
auto SuccessBB = BasicBlock::Create(Ctx, "cmpxchg.success", F, NoStoreBB);
auto TryStoreBB = BasicBlock::Create(Ctx, "cmpxchg.trystore", F, SuccessBB);
auto LoopBB = BasicBlock::Create(Ctx, "cmpxchg.start", F, TryStoreBB);
// This grabs the DebugLoc from CI
IRBuilder<> Builder(CI);
// The split call above "helpfully" added a branch at the end of BB (to the
// wrong place), but we might want a fence too. It's easiest to just remove
// the branch entirely.
std::prev(BB->end())->eraseFromParent();
Builder.SetInsertPoint(BB);
TLI->emitLeadingFence(Builder, SuccessOrder, /*IsStore=*/true,
/*IsLoad=*/true);
Builder.CreateBr(LoopBB);
// Start the main loop block now that we've taken care of the preliminaries.
Builder.SetInsertPoint(LoopBB);
Value *Loaded = TLI->emitLoadLinked(Builder, Addr, MemOpOrder);
Value *ShouldStore =
Builder.CreateICmpEQ(Loaded, CI->getCompareOperand(), "should_store");
// If the cmpxchg doesn't actually need any ordering when it fails, we can
// jump straight past that fence instruction (if it exists).
Builder.CreateCondBr(ShouldStore, TryStoreBB, NoStoreBB);
Builder.SetInsertPoint(TryStoreBB);
Value *StoreSuccess = TLI->emitStoreConditional(
Builder, CI->getNewValOperand(), Addr, MemOpOrder);
StoreSuccess = Builder.CreateICmpEQ(
StoreSuccess, ConstantInt::get(Type::getInt32Ty(Ctx), 0), "success");
Builder.CreateCondBr(StoreSuccess, SuccessBB,
CI->isWeak() ? FailureBB : LoopBB);
// Make sure later instructions don't get reordered with a fence if necessary.
Builder.SetInsertPoint(SuccessBB);
TLI->emitTrailingFence(Builder, SuccessOrder, /*IsStore=*/true,
/*IsLoad=*/true);
Builder.CreateBr(ExitBB);
Builder.SetInsertPoint(NoStoreBB);
// In the failing case, where we don't execute the store-conditional, the
// target might want to balance out the load-linked with a dedicated
// instruction (e.g., on ARM, clearing the exclusive monitor).
TLI->emitAtomicCmpXchgNoStoreLLBalance(Builder);
Builder.CreateBr(FailureBB);
Builder.SetInsertPoint(FailureBB);
TLI->emitTrailingFence(Builder, FailureOrder, /*IsStore=*/true,
/*IsLoad=*/true);
Builder.CreateBr(ExitBB);
// Finally, we have control-flow based knowledge of whether the cmpxchg
// succeeded or not. We expose this to later passes by converting any
// subsequent "icmp eq/ne %loaded, %oldval" into a use of an appropriate PHI.
// Setup the builder so we can create any PHIs we need.
Builder.SetInsertPoint(ExitBB, ExitBB->begin());
PHINode *Success = Builder.CreatePHI(Type::getInt1Ty(Ctx), 2);
Success->addIncoming(ConstantInt::getTrue(Ctx), SuccessBB);
Success->addIncoming(ConstantInt::getFalse(Ctx), FailureBB);
// Look for any users of the cmpxchg that are just comparing the loaded value
// against the desired one, and replace them with the CFG-derived version.
SmallVector<ExtractValueInst *, 2> PrunedInsts;
for (auto User : CI->users()) {
ExtractValueInst *EV = dyn_cast<ExtractValueInst>(User);
if (!EV)
continue;
assert(EV->getNumIndices() == 1 && EV->getIndices()[0] <= 1 &&
"weird extraction from { iN, i1 }");
if (EV->getIndices()[0] == 0)
EV->replaceAllUsesWith(Loaded);
else
EV->replaceAllUsesWith(Success);
PrunedInsts.push_back(EV);
}
// We can remove the instructions now we're no longer iterating through them.
for (auto EV : PrunedInsts)
EV->eraseFromParent();
if (!CI->use_empty()) {
// Some use of the full struct return that we don't understand has happened,
// so we've got to reconstruct it properly.
Value *Res;
Res = Builder.CreateInsertValue(UndefValue::get(CI->getType()), Loaded, 0);
Res = Builder.CreateInsertValue(Res, Success, 1);
CI->replaceAllUsesWith(Res);
}
CI->eraseFromParent();
return true;
}
示例3: 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 SimplifyEV::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;) {
ExtractValueInst *EV = dyn_cast<ExtractValueInst>(I++);
if(!EV)
continue;
Value *Agg = EV->getAggregateOperand();
if (!EV->hasIndices()) {
EV->replaceAllUsesWith(Agg);
DEBUG(errs() << "EV:");
DEBUG(errs() << "ERASE:");
DEBUG(EV->dump());
EV->eraseFromParent();
numErased++;
changed = true;
continue;
}
if (Constant *C = dyn_cast<Constant>(Agg)) {
if (isa<UndefValue>(C)) {
EV->replaceAllUsesWith(UndefValue::get(EV->getType()));
DEBUG(errs() << "EV:");
DEBUG(errs() << "ERASE:");
DEBUG(EV->dump());
EV->eraseFromParent();
numErased++;
changed = true;
continue;
}
if (isa<ConstantAggregateZero>(C)) {
EV->replaceAllUsesWith(Constant::getNullValue(EV->getType()));
DEBUG(errs() << "EV:");
DEBUG(errs() << "ERASE:");
DEBUG(EV->dump());
EV->eraseFromParent();
numErased++;
changed = true;
continue;
}
if (isa<ConstantArray>(C) || isa<ConstantStruct>(C)) {
// Extract the element indexed by the first index out of the constant
Value *V = C->getOperand(*EV->idx_begin());
if (EV->getNumIndices() > 1) {
// Extract the remaining indices out of the constant indexed by the
// first index
ExtractValueInst *EV_new = ExtractValueInst::Create(V,
EV->getIndices().slice(1),
"", EV);
EV->replaceAllUsesWith(EV_new);
DEBUG(errs() << "EV:");
DEBUG(errs() << "ERASE:");
DEBUG(EV->dump());
EV->eraseFromParent();
numErased++;
changed = true;
continue;
} else {
EV->replaceAllUsesWith(V);
DEBUG(errs() << "EV:");
DEBUG(errs() << "ERASE:");
DEBUG(EV->dump());
EV->eraseFromParent();
numErased++;
changed = true;
continue;
}
}
continue;
}
if (LoadInst * LI = dyn_cast<LoadInst>(Agg)) {
// if the Agg value came from a load instruction
// replace the extract value intruction with
// a gep and a load.
SmallVector<Value*, 8> Indices;
Type *Int32Ty = Type::getInt32Ty(M.getContext());
Indices.push_back(Constant::getNullValue(Int32Ty));
for (ExtractValueInst::idx_iterator I = EV->idx_begin(), E = EV->idx_end();
I != E; ++I) {
Indices.push_back(ConstantInt::get(Int32Ty, *I));
//.........这里部分代码省略.........