Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 09:37:14 +08:00
|
|
|
//===-- ARMTargetTransformInfo.cpp - ARM specific TTI pass ----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This file implements a TargetTransformInfo analysis pass specific to the
|
|
|
|
/// ARM target machine. It uses the target's detailed information to provide
|
|
|
|
/// more precise answers to certain TTI queries, while letting the target
|
|
|
|
/// independent and default TTI implementations handle the rest.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "armtti"
|
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMTargetMachine.h"
|
2013-01-07 11:08:10 +08:00
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 09:37:14 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Target/TargetLowering.h"
|
2013-01-30 07:31:38 +08:00
|
|
|
#include "llvm/Target/CostTable.h"
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 09:37:14 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Declare the pass initialization routine locally as target-specific passes
|
|
|
|
// don't havve a target-wide initialization entry point, and so we rely on the
|
|
|
|
// pass constructor initialization.
|
|
|
|
namespace llvm {
|
|
|
|
void initializeARMTTIPass(PassRegistry &);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ARMTTI : public ImmutablePass, public TargetTransformInfo {
|
|
|
|
const ARMBaseTargetMachine *TM;
|
|
|
|
const ARMSubtarget *ST;
|
2013-01-30 07:31:38 +08:00
|
|
|
const ARMTargetLowering *TLI;
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 09:37:14 +08:00
|
|
|
|
|
|
|
/// Estimate the overhead of scalarizing an instruction. Insert and Extract
|
|
|
|
/// are set if the result needs to be inserted and/or extracted from vectors.
|
|
|
|
unsigned getScalarizationOverhead(Type *Ty, bool Insert, bool Extract) const;
|
|
|
|
|
|
|
|
public:
|
2013-01-30 07:31:38 +08:00
|
|
|
ARMTTI() : ImmutablePass(ID), TM(0), ST(0), TLI(0) {
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 09:37:14 +08:00
|
|
|
llvm_unreachable("This pass cannot be directly constructed");
|
|
|
|
}
|
|
|
|
|
|
|
|
ARMTTI(const ARMBaseTargetMachine *TM)
|
2013-01-30 07:31:38 +08:00
|
|
|
: ImmutablePass(ID), TM(TM), ST(TM->getSubtargetImpl()),
|
|
|
|
TLI(TM->getTargetLowering()) {
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 09:37:14 +08:00
|
|
|
initializeARMTTIPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void initializePass() {
|
|
|
|
pushTTIStack(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void finalizePass() {
|
|
|
|
popTTIStack();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
TargetTransformInfo::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Pass identification.
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
/// Provide necessary pointer adjustments for the two base classes.
|
|
|
|
virtual void *getAdjustedAnalysisPointer(const void *ID) {
|
|
|
|
if (ID == &TargetTransformInfo::ID)
|
|
|
|
return (TargetTransformInfo*)this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \name Scalar TTI Implementations
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
virtual unsigned getIntImmCost(const APInt &Imm, Type *Ty) const;
|
|
|
|
|
|
|
|
/// @}
|
2013-01-09 09:15:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
/// \name Vector TTI Implementations
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
unsigned getNumberOfRegisters(bool Vector) const {
|
|
|
|
if (Vector) {
|
|
|
|
if (ST->hasNEON())
|
|
|
|
return 16;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ST->isThumb1Only())
|
|
|
|
return 8;
|
|
|
|
return 16;
|
|
|
|
}
|
|
|
|
|
2013-01-10 06:29:00 +08:00
|
|
|
unsigned getRegisterBitWidth(bool Vector) const {
|
|
|
|
if (Vector) {
|
|
|
|
if (ST->hasNEON())
|
|
|
|
return 128;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
2013-01-09 09:15:42 +08:00
|
|
|
unsigned getMaximumUnrollFactor() const {
|
|
|
|
// These are out of order CPUs:
|
|
|
|
if (ST->isCortexA15() || ST->isSwift())
|
|
|
|
return 2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-02-12 10:40:39 +08:00
|
|
|
unsigned getShuffleCost(ShuffleKind Kind, Type *Tp,
|
|
|
|
int Index, Type *SubTp) const;
|
|
|
|
|
2013-01-30 07:31:38 +08:00
|
|
|
unsigned getCastInstrCost(unsigned Opcode, Type *Dst,
|
|
|
|
Type *Src) const;
|
|
|
|
|
2013-02-08 00:10:15 +08:00
|
|
|
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy) const;
|
|
|
|
|
2013-02-04 10:52:05 +08:00
|
|
|
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index) const;
|
2013-02-08 22:50:48 +08:00
|
|
|
|
|
|
|
unsigned getAddressComputationCost(Type *Val) const;
|
2013-01-09 09:15:42 +08:00
|
|
|
/// @}
|
Switch TargetTransformInfo from an immutable analysis pass that requires
a TargetMachine to construct (and thus isn't always available), to an
analysis group that supports layered implementations much like
AliasAnalysis does. This is a pretty massive change, with a few parts
that I was unable to easily separate (sorry), so I'll walk through it.
The first step of this conversion was to make TargetTransformInfo an
analysis group, and to sink the nonce implementations in
ScalarTargetTransformInfo and VectorTargetTranformInfo into
a NoTargetTransformInfo pass. This allows other passes to add a hard
requirement on TTI, and assume they will always get at least on
implementation.
The TargetTransformInfo analysis group leverages the delegation chaining
trick that AliasAnalysis uses, where the base class for the analysis
group delegates to the previous analysis *pass*, allowing all but tho
NoFoo analysis passes to only implement the parts of the interfaces they
support. It also introduces a new trick where each pass in the group
retains a pointer to the top-most pass that has been initialized. This
allows passes to implement one API in terms of another API and benefit
when some other pass above them in the stack has more precise results
for the second API.
The second step of this conversion is to create a pass that implements
the TargetTransformInfo analysis using the target-independent
abstractions in the code generator. This replaces the
ScalarTargetTransformImpl and VectorTargetTransformImpl classes in
lib/Target with a single pass in lib/CodeGen called
BasicTargetTransformInfo. This class actually provides most of the TTI
functionality, basing it upon the TargetLowering abstraction and other
information in the target independent code generator.
The third step of the conversion adds support to all TargetMachines to
register custom analysis passes. This allows building those passes with
access to TargetLowering or other target-specific classes, and it also
allows each target to customize the set of analysis passes desired in
the pass manager. The baseline LLVMTargetMachine implements this
interface to add the BasicTTI pass to the pass manager, and all of the
tools that want to support target-aware TTI passes call this routine on
whatever target machine they end up with to add the appropriate passes.
The fourth step of the conversion created target-specific TTI analysis
passes for the X86 and ARM backends. These passes contain the custom
logic that was previously in their extensions of the
ScalarTargetTransformInfo and VectorTargetTransformInfo interfaces.
I separated them into their own file, as now all of the interface bits
are private and they just expose a function to create the pass itself.
Then I extended these target machines to set up a custom set of analysis
passes, first adding BasicTTI as a fallback, and then adding their
customized TTI implementations.
The fourth step required logic that was shared between the target
independent layer and the specific targets to move to a different
interface, as they no longer derive from each other. As a consequence,
a helper functions were added to TargetLowering representing the common
logic needed both in the target implementation and the codegen
implementation of the TTI pass. While technically this is the only
change that could have been committed separately, it would have been
a nightmare to extract.
The final step of the conversion was just to delete all the old
boilerplate. This got rid of the ScalarTargetTransformInfo and
VectorTargetTransformInfo classes, all of the support in all of the
targets for producing instances of them, and all of the support in the
tools for manually constructing a pass based around them.
Now that TTI is a relatively normal analysis group, two things become
straightforward. First, we can sink it into lib/Analysis which is a more
natural layer for it to live. Second, clients of this interface can
depend on it *always* being available which will simplify their code and
behavior. These (and other) simplifications will follow in subsequent
commits, this one is clearly big enough.
Finally, I'm very aware that much of the comments and documentation
needs to be updated. As soon as I had this working, and plausibly well
commented, I wanted to get it committed and in front of the build bots.
I'll be doing a few passes over documentation later if it sticks.
Commits to update DragonEgg and Clang will be made presently.
llvm-svn: 171681
2013-01-07 09:37:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
INITIALIZE_AG_PASS(ARMTTI, TargetTransformInfo, "armtti",
|
|
|
|
"ARM Target Transform Info", true, true, false)
|
|
|
|
char ARMTTI::ID = 0;
|
|
|
|
|
|
|
|
ImmutablePass *
|
|
|
|
llvm::createARMTargetTransformInfoPass(const ARMBaseTargetMachine *TM) {
|
|
|
|
return new ARMTTI(TM);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned ARMTTI::getIntImmCost(const APInt &Imm, Type *Ty) const {
|
|
|
|
assert(Ty->isIntegerTy());
|
|
|
|
|
|
|
|
unsigned Bits = Ty->getPrimitiveSizeInBits();
|
|
|
|
if (Bits == 0 || Bits > 32)
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
int32_t SImmVal = Imm.getSExtValue();
|
|
|
|
uint32_t ZImmVal = Imm.getZExtValue();
|
|
|
|
if (!ST->isThumb()) {
|
|
|
|
if ((SImmVal >= 0 && SImmVal < 65536) ||
|
|
|
|
(ARM_AM::getSOImmVal(ZImmVal) != -1) ||
|
|
|
|
(ARM_AM::getSOImmVal(~ZImmVal) != -1))
|
|
|
|
return 1;
|
|
|
|
return ST->hasV6T2Ops() ? 2 : 3;
|
|
|
|
} else if (ST->isThumb2()) {
|
|
|
|
if ((SImmVal >= 0 && SImmVal < 65536) ||
|
|
|
|
(ARM_AM::getT2SOImmVal(ZImmVal) != -1) ||
|
|
|
|
(ARM_AM::getT2SOImmVal(~ZImmVal) != -1))
|
|
|
|
return 1;
|
|
|
|
return ST->hasV6T2Ops() ? 2 : 3;
|
|
|
|
} else /*Thumb1*/ {
|
|
|
|
if (SImmVal >= 0 && SImmVal < 256)
|
|
|
|
return 1;
|
|
|
|
if ((~ZImmVal < 256) || ARM_AM::isThumbImmShiftedVal(ZImmVal))
|
|
|
|
return 2;
|
|
|
|
// Load from constantpool.
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
2013-01-30 07:31:38 +08:00
|
|
|
|
|
|
|
unsigned ARMTTI::getCastInstrCost(unsigned Opcode, Type *Dst,
|
|
|
|
Type *Src) const {
|
|
|
|
int ISD = TLI->InstructionOpcodeToISD(Opcode);
|
|
|
|
assert(ISD && "Invalid opcode");
|
|
|
|
|
2013-03-15 23:10:47 +08:00
|
|
|
// Single to/from double precision conversions.
|
|
|
|
static const CostTblEntry<MVT> NEONFltDblTbl[] = {
|
|
|
|
// Vector fptrunc/fpext conversions.
|
|
|
|
{ ISD::FP_ROUND, MVT::v2f64, 2 },
|
|
|
|
{ ISD::FP_EXTEND, MVT::v2f32, 2 },
|
|
|
|
{ ISD::FP_EXTEND, MVT::v4f32, 4 }
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Src->isVectorTy() && ST->hasNEON() && (ISD == ISD::FP_ROUND ||
|
|
|
|
ISD == ISD::FP_EXTEND)) {
|
|
|
|
std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Src);
|
|
|
|
int Idx = CostTableLookup<MVT>(NEONFltDblTbl, array_lengthof(NEONFltDblTbl),
|
|
|
|
ISD, LT.second);
|
|
|
|
if (Idx != -1)
|
|
|
|
return LT.first * NEONFltDblTbl[Idx].Cost;
|
|
|
|
}
|
|
|
|
|
2013-01-30 07:31:38 +08:00
|
|
|
EVT SrcTy = TLI->getValueType(Src);
|
|
|
|
EVT DstTy = TLI->getValueType(Dst);
|
|
|
|
|
|
|
|
if (!SrcTy.isSimple() || !DstTy.isSimple())
|
|
|
|
return TargetTransformInfo::getCastInstrCost(Opcode, Dst, Src);
|
|
|
|
|
|
|
|
// Some arithmetic, load and store operations have specific instructions
|
2013-02-05 22:05:55 +08:00
|
|
|
// to cast up/down their types automatically at no extra cost.
|
|
|
|
// TODO: Get these tables to know at least what the related operations are.
|
|
|
|
static const TypeConversionCostTblEntry<MVT> NEONVectorConversionTbl[] = {
|
2013-01-30 07:31:38 +08:00
|
|
|
{ ISD::SIGN_EXTEND, MVT::v4i32, MVT::v4i16, 0 },
|
|
|
|
{ ISD::ZERO_EXTEND, MVT::v4i32, MVT::v4i16, 0 },
|
|
|
|
{ ISD::SIGN_EXTEND, MVT::v2i64, MVT::v2i32, 1 },
|
|
|
|
{ ISD::ZERO_EXTEND, MVT::v2i64, MVT::v2i32, 1 },
|
|
|
|
{ ISD::TRUNCATE, MVT::v4i32, MVT::v4i64, 0 },
|
|
|
|
{ ISD::TRUNCATE, MVT::v4i16, MVT::v4i32, 1 },
|
2013-02-05 22:05:55 +08:00
|
|
|
|
2013-03-19 16:15:38 +08:00
|
|
|
// The number of vmovl instructions for the extension.
|
|
|
|
{ ISD::SIGN_EXTEND, MVT::v4i64, MVT::v4i16, 3 },
|
|
|
|
{ ISD::ZERO_EXTEND, MVT::v4i64, MVT::v4i16, 3 },
|
|
|
|
{ ISD::SIGN_EXTEND, MVT::v8i32, MVT::v8i8, 3 },
|
|
|
|
{ ISD::ZERO_EXTEND, MVT::v8i32, MVT::v8i8, 3 },
|
|
|
|
{ ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i8, 7 },
|
|
|
|
{ ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i8, 7 },
|
|
|
|
{ ISD::SIGN_EXTEND, MVT::v8i64, MVT::v8i16, 6 },
|
|
|
|
{ ISD::ZERO_EXTEND, MVT::v8i64, MVT::v8i16, 6 },
|
|
|
|
{ ISD::SIGN_EXTEND, MVT::v16i32, MVT::v16i8, 6 },
|
|
|
|
{ ISD::ZERO_EXTEND, MVT::v16i32, MVT::v16i8, 6 },
|
|
|
|
|
2013-03-13 05:19:22 +08:00
|
|
|
// Operations that we legalize using load/stores to the stack.
|
|
|
|
{ ISD::TRUNCATE, MVT::v16i8, MVT::v16i32, 4*1 + 16*2 + 2*1 },
|
|
|
|
{ ISD::TRUNCATE, MVT::v8i8, MVT::v8i32, 2*1 + 8*2 + 1 },
|
|
|
|
|
2013-02-05 22:05:55 +08:00
|
|
|
// Vector float <-> i32 conversions.
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i32, 1 },
|
2013-03-19 06:47:09 +08:00
|
|
|
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i8, 3 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i8, 3 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i16, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i16, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v2f32, MVT::v2i32, 1 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v2f32, MVT::v2i32, 1 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i1, 3 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i1, 3 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i8, 3 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i8, 3 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v4f32, MVT::v4i16, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v4f32, MVT::v4i16, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i16, 4 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i16, 4 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v8f32, MVT::v8i32, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v8f32, MVT::v8i32, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i16, 8 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i16, 8 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v16f32, MVT::v16i32, 4 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v16f32, MVT::v16i32, 4 },
|
|
|
|
|
2013-02-05 22:05:55 +08:00
|
|
|
{ ISD::FP_TO_SINT, MVT::v4i32, MVT::v4f32, 1 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::v4i32, MVT::v4f32, 1 },
|
2013-03-19 06:47:06 +08:00
|
|
|
{ ISD::FP_TO_SINT, MVT::v4i8, MVT::v4f32, 3 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::v4i8, MVT::v4f32, 3 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::v4i16, MVT::v4f32, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::v4i16, MVT::v4f32, 2 },
|
2013-02-05 22:05:55 +08:00
|
|
|
|
|
|
|
// Vector double <-> i32 conversions.
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i32, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, 2 },
|
2013-03-19 06:47:09 +08:00
|
|
|
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i8, 4 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i8, 4 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i16, 3 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i16, 3 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::v2f64, MVT::v2i32, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::v2f64, MVT::v2i32, 2 },
|
|
|
|
|
2013-02-05 22:05:55 +08:00
|
|
|
{ ISD::FP_TO_SINT, MVT::v2i32, MVT::v2f64, 2 },
|
2013-03-19 06:47:06 +08:00
|
|
|
{ ISD::FP_TO_UINT, MVT::v2i32, MVT::v2f64, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::v8i16, MVT::v8f32, 4 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::v8i16, MVT::v8f32, 4 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::v16i16, MVT::v16f32, 8 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::v16i16, MVT::v16f32, 8 }
|
2013-01-30 07:31:38 +08:00
|
|
|
};
|
|
|
|
|
2013-02-05 22:05:55 +08:00
|
|
|
if (SrcTy.isVector() && ST->hasNEON()) {
|
|
|
|
int Idx = ConvertCostTableLookup<MVT>(NEONVectorConversionTbl,
|
|
|
|
array_lengthof(NEONVectorConversionTbl),
|
2013-01-30 07:31:38 +08:00
|
|
|
ISD, DstTy.getSimpleVT(), SrcTy.getSimpleVT());
|
|
|
|
if (Idx != -1)
|
2013-02-05 22:05:55 +08:00
|
|
|
return NEONVectorConversionTbl[Idx].Cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scalar float to integer conversions.
|
|
|
|
static const TypeConversionCostTblEntry<MVT> NEONFloatConversionTbl[] = {
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i1, MVT::f32, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i1, MVT::f32, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i1, MVT::f64, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i1, MVT::f64, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i8, MVT::f32, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i8, MVT::f32, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i8, MVT::f64, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i8, MVT::f64, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i16, MVT::f32, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i16, MVT::f32, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i16, MVT::f64, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i16, MVT::f64, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i32, MVT::f32, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i32, MVT::f32, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i32, MVT::f64, 2 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i32, MVT::f64, 2 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i64, MVT::f32, 10 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i64, MVT::f32, 10 },
|
|
|
|
{ ISD::FP_TO_SINT, MVT::i64, MVT::f64, 10 },
|
|
|
|
{ ISD::FP_TO_UINT, MVT::i64, MVT::f64, 10 }
|
|
|
|
};
|
|
|
|
if (SrcTy.isFloatingPoint() && ST->hasNEON()) {
|
|
|
|
int Idx = ConvertCostTableLookup<MVT>(NEONFloatConversionTbl,
|
|
|
|
array_lengthof(NEONFloatConversionTbl),
|
|
|
|
ISD, DstTy.getSimpleVT(),
|
|
|
|
SrcTy.getSimpleVT());
|
|
|
|
if (Idx != -1)
|
|
|
|
return NEONFloatConversionTbl[Idx].Cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scalar integer to float conversions.
|
|
|
|
static const TypeConversionCostTblEntry<MVT> NEONIntegerConversionTbl[] = {
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f32, MVT::i1, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f32, MVT::i1, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f64, MVT::i1, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f64, MVT::i1, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f32, MVT::i8, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f32, MVT::i8, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f64, MVT::i8, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f64, MVT::i8, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f32, MVT::i16, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f32, MVT::i16, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f64, MVT::i16, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f64, MVT::i16, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f32, MVT::i32, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f32, MVT::i32, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f64, MVT::i32, 2 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f64, MVT::i32, 2 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f32, MVT::i64, 10 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f32, MVT::i64, 10 },
|
|
|
|
{ ISD::SINT_TO_FP, MVT::f64, MVT::i64, 10 },
|
|
|
|
{ ISD::UINT_TO_FP, MVT::f64, MVT::i64, 10 }
|
|
|
|
};
|
|
|
|
|
|
|
|
if (SrcTy.isInteger() && ST->hasNEON()) {
|
|
|
|
int Idx = ConvertCostTableLookup<MVT>(NEONIntegerConversionTbl,
|
|
|
|
array_lengthof(NEONIntegerConversionTbl),
|
|
|
|
ISD, DstTy.getSimpleVT(),
|
|
|
|
SrcTy.getSimpleVT());
|
|
|
|
if (Idx != -1)
|
|
|
|
return NEONIntegerConversionTbl[Idx].Cost;
|
2013-01-30 07:31:38 +08:00
|
|
|
}
|
|
|
|
|
2013-02-05 22:05:55 +08:00
|
|
|
// Scalar integer conversion costs.
|
|
|
|
static const TypeConversionCostTblEntry<MVT> ARMIntegerConversionTbl[] = {
|
|
|
|
// i16 -> i64 requires two dependent operations.
|
|
|
|
{ ISD::SIGN_EXTEND, MVT::i64, MVT::i16, 2 },
|
|
|
|
|
|
|
|
// Truncates on i64 are assumed to be free.
|
|
|
|
{ ISD::TRUNCATE, MVT::i32, MVT::i64, 0 },
|
|
|
|
{ ISD::TRUNCATE, MVT::i16, MVT::i64, 0 },
|
|
|
|
{ ISD::TRUNCATE, MVT::i8, MVT::i64, 0 },
|
|
|
|
{ ISD::TRUNCATE, MVT::i1, MVT::i64, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
if (SrcTy.isInteger()) {
|
|
|
|
int Idx =
|
|
|
|
ConvertCostTableLookup<MVT>(ARMIntegerConversionTbl,
|
|
|
|
array_lengthof(ARMIntegerConversionTbl),
|
|
|
|
ISD, DstTy.getSimpleVT(),
|
|
|
|
SrcTy.getSimpleVT());
|
|
|
|
if (Idx != -1)
|
|
|
|
return ARMIntegerConversionTbl[Idx].Cost;
|
|
|
|
}
|
|
|
|
|
2013-01-30 07:31:38 +08:00
|
|
|
return TargetTransformInfo::getCastInstrCost(Opcode, Dst, Src);
|
|
|
|
}
|
2013-02-04 10:52:05 +08:00
|
|
|
|
|
|
|
unsigned ARMTTI::getVectorInstrCost(unsigned Opcode, Type *ValTy,
|
|
|
|
unsigned Index) const {
|
2013-02-08 22:50:48 +08:00
|
|
|
// Penalize inserting into an D-subregister. We end up with a three times
|
|
|
|
// lower estimated throughput on swift.
|
2013-02-04 10:52:05 +08:00
|
|
|
if (ST->isSwift() &&
|
|
|
|
Opcode == Instruction::InsertElement &&
|
|
|
|
ValTy->isVectorTy() &&
|
|
|
|
ValTy->getScalarSizeInBits() <= 32)
|
2013-02-08 22:50:48 +08:00
|
|
|
return 3;
|
2013-02-04 10:52:05 +08:00
|
|
|
|
|
|
|
return TargetTransformInfo::getVectorInstrCost(Opcode, ValTy, Index);
|
|
|
|
}
|
2013-02-08 00:10:15 +08:00
|
|
|
|
|
|
|
unsigned ARMTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy,
|
|
|
|
Type *CondTy) const {
|
|
|
|
|
|
|
|
int ISD = TLI->InstructionOpcodeToISD(Opcode);
|
|
|
|
// On NEON a a vector select gets lowered to vbsl.
|
|
|
|
if (ST->hasNEON() && ValTy->isVectorTy() && ISD == ISD::SELECT) {
|
2013-03-15 03:17:02 +08:00
|
|
|
// Lowering of some vector selects is currently far from perfect.
|
|
|
|
static const TypeConversionCostTblEntry<MVT> NEONVectorSelectTbl[] = {
|
|
|
|
{ ISD::SELECT, MVT::v16i1, MVT::v16i16, 2*16 + 1 + 3*1 + 4*1 },
|
|
|
|
{ ISD::SELECT, MVT::v8i1, MVT::v8i32, 4*8 + 1*3 + 1*4 + 1*2 },
|
|
|
|
{ ISD::SELECT, MVT::v16i1, MVT::v16i32, 4*16 + 1*6 + 1*8 + 1*4 },
|
|
|
|
{ ISD::SELECT, MVT::v4i1, MVT::v4i64, 4*4 + 1*2 + 1 },
|
|
|
|
{ ISD::SELECT, MVT::v8i1, MVT::v8i64, 50 },
|
|
|
|
{ ISD::SELECT, MVT::v16i1, MVT::v16i64, 100 }
|
|
|
|
};
|
|
|
|
|
|
|
|
EVT SelCondTy = TLI->getValueType(CondTy);
|
|
|
|
EVT SelValTy = TLI->getValueType(ValTy);
|
|
|
|
int Idx = ConvertCostTableLookup<MVT>(NEONVectorSelectTbl,
|
|
|
|
array_lengthof(NEONVectorSelectTbl),
|
|
|
|
ISD, SelCondTy.getSimpleVT(),
|
|
|
|
SelValTy.getSimpleVT());
|
|
|
|
if (Idx != -1)
|
|
|
|
return NEONVectorSelectTbl[Idx].Cost;
|
|
|
|
|
2013-02-08 00:10:15 +08:00
|
|
|
std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(ValTy);
|
|
|
|
return LT.first;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TargetTransformInfo::getCmpSelInstrCost(Opcode, ValTy, CondTy);
|
|
|
|
}
|
2013-02-08 22:50:48 +08:00
|
|
|
|
|
|
|
unsigned ARMTTI::getAddressComputationCost(Type *Ty) const {
|
|
|
|
// In many cases the address computation is not merged into the instruction
|
|
|
|
// addressing mode.
|
|
|
|
return 1;
|
|
|
|
}
|
2013-02-12 10:40:39 +08:00
|
|
|
|
|
|
|
unsigned ARMTTI::getShuffleCost(ShuffleKind Kind, Type *Tp, int Index,
|
|
|
|
Type *SubTp) const {
|
|
|
|
// We only handle costs of reverse shuffles for now.
|
|
|
|
if (Kind != SK_Reverse)
|
|
|
|
return TargetTransformInfo::getShuffleCost(Kind, Tp, Index, SubTp);
|
|
|
|
|
|
|
|
static const CostTblEntry<MVT> NEONShuffleTbl[] = {
|
|
|
|
// Reverse shuffle cost one instruction if we are shuffling within a double
|
|
|
|
// word (vrev) or two if we shuffle a quad word (vrev, vext).
|
|
|
|
{ ISD::VECTOR_SHUFFLE, MVT::v2i32, 1 },
|
|
|
|
{ ISD::VECTOR_SHUFFLE, MVT::v2f32, 1 },
|
|
|
|
{ ISD::VECTOR_SHUFFLE, MVT::v2i64, 1 },
|
|
|
|
{ ISD::VECTOR_SHUFFLE, MVT::v2f64, 1 },
|
|
|
|
|
|
|
|
{ ISD::VECTOR_SHUFFLE, MVT::v4i32, 2 },
|
|
|
|
{ ISD::VECTOR_SHUFFLE, MVT::v4f32, 2 },
|
|
|
|
{ ISD::VECTOR_SHUFFLE, MVT::v8i16, 2 },
|
|
|
|
{ ISD::VECTOR_SHUFFLE, MVT::v16i8, 2 }
|
|
|
|
};
|
|
|
|
|
|
|
|
std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Tp);
|
|
|
|
|
|
|
|
int Idx = CostTableLookup<MVT>(NEONShuffleTbl, array_lengthof(NEONShuffleTbl),
|
|
|
|
ISD::VECTOR_SHUFFLE, LT.second);
|
|
|
|
if (Idx == -1)
|
|
|
|
return TargetTransformInfo::getShuffleCost(Kind, Tp, Index, SubTp);
|
|
|
|
|
|
|
|
return LT.first * NEONShuffleTbl[Idx].Cost;
|
|
|
|
}
|