aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2011-04-12 00:29:07 +0000
committerNick Lewycky <nicholas@mxc.ca>2011-04-12 00:29:07 +0000
commitcb4e4eae1afaa243c0654bc5dd668f9eb5085f06 (patch)
tree33579950a93393c3f035e5d3bc8d1d1e399a30df
parent7cbf92d1d9945c35d1021458280bb7984f796a01 (diff)
downloadexternal_llvm-cb4e4eae1afaa243c0654bc5dd668f9eb5085f06.zip
external_llvm-cb4e4eae1afaa243c0654bc5dd668f9eb5085f06.tar.gz
external_llvm-cb4e4eae1afaa243c0654bc5dd668f9eb5085f06.tar.bz2
Make IRBuilder support StringRef for building strings.
Also document that the global variables produced are mergable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129330 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/IRBuilder.h10
-rw-r--r--lib/VMCore/IRBuilder.cpp2
2 files changed, 7 insertions, 5 deletions
diff --git a/include/llvm/Support/IRBuilder.h b/include/llvm/Support/IRBuilder.h
index 626d22c..8e6de4b 100644
--- a/include/llvm/Support/IRBuilder.h
+++ b/include/llvm/Support/IRBuilder.h
@@ -18,6 +18,7 @@
#include "llvm/Instructions.h"
#include "llvm/BasicBlock.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ConstantFolder.h"
@@ -153,9 +154,10 @@ public:
/// CreateGlobalString - Make a new global variable with an initializer that
/// has array of i8 type filled in with the nul terminated string value
- /// specified. If Name is specified, it is the name of the global variable
- /// created.
- Value *CreateGlobalString(const char *Str = "", const Twine &Name = "");
+ /// specified. The new global variable will be marked mergable with any
+ /// others of the same contents. If Name is specified, it is the name of the
+ /// global variable created.
+ Value *CreateGlobalString(StringRef Str, const Twine &Name = "");
/// getInt1 - Get a constant value representing either true or false.
ConstantInt *getInt1(bool V) {
@@ -862,7 +864,7 @@ public:
/// CreateGlobalStringPtr - Same as CreateGlobalString, but return a pointer
/// with "i8*" type instead of a pointer to array of i8.
- Value *CreateGlobalStringPtr(const char *Str = "", const Twine &Name = "") {
+ Value *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "") {
Value *gv = CreateGlobalString(Str, Name);
Value *zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
Value *Args[] = { zero, zero };
diff --git a/lib/VMCore/IRBuilder.cpp b/lib/VMCore/IRBuilder.cpp
index 1658d79..2149155 100644
--- a/lib/VMCore/IRBuilder.cpp
+++ b/lib/VMCore/IRBuilder.cpp
@@ -23,7 +23,7 @@ using namespace llvm;
/// has array of i8 type filled in with the nul terminated string value
/// specified. If Name is specified, it is the name of the global variable
/// created.
-Value *IRBuilderBase::CreateGlobalString(const char *Str, const Twine &Name) {
+Value *IRBuilderBase::CreateGlobalString(StringRef Str, const Twine &Name) {
Constant *StrConstant = ConstantArray::get(Context, Str, true);
Module &M = *BB->getParent()->getParent();
GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(),