本文整理汇总了C++中TargetData类的典型用法代码示例。如果您正苦于以下问题:C++ TargetData类的具体用法?C++ TargetData怎么用?C++ TargetData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TargetData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: Target
void
nest::TargetTable::add_target( const thread tid,
const thread target_rank,
const TargetData& target_data )
{
const index lid = target_data.get_source_lid();
vector_util::grow( targets_[ tid ][ lid ] );
if ( target_data.is_primary() )
{
const TargetDataFields& target_fields = target_data.target_data;
targets_[ tid ][ lid ].push_back( Target( target_fields.get_tid(),
target_rank,
target_fields.get_syn_id(),
target_fields.get_lcid() ) );
}
else
{
const SecondaryTargetDataFields& secondary_fields =
target_data.secondary_data;
const size_t send_buffer_pos = secondary_fields.get_send_buffer_pos();
const synindex syn_id = secondary_fields.get_syn_id();
assert( syn_id < secondary_send_buffer_pos_[ tid ][ lid ].size() );
secondary_send_buffer_pos_[ tid ][ lid ][ syn_id ].push_back(
send_buffer_pos );
}
}
开发者ID:apeyser,项目名称:nest-simulator,代码行数:30,代码来源:target_table.cpp
示例2: QDialog
NewProjectDialog::NewProjectDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewProjectDialog)
{
ui->setupUi(this);
/* Getting the default directory from the application settings */
QSettings settings;
settings.beginGroup("NewProjectDialog");
ui->locationBox->setText(settings.value("defaultDir",
QDir::home().absolutePath())
.toString());
settings.endGroup();
/* Populating the target box */
TargetData targets;
for(int i = 0; i < targets.count(); i++)
{
ui->targetBox->insertItem(i, QIcon(), targets.name(i), targets.id(i));
}
targetChange(0);
/* Connecting the browse button and target box */
QObject::connect(ui->browseButton, SIGNAL(clicked()),
this, SLOT(browse()));
QObject::connect(ui->targetBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(targetChange(int)));
}
开发者ID:victor2002,项目名称:rockbox_victor_clipplus,代码行数:30,代码来源:newprojectdialog.cpp
示例3: qPrintable
// Write ViewPaneBlock keywords
bool UChromaSession::writeViewPaneBlock(LineParser& parser, ViewPane* pane)
{
parser.writeLineF(" %s '%s'\n", UChromaSession::viewKeyword(UChromaSession::ViewPaneBlockKeyword), qPrintable(pane->name()));
parser.writeLineF(" %s %s\n", UChromaSession::viewPaneKeyword(UChromaSession::AutoPositionTitlesKeyword), stringBool(pane->axes().autoPositionTitles()));
for (int axis=0; axis < 3; ++axis) writeAxisBlock(parser, pane->axes(), axis);
parser.writeLineF(" %s %i\n", UChromaSession::viewPaneKeyword(UChromaSession::BoundingBoxKeyword), pane->boundingBox());
parser.writeLineF(" %s %f\n", UChromaSession::viewPaneKeyword(UChromaSession::BoundingBoxPlaneYKeyword), pane->boundingBoxPlaneY());
parser.writeLineF(" %s %s\n", UChromaSession::viewPaneKeyword(UChromaSession::FlatLabelsKeyword), stringBool(pane->flatLabels()));
parser.writeLineF(" %s %i %i %i %i\n", UChromaSession::viewPaneKeyword(UChromaSession::GeometryKeyword), pane->bottomEdge(), pane->leftEdge(), pane->width(), pane->height());
parser.writeLineF(" %s %f\n", UChromaSession::viewPaneKeyword(UChromaSession::LabelPointSizeKeyword), pane->labelPointSize());
parser.writeLineF(" %s %f\n", UChromaSession::viewPaneKeyword(UChromaSession::TitlePointSizeKeyword), pane->titlePointSize());
Matrix mat = pane->viewRotation();
Vec3<double> trans = pane->viewTranslation();
parser.writeLineF(" %s %f %f %f\n", UChromaSession::viewPaneKeyword(UChromaSession::RotationXKeyword), mat[0], mat[1], mat[2]);
parser.writeLineF(" %s %f %f %f\n", UChromaSession::viewPaneKeyword(UChromaSession::RotationYKeyword), mat[4], mat[5], mat[6]);
parser.writeLineF(" %s %f %f %f\n", UChromaSession::viewPaneKeyword(UChromaSession::RotationZKeyword), mat[8], mat[9], mat[10]);
parser.writeLineF(" %s %f %f %f\n", UChromaSession::viewPaneKeyword(UChromaSession::TranslationKeyword), trans.x, trans.y, trans.z);
parser.writeLineF(" %s %s\n", UChromaSession::viewPaneKeyword(UChromaSession::PerspectiveKeyword), stringBool(pane->hasPerspective()));
parser.writeLineF(" %s '%s'\n", UChromaSession::viewPaneKeyword(UChromaSession::RoleKeyword), ViewPane::paneRole(pane->role()));
for (TargetData* target = pane->collectionTargets(); target != NULL; target = target->next)
{
if (!Collection::objectValid(target->collection(), "collection in UChromaSession::writeViewPaneBlock")) continue;
parser.writeLineF(" %s '%s'\n", UChromaSession::viewPaneKeyword(UChromaSession::RoleTargetCollectionKeyword), qPrintable(target->collection()->locator()));
}
for (RefListItem<ViewPane,bool>* ri = pane->paneTargets(); ri != NULL; ri = ri->next) parser.writeLineF(" %s '%s'\n", UChromaSession::viewPaneKeyword(UChromaSession::RoleTargetPaneKeyword), qPrintable(ri->item->name()));
parser.writeLineF(" %s %s\n", UChromaSession::viewPaneKeyword(UChromaSession::UseBestFlatViewKeyword), stringBool(pane->axes().useBestFlatView()));
parser.writeLineF(" %s '%s'\n", UChromaSession::viewPaneKeyword(UChromaSession::ViewTypeKeyword), ViewPane::viewType(pane->viewType()));
parser.writeLineF(" %s\n", UChromaSession::viewPaneKeyword(UChromaSession::EndViewPaneKeyword));
return true;
}
开发者ID:trisyoungs,项目名称:uchroma,代码行数:32,代码来源:save.cpp
示例4: GetOffsetFromIndex
static int64_t GetOffsetFromIndex(const GEPOperator *GEP, unsigned Idx,
bool &VariableIdxFound, const TargetData &TD) {
// Skip over the first indices.
gep_type_iterator GTI = gep_type_begin(GEP);
for (unsigned i = 1; i != Idx; ++i, ++GTI)
/*skip along*/;
// Compute the offset implied by the rest of the indices.
int64_t Offset = 0;
for (unsigned i = Idx, e = GEP->getNumOperands(); i != e; ++i, ++GTI) {
ConstantInt *OpC = dyn_cast<ConstantInt>(GEP->getOperand(i));
if (OpC == 0)
return VariableIdxFound = true;
if (OpC->isZero()) continue; // No offset.
// Handle struct indices, which add their field offset to the pointer.
if (StructType *STy = dyn_cast<StructType>(*GTI)) {
Offset += TD.getStructLayout(STy)->getElementOffset(OpC->getZExtValue());
continue;
}
// Otherwise, we have a sequential type like an array or vector. Multiply
// the index by the ElementSize.
uint64_t Size = TD.getTypeAllocSize(GTI.getIndexedType());
Offset += Size*OpC->getSExtValue();
}
return Offset;
}
开发者ID:darlinghq,项目名称:darling-llvmCore,代码行数:29,代码来源:MemCpyOptimizer.cpp
示例5: getTypeSize
static unsigned getTypeSize(TargetData &TD, Type *type) {
if (type->isFunctionTy()) /* it is not sized, weird */
return TD.getPointerSize();
if (!type->isSized())
return 100; /* FIXME */
if (StructType *ST = dyn_cast<StructType>(type))
return TD.getStructLayout(ST)->getSizeInBytes();
return TD.getTypeAllocSize(type);
}
开发者ID:stormspirit,项目名称:LLVMSlicer,代码行数:12,代码来源:Kleerer.cpp
示例6: IsConstantOffsetFromGlobal
/// IsConstantOffsetFromGlobal - If this constant is actually a constant offset
/// from a global, return the global and the constant. Because of
/// constantexprs, this function is recursive.
static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV,
int64_t &Offset, const TargetData &TD) {
// Trivial case, constant is the global.
if ((GV = dyn_cast<GlobalValue>(C))) {
Offset = 0;
return true;
}
// Otherwise, if this isn't a constant expr, bail out.
ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
if (!CE) return false;
// Look through ptr->int and ptr->ptr casts.
if (CE->getOpcode() == Instruction::PtrToInt ||
CE->getOpcode() == Instruction::BitCast)
return IsConstantOffsetFromGlobal(CE->getOperand(0), GV, Offset, TD);
// i32* getelementptr ([5 x i32]* @a, i32 0, i32 5)
if (CE->getOpcode() == Instruction::GetElementPtr) {
// Cannot compute this if the element type of the pointer is missing size
// info.
if (!cast<PointerType>(CE->getOperand(0)->getType())->getElementType()->isSized())
return false;
// If the base isn't a global+constant, we aren't either.
if (!IsConstantOffsetFromGlobal(CE->getOperand(0), GV, Offset, TD))
return false;
// Otherwise, add any offset that our operands provide.
gep_type_iterator GTI = gep_type_begin(CE);
for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i, ++GTI) {
ConstantInt *CI = dyn_cast<ConstantInt>(CE->getOperand(i));
if (!CI) return false; // Index isn't a simple constant?
if (CI->getZExtValue() == 0) continue; // Not adding anything.
if (const StructType *ST = dyn_cast<StructType>(*GTI)) {
// N = N + Offset
Offset += TD.getStructLayout(ST)->getElementOffset(CI->getZExtValue());
} else {
const SequentialType *SQT = cast<SequentialType>(*GTI);
Offset += TD.getTypeSize(SQT->getElementType())*CI->getSExtValue();
}
}
return true;
}
return false;
}
开发者ID:BackupTheBerlios,项目名称:iphone-binutils-svn,代码行数:51,代码来源:ConstantFolding.cpp
示例7: ComputeStructureFieldIndices
static void ComputeStructureFieldIndices(const Type *Ty, unsigned Offset,
std::vector<unsigned> &Idxs,
const TargetData &TD) {
if (Ty->isFirstClassType()) {
assert(Offset == 0 && "Illegal structure index!");
return;
}
if (const SequentialType *STy = dyn_cast<SequentialType>(Ty)) {
ComputeStructureFieldIndices(STy->getElementType(), Offset, Idxs, TD);
} else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
const StructLayout *SL = TD.getStructLayout(STy);
std::vector<uint64_t>::const_iterator SI =
std::upper_bound(SL->MemberOffsets.begin(), SL->MemberOffsets.end(),
Offset);
assert(SI != SL->MemberOffsets.begin() && "Offset not in structure type!");
--SI;
assert(*SI <= Offset && "upper_bound didn't work");
assert((SI == SL->MemberOffsets.begin() || *(SI-1) < Offset) &&
(SI+1 == SL->MemberOffsets.end() || *(SI+1) > Offset) &&
"Upper bound didn't work!");
Offset -= *SI; // Skip over the offset to this structure field.
unsigned Idx = SI - SL->MemberOffsets.begin();
assert(Idx < STy->getNumElements() && "Illegal structure index");
Idxs.push_back(Idx);
ComputeStructureFieldIndices(STy->getElementType(Idx), Offset, Idxs, TD);
} else {
assert(0 && "Unknown type to index into!");
}
}
开发者ID:brills,项目名称:pfpa,代码行数:31,代码来源:StructureFieldVisitor.cpp
示例8: isObjectSmallerThan
/// isObjectSmallerThan - Return true if we can prove that the object specified
/// by V is smaller than Size.
static bool isObjectSmallerThan(const Value *V, unsigned Size,
const TargetData &TD) {
const Type *AccessTy;
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
AccessTy = GV->getType()->getElementType();
} else if (const AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
if (!AI->isArrayAllocation())
AccessTy = AI->getType()->getElementType();
else
return false;
} else if (const CallInst* CI = extractMallocCall(V)) {
if (!isArrayMalloc(V, &TD))
// The size is the argument to the malloc call.
if (const ConstantInt* C = dyn_cast<ConstantInt>(CI->getOperand(1)))
return (C->getZExtValue() < Size);
return false;
} else if (const Argument *A = dyn_cast<Argument>(V)) {
if (A->hasByValAttr())
AccessTy = cast<PointerType>(A->getType())->getElementType();
else
return false;
} else {
return false;
}
if (AccessTy->isSized())
return TD.getTypeAllocSize(AccessTy) < Size;
return false;
}
开发者ID:aaasz,项目名称:SHP,代码行数:31,代码来源:BasicAliasAnalysis.cpp
示例9: getPointeeAlignment
/// getPointeeAlignment - Compute the minimum alignment of the value pointed
/// to by the given pointer.
static unsigned getPointeeAlignment(Value *V, const TargetData &TD) {
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
if (CE->getOpcode() == Instruction::BitCast ||
(CE->getOpcode() == Instruction::GetElementPtr &&
cast<GEPOperator>(CE)->hasAllZeroIndices()))
return getPointeeAlignment(CE->getOperand(0), TD);
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
if (!GV->isDeclaration())
return TD.getPreferredAlignment(GV);
if (PointerType *PT = dyn_cast<PointerType>(V->getType()))
return TD.getABITypeAlignment(PT->getElementType());
return 0;
}
开发者ID:Leon555,项目名称:Mac-src-essentials,代码行数:18,代码来源:InstCombineLoadStoreAlloca.cpp
示例10: getEntryAlignment
/// getEntryAlignment - Return the alignment of each entry in the jump table.
unsigned MachineJumpTableInfo::getEntryAlignment(const TargetData &TD) const {
// The alignment of a jump table entry is the alignment of int32 unless the
// entry is just the address of a block, in which case it is the pointer
// alignment.
switch (getEntryKind()) {
case MachineJumpTableInfo::EK_BlockAddress:
return TD.getPointerABIAlignment();
case MachineJumpTableInfo::EK_GPRel32BlockAddress:
case MachineJumpTableInfo::EK_LabelDifference32:
case MachineJumpTableInfo::EK_Custom32:
return TD.getABIIntegerTypeAlignment(32);
case MachineJumpTableInfo::EK_Inline:
return 1;
}
assert(0 && "Unknown jump table encoding!");
return ~0;
}
开发者ID:wodeaei,项目名称:VC-Project,代码行数:18,代码来源:MachineFunction.cpp
示例11: Kleerer
Kleerer(ModulePass &modPass, Module &M, TargetData &TD,
callgraph::Callgraph &CG) : modPass(modPass),
M(M), TD(TD), CG(CG), C(M.getContext()), intPtrTy(TD.getIntPtrType(C)),
done(false) {
voidPtrType = TypeBuilder<void *, false>::get(C);
intType = TypeBuilder<int, false>::get(C);
uintType = TypeBuilder<unsigned, false>::get(C);
}
开发者ID:stormspirit,项目名称:LLVMSlicer,代码行数:8,代码来源:Kleerer.cpp
示例12: MallocConvertibleToType
// Peephole Malloc instructions: we take a look at the use chain of the
// malloc instruction, and try to find out if the following conditions hold:
// 1. The malloc is of the form: 'malloc [sbyte], uint <constant>'
// 2. The only users of the malloc are cast & add instructions
// 3. Of the cast instructions, there is only one destination pointer type
// [RTy] where the size of the pointed to object is equal to the number
// of bytes allocated.
//
// If these conditions hold, we convert the malloc to allocate an [RTy]
// element. TODO: This comment is out of date WRT arrays
//
static bool MallocConvertibleToType(MallocInst *MI, const Type *Ty,
ValueTypeCache &CTMap,
const TargetData &TD) {
if (!isa<PointerType>(Ty)) return false; // Malloc always returns pointers
// Deal with the type to allocate, not the pointer type...
Ty = cast<PointerType>(Ty)->getElementType();
if (!Ty->isSized()) return false; // Can only alloc something with a size
// Analyze the number of bytes allocated...
ExprType Expr = ClassifyExpr(MI->getArraySize());
// Get information about the base datatype being allocated, before & after
int ReqTypeSize = TD.getTypeSize(Ty);
if (ReqTypeSize == 0) return false;
unsigned OldTypeSize = TD.getTypeSize(MI->getType()->getElementType());
// Must have a scale or offset to analyze it...
if (!Expr.Offset && !Expr.Scale && OldTypeSize == 1) return false;
// Get the offset and scale of the allocation...
int64_t OffsetVal = Expr.Offset ? getConstantValue(Expr.Offset) : 0;
int64_t ScaleVal = Expr.Scale ? getConstantValue(Expr.Scale) :(Expr.Var != 0);
// The old type might not be of unit size, take old size into consideration
// here...
int64_t Offset = OffsetVal * OldTypeSize;
int64_t Scale = ScaleVal * OldTypeSize;
// In order to be successful, both the scale and the offset must be a multiple
// of the requested data type's size.
//
if (Offset/ReqTypeSize*ReqTypeSize != Offset ||
Scale/ReqTypeSize*ReqTypeSize != Scale)
return false; // Nope.
return true;
}
开发者ID:chris-wood,项目名称:llvm-pgopre,代码行数:49,代码来源:ExprTypeConvert.cpp
示例13: targetChange
void NewProjectDialog::targetChange(int target)
{
TargetData targets;
if(targets.fm(target))
{
ui->fmsBox->setEnabled(true);
ui->rfmsBox->setEnabled(true);
}
else
{
ui->fmsBox->setChecked(false);
ui->rfmsBox->setChecked(false);
ui->fmsBox->setEnabled(false);
ui->rfmsBox->setEnabled(false);
}
if(targets.remoteDepth(target) == TargetData::None)
{
ui->rwpsBox->setChecked(false);
ui->rsbsBox->setChecked(false);
ui->rfmsBox->setChecked(false);
ui->rsbsBox->setEnabled(false);
ui->rwpsBox->setEnabled(false);
ui->rfmsBox->setEnabled(false);
}
else
{
ui->rsbsBox->setEnabled(true);
ui->rwpsBox->setEnabled(true);
if(targets.fm(target))
ui->rfmsBox->setEnabled(true);
}
}
开发者ID:victor2002,项目名称:rockbox_victor_clipplus,代码行数:37,代码来源:newprojectdialog.cpp
示例14: getEntrySize
/// getEntrySize - Return the size of each entry in the jump table.
unsigned MachineJumpTableInfo::getEntrySize(const TargetData &TD) const {
// The size of a jump table entry is 4 bytes unless the entry is just the
// address of a block, in which case it is the pointer size.
switch (getEntryKind()) {
case MachineJumpTableInfo::EK_BlockAddress:
return TD.getPointerSize();
case MachineJumpTableInfo::EK_GPRel32BlockAddress:
case MachineJumpTableInfo::EK_LabelDifference32:
case MachineJumpTableInfo::EK_Custom32:
return 4;
case MachineJumpTableInfo::EK_Inline:
return 0;
}
assert(0 && "Unknown jump table encoding!");
return ~0;
}
开发者ID:wodeaei,项目名称:VC-Project,代码行数:17,代码来源:MachineFunction.cpp
示例15: isObjectSmallerThan
/// isObjectSmallerThan - Return true if we can prove that the object specified
/// by V is smaller than Size.
static bool isObjectSmallerThan(const Value *V, unsigned Size,
const TargetData &TD) {
const Type *AccessTy;
if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
AccessTy = GV->getType()->getElementType();
} else if (const AllocationInst *AI = dyn_cast<AllocationInst>(V)) {
if (!AI->isArrayAllocation())
AccessTy = AI->getType()->getElementType();
else
return false;
} else if (const Argument *A = dyn_cast<Argument>(V)) {
if (A->hasByValAttr())
AccessTy = cast<PointerType>(A->getType())->getElementType();
else
return false;
} else {
return false;
}
if (AccessTy->isSized())
return TD.getTypePaddedSize(AccessTy) < Size;
return false;
}
开发者ID:chrislipa,项目名称:fractalstream,代码行数:25,代码来源:BasicAliasAnalysis.cpp
示例16: processByValArgument
/// processByValArgument - This is called on every byval argument in call sites.
bool MemCpyOpt::processByValArgument(CallSite CS, unsigned ArgNo) {
TargetData *TD = getAnalysisIfAvailable<TargetData>();
if (!TD) return false;
// Find out what feeds this byval argument.
Value *ByValArg = CS.getArgument(ArgNo);
const Type *ByValTy =cast<PointerType>(ByValArg->getType())->getElementType();
uint64_t ByValSize = TD->getTypeAllocSize(ByValTy);
MemDepResult DepInfo =
MD->getPointerDependencyFrom(AliasAnalysis::Location(ByValArg, ByValSize),
true, CS.getInstruction(),
CS.getInstruction()->getParent());
if (!DepInfo.isClobber())
return false;
// If the byval argument isn't fed by a memcpy, ignore it. If it is fed by
// a memcpy, see if we can byval from the source of the memcpy instead of the
// result.
MemCpyInst *MDep = dyn_cast<MemCpyInst>(DepInfo.getInst());
if (MDep == 0 || MDep->isVolatile() ||
ByValArg->stripPointerCasts() != MDep->getDest())
return false;
// The length of the memcpy must be larger or equal to the size of the byval.
ConstantInt *C1 = dyn_cast<ConstantInt>(MDep->getLength());
if (C1 == 0 || C1->getValue().getZExtValue() < ByValSize)
return false;
// Get the alignment of the byval. If it is greater than the memcpy, then we
// can't do the substitution. If the call doesn't specify the alignment, then
// it is some target specific value that we can't know.
unsigned ByValAlign = CS.getParamAlignment(ArgNo+1);
if (ByValAlign == 0 || MDep->getAlignment() < ByValAlign)
return false;
// Verify that the copied-from memory doesn't change in between the memcpy and
// the byval call.
// memcpy(a <- b)
// *b = 42;
// foo(*a)
// It would be invalid to transform the second memcpy into foo(*b).
//
// NOTE: This is conservative, it will stop on any read from the source loc,
// not just the defining memcpy.
MemDepResult SourceDep =
MD->getPointerDependencyFrom(AliasAnalysis::getLocationForSource(MDep),
false, CS.getInstruction(), MDep->getParent());
if (!SourceDep.isClobber() || SourceDep.getInst() != MDep)
return false;
Value *TmpCast = MDep->getSource();
if (MDep->getSource()->getType() != ByValArg->getType())
TmpCast = new BitCastInst(MDep->getSource(), ByValArg->getType(),
"tmpcast", CS.getInstruction());
DEBUG(dbgs() << "MemCpyOpt: Forwarding memcpy to byval:\n"
<< " " << *MDep << "\n"
<< " " << *CS.getInstruction() << "\n");
// Otherwise we're good! Update the byval argument.
CS.setArgument(ArgNo, TmpCast);
++NumMemCpyInstr;
return true;
}
开发者ID:dmlap,项目名称:llvm-js-backend,代码行数:65,代码来源:MemCpyOptimizer.cpp
示例17: AddConstant
void SVMBlockSizeAccumulator::AddConstant(const TargetData &TD,
const MachineConstantPoolEntry &CPE)
{
AddConstant(TD.getTypeAllocSize(CPE.getType()), CPE.getAlignment());
}
开发者ID:honnet,项目名称:thundercracker,代码行数:5,代码来源:SVMBlockSizeAccumulator.cpp
示例18: ExpressionConvertibleToType
// ExpressionConvertibleToType - Return true if it is possible
bool llvm::ExpressionConvertibleToType(Value *V, const Type *Ty,
ValueTypeCache &CTMap, const TargetData &TD) {
// Expression type must be holdable in a register.
if (!Ty->isFirstClassType())
return false;
ValueTypeCache::iterator CTMI = CTMap.find(V);
if (CTMI != CTMap.end()) return CTMI->second == Ty;
// If it's a constant... all constants can be converted to a different
// type.
//
if (isa<Constant>(V) && !isa<GlobalValue>(V))
return true;
CTMap[V] = Ty;
if (V->getType() == Ty) return true; // Expression already correct type!
Instruction *I = dyn_cast<Instruction>(V);
if (I == 0) return false; // Otherwise, we can't convert!
switch (I->getOpcode()) {
case Instruction::Cast:
// We can convert the expr if the cast destination type is losslessly
// convertible to the requested type.
if (!Ty->isLosslesslyConvertibleTo(I->getType())) return false;
// We also do not allow conversion of a cast that casts from a ptr to array
// of X to a *X. For example: cast [4 x %List *] * %val to %List * *
//
if (const PointerType *SPT =
dyn_cast<PointerType>(I->getOperand(0)->getType()))
if (const PointerType *DPT = dyn_cast<PointerType>(I->getType()))
if (const ArrayType *AT = dyn_cast<ArrayType>(SPT->getElementType()))
if (AT->getElementType() == DPT->getElementType())
return false;
break;
case Instruction::Add:
case Instruction::Sub:
if (!Ty->isInteger() && !Ty->isFloatingPoint()) return false;
if (!ExpressionConvertibleToType(I->getOperand(0), Ty, CTMap, TD) ||
!ExpressionConvertibleToType(I->getOperand(1), Ty, CTMap, TD))
return false;
break;
case Instruction::Shr:
if (!Ty->isInteger()) return false;
if (Ty->isSigned() != V->getType()->isSigned()) return false;
// FALL THROUGH
case Instruction::Shl:
if (!Ty->isInteger()) return false;
if (!ExpressionConvertibleToType(I->getOperand(0), Ty, CTMap, TD))
return false;
break;
case Instruction::Load: {
LoadInst *LI = cast<LoadInst>(I);
if (!ExpressionConvertibleToType(LI->getPointerOperand(),
PointerType::get(Ty), CTMap, TD))
return false;
break;
}
case Instruction::PHI: {
PHINode *PN = cast<PHINode>(I);
// Be conservative if we find a giant PHI node.
if (PN->getNumIncomingValues() > 32) return false;
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i)
if (!ExpressionConvertibleToType(PN->getIncomingValue(i), Ty, CTMap, TD))
return false;
break;
}
case Instruction::Malloc:
if (!MallocConvertibleToType(cast<MallocInst>(I), Ty, CTMap, TD))
return false;
break;
case Instruction::GetElementPtr: {
// GetElementPtr's are directly convertible to a pointer type if they have
// a number of zeros at the end. Because removing these values does not
// change the logical offset of the GEP, it is okay and fair to remove them.
// This can change this:
// %t1 = getelementptr %Hosp * %hosp, ubyte 4, ubyte 0 ; <%List **>
// %t2 = cast %List * * %t1 to %List *
// into
// %t2 = getelementptr %Hosp * %hosp, ubyte 4 ; <%List *>
//
GetElementPtrInst *GEP = cast<GetElementPtrInst>(I);
const PointerType *PTy = dyn_cast<PointerType>(Ty);
if (!PTy) return false; // GEP must always return a pointer...
const Type *PVTy = PTy->getElementType();
// Check to see if there are zero elements that we can remove from the
// index array. If there are, check to see if removing them causes us to
// get to the right type...
//
std::vector<Value*> Indices(GEP->idx_begin(), GEP->idx_end());
const Type *BaseType = GEP->getPointerOperand()->getType();
//.........这里部分代码省略.........
开发者ID:chris-wood,项目名称:llvm-pgopre,代码行数:101,代码来源:ExprTypeConvert.cpp
示例19: OperandConvertibleToType
// OperandConvertibleToType - Return true if it is possible to convert operand
// V of User (instruction) U to the specified type. This is true iff it is
// possible to change the specified instruction to accept this. CTMap is a map
// of converted types, so that circular definitions will see the future type of
// the expression, not the static current type.
//
static bool OperandConvertibleToType(User *U, Value *V, const Type *Ty,
ValueTypeCache &CTMap,
const TargetData &TD) {
// if (V->getType() == Ty) return true; // Operand already the right type?
// Expression type must be holdable in a register.
if (!Ty->isFirstClassType())
return false;
Instruction *I = dyn_cast<Instruction>(U);
if (I == 0) return false; // We can't convert!
switch (I->getOpcode()) {
case Instruction::Cast:
assert(I->getOperand(0) == V);
// We can convert the expr if the cast destination type is losslessly
// convertible to the requested type.
// Also, do not change a cast that is a noop cast. For all intents and
// purposes it should be eliminated.
if (!Ty->isLosslesslyConvertibleTo(I->getOperand(0)->getType()) ||
I->getType() == I->getOperand(0)->getType())
return false;
// Do not allow a 'cast ushort %V to uint' to have it's first operand be
// converted to a 'short' type. Doing so changes the way sign promotion
// happens, and breaks things. Only allow the cast to take place if the
// signedness doesn't change... or if the current cast is not a lossy
// conversion.
//
if (!I->getType()->isLosslesslyConvertibleTo(I->getOperand(0)->getType()) &&
I->getOperand(0)->getType()->isSigned() != Ty->isSigned())
return false;
// We also do not allow conversion of a cast that casts from a ptr to array
// of X to a *X. For example: cast [4 x %List *] * %val to %List * *
//
if (const PointerType *SPT =
dyn_cast<PointerType>(I->getOperand(0)->getType()))
if (const PointerType *DPT = dyn_cast<PointerType>(I->getType()))
if (const ArrayType *AT = dyn_cast<ArrayType>(SPT->getElementType()))
if (AT->getElementType() == DPT->getElementType())
return false;
return true;
case Instruction::Add:
if (isa<PointerType>(Ty)) {
Value *IndexVal = I->getOperand(V == I->getOperand(0) ? 1 : 0);
std::vector<Value*> Indices;
if (const Type *ETy = ConvertibleToGEP(Ty, IndexVal, Indices, TD)) {
const Type *RetTy = PointerType::get(ETy);
// Only successful if we can convert this type to the required type
if (ValueConvertibleToType(I, RetTy, CTMap, TD)) {
CTMap[I] = RetTy;
return true;
}
// We have to return failure here because ValueConvertibleToType could
// have polluted our map
return false;
}
}
// FALLTHROUGH
case Instruction::Sub: {
if (!Ty->isInteger() && !Ty->isFloatingPoint()) return false;
Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
return ValueConvertibleToType(I, Ty, CTMap, TD) &&
ExpressionConvertibleToType(OtherOp, Ty, CTMap, TD);
}
case Instruction::SetEQ:
case Instruction::SetNE: {
Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
return ExpressionConvertibleToType(OtherOp, Ty, CTMap, TD);
}
case Instruction::Shr:
if (Ty->isSigned() != V->getType()->isSigned()) return false;
// FALL THROUGH
case Instruction::Shl:
if (I->getOperand(1) == V) return false; // Cannot change shift amount type
if (!Ty->isInteger()) return false;
return ValueConvertibleToType(I, Ty, CTMap, TD);
case Instruction::Free:
assert(I->getOperand(0) == V);
return isa<PointerType>(Ty); // Free can free any pointer type!
case Instruction::Load:
// Cannot convert the types of any subscripts...
if (I->getOperand(0) != V) return false;
if (const PointerType *PT = dyn_cast<PointerType>(Ty)) {
LoadInst *LI = cast<LoadInst>(I);
const Type *LoadedTy = PT->getElementType();
//.........这里部分代码省略.........
开发者ID:chris-wood,项目名称:llvm-pgopre,代码行数:101,代码来源:ExprTypeConvert.cpp
示例20: while
bool
nest::SourceTable::get_next_target_data( const thread tid,
const thread rank_start,
const thread rank_end,
thread& source_rank,
TargetData& next_target_data )
{
SourceTablePosition& current_position = current_positions_[ tid ];
// we stay in this loop either until we can return a valid
// TargetData object or we have reached the end of the sources table
while ( true )
{
current_position.wrap_position( sources_ );
if ( current_position.is_at_end() )
{
return false; // reached the end of the sources table
}
// the current position contains an entry, so we retrieve it
const Source& const_current_source =
sources_[ current_position.tid ][ current_position
.syn_id ][ current_position.lcid ];
if ( const_current_source.is_processed()
or const_current_source.is_disabled() )
{
// looks like we've processed this already, let's continue
--current_position.lcid;
continue;
}
source_rank = kernel().mpi_manager.get_process_id_of_gid(
const_current_source.get_gid() );
// determine whether this thread is responsible for this part of
// the MPI buffer; if not we just continue with the next iteration
// of the loop
if ( source_rank < rank_start or source_rank >= rank_end )
{
--current_position.lcid;
continue;
}
Source& current_source =
sources_[ current_position.tid ][ current_position
.syn_id ][ current_position.lcid ];
// we have found a valid entry, so mark it as processed
current_source.set_processed( true );
// we need to set a marker stating whether the entry following this
// entry, if existent, has the same source; start by assuming it
// has a different source, only change if necessary
kernel().connection_manager.set_has_source_subsequent_targets(
current_position.tid,
current_position.syn_id,
current_position.lcid,
false );
if ( ( current_position.lcid + 1
< static_cast< long >(
sources_[ current_position.tid ][ current_position.syn_id ]
.size() )
and sources_[ current_position.tid ][ current_position.syn_id ]
[ current_position.lcid + 1 ].get_gid()
== current_source.get_gid() ) )
{
kernel().connection_manager.set_has_source_subsequent_targets(
current_position.tid,
current_position.syn_id,
current_position.lcid,
true );
}
// decrease the position without returning a TargetData if the
// entry preceding this entry has the same source, but only if
// the preceding entry was not processed yet
if ( ( current_position.lcid - 1 >= 0 )
and ( sources_[ current_position.tid ][ current_position.syn_id ]
[ current_position.lcid - 1 ].get_gid()
== current_source.get_gid() )
and ( not sources_[ current_position.tid ][ current_position.syn_id ]
[ current_position.lcid - 1 ].is_processed() ) )
{
--current_position.lcid;
continue;
}
// otherwise we return a valid TargetData
else
{
// set values of next_target_data
next_target_data.set_source_lid(
kernel().vp_manager.gid_to_lid( current_source.get_gid() ) );
next_target_data.set_source_tid( kernel().vp_manager.vp_to_thread(
kernel().vp_manager.suggest_vp_for_gid( current_source.get_gid() ) ) );
next_target_data.reset_marker();
if ( current_source.is_primary() )
{
next_target_data.set_is_primary( true );
//.........这里部分代码省略.........
开发者ID:apeyser,项目名称:nest-simulator,代码行数:101,代码来源:source_table.cpp
注:本文中的TargetData类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论