[llvm] r187662 - Teach EmitGEPOffset about address spaces

Eli Friedman eli.friedman at gmail.com
Fri Aug 2 17:00:05 PDT 2013


On Fri, Aug 2, 2013 at 11:33 AM, Matt Arsenault
<Matthew.Arsenault at amd.com> wrote:
> Author: arsenm
> Date: Fri Aug  2 13:33:34 2013
> New Revision: 187662
>
> URL: http://llvm.org/viewvc/llvm-project?rev=187662&view=rev
> Log:
> Teach EmitGEPOffset about address spaces
>
> Modified:
>     llvm/trunk/include/llvm/Transforms/Utils/Local.h
>
> Modified: llvm/trunk/include/llvm/Transforms/Utils/Local.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Local.h?rev=187662&r1=187661&r2=187662&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Transforms/Utils/Local.h (original)
> +++ llvm/trunk/include/llvm/Transforms/Utils/Local.h Fri Aug  2 13:33:34 2013
> @@ -42,7 +42,7 @@ class DIBuilder;
>  class AliasAnalysis;
>
>  template<typename T> class SmallVectorImpl;
> -
> +
>  //===----------------------------------------------------------------------===//
>  //  Local constant propagation.
>  //
> @@ -80,7 +80,7 @@ bool RecursivelyDeleteTriviallyDeadInstr
>  /// too, recursively.  Return true if a change was made.
>  bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=0);
>
> -
> +
>  /// SimplifyInstructionsInBlock - Scan the specified basic block and try to
>  /// simplify any instructions in it and recursively delete dead instructions.
>  ///
> @@ -88,7 +88,7 @@ bool RecursivelyDeleteDeadPHINode(PHINod
>  /// instructions in other blocks as well in this block.
>  bool SimplifyInstructionsInBlock(BasicBlock *BB, const DataLayout *TD = 0,
>                                   const TargetLibraryInfo *TLI = 0);
> -
> +
>  //===----------------------------------------------------------------------===//
>  //  Control Flow Graph Restructuring.
>  //
> @@ -106,15 +106,15 @@ bool SimplifyInstructionsInBlock(BasicBl
>  /// recursively fold the 'and' to 0.
>  void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred,
>                                    DataLayout *TD = 0);
> -
> -
> +
> +
>  /// MergeBasicBlockIntoOnlyPred - BB is a block with one predecessor and its
>  /// predecessor is known to have one successor (BB!).  Eliminate the edge
>  /// between them, moving the instructions in the predecessor into BB.  This
>  /// deletes the predecessor block.
>  ///
>  void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, Pass *P = 0);
> -
> +
>
>  /// TryToSimplifyUncondBranchFromEmptyBlock - BB is known to contain an
>  /// unconditional branch, and contains no instructions other than PHI nodes,
> @@ -157,7 +157,7 @@ AllocaInst *DemoteRegToStack(Instruction
>
>  /// DemotePHIToStack - This function takes a virtual register computed by a phi
>  /// node and replaces it with a slot in the stack frame, allocated via alloca.
> -/// The phi node is deleted and it returns the pointer to the alloca inserted.
> +/// The phi node is deleted and it returns the pointer to the alloca inserted.
>  AllocaInst *DemotePHIToStack(PHINode *P, Instruction *AllocaPoint = 0);
>
>  /// getOrEnforceKnownAlignment - If the specified pointer has an alignment that
> @@ -180,18 +180,20 @@ static inline unsigned getKnownAlignment
>  template<typename IRBuilderTy>
>  Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &TD, User *GEP,
>                       bool NoAssumptions = false) {
> -  gep_type_iterator GTI = gep_type_begin(GEP);
> -  Type *IntPtrTy = TD.getIntPtrType(GEP->getContext());
> +  GEPOperator *GEPOp = cast<GEPOperator>(GEP);
> +  unsigned AS = GEPOp->getPointerAddressSpace();
> +  Type *IntPtrTy = TD.getIntPtrType(GEP->getContext(), AS);
>    Value *Result = Constant::getNullValue(IntPtrTy);

It would probably be better to write this as "Type *IntPtrTy =
TD.getIntPtrType(GEP->getType())".  I'm not a fan of "AS" variables
floating around when it can be avoided.

Also, testcase?

-Eli



More information about the llvm-commits mailing list