Index: llvm/trunk/include/llvm/Transforms/Scalar.h =================================================================== --- llvm/trunk/include/llvm/Transforms/Scalar.h +++ llvm/trunk/include/llvm/Transforms/Scalar.h @@ -383,9 +383,10 @@ // // InferAddressSpaces - Modify users of addrspacecast instructions with values // in the source address space if using the destination address space is slower -// on the target. +// on the target. If AddressSpace is left to its default value, it will be +// obtained from the TargetTransformInfo. // -FunctionPass *createInferAddressSpacesPass(); +FunctionPass *createInferAddressSpacesPass(unsigned AddressSpace = ~0u); extern char &InferAddressSpacesID; //===----------------------------------------------------------------------===// Index: llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp =================================================================== --- llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ llvm/trunk/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -148,7 +148,9 @@ public: static char ID; - InferAddressSpaces() : FunctionPass(ID) {} + InferAddressSpaces() : + FunctionPass(ID), FlatAddrSpace(UninitializedAddressSpace) {} + InferAddressSpaces(unsigned AS) : FunctionPass(ID), FlatAddrSpace(AS) {} void getAnalysisUsage(AnalysisUsage &AU) const override { AU.setPreservesCFG(); @@ -624,9 +626,12 @@ const TargetTransformInfo &TTI = getAnalysis().getTTI(F); - FlatAddrSpace = TTI.getFlatAddressSpace(); - if (FlatAddrSpace == UninitializedAddressSpace) - return false; + + if (FlatAddrSpace == UninitializedAddressSpace) { + FlatAddrSpace = TTI.getFlatAddressSpace(); + if (FlatAddrSpace == UninitializedAddressSpace) + return false; + } // Collects all flat address expressions in postorder. std::vector Postorder = collectFlatAddressExpressions(F); @@ -1018,6 +1023,6 @@ return true; } -FunctionPass *llvm::createInferAddressSpacesPass() { - return new InferAddressSpaces(); +FunctionPass *llvm::createInferAddressSpacesPass(unsigned AddressSpace) { + return new InferAddressSpaces(AddressSpace); }