Add IRBuilderBase::getIntPtrTy.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Wed, 31 Oct 2012 09:50:01 +0000 (09:50 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Wed, 31 Oct 2012 09:50:01 +0000 (09:50 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167111 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IRBuilder.h
unittests/VMCore/IRBuilderTest.cpp

index 46720983e4f6bfae3095dd883de2029b86472e0f..f63a16051e300b1a011930bffc9141ba99b464b5 100644 (file)
@@ -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 @@ public:
     return Type::getInt8PtrTy(Context, AddrSpace);
   }
 
+  IntegerType* getIntPtrTy(DataLayout *DL, unsigned AddrSpace = 0) {
+    return DL->getIntPtrType(Context, AddrSpace);
+  }
+
   //===--------------------------------------------------------------------===//
   // Intrinsic creation methods
   //===--------------------------------------------------------------------===//
index b6a3795fd0f4c03df5049003da8dbee5d91af2a2..9f26936df4757ef8d091d0277698444d4bdc1e43 100644 (file)
@@ -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 @@ TEST_F(IRBuilderTest, CreateCondBr) {
   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));
+}
+
 }