[Beignet] [PATCH 3/3] do not use C++11 features inside libgbeinterp
Zhigang Gong
zhigang.gong at linux.intel.com
Tue Jan 6 00:19:15 PST 2015
LGTM, will push latter, thanks.
On Sun, Dec 28, 2014 at 09:23:19PM +0800, Guo Yejun wrote:
> some embedded systems have not upgraded the c/c++ environment, it
> makes the request to remove the C++11 features. It is possible for
> the CL_EMBEDDED_PROFILE with some more changes (to be done later).
> This change modifies the keyword auto and nullptr.
>
> btw, C++ new feature is a must for libgbe (the OpenCL compiler)
> which depends on LLVM/clang
>
> Signed-off-by: Guo Yejun <yejun.guo at intel.com>
> ---
> backend/src/backend/program.cpp | 17 ++++---
> backend/src/backend/program.hpp | 6 +--
> backend/src/ir/constant.cpp | 3 +-
> backend/src/ir/constant.hpp | 5 ++-
> backend/src/ir/function.hpp | 22 +++++++--
> backend/src/ir/image.cpp | 98 ++++++++++++++++++++---------------------
> backend/src/ir/liveness.hpp | 8 ++--
> backend/src/ir/printf.cpp | 12 ++---
> backend/src/ir/printf.hpp | 6 ++-
> backend/src/ir/sampler.cpp | 14 +++---
> backend/src/ir/sampler.hpp | 4 +-
> backend/src/ir/unit.hpp | 3 +-
> 12 files changed, 111 insertions(+), 87 deletions(-)
>
> diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
> index abdb1e4..8ccf115 100644
> --- a/backend/src/backend/program.cpp
> +++ b/backend/src/backend/program.cpp
> @@ -106,7 +106,8 @@ namespace gbe {
>
> Program::Program(void) : constantSet(NULL) {}
> Program::~Program(void) {
> - for (auto &kernel : kernels) GBE_DELETE(kernel.second);
> + for (map<std::string, Kernel*>::iterator it = kernels.begin(); it != kernels.end(); ++it)
> + GBE_DELETE(it->second);
> if (constantSet) delete constantSet;
> }
>
> @@ -191,8 +192,8 @@ namespace gbe {
> }
>
> OUT_UPDATE_SZ(ker_num);
> - for (auto ker : kernels) {
> - size_t sz = ker.second->serializeToBin(outs);
> + for (map<std::string, Kernel*>::iterator it = kernels.begin(); it != kernels.end(); ++it) {
> + size_t sz = it->second->serializeToBin(outs);
> if (!sz)
> return 0;
>
> @@ -275,7 +276,8 @@ namespace gbe {
> }
>
> OUT_UPDATE_SZ(patches.size());
> - for (auto patch : patches) {
> + for (size_t i = 0; i < patches.size(); ++i) {
> + PatchInfo& patch = patches[i];
It's better to use const PatchInfo& patch here.
> unsigned int tmp;
> tmp = patch.type;
> OUT_UPDATE_SZ(tmp);
> @@ -446,8 +448,8 @@ namespace gbe {
> constantSet->printStatus(indent + 4, outs);
> }
>
> - for (auto ker : kernels) {
> - ker.second->printStatus(indent + 4, outs);
> + for (map<std::string, Kernel*>::iterator it = kernels.begin(); it != kernels.end(); ++it) {
> + it->second->printStatus(indent + 4, outs);
> }
>
> outs << spaces << "================ End Program ================" << "\n";
> @@ -481,7 +483,8 @@ namespace gbe {
>
> outs << spaces_nl << " Patches Number is " << patches.size() << "\n";
> num = 0;
> - for (auto patch : patches) {
> + for (size_t i = 0; i < patches.size(); ++i) {
> + PatchInfo& patch = patches[i];
> num++;
> outs << spaces_nl << " patch " << num << ":\n";
> outs << spaces_nl << " type value: "<< patch.type << "\n";
> diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
> index 446c521..66f90aa 100644
> --- a/backend/src/backend/program.hpp
> +++ b/backend/src/backend/program.hpp
> @@ -250,7 +250,7 @@ namespace gbe {
> uint32_t getKernelNum(void) const { return kernels.size(); }
> /*! Get the kernel from its name */
> Kernel *getKernel(const std::string &name) const {
> - auto it = kernels.find(name);
> + map<std::string, Kernel*>::const_iterator it = kernels.find(name);
> if (it == kernels.end())
> return NULL;
> else
> @@ -260,9 +260,9 @@ namespace gbe {
> Kernel *getKernel(uint32_t ID) const {
> uint32_t currID = 0;
> Kernel *kernel = NULL;
> - for (const auto &pair : kernels) {
> + for (map<std::string, Kernel*>::const_iterator it = kernels.begin(); it != kernels.end(); ++it) {
> if (currID == ID) {
> - kernel = pair.second;
> + kernel = it->second;
> break;
> }
> currID++;
> diff --git a/backend/src/ir/constant.cpp b/backend/src/ir/constant.cpp
> index 6ef8ea6..fa4e14a 100644
> --- a/backend/src/ir/constant.cpp
> +++ b/backend/src/ir/constant.cpp
> @@ -56,7 +56,8 @@ namespace ir {
> }
>
> OUT_UPDATE_SZ(constants.size());
> - for (auto const &cnst : constants) {
> + for (size_t i = 0; i < constants.size(); ++i) {
> + Constant& cnst = constants[i];
> size_t bytes = sizeof(cnst.getName().size()) //name length self
> + cnst.getName().size()*sizeof(char) //name
> + sizeof(cnst.getSize()) //size
> diff --git a/backend/src/ir/constant.hpp b/backend/src/ir/constant.hpp
> index f5f172d..0891d7b 100644
> --- a/backend/src/ir/constant.hpp
> +++ b/backend/src/ir/constant.hpp
> @@ -76,12 +76,13 @@ namespace ir {
> Constant& getConstant(size_t i) { return constants[i]; }
> /*! Get a special constant */
> Constant& getConstant(const std::string & name) {
> - for (auto & c : constants) {
> + for (size_t i = 0; i < constants.size(); ++i) {
> + Constant& c = constants[i];
> if (c.getName() == name)
> return c;
> }
> GBE_ASSERT(false);
> - return *(Constant *)nullptr;
> + return *(Constant *)NULL;
> }
> /*! Number of bytes of serialized constant data */
> size_t getDataSize(void) const { return data.size(); }
> diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp
> index 4aea087..5d00cca 100644
> --- a/backend/src/ir/function.hpp
> +++ b/backend/src/ir/function.hpp
> @@ -353,12 +353,20 @@ namespace ir {
> * this is not an input argument
> */
> INLINE const FunctionArgument *getArg(const Register ®) const {
> - for (auto arg : args) if (arg->reg == reg) return arg;
> + for (size_t i = 0; i < args.size(); ++i) {
> + const FunctionArgument* arg = args[i];
> + if (arg->reg == reg)
> + return arg;
> + }
> return NULL;
> }
>
> INLINE FunctionArgument *getArg(const Register ®) {
> - for (auto arg : args) if (arg->reg == reg) return arg;
> + for (size_t i = 0; i < args.size(); ++i) {
> + FunctionArgument* arg = args[i];
> + if (arg->reg == reg)
> + return arg;
> + }
> return NULL;
> }
>
> @@ -417,12 +425,18 @@ namespace ir {
> /*! Apply the given functor on all basic blocks */
> template <typename T>
> INLINE void foreachBlock(const T &functor) const {
> - for (auto block : blocks) functor(*block);
> + for (size_t i = 0; i < blocks.size(); ++i) {
> + BasicBlock* block = blocks[i];
> + functor(*block);
> + }
> }
> /*! Apply the given functor on all instructions */
> template <typename T>
> INLINE void foreachInstruction(const T &functor) const {
> - for (auto block : blocks) block->foreach(functor);
> + for (size_t i = 0; i < blocks.size(); ++i) {
> + BasicBlock* block = blocks[i];
> + block->foreach(functor);
> + }
> }
> /*! Does it use SLM */
> INLINE bool getUseSLM(void) const { return this->useSLM; }
> diff --git a/backend/src/ir/image.cpp b/backend/src/ir/image.cpp
> index d28a72a..8976a68 100644
> --- a/backend/src/ir/image.cpp
> +++ b/backend/src/ir/image.cpp
> @@ -58,7 +58,7 @@ namespace ir {
>
> void ImageSet::appendInfo(ImageInfoKey key, uint32_t offset)
> {
> - auto it = indexMap.find(key.index);
> + map<uint32_t, struct ImageInfo *>::iterator it = indexMap.find(key.index);
> assert(it != indexMap.end());
> struct ImageInfo *imageInfo = it->second;
> setInfoOffset4Type(imageInfo, key.type, offset);
> @@ -67,8 +67,8 @@ namespace ir {
> void ImageSet::clearInfo()
> {
> struct ImageInfo *imageInfo;
> - for(auto &it : indexMap) {
> - imageInfo = it.second;
> + for (map<uint32_t, struct ImageInfo *>::iterator it = indexMap.begin(); it != indexMap.end(); ++it) {
> + imageInfo = it->second;
> imageInfo->wSlot = -1;
> imageInfo->hSlot = -1;
> imageInfo->depthSlot = -1;
> @@ -78,7 +78,7 @@ namespace ir {
> }
> int32_t ImageSet::getInfoOffset(ImageInfoKey key) const
> {
> - auto it = indexMap.find(key.index);
> + map<uint32_t, struct ImageInfo *>::const_iterator it = indexMap.find(key.index);
> if (it == indexMap.end())
> return -1;
> struct ImageInfo *imageInfo = it->second;
> @@ -87,20 +87,20 @@ namespace ir {
>
> uint32_t ImageSet::getIdx(const Register imageReg) const
> {
> - auto it = regMap.find(imageReg);
> + map<Register, struct ImageInfo *>::const_iterator it = regMap.find(imageReg);
> GBE_ASSERT(it != regMap.end());
> return it->second->idx;
> }
>
> void ImageSet::getData(struct ImageInfo *imageInfos) const {
> int id = 0;
> - for(auto &it : regMap)
> - imageInfos[id++] = *it.second;
> + for (map<Register, struct ImageInfo *>::const_iterator it = regMap.begin(); it != regMap.end(); ++it)
> + imageInfos[id++] = *(it->second);
> }
>
> ImageSet::~ImageSet() {
> - for(auto &it : regMap)
> - GBE_DELETE(it.second);
> + for (map<Register, struct ImageInfo *>::const_iterator it = regMap.begin(); it != regMap.end(); ++it)
> + GBE_DELETE(it->second);
> }
>
> #define OUT_UPDATE_SZ(elt) SERIALIZE_OUT(elt, outs, ret_size)
> @@ -113,29 +113,29 @@ namespace ir {
> OUT_UPDATE_SZ(magic_begin);
>
> OUT_UPDATE_SZ(regMap.size());
> - for (auto iter : regMap) {
> - OUT_UPDATE_SZ(iter.first);
> - OUT_UPDATE_SZ(iter.second->arg_idx);
> - OUT_UPDATE_SZ(iter.second->idx);
> - OUT_UPDATE_SZ(iter.second->wSlot);
> - OUT_UPDATE_SZ(iter.second->hSlot);
> - OUT_UPDATE_SZ(iter.second->depthSlot);
> - OUT_UPDATE_SZ(iter.second->dataTypeSlot);
> - OUT_UPDATE_SZ(iter.second->channelOrderSlot);
> - OUT_UPDATE_SZ(iter.second->dimOrderSlot);
> + for (map<Register, struct ImageInfo *>::const_iterator it = regMap.begin(); it != regMap.end(); ++it) {
> + OUT_UPDATE_SZ(it->first);
> + OUT_UPDATE_SZ(it->second->arg_idx);
> + OUT_UPDATE_SZ(it->second->idx);
> + OUT_UPDATE_SZ(it->second->wSlot);
> + OUT_UPDATE_SZ(it->second->hSlot);
> + OUT_UPDATE_SZ(it->second->depthSlot);
> + OUT_UPDATE_SZ(it->second->dataTypeSlot);
> + OUT_UPDATE_SZ(it->second->channelOrderSlot);
> + OUT_UPDATE_SZ(it->second->dimOrderSlot);
> }
>
> OUT_UPDATE_SZ(indexMap.size());
> - for (auto iter : indexMap) {
> - OUT_UPDATE_SZ(iter.first);
> - OUT_UPDATE_SZ(iter.second->arg_idx);
> - OUT_UPDATE_SZ(iter.second->idx);
> - OUT_UPDATE_SZ(iter.second->wSlot);
> - OUT_UPDATE_SZ(iter.second->hSlot);
> - OUT_UPDATE_SZ(iter.second->depthSlot);
> - OUT_UPDATE_SZ(iter.second->dataTypeSlot);
> - OUT_UPDATE_SZ(iter.second->channelOrderSlot);
> - OUT_UPDATE_SZ(iter.second->dimOrderSlot);
> + for (map<uint32_t, struct ImageInfo *>::iterator it = indexMap.begin(); it != indexMap.end(); ++it) {
> + OUT_UPDATE_SZ(it->first);
> + OUT_UPDATE_SZ(it->second->arg_idx);
> + OUT_UPDATE_SZ(it->second->idx);
> + OUT_UPDATE_SZ(it->second->wSlot);
> + OUT_UPDATE_SZ(it->second->hSlot);
> + OUT_UPDATE_SZ(it->second->depthSlot);
> + OUT_UPDATE_SZ(it->second->dataTypeSlot);
> + OUT_UPDATE_SZ(it->second->channelOrderSlot);
> + OUT_UPDATE_SZ(it->second->dimOrderSlot);
> }
>
> OUT_UPDATE_SZ(magic_end);
> @@ -211,31 +211,31 @@ namespace ir {
> outs << spaces_nl << " ImageSet Map: [reg, arg_idx, idx, wSlot, hSlot, depthSlot, "
> "dataTypeSlot, channelOrderSlot, dimOrderSlot]\n";
> outs << spaces_nl << " regMap size: " << regMap.size() << "\n";
> - for (auto iter : regMap) {
> - outs << spaces_nl << " [" << iter.first << ", "
> - << iter.second->arg_idx << ", "
> - << iter.second->idx << ", "
> - << iter.second->wSlot << ", "
> - << iter.second->hSlot << ", "
> - << iter.second->depthSlot << ", "
> - << iter.second->dataTypeSlot << ", "
> - << iter.second->channelOrderSlot << ", "
> - << iter.second->dimOrderSlot << "]" << "\n";
> + for (map<Register, struct ImageInfo *>::const_iterator it = regMap.begin(); it != regMap.end(); ++it) {
> + outs << spaces_nl << " [" << it->first << ", "
> + << it->second->arg_idx << ", "
> + << it->second->idx << ", "
> + << it->second->wSlot << ", "
> + << it->second->hSlot << ", "
> + << it->second->depthSlot << ", "
> + << it->second->dataTypeSlot << ", "
> + << it->second->channelOrderSlot << ", "
> + << it->second->dimOrderSlot << "]" << "\n";
> }
>
> outs << spaces_nl << " ImageSet Map: [index, arg_idx, idx, wSlot, hSlot, depthSlot, "
> "dataTypeSlot, channelOrderSlot, dimOrderSlot]\n";
> outs << spaces_nl << " regMap size: " << indexMap.size() << "\n";
> - for (auto iter : indexMap) {
> - outs << spaces_nl << " [" << iter.first << ", "
> - << iter.second->arg_idx << ", "
> - << iter.second->idx << ", "
> - << iter.second->wSlot << ", "
> - << iter.second->hSlot << ", "
> - << iter.second->depthSlot << ", "
> - << iter.second->dataTypeSlot << ", "
> - << iter.second->channelOrderSlot << ", "
> - << iter.second->dimOrderSlot << ", " << "\n";
> + for (map<uint32_t, struct ImageInfo *>::iterator it = indexMap.begin(); it != indexMap.end(); ++it) {
> + outs << spaces_nl << " [" << it->first << ", "
> + << it->second->arg_idx << ", "
> + << it->second->idx << ", "
> + << it->second->wSlot << ", "
> + << it->second->hSlot << ", "
> + << it->second->depthSlot << ", "
> + << it->second->dataTypeSlot << ", "
> + << it->second->channelOrderSlot << ", "
> + << it->second->dimOrderSlot << ", " << "\n";
> }
>
> outs << spaces << "------------- End ImageSet -------------" << "\n";
> diff --git a/backend/src/ir/liveness.hpp b/backend/src/ir/liveness.hpp
> index 1bc66fe..4a7dc4e 100644
> --- a/backend/src/ir/liveness.hpp
> +++ b/backend/src/ir/liveness.hpp
> @@ -100,8 +100,8 @@ namespace ir {
> template <DataFlowDirection dir, typename T>
> void foreach(const T &functor) {
> // Iterate on all blocks
> - for (const auto &pair : liveness) {
> - BlockInfo &info = *pair.second;
> + for (Info::iterator pair = liveness.begin(); pair != liveness.end(); ++pair) {
> + BlockInfo &info = *(pair->second);
> const BasicBlock &bb = info.bb;
> const BlockSet *set = NULL;
> if (dir == DF_SUCC)
> @@ -109,8 +109,8 @@ namespace ir {
> else
> set = &bb.getPredecessorSet();
> // Iterate over all successors
> - for (auto other : *set) {
> - auto otherInfo = liveness.find(other);
> + for (BlockSet::iterator other = (*set).begin(); other != (*set).end(); ++other) {
> + Info::iterator otherInfo = liveness.find(*other);
> GBE_ASSERT(otherInfo != liveness.end() && otherInfo->second != NULL);
> functor(info, *otherInfo->second);
> }
> diff --git a/backend/src/ir/printf.cpp b/backend/src/ir/printf.cpp
> index 7b670f7..0e9f81c 100644
> --- a/backend/src/ir/printf.cpp
> +++ b/backend/src/ir/printf.cpp
> @@ -35,11 +35,11 @@ namespace gbe
> {
> fmts.push_back(*fmt);
>
> - for (auto &f : fmts.back()) {
> - if (f.type == PRINTF_SLOT_TYPE_STRING)
> + for (PrintfFmt::iterator f = fmts.back().begin(); f != fmts.back().end(); ++f) {
> + if (f->type == PRINTF_SLOT_TYPE_STRING)
> continue;
>
> - slots.push_back(&f);
> + slots.push_back(&(*f));
> }
>
> /* Update the total size of size. */
> @@ -121,14 +121,16 @@ namespace gbe
> std::string pf_str;
> int stmt = 0;
>
> - for (auto &pf : fmts) {
> + for (size_t count = 0; count < fmts.size(); ++count) {
> + PrintfFmt& pf = fmts[count];
> for (i = 0; i < global_wk_sz0; i++) {
> for (j = 0; j < global_wk_sz1; j++) {
> for (k = 0; k < global_wk_sz2; k++) {
> int loop_num = ((int *)index_addr)[stmt*global_wk_sz0*global_wk_sz1*global_wk_sz2
> + k*global_wk_sz0*global_wk_sz1 + j*global_wk_sz0 + i];
> for (int n = 0; n < loop_num; n++) {
> - for (auto &slot : pf) {
> + for (PrintfFmt::iterator pfit = pf.begin(); pfit != pf.end(); ++pfit) {
> + PrintfSlot& slot = *pfit;
> pf_str = "";
> int vec_num;
>
> diff --git a/backend/src/ir/printf.hpp b/backend/src/ir/printf.hpp
> index b9f7619..8639644 100644
> --- a/backend/src/ir/printf.hpp
> +++ b/backend/src/ir/printf.hpp
> @@ -146,11 +146,13 @@ namespace gbe
> {
> public:
> PrintfSet(const PrintfSet& other) {
> - for (auto &f : other.fmts) {
> + for (size_t i = 0; i < other.fmts.size(); ++i) {
> + const PrintfFmt& f = other.fmts[i];
> fmts.push_back(f);
> }
>
> - for (auto &s : other.slots) {
> + for (size_t i = 0; i < other.fmts.size(); ++i) {
> + PrintfSlot* s = other.slots[i];
> slots.push_back(s);
> }
>
> diff --git a/backend/src/ir/sampler.cpp b/backend/src/ir/sampler.cpp
> index e4accca..a4e1ddd 100644
> --- a/backend/src/ir/sampler.cpp
> +++ b/backend/src/ir/sampler.cpp
> @@ -53,7 +53,7 @@ namespace ir {
> int32_t id = ctx->getFunction().getArgID(arg);
> GBE_ASSERT(id < (1 << __CLK_SAMPLER_ARG_BITS));
>
> - auto it = samplerMap.find(SAMPLER_ID(id));
> + map<uint32_t, uint32_t>::iterator it = samplerMap.find(SAMPLER_ID(id));
> if (it != samplerMap.end()) {
> return it->second;
> }
> @@ -71,9 +71,9 @@ namespace ir {
> OUT_UPDATE_SZ(magic_begin);
>
> OUT_UPDATE_SZ(samplerMap.size());
> - for (auto iter : samplerMap) {
> - OUT_UPDATE_SZ(iter.first);
> - OUT_UPDATE_SZ(iter.second);
> + for (map<uint32_t, uint32_t>::iterator it = samplerMap.begin(); it != samplerMap.end(); ++it) {
> + OUT_UPDATE_SZ(it->first);
> + OUT_UPDATE_SZ(it->second);
> }
>
> OUT_UPDATE_SZ(magic_end);
> @@ -123,9 +123,9 @@ namespace ir {
> outs << spaces_nl << " SamplerSet Map: [index, sampler_reg, sampler_slot]\n";
> outs << spaces_nl << " samplerMap size: " << samplerMap.size() << "\n";
>
> - for (auto iter : samplerMap) {
> - outs << spaces_nl << " [" << iter.first << ", "
> - << iter.second << "]\n";
> + for (map<uint32_t, uint32_t>::iterator it = samplerMap.begin(); it != samplerMap.end(); ++it) {
> + outs << spaces_nl << " [" << it->first << ", "
> + << it->second << "]\n";
> }
>
> outs << spaces << "------------- End SamplerSet -------------" << "\n";
> diff --git a/backend/src/ir/sampler.hpp b/backend/src/ir/sampler.hpp
> index a23f871..85e6d54 100644
> --- a/backend/src/ir/sampler.hpp
> +++ b/backend/src/ir/sampler.hpp
> @@ -48,8 +48,8 @@ namespace ir {
> size_t getDataSize(void) { return samplerMap.size(); }
> size_t getDataSize(void) const { return samplerMap.size(); }
> void getData(uint32_t *samplers) const {
> - for(auto &it : samplerMap)
> - samplers[it.second] = it.first;
> + for (map<uint32_t, uint32_t>::const_iterator it = samplerMap.begin(); it != samplerMap.end(); ++it)
> + samplers[it->second] = it->first;
> }
>
> void operator = (const SamplerSet& other) {
> diff --git a/backend/src/ir/unit.hpp b/backend/src/ir/unit.hpp
> index e2ccbe8..8ff858d 100644
> --- a/backend/src/ir/unit.hpp
> +++ b/backend/src/ir/unit.hpp
> @@ -56,7 +56,8 @@ namespace ir {
> /*! Apply the given functor on all the functions */
> template <typename T>
> INLINE void apply(const T &functor) const {
> - for (const auto &pair : functions) functor(*pair.second);
> + for (FunctionSet::const_iterator it = functions.begin(); it != functions.end(); ++it)
> + functor(*(it->second));
> }
> /*! Return the size of the pointers manipulated */
> INLINE PointerSize getPointerSize(void) const { return pointerSize; }
> --
> 1.9.1
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list