diff options
author | Renato Golin <renato.golin@linaro.org> | 2013-01-16 21:29:55 +0000 |
---|---|---|
committer | Renato Golin <renato.golin@linaro.org> | 2013-01-16 21:29:55 +0000 |
commit | d3c965d6251e6d939f7797f8704d4e3a82f7e274 (patch) | |
tree | 8efa0dd2fa26f1d3c24e434257eeabe7bce8db22 /lib/Analysis | |
parent | ac47c1bc39d9d5de51d8ef5385545e643e076556 (diff) | |
download | external_llvm-d3c965d6251e6d939f7797f8704d4e3a82f7e274.zip external_llvm-d3c965d6251e6d939f7797f8704d4e3a82f7e274.tar.gz external_llvm-d3c965d6251e6d939f7797f8704d4e3a82f7e274.tar.bz2 |
Change CostTable model to be global to all targets
Moving the X86CostTable to a common place, so that other back-ends
can share the code. Also simplifying it a bit and commoning up
tables with one and two types on operations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172658 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/TargetTransformInfo.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/Analysis/TargetTransformInfo.cpp b/lib/Analysis/TargetTransformInfo.cpp index 3ef74eb..344be71 100644 --- a/lib/Analysis/TargetTransformInfo.cpp +++ b/lib/Analysis/TargetTransformInfo.cpp @@ -286,3 +286,44 @@ char NoTTI::ID = 0; ImmutablePass *llvm::createNoTargetTransformInfoPass() { return new NoTTI(); } + +//======================================= COST TABLES == + +CostTable::CostTable(const CostTableEntry *table, const size_t size, unsigned numTypes) + : table(table), size(size), numTypes(numTypes) { + assert(table && "missing cost table"); + assert(size > 0 && "empty cost table"); +} + +unsigned CostTable::_findCost(int ISD, MVT *Types) const { + for (unsigned i = 0; i < size; ++i) { + if (table[i].ISD == ISD) { + bool found = true; + for (unsigned t=0; t<numTypes; t++) { + if (table[i].Types[t] != Types[t]) { + found = false; + break; + } + } + if (found) + return table[i].Cost; + } + } + return COST_NOT_FOUND; +} + +UnaryCostTable::UnaryCostTable(const CostTableEntry *table, const size_t size) + : CostTable(table, size, 1) { } + +unsigned UnaryCostTable::findCost(int ISD, MVT Type) const { + MVT tys[1] = { Type }; + return _findCost(ISD, tys); +} + +BinaryCostTable::BinaryCostTable(const CostTableEntry *table, const size_t size) + : CostTable(table, size, 2) { } + +unsigned BinaryCostTable::findCost(int ISD, MVT Type, MVT SrcType) const { + MVT tys[2] = { Type, SrcType }; + return _findCost(ISD, tys); +} |