[llvm-commits] [PATCH] Add IRBuilderBase::getIntPtrTy
Evgeniy Stepanov
eugenis at google.com
Wed Oct 31 02:23:13 PDT 2012
Simplified getIntPtrTy implementation and added a unit test.
http://llvm-reviews.chandlerc.com/D90
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D90?vs=235&id=236#toc
Files:
llvm/include/llvm/IRBuilder.h
llvm/unittests/VMCore/IRBuilderTest.cpp
Index: llvm/include/llvm/IRBuilder.h
===================================================================
--- llvm/include/llvm/IRBuilder.h
+++ llvm/include/llvm/IRBuilder.h
@@ -17,6 +17,7 @@
#include "llvm/Instructions.h"
#include "llvm/BasicBlock.h"
+#include "llvm/DataLayout.h"
#include "llvm/LLVMContext.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
@@ -266,6 +267,10 @@
return Type::getInt8PtrTy(Context, AddrSpace);
}
+ IntegerType* getIntPtrTy(DataLayout *DL, unsigned AddrSpace = 0) {
+ return DL->getIntPtrType(Context, AddrSpace);
+ }
+
//===--------------------------------------------------------------------===//
// Intrinsic creation methods
//===--------------------------------------------------------------------===//
Index: llvm/unittests/VMCore/IRBuilderTest.cpp
===================================================================
--- llvm/unittests/VMCore/IRBuilderTest.cpp
+++ llvm/unittests/VMCore/IRBuilderTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/BasicBlock.h"
+#include "llvm/DataLayout.h"
#include "llvm/Function.h"
#include "llvm/IRBuilder.h"
#include "llvm/IntrinsicInst.h"
@@ -96,4 +97,15 @@
EXPECT_EQ(Weights, TI->getMetadata(LLVMContext::MD_prof));
}
+TEST_F(IRBuilderTest, GetIntTy) {
+ IRBuilder<> Builder(BB);
+ IntegerType *Ty1 = Builder.getInt1Ty();
+ EXPECT_EQ(Ty1, IntegerType::get(getGlobalContext(), 1));
+
+ DataLayout* DL = new DataLayout(M.get());
+ IntegerType *IntPtrTy = Builder.getIntPtrTy(DL);
+ unsigned IntPtrBitSize = DL->getPointerSizeInBits(0);
+ EXPECT_EQ(IntPtrTy, IntegerType::get(getGlobalContext(), IntPtrBitSize));
+}
+
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90.2.patch
Type: text/x-patch
Size: 1733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121031/124b6c79/attachment.bin>
More information about the llvm-commits
mailing list