From ee437193fbd4934e74175769dbc00e9ea43a17a2 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Mon, 19 Mar 2012 11:31:19 -0700 Subject: [PATCH] Add LLVMDumpValue() utility routine --- llvmutil.cpp | 32 +++++++++++++++++++++++++++++++- llvmutil.h | 7 ++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/llvmutil.cpp b/llvmutil.cpp index 0f5bfd1b..0bca5725 100644 --- a/llvmutil.cpp +++ b/llvmutil.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2010-2011, Intel Corporation + Copyright (c) 2010-2012, Intel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without @@ -39,6 +39,7 @@ #include "ispc.h" #include "type.h" #include +#include LLVM_TYPE_CONST llvm::Type *LLVMTypes::VoidType = NULL; LLVM_TYPE_CONST llvm::PointerType *LLVMTypes::VoidPointerType = NULL; @@ -752,3 +753,32 @@ LLVMVectorValuesAllEqual(llvm::Value *v, int vectorLength, } + + +static void +lDumpValue(llvm::Value *v, std::set &done) { + if (done.find(v) != done.end()) + return; + + llvm::Instruction *inst = llvm::dyn_cast(v); + if (done.size() > 0 && inst == NULL) + return; + + fprintf(stderr, " "); + v->dump(); + done.insert(v); + + if (inst == NULL) + return; + + for (unsigned i = 0; i < inst->getNumOperands(); ++i) + lDumpValue(inst->getOperand(i), done); +} + + +void +LLVMDumpValue(llvm::Value *v) { + std::set done; + lDumpValue(v, done); + fprintf(stderr, "----\n"); +} diff --git a/llvmutil.h b/llvmutil.h index 02857e34..b5875ac6 100644 --- a/llvmutil.h +++ b/llvmutil.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2010-2011, Intel Corporation + Copyright (c) 2010-2012, Intel Corporation All rights reserved. Redistribution and use in source and binary forms, with or without @@ -234,4 +234,9 @@ extern bool LLVMVectorValuesAllEqual(llvm::Value *v, int vectorLength, void LLVMFlattenInsertChain(llvm::InsertElementInst *ie, int vectorWidth, llvm::Value **elements); +/** This is a utility routine for debugging that dumps out the given LLVM + value as well as (recursively) all of the other values that it depends + on. */ +extern void LLVMDumpValue(llvm::Value *v); + #endif // ISPC_LLVMUTIL_H