From: Sven van Haastregt Date: Fri, 26 Apr 2019 09:21:25 +0000 (+0000) Subject: [InferAddressSpaces] Add AS parameter to the pass factory X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75b3428a2d261249127db284c62b5c4be035783c;p=llvm [InferAddressSpaces] Add AS parameter to the pass factory This enables the pass to be used in the absence of TargetTransformInfo. When the argument isn't passed, the factory defaults to UninitializedAddressSpace and the flat address space is obtained from the TargetTransformInfo as before this change. Existing users won't have to change. Patch by Kevin Petit. Differential Revision: https://reviews.llvm.org/D60602 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359290 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Transforms/Scalar.h b/include/llvm/Transforms/Scalar.h index a35edb15adb..8f9d337e385 100644 --- a/include/llvm/Transforms/Scalar.h +++ b/include/llvm/Transforms/Scalar.h @@ -383,9 +383,10 @@ Pass *createCorrelatedValuePropagationPass(); // // 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; //===----------------------------------------------------------------------===// diff --git a/lib/Transforms/Scalar/InferAddressSpaces.cpp b/lib/Transforms/Scalar/InferAddressSpaces.cpp index 1501b4888b1..a59248cc8c5 100644 --- a/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -148,7 +148,9 @@ class InferAddressSpaces : public FunctionPass { 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 @@ bool InferAddressSpaces::runOnFunction(Function &F) { 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 @@ bool InferAddressSpaces::rewriteWithNewAddressSpaces( return true; } -FunctionPass *llvm::createInferAddressSpacesPass() { - return new InferAddressSpaces(); +FunctionPass *llvm::createInferAddressSpacesPass(unsigned AddressSpace) { + return new InferAddressSpaces(AddressSpace); }