[polly] r213908 - [Refactor] Expose the runtime debug builder
Johannes Doerfert
jdoerfert at codeaurora.org
Thu Jul 24 16:55:19 PDT 2014
Author: jdoerfert
Date: Thu Jul 24 18:55:19 2014
New Revision: 213908
URL: http://llvm.org/viewvc/llvm-project?rev=213908&view=rev
Log:
[Refactor] Expose the runtime debug builder
Added:
polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h
polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp
Modified:
polly/trunk/lib/CodeGen/IslCodeGeneration.cpp
Added: polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h?rev=213908&view=auto
==============================================================================
--- polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h (added)
+++ polly/trunk/include/polly/CodeGen/RuntimeDebugBuilder.h Thu Jul 24 18:55:19 2014
@@ -0,0 +1,59 @@
+//===--- RuntimeDebugBuilder.h --- Helper to insert prints into LLVM-IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef RUNTIME_DEBUG_BUILDER_H
+#define RUNTIME_DEBUG_BUILDER_H
+
+#include "polly/CodeGen/IRBuilder.h"
+
+#include <string>
+
+namespace llvm {
+class Value;
+class Function;
+}
+
+namespace polly {
+
+/// @brief Insert function calls that print certain LLVM values at run time.
+///
+/// This class inserts libc function calls to print certain LLVM values at
+/// run time.
+struct RuntimeDebugBuilder {
+
+ /// @brief Print a string to stdout.
+ ///
+ /// @param String The string to print.
+ static void createStrPrinter(PollyIRBuilder &Builder,
+ const std::string &String);
+
+ /// @brief Print a value to stdout.
+ ///
+ /// @param V The value to print.
+ ///
+ /// @note Only integer, floating point and pointer values up to 64bit are
+ /// supported.
+ static void createValuePrinter(PollyIRBuilder &Builder, llvm::Value *V);
+
+ /// @brief Add a call to the fflush function with no file pointer given.
+ ///
+ /// This call will flush all opened file pointers including stdout and stderr.
+ static void createFlush(PollyIRBuilder &Builder);
+
+ /// @brief Get a reference to the 'printf' function.
+ ///
+ /// If the current module does not yet contain a reference to printf, we
+ /// insert a reference to it. Otherwise the existing reference is returned.
+ static llvm::Function *getPrintF(PollyIRBuilder &Builder);
+};
+}
+
+#endif
Modified: polly/trunk/lib/CodeGen/IslCodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslCodeGeneration.cpp?rev=213908&r1=213907&r2=213908&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslCodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/IslCodeGeneration.cpp Thu Jul 24 18:55:19 2014
@@ -54,89 +54,6 @@ using namespace llvm;
#define DEBUG_TYPE "polly-codegen-isl"
-/// @brief Insert function calls that print certain LLVM values at run time.
-///
-/// This class inserts libc function calls to print certain LLVM values at
-/// run time.
-class RuntimeDebugBuilder {
-public:
- RuntimeDebugBuilder(PollyIRBuilder &Builder) : Builder(Builder) {}
-
- /// @brief Print a string to stdout.
- ///
- /// @param String The string to print.
- void createStrPrinter(std::string String);
-
- /// @brief Print an integer value to stdout.
- ///
- /// @param V The value to print.
- void createIntPrinter(Value *V);
-
-private:
- PollyIRBuilder &Builder;
-
- /// @brief Add a call to the fflush function with no file pointer given.
- ///
- /// This call will flush all opened file pointers including stdout and stderr.
- void createFlush();
-
- /// @brief Get a reference to the 'printf' function.
- ///
- /// If the current module does not yet contain a reference to printf, we
- /// insert a reference to it. Otherwise the existing reference is returned.
- Function *getPrintF();
-};
-
-Function *RuntimeDebugBuilder::getPrintF() {
- Module *M = Builder.GetInsertBlock()->getParent()->getParent();
- const char *Name = "printf";
- Function *F = M->getFunction(Name);
-
- if (!F) {
- GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
- FunctionType *Ty =
- FunctionType::get(Builder.getInt32Ty(), Builder.getInt8PtrTy(), true);
- F = Function::Create(Ty, Linkage, Name, M);
- }
-
- return F;
-}
-
-void RuntimeDebugBuilder::createFlush() {
- Module *M = Builder.GetInsertBlock()->getParent()->getParent();
- const char *Name = "fflush";
- Function *F = M->getFunction(Name);
-
- if (!F) {
- GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
- FunctionType *Ty =
- FunctionType::get(Builder.getInt32Ty(), Builder.getInt8PtrTy(), false);
- F = Function::Create(Ty, Linkage, Name, M);
- }
-
- Builder.CreateCall(F, Constant::getNullValue(Builder.getInt8PtrTy()));
-}
-
-void RuntimeDebugBuilder::createStrPrinter(std::string String) {
- Function *F = getPrintF();
- Value *StringValue = Builder.CreateGlobalStringPtr(String);
- Builder.CreateCall(F, StringValue);
-
- createFlush();
-}
-
-void RuntimeDebugBuilder::createIntPrinter(Value *V) {
- IntegerType *Ty = dyn_cast<IntegerType>(V->getType());
- (void)Ty;
- assert(Ty && Ty->getBitWidth() == 64 &&
- "Cannot insert printer for this type.");
-
- Function *F = getPrintF();
- Value *String = Builder.CreateGlobalStringPtr("%ld");
- Builder.CreateCall2(F, String, V);
- createFlush();
-}
-
/// @brief LLVM-IR generator for isl_ast_expr[essions]
///
/// This generator generates LLVM-IR that performs the computation described by
Added: polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp?rev=213908&view=auto
==============================================================================
--- polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp (added)
+++ polly/trunk/lib/CodeGen/RuntimeDebugBuilder.cpp Thu Jul 24 18:55:19 2014
@@ -0,0 +1,74 @@
+//===--- RuntimeDebugBuilder.cpp - Helper to insert prints into LLVM-IR ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//===----------------------------------------------------------------------===//
+
+#include "polly/CodeGen/RuntimeDebugBuilder.h"
+
+#include "llvm/IR/Module.h"
+
+using namespace llvm;
+using namespace polly;
+
+Function *RuntimeDebugBuilder::getPrintF(PollyIRBuilder &Builder) {
+ Module *M = Builder.GetInsertBlock()->getParent()->getParent();
+ const char *Name = "printf";
+ Function *F = M->getFunction(Name);
+
+ if (!F) {
+ GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
+ FunctionType *Ty =
+ FunctionType::get(Builder.getInt32Ty(), Builder.getInt8PtrTy(), true);
+ F = Function::Create(Ty, Linkage, Name, M);
+ }
+
+ return F;
+}
+
+void RuntimeDebugBuilder::createFlush(PollyIRBuilder &Builder) {
+ Module *M = Builder.GetInsertBlock()->getParent()->getParent();
+ const char *Name = "fflush";
+ Function *F = M->getFunction(Name);
+
+ if (!F) {
+ GlobalValue::LinkageTypes Linkage = Function::ExternalLinkage;
+ FunctionType *Ty =
+ FunctionType::get(Builder.getInt32Ty(), Builder.getInt8PtrTy(), false);
+ F = Function::Create(Ty, Linkage, Name, M);
+ }
+
+ Builder.CreateCall(F, Constant::getNullValue(Builder.getInt8PtrTy()));
+}
+
+void RuntimeDebugBuilder::createStrPrinter(PollyIRBuilder &Builder,
+ const std::string &String) {
+ Value *StringValue = Builder.CreateGlobalStringPtr(String);
+ Builder.CreateCall(getPrintF(Builder), StringValue);
+
+ createFlush(Builder);
+}
+
+void RuntimeDebugBuilder::createValuePrinter(PollyIRBuilder &Builder,
+ Value *V) {
+ const char *Format = nullptr;
+
+ Type *Ty = V->getType();
+ if (Ty->isIntegerTy())
+ Format = "%ld";
+ else if (Ty->isFloatingPointTy())
+ Format = "%lf";
+ else if (Ty->isPointerTy())
+ Format = "%p";
+
+ assert(Format && Ty->getPrimitiveSizeInBits() <= 64 && "Bad type to print.");
+
+ Value *FormatString = Builder.CreateGlobalStringPtr(Format);
+ Builder.CreateCall2(getPrintF(Builder), FormatString, V);
+ createFlush(Builder);
+}
More information about the llvm-commits
mailing list