135#define DEBUG_TYPE "infer-address-spaces"
141 cl::desc(
"The default address space is assumed as the flat address space. "
142 "This is mainly for test purpose."));
145 std::numeric_limits<unsigned>::max();
156using PredicatedAddrSpaceMapTy =
161 unsigned FlatAddrSpace = 0;
170 InferAddressSpaces(
unsigned AS) : FunctionPass(ID), FlatAddrSpace(AS) {
174 void getAnalysisUsage(AnalysisUsage &AU)
const override {
184class InferAddressSpacesImpl {
187 const DominatorTree *DT =
nullptr;
188 const TargetTransformInfo *TTI =
nullptr;
189 const DataLayout *DL =
nullptr;
193 unsigned FlatAddrSpace = 0;
197 bool updateAddressSpace(
const Value &V,
198 ValueToAddrSpaceMapTy &InferredAddrSpace,
199 PredicatedAddrSpaceMapTy &PredicatedAS)
const;
204 ValueToAddrSpaceMapTy &InferredAddrSpace,
205 PredicatedAddrSpaceMapTy &PredicatedAS)
const;
207 bool isSafeToCastConstAddrSpace(Constant *
C,
unsigned NewAS)
const;
209 Value *cloneInstructionWithNewAddressSpace(
210 Instruction *
I,
unsigned NewAddrSpace,
212 const PredicatedAddrSpaceMapTy &PredicatedAS,
213 SmallVectorImpl<const Use *> *PoisonUsesToFix)
const;
215 void performPointerReplacement(
217 SmallVectorImpl<Instruction *> &DeadInstructions)
const;
222 bool rewriteWithNewAddressSpaces(
224 const ValueToAddrSpaceMapTy &InferredAddrSpace,
225 const PredicatedAddrSpaceMapTy &PredicatedAS)
const;
227 void appendsFlatAddressExpressionToPostorderStack(
228 Value *V, PostorderStackTy &PostorderStack,
229 DenseSet<Value *> &Visited)
const;
231 bool rewriteIntrinsicOperands(IntrinsicInst *
II,
Value *OldV,
233 void collectRewritableIntrinsicOperands(IntrinsicInst *
II,
234 PostorderStackTy &PostorderStack,
235 DenseSet<Value *> &Visited)
const;
237 std::vector<WeakTrackingVH> collectFlatAddressExpressions(Function &F)
const;
239 Value *cloneValueWithNewAddressSpace(
240 Value *V,
unsigned NewAddrSpace,
242 const PredicatedAddrSpaceMapTy &PredicatedAS,
243 SmallVectorImpl<const Use *> *PoisonUsesToFix)
const;
244 unsigned joinAddressSpaces(
unsigned AS1,
unsigned AS2)
const;
246 unsigned getPredicatedAddrSpace(
const Value &PtrV,
247 const Value *UserCtx)
const;
250 InferAddressSpacesImpl(AssumptionCache &AC,
const DominatorTree *DT,
251 const TargetTransformInfo *TTI,
unsigned FlatAddrSpace)
252 : AC(AC), DT(DT), TTI(TTI), FlatAddrSpace(FlatAddrSpace) {}
253 bool run(Function &F);
258char InferAddressSpaces::ID = 0;
268 assert(Ty->isPtrOrPtrVectorTy());
270 return Ty->getWithNewType(NPT);
280 if (!P2I || P2I->getOpcode() != Instruction::PtrToInt)
296 unsigned P2IOp0AS = P2I->getOperand(0)->getType()->getPointerAddressSpace();
302 P2I->getOperand(0)->getType(), P2I->getType(),
304 (P2IOp0AS == I2PAS ||
TTI->isNoopAddrSpaceCast(P2IOp0AS, I2PAS));
315 return Arg->getType()->isPointerTy() &&
322 switch (
Op->getOpcode()) {
323 case Instruction::PHI:
324 assert(
Op->getType()->isPtrOrPtrVectorTy());
326 case Instruction::BitCast:
327 case Instruction::AddrSpaceCast:
328 case Instruction::GetElementPtr:
330 case Instruction::Select:
331 return Op->getType()->isPtrOrPtrVectorTy();
332 case Instruction::Call: {
334 return II &&
II->getIntrinsicID() == Intrinsic::ptrmask;
336 case Instruction::IntToPtr:
354 switch (
Op.getOpcode()) {
355 case Instruction::PHI: {
357 return {IncomingValues.begin(), IncomingValues.end()};
359 case Instruction::BitCast:
360 case Instruction::AddrSpaceCast:
361 case Instruction::GetElementPtr:
362 return {
Op.getOperand(0)};
363 case Instruction::Select:
364 return {
Op.getOperand(1),
Op.getOperand(2)};
365 case Instruction::Call: {
367 assert(
II.getIntrinsicID() == Intrinsic::ptrmask &&
368 "unexpected intrinsic call");
369 return {
II.getArgOperand(0)};
371 case Instruction::IntToPtr: {
374 return {P2I->getOperand(0)};
381bool InferAddressSpacesImpl::rewriteIntrinsicOperands(
IntrinsicInst *
II,
384 Module *
M =
II->getParent()->getParent()->getParent();
387 case Intrinsic::objectsize:
388 case Intrinsic::masked_load: {
389 Type *DestTy =
II->getType();
393 II->setArgOperand(0, NewV);
394 II->setCalledFunction(NewDecl);
397 case Intrinsic::ptrmask:
400 case Intrinsic::masked_gather: {
401 Type *RetTy =
II->getType();
405 II->setArgOperand(0, NewV);
406 II->setCalledFunction(NewDecl);
409 case Intrinsic::masked_store:
410 case Intrinsic::masked_scatter: {
411 Type *ValueTy =
II->getOperand(0)->getType();
414 M,
II->getIntrinsicID(), {ValueTy, NewPtrTy});
415 II->setArgOperand(1, NewV);
416 II->setCalledFunction(NewDecl);
419 case Intrinsic::prefetch:
420 case Intrinsic::is_constant: {
422 M,
II->getIntrinsicID(), {NewV->getType()});
423 II->setArgOperand(0, NewV);
424 II->setCalledFunction(NewDecl);
427 case Intrinsic::fake_use: {
428 II->replaceUsesOfWith(OldV, NewV);
431 case Intrinsic::lifetime_start:
432 case Intrinsic::lifetime_end: {
436 M,
II->getIntrinsicID(), {NewV->getType()});
437 II->setArgOperand(0, NewV);
438 II->setCalledFunction(NewDecl);
446 II->replaceAllUsesWith(Rewrite);
452void InferAddressSpacesImpl::collectRewritableIntrinsicOperands(
453 IntrinsicInst *
II, PostorderStackTy &PostorderStack,
454 DenseSet<Value *> &Visited)
const {
455 auto IID =
II->getIntrinsicID();
457 case Intrinsic::ptrmask:
458 case Intrinsic::objectsize:
459 appendsFlatAddressExpressionToPostorderStack(
II->getArgOperand(0),
460 PostorderStack, Visited);
462 case Intrinsic::is_constant: {
463 Value *Ptr =
II->getArgOperand(0);
465 appendsFlatAddressExpressionToPostorderStack(Ptr, PostorderStack,
471 case Intrinsic::masked_load:
472 case Intrinsic::masked_gather:
473 case Intrinsic::prefetch:
474 appendsFlatAddressExpressionToPostorderStack(
II->getArgOperand(0),
475 PostorderStack, Visited);
477 case Intrinsic::masked_store:
478 case Intrinsic::masked_scatter:
479 appendsFlatAddressExpressionToPostorderStack(
II->getArgOperand(1),
480 PostorderStack, Visited);
482 case Intrinsic::fake_use: {
484 if (
Op->getType()->isPtrOrPtrVectorTy()) {
485 appendsFlatAddressExpressionToPostorderStack(
Op, PostorderStack,
492 case Intrinsic::lifetime_start:
493 case Intrinsic::lifetime_end: {
494 appendsFlatAddressExpressionToPostorderStack(
II->getArgOperand(0),
495 PostorderStack, Visited);
499 SmallVector<int, 2> OpIndexes;
501 for (
int Idx : OpIndexes) {
502 appendsFlatAddressExpressionToPostorderStack(
II->getArgOperand(Idx),
503 PostorderStack, Visited);
513void InferAddressSpacesImpl::appendsFlatAddressExpressionToPostorderStack(
514 Value *V, PostorderStackTy &PostorderStack,
515 DenseSet<Value *> &Visited)
const {
516 assert(
V->getType()->isPtrOrPtrVectorTy());
523 PostorderStack.emplace_back(CE,
false);
528 if (
V->getType()->getPointerAddressSpace() == FlatAddrSpace &&
530 if (Visited.
insert(V).second) {
531 PostorderStack.emplace_back(V,
false);
534 for (
auto &O :
Op->operands())
537 PostorderStack.emplace_back(CE,
false);
544std::vector<WeakTrackingVH>
545InferAddressSpacesImpl::collectFlatAddressExpressions(Function &
F)
const {
548 PostorderStackTy PostorderStack;
550 DenseSet<Value *> Visited;
552 auto PushPtrOperand = [&](
Value *Ptr) {
553 appendsFlatAddressExpressionToPostorderStack(Ptr, PostorderStack, Visited);
561 PushPtrOperand(
GEP->getPointerOperand());
563 PushPtrOperand(LI->getPointerOperand());
565 PushPtrOperand(
SI->getPointerOperand());
567 PushPtrOperand(RMW->getPointerOperand());
569 PushPtrOperand(CmpX->getPointerOperand());
572 PushPtrOperand(
MI->getRawDest());
576 PushPtrOperand(MTI->getRawSource());
578 collectRewritableIntrinsicOperands(
II, PostorderStack, Visited);
580 if (
Cmp->getOperand(0)->getType()->isPtrOrPtrVectorTy()) {
581 PushPtrOperand(
Cmp->getOperand(0));
582 PushPtrOperand(
Cmp->getOperand(1));
585 PushPtrOperand(ASC->getPointerOperand());
588 PushPtrOperand(
cast<Operator>(I2P->getOperand(0))->getOperand(0));
590 if (
auto *RV = RI->getReturnValue();
591 RV && RV->getType()->isPtrOrPtrVectorTy())
596 std::vector<WeakTrackingVH> Postorder;
597 while (!PostorderStack.empty()) {
598 Value *TopVal = PostorderStack.back().getPointer();
601 if (PostorderStack.back().getInt()) {
603 Postorder.push_back(TopVal);
604 PostorderStack.pop_back();
608 PostorderStack.back().setInt(
true);
612 appendsFlatAddressExpressionToPostorderStack(PtrOperand, PostorderStack,
624 auto InsertBefore = [NewI](
auto It) {
634 auto InsertI =
F->getEntryBlock().getFirstNonPHIIt();
635 return InsertBefore(InsertI);
645 auto InsertI = OpInst->
getParent()->getFirstNonPHIIt();
646 return InsertBefore(InsertI);
659 const Use &OperandUse,
unsigned NewAddrSpace,
661 const PredicatedAddrSpaceMapTy &PredicatedAS,
670 if (
Value *NewOperand = ValueWithNewAddrSpace.
lookup(Operand))
674 auto I = PredicatedAS.find(std::make_pair(Inst, Operand));
675 if (
I != PredicatedAS.end()) {
677 unsigned NewAS =
I->second;
705Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace(
706 Instruction *
I,
unsigned NewAddrSpace,
708 const PredicatedAddrSpaceMapTy &PredicatedAS,
709 SmallVectorImpl<const Use *> *PoisonUsesToFix)
const {
712 if (
I->getOpcode() == Instruction::AddrSpaceCast) {
713 Value *Src =
I->getOperand(0);
717 assert(Src->getType()->getPointerAddressSpace() == NewAddrSpace);
724 assert(
II->getIntrinsicID() == Intrinsic::ptrmask);
726 II->getArgOperandUse(0), NewAddrSpace, ValueWithNewAddrSpace,
727 PredicatedAS, PoisonUsesToFix);
731 assert(Rewrite !=
II &&
"cannot modify this pointer operation in place");
743 auto *NewI =
new AddrSpaceCastInst(
I, NewPtrTy);
744 NewI->insertAfter(
I->getIterator());
745 NewI->setDebugLoc(
I->getDebugLoc());
751 for (
const Use &OperandUse :
I->operands()) {
752 if (!OperandUse.get()->getType()->isPtrOrPtrVectorTy())
756 OperandUse, NewAddrSpace, ValueWithNewAddrSpace, PredicatedAS,
760 switch (
I->getOpcode()) {
761 case Instruction::BitCast:
762 return new BitCastInst(NewPointerOperands[0], NewPtrType);
763 case Instruction::PHI: {
764 assert(
I->getType()->isPtrOrPtrVectorTy());
767 for (
unsigned Index = 0;
Index <
PHI->getNumIncomingValues(); ++
Index) {
770 PHI->getIncomingBlock(Index));
774 case Instruction::GetElementPtr: {
777 GEP->getSourceElementType(), NewPointerOperands[0],
782 case Instruction::Select:
783 assert(
I->getType()->isPtrOrPtrVectorTy());
785 NewPointerOperands[2],
"",
nullptr,
I);
786 case Instruction::IntToPtr: {
789 if (Src->getType() == NewPtrType)
795 return new AddrSpaceCastInst(Src, NewPtrType);
810 CE->getType()->isPtrOrPtrVectorTy()
814 if (CE->getOpcode() == Instruction::AddrSpaceCast) {
818 assert(CE->getOperand(0)->getType()->getPointerAddressSpace() ==
820 return CE->getOperand(0);
823 if (CE->getOpcode() == Instruction::BitCast) {
824 if (
Value *NewOperand = ValueWithNewAddrSpace.
lookup(CE->getOperand(0)))
829 if (CE->getOpcode() == Instruction::IntToPtr) {
832 assert(Src->getType()->getPointerAddressSpace() == NewAddrSpace);
839 for (
unsigned Index = 0; Index < CE->getNumOperands(); ++Index) {
840 Constant *Operand = CE->getOperand(Index);
846 if (
Value *NewOperand = ValueWithNewAddrSpace.
lookup(Operand)) {
853 CExpr, NewAddrSpace, ValueWithNewAddrSpace,
DL,
TTI)) {
867 if (CE->getOpcode() == Instruction::GetElementPtr) {
870 return CE->getWithOperands(NewOperands, TargetType,
false,
874 return CE->getWithOperands(NewOperands, TargetType);
882Value *InferAddressSpacesImpl::cloneValueWithNewAddressSpace(
883 Value *V,
unsigned NewAddrSpace,
885 const PredicatedAddrSpaceMapTy &PredicatedAS,
886 SmallVectorImpl<const Use *> *PoisonUsesToFix)
const {
888 assert(
V->getType()->getPointerAddressSpace() == FlatAddrSpace &&
897 Type *NewPtrTy = PointerType::get(Arg->getContext(), NewAddrSpace);
898 auto *NewI =
new AddrSpaceCastInst(Arg, NewPtrTy);
899 NewI->insertBefore(Insert);
904 Value *NewV = cloneInstructionWithNewAddressSpace(
905 I, NewAddrSpace, ValueWithNewAddrSpace, PredicatedAS, PoisonUsesToFix);
907 if (NewI->getParent() ==
nullptr) {
908 NewI->insertBefore(
I->getIterator());
910 NewI->setDebugLoc(
I->getDebugLoc());
922unsigned InferAddressSpacesImpl::joinAddressSpaces(
unsigned AS1,
923 unsigned AS2)
const {
924 if (AS1 == FlatAddrSpace || AS2 == FlatAddrSpace)
925 return FlatAddrSpace;
933 return (AS1 == AS2) ? AS1 : FlatAddrSpace;
936bool InferAddressSpacesImpl::run(Function &CurFn) {
938 DL = &
F->getDataLayout();
950 std::vector<WeakTrackingVH> Postorder = collectFlatAddressExpressions(*
F);
954 ValueToAddrSpaceMapTy InferredAddrSpace;
955 PredicatedAddrSpaceMapTy PredicatedAS;
956 inferAddressSpaces(Postorder, InferredAddrSpace, PredicatedAS);
960 return rewriteWithNewAddressSpaces(Postorder, InferredAddrSpace,
966void InferAddressSpacesImpl::inferAddressSpaces(
968 ValueToAddrSpaceMapTy &InferredAddrSpace,
969 PredicatedAddrSpaceMapTy &PredicatedAS)
const {
972 for (
Value *V : Postorder)
975 while (!Worklist.empty()) {
976 Value *
V = Worklist.pop_back_val();
980 if (!updateAddressSpace(*V, InferredAddrSpace, PredicatedAS))
983 for (
Value *User :
V->users()) {
985 if (Worklist.count(User))
988 auto Pos = InferredAddrSpace.find(User);
991 if (Pos == InferredAddrSpace.end())
997 if (Pos->second == FlatAddrSpace)
1000 Worklist.insert(User);
1006InferAddressSpacesImpl::getPredicatedAddrSpace(
const Value &Ptr,
1007 const Value *UserCtx)
const {
1030bool InferAddressSpacesImpl::updateAddressSpace(
1031 const Value &V, ValueToAddrSpaceMapTy &InferredAddrSpace,
1032 PredicatedAddrSpaceMapTy &PredicatedAS)
const {
1033 assert(InferredAddrSpace.count(&V));
1035 LLVM_DEBUG(
dbgs() <<
"Updating the address space of\n " << V <<
'\n');
1052 auto I = InferredAddrSpace.find(PtrOperand);
1054 if (
I == InferredAddrSpace.end()) {
1055 OperandAS = PtrOperand->getType()->getPointerAddressSpace();
1057 C && OperandAS == FlatAddrSpace) {
1062 if (OperandAS == FlatAddrSpace) {
1064 unsigned AS = getPredicatedAddrSpace(*PtrOperand, &V);
1067 <<
" deduce operand AS from the predicate addrspace "
1071 PredicatedAS[std::make_pair(&V, PtrOperand)] = OperandAS;
1075 OperandAS =
I->second;
1078 NewAS = joinAddressSpaces(NewAS, OperandAS);
1079 if (NewAS == FlatAddrSpace)
1083 if (
any_of(ConstantPtrOps, [=](Constant *
C) {
1084 return !isSafeToCastConstAddrSpace(
C, NewAS);
1086 NewAS = FlatAddrSpace;
1090 unsigned OldAS = InferredAddrSpace.lookup(&V);
1091 assert(OldAS != FlatAddrSpace);
1098 InferredAddrSpace[&
V] = NewAS;
1107 if (U.get() == OldVal) {
1115template <
typename InstrType>
1117 InstrType *MemInstr,
unsigned AddrSpace,
1119 if (!MemInstr->isVolatile() ||
TTI.hasVolatileVariant(MemInstr, AddrSpace)) {
1135 User *Inst,
unsigned AddrSpace,
1159 B.CreateMemSet(NewV, MSI->getValue(), MSI->getLength(), MSI->getDestAlign(),
1161 MI->getAAMetadata());
1163 Value *Src = MTI->getRawSource();
1164 Value *Dest = MTI->getRawDest();
1174 if (MCI->isForceInlined())
1175 B.CreateMemCpyInline(Dest, MTI->getDestAlign(), Src,
1176 MTI->getSourceAlign(), MTI->getLength(),
1178 MI->getAAMetadata());
1180 B.CreateMemCpy(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),
1183 MI->getAAMetadata());
1186 B.CreateMemMove(Dest, MTI->getDestAlign(), Src, MTI->getSourceAlign(),
1189 MI->getAAMetadata());
1194 MI->eraseFromParent();
1200bool InferAddressSpacesImpl::isSafeToCastConstAddrSpace(Constant *
C,
1201 unsigned NewAS)
const {
1204 unsigned SrcAS =
C->getType()->getPointerAddressSpace();
1209 if (SrcAS != FlatAddrSpace && NewAS != FlatAddrSpace)
1218 if (
Op->getOpcode() == Instruction::AddrSpaceCast)
1222 if (
Op->getOpcode() == Instruction::IntToPtr &&
1223 Op->getType()->getPointerAddressSpace() == FlatAddrSpace)
1232 User *CurUser =
I->getUser();
1235 while (
I != End &&
I->getUser() == CurUser)
1241void InferAddressSpacesImpl::performPointerReplacement(
1243 SmallVectorImpl<Instruction *> &DeadInstructions)
const {
1245 User *CurUser =
U.getUser();
1247 unsigned AddrSpace =
V->getType()->getPointerAddressSpace();
1252 if (CurUser == NewV)
1256 if (!CurUserI || CurUserI->getFunction() !=
F)
1266 if (rewriteIntrinsicOperands(
II, V, NewV))
1278 int SrcIdx =
U.getOperandNo();
1279 int OtherIdx = (SrcIdx == 0) ? 1 : 0;
1280 Value *OtherSrc =
Cmp->getOperand(OtherIdx);
1282 if (
Value *OtherNewV = ValueWithNewAddrSpace.
lookup(OtherSrc)) {
1283 if (OtherNewV->getType()->getPointerAddressSpace() == NewAS) {
1284 Cmp->setOperand(OtherIdx, OtherNewV);
1285 Cmp->setOperand(SrcIdx, NewV);
1292 if (isSafeToCastConstAddrSpace(KOtherSrc, NewAS)) {
1293 Cmp->setOperand(SrcIdx, NewV);
1303 if (ASC->getDestAddressSpace() == NewAS) {
1304 ASC->replaceAllUsesWith(NewV);
1319 InsertPos = std::next(NewVInst->getIterator());
1327 V,
new AddrSpaceCastInst(NewV,
V->getType(),
"", InsertPos));
1329 CurUserI->replaceUsesOfWith(
1334bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
1336 const ValueToAddrSpaceMapTy &InferredAddrSpace,
1337 const PredicatedAddrSpaceMapTy &PredicatedAS)
const {
1344 for (
Value *V : Postorder) {
1345 unsigned NewAddrSpace = InferredAddrSpace.lookup(V);
1352 if (
V->getType()->getPointerAddressSpace() != NewAddrSpace) {
1354 cloneValueWithNewAddressSpace(V, NewAddrSpace, ValueWithNewAddrSpace,
1355 PredicatedAS, &PoisonUsesToFix);
1357 ValueWithNewAddrSpace[
V] =
New;
1361 if (ValueWithNewAddrSpace.
empty())
1365 for (
const Use *PoisonUse : PoisonUsesToFix) {
1366 User *
V = PoisonUse->getUser();
1371 unsigned OperandNo = PoisonUse->getOperandNo();
1373 NewV->
setOperand(OperandNo, ValueWithNewAddrSpace.
lookup(PoisonUse->get()));
1376 SmallVector<Instruction *, 16> DeadInstructions;
1381 for (
const WeakTrackingVH &WVH : Postorder) {
1382 assert(WVH &&
"value was unexpectedly deleted");
1385 if (NewV ==
nullptr)
1388 LLVM_DEBUG(
dbgs() <<
"Replacing the uses of " << *V <<
"\n with\n "
1395 LLVM_DEBUG(
dbgs() <<
"Inserting replacement const cast: " << Replace
1396 <<
": " << *Replace <<
'\n');
1400 if (
I->getFunction() ==
F)
1401 I->replaceUsesOfWith(
C, Replace);
1403 WorkList.
append(
U->user_begin(),
U->user_end());
1406 if (!WorkList.
empty()) {
1408 DenseSet<User *> Visited{WorkList.
begin(), WorkList.
end()};
1409 while (!WorkList.
empty()) {
1412 if (
I->getFunction() ==
F)
1413 VMapper.remapInstruction(*
I);
1416 for (User *U2 :
U->users())
1417 if (Visited.
insert(U2).second)
1425 Value::use_iterator
I,
E,
Next;
1426 for (
I =
V->use_begin(),
E =
V->use_end();
I !=
E;) {
1433 performPointerReplacement(V, NewV, U, ValueWithNewAddrSpace,
1437 if (
V->use_empty()) {
1443 for (Instruction *
I : DeadInstructions)
1449bool InferAddressSpaces::runOnFunction(Function &
F) {
1450 if (skipFunction(
F))
1453 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
1454 DominatorTree *DT = DTWP ? &DTWP->getDomTree() :
nullptr;
1455 return InferAddressSpacesImpl(
1456 getAnalysis<AssumptionCacheTracker>().getAssumptionCache(
F), DT,
1457 &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
F),
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_UNLIKELY(EXPR)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
static bool runOnFunction(Function &F, bool PostInlining)
This header defines various interfaces for pass management in LLVM.
This defines the Use class.
static bool replaceIfSimplePointerUse(const TargetTransformInfo &TTI, User *Inst, unsigned AddrSpace, Value *OldV, Value *NewV)
If OldV is used as the pointer operand of a compatible memory operation Inst, replaces the pointer op...
static bool replaceOperandIfSame(Instruction *Inst, unsigned OpIdx, Value *OldVal, Value *NewVal)
Replace operand OpIdx in Inst, if the value is the same as OldVal with NewVal.
static cl::opt< bool > AssumeDefaultIsFlatAddressSpace("assume-default-is-flat-addrspace", cl::init(false), cl::ReallyHidden, cl::desc("The default address space is assumed as the flat address space. " "This is mainly for test purpose."))
static bool isNoopPtrIntCastPair(const Operator *I2P, const DataLayout &DL, const TargetTransformInfo *TTI)
static Value * phiNodeOperandWithNewAddressSpace(AddrSpaceCastInst *NewI, Value *Operand)
static bool isAddressExpression(const Value &V, const DataLayout &DL, const TargetTransformInfo *TTI)
static bool handleMemIntrinsicPtrUse(MemIntrinsic *MI, Value *OldV, Value *NewV)
Update memory intrinsic uses that require more complex processing than simple memory instructions.
static SmallVector< Value *, 2 > getPointerOperands(const Value &V, const DataLayout &DL, const TargetTransformInfo *TTI)
static Value * operandWithNewAddressSpaceOrCreatePoison(const Use &OperandUse, unsigned NewAddrSpace, const ValueToValueMapTy &ValueWithNewAddrSpace, const PredicatedAddrSpaceMapTy &PredicatedAS, SmallVectorImpl< const Use * > *PoisonUsesToFix)
static Value * cloneConstantExprWithNewAddressSpace(ConstantExpr *CE, unsigned NewAddrSpace, const ValueToValueMapTy &ValueWithNewAddrSpace, const DataLayout *DL, const TargetTransformInfo *TTI)
static Value::use_iterator skipToNextUser(Value::use_iterator I, Value::use_iterator End)
Infer address static false Type * getPtrOrVecOfPtrsWithNewAS(Type *Ty, unsigned NewAddrSpace)
static bool replaceSimplePointerUse(const TargetTransformInfo &TTI, InstrType *MemInstr, unsigned AddrSpace, Value *OldV, Value *NewV)
static const unsigned UninitializedAddressSpace
Machine Check Debug Module
MachineInstr unsigned OpIdx
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
This class represents a conversion between pointers from one address space to another.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
This class represents an incoming formal argument to a Function.
A function analysis which provides an AssumptionCache.
An immutable pass that tracks lazily created AssumptionCache objects.
MutableArrayRef< ResultElem > assumptionsFor(const Value *V)
Access the list of assumptions which affect this value.
InstListType::iterator iterator
Instruction iterators...
Represents analyses that only rely on functions' control flow.
Value * getArgOperand(unsigned i) const
static LLVM_ABI bool isNoopCast(Instruction::CastOps Opcode, Type *SrcTy, Type *DstTy, const DataLayout &DL)
A no-op cast is one that can be effected without changing any bits.
A constant value that is initialized with an expression using other constant values.
static LLVM_ABI Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
Analysis pass which computes a DominatorTree.
FunctionPass class - This class is used to implement most global optimizations.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI void setIsInBounds(bool b=true)
Set or clear the inbounds flag on this GEP instruction.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM_ABI void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction.
A wrapper class for inspecting calls to intrinsic functions.
This is the common base class for memset/memcpy/memmove.
This is a utility class that provides an abstraction for the common functionality between Instruction...
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static unsigned getOperandNumForIncomingValue(unsigned i)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetTransformInfo.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
A Use represents the edge between a Value definition and its users.
User * getUser() const
Returns the User that contains this Use.
const Use & getOperandUse(unsigned i) const
void setOperand(unsigned i, Value *Val)
LLVM_ABI bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
Value * getOperand(unsigned i) const
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
use_iterator_impl< Use > use_iterator
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
std::pair< iterator, bool > insert(const ValueT &V)
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
InstrType
This represents what is and is not supported when finding similarity in Instructions.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
LLVM_ABI bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
LLVM_ABI bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
LLVM_ABI void initializeInferAddressSpacesPass(PassRegistry &)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
constexpr from_range_t from_range
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
auto cast_or_null(const Y &Val)
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
@ RF_IgnoreMissingLocals
If this flag is set, the remapper ignores missing function-local entries (Argument,...
@ RF_NoModuleLevelChanges
If this flag is set, the remapper knows that only local values within a function (such as an instruct...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
FunctionAddr VTableAddr Next
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
ValueMap< const Value *, WeakTrackingVH > ValueToValueMapTy
LLVM_ABI FunctionPass * createInferAddressSpacesPass(unsigned AddressSpace=~0u)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)