[Beignet] [PATCH] GBE: Output CFG of Gen IR to dot file.
Zhigang Gong
zhigang.gong at linux.intel.com
Sun Nov 30 23:45:03 PST 2014
LGTM, pushed, thanks.
On Wed, Nov 26, 2014 at 09:38:51AM +0800, Ruiling Song wrote:
> Add an environment variable 'OCL_OUTPUT_CFG_GEN_IR' to control it.
>
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
> backend/src/ir/function.cpp | 21 +++++++++++++++++++++
> backend/src/ir/function.hpp | 2 ++
> backend/src/llvm/llvm_to_gen.cpp | 3 +++
> 3 files changed, 26 insertions(+)
>
> diff --git a/backend/src/ir/function.cpp b/backend/src/ir/function.cpp
> index 7983778..6dde6e2 100644
> --- a/backend/src/ir/function.cpp
> +++ b/backend/src/ir/function.cpp
> @@ -281,6 +281,27 @@ namespace ir {
> });
> }
>
> + void Function::outputCFG(void) {
> + std::string fileName = getName() + std::string(".dot");
> + ::FILE *fp = fopen(fileName.c_str(), "w");
> + if (fp == NULL) return;
> +
> + printf("writing Gen IR CFG to %s\n", fileName.c_str());
> + fprintf(fp, "digraph \"%s\" {\n", getName().c_str());
> + this->foreachBlock([this, fp](BasicBlock &bb) {
> + uint32_t lid = bb.getLabelIndex();
> + fprintf(fp, "Node%d [shape=record, label=\"{%d}\"];\n", lid, lid);
> + set<BasicBlock*> &succ = bb.successors;
> + for (auto x : succ) {
> + uint32_t next = x->getLabelIndex();
> + fprintf(fp, "Node%d -> Node%d\n", lid, next);
> + }
> + });
> + fprintf(fp, "}\n");
> + fclose(fp);
> + }
> +
> +
> std::ostream &operator<< (std::ostream &out, const Function &fn)
> {
> out << ".decl_function " << fn.getName() << std::endl;
> diff --git a/backend/src/ir/function.hpp b/backend/src/ir/function.hpp
> index 0381095..1163a19 100644
> --- a/backend/src/ir/function.hpp
> +++ b/backend/src/ir/function.hpp
> @@ -428,6 +428,8 @@ namespace ir {
> /*! Get surface starting address register from bti */
> Register getSurfaceBaseReg(uint8_t bti) const;
> void appendSurface(uint8_t bti, Register reg);
> + /*! Output the control flow graph to .dot file */
> + void outputCFG();
> private:
> friend class Context; //!< Can freely modify a function
> std::string name; //!< Function name
> diff --git a/backend/src/llvm/llvm_to_gen.cpp b/backend/src/llvm/llvm_to_gen.cpp
> index eb75ba1..e1bf12f 100644
> --- a/backend/src/llvm/llvm_to_gen.cpp
> +++ b/backend/src/llvm/llvm_to_gen.cpp
> @@ -74,6 +74,7 @@ namespace gbe
> {
> BVAR(OCL_OUTPUT_CFG, false);
> BVAR(OCL_OUTPUT_CFG_ONLY, false);
> + BVAR(OCL_OUTPUT_CFG_GEN_IR, false);
> using namespace llvm;
>
> void runFuntionPass(Module &mod, TargetLibraryInfo *libraryInfo, const DataLayout &DL)
> @@ -297,6 +298,8 @@ namespace gbe
> analysis::ControlTree *ct = new analysis::ControlTree(iter->second);
> ct->analyze();
> delete ct;
> + if (OCL_OUTPUT_CFG_GEN_IR)
> + iter->second->outputCFG();
> iter++;
> }
>
> --
> 1.7.10.4
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list