blob: 4bc3cbb2d6e98c80e75bcd7563dabed1931b323c [file] [log] [blame]
Chris Lattner17079fc2009-12-28 21:28:46 +00001//===---- IRBuilder.cpp - Builder for LLVM Instrs -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the IRBuilder class, which is used as a convenient way
11// to create LLVM instructions with a consistent and simplified interface.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/Support/IRBuilder.h"
16#include "llvm/GlobalVariable.h"
Chris Lattner49f9f762009-12-28 21:50:56 +000017#include "llvm/Function.h"
Chris Lattner7ef1cac2009-12-28 21:45:40 +000018#include "llvm/LLVMContext.h"
Chris Lattner17079fc2009-12-28 21:28:46 +000019using namespace llvm;
20
21/// CreateGlobalString - Make a new global variable with an initializer that
Dan Gohman4a618822010-02-10 16:03:48 +000022/// has array of i8 type filled in the nul terminated string value
Chris Lattner17079fc2009-12-28 21:28:46 +000023/// specified. If Name is specified, it is the name of the global variable
24/// created.
25Value *IRBuilderBase::CreateGlobalString(const char *Str, const Twine &Name) {
26 Constant *StrConstant = ConstantArray::get(Context, Str, true);
27 Module &M = *BB->getParent()->getParent();
28 GlobalVariable *GV = new GlobalVariable(M, StrConstant->getType(),
29 true, GlobalValue::InternalLinkage,
30 StrConstant, "", 0, false);
31 GV->setName(Name);
32 return GV;
33}
Chris Lattner7ef1cac2009-12-28 21:45:40 +000034
35/// SetCurrentDebugLocation - Set location information used by debugging
36/// information.
37void IRBuilderBase::SetCurrentDebugLocation(MDNode *L) {
38 if (DbgMDKind == 0)
Chris Lattnera0566972009-12-29 09:01:33 +000039 DbgMDKind = Context.getMDKindID("dbg");
Chris Lattner7ef1cac2009-12-28 21:45:40 +000040 CurDbgLocation = L;
41}
42
43void IRBuilderBase::SetInstDebugLocation(Instruction *I) const {
44 if (CurDbgLocation)
Chris Lattner2f2aa2b2009-12-28 23:41:32 +000045 I->setMetadata(DbgMDKind, CurDbgLocation);
Chris Lattner7ef1cac2009-12-28 21:45:40 +000046}
Chris Lattner49f9f762009-12-28 21:50:56 +000047
48const Type *IRBuilderBase::getCurrentFunctionReturnType() const {
49 assert(BB && BB->getParent() && "No current function!");
50 return BB->getParent()->getReturnType();
51}