Index: include/llvm/Transforms/Scalar.h =================================================================== --- include/llvm/Transforms/Scalar.h +++ include/llvm/Transforms/Scalar.h @@ -381,7 +381,7 @@ // in the source address space if using the destination address space is slower // on the target. // -FunctionPass *createInferAddressSpacesPass(); +FunctionPass *createInferAddressSpacesPass(unsigned AS = ~0u); extern char &InferAddressSpacesID; //===----------------------------------------------------------------------===// Index: lib/Transforms/Scalar/InferAddressSpaces.cpp =================================================================== --- lib/Transforms/Scalar/InferAddressSpaces.cpp +++ 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,13 @@ 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 +1024,6 @@ return true; } -FunctionPass *llvm::createInferAddressSpacesPass() { - return new InferAddressSpaces(); +FunctionPass *llvm::createInferAddressSpacesPass(unsigned AS) { + return new InferAddressSpaces(AS); }