llvm.org GIT mirror llvm / 3d29df3
Push LLVMContext through GlobalVariables and IRBuilder. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74985 91177308-0d34-0410-b5e6-96231b3b80d8 Owen Anderson 11 years ago
21 changed file(s) with 114 addition(s) and 75 deletion(s). Raw diff Collapse all Expand all
127127 get("Error: The head has left the tape.", true);
128128
129129 GlobalVariable *aberrormsg = new GlobalVariable(
130 module->getContext(),
130131 msg_0->getType(),
131132 true,
132133 GlobalValue::InternalLinkage,
2525
2626 namespace llvm {
2727
28 class LLVMContext;
2829 class Module;
2930 class Constant;
3031 template
4849 }
4950 /// GlobalVariable ctor - If a parent module is specified, the global is
5051 /// automatically inserted into the end of the specified modules global list.
51 GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
52 GlobalVariable(LLVMContext &Context, const Type *Ty,
53 bool isConstant, LinkageTypes Linkage,
5254 Constant *Initializer = 0, const std::string &Name = "",
5355 Module *Parent = 0, bool ThreadLocal = false,
5456 unsigned AddressSpace = 0);
5557 /// GlobalVariable ctor - This creates a global and inserts it before the
5658 /// specified other global.
57 GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
59 GlobalVariable(LLVMContext &Context, const Type *Ty,
60 bool isConstant, LinkageTypes Linkage,
5861 Constant *Initializer, const std::string &Name,
5962 GlobalVariable *InsertBefore, bool ThreadLocal = false,
6063 unsigned AddressSpace = 0);
1919 #include "llvm/GlobalAlias.h"
2020 #include "llvm/GlobalVariable.h"
2121 #include "llvm/Function.h"
22 #include "llvm/LLVMContext.h"
2223 #include "llvm/Support/ConstantFolder.h"
2324
2425 namespace llvm {
4142 BasicBlock *BB;
4243 BasicBlock::iterator InsertPt;
4344 T Folder;
45 LLVMContext& Context;
4446 public:
45 IRBuilder(const T& F = T()) : Folder(F) { ClearInsertionPoint(); }
46 explicit IRBuilder(BasicBlock *TheBB, const T& F = T())
47 : Folder(F) { SetInsertPoint(TheBB); }
48 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T())
49 : Folder(F) { SetInsertPoint(TheBB, IP); }
47 IRBuilder(const T& F = T(), LLVMContext &C = getGlobalContext()) :
48 Folder(F), Context(C) { ClearInsertionPoint(); }
49 explicit IRBuilder(BasicBlock *TheBB, const T& F = T(),
50 LLVMContext &C = getGlobalContext()) :
51 Folder(F), Context(C) { SetInsertPoint(TheBB); }
52 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T& F = T(),
53 LLVMContext &C = getGlobalContext())
54 : Folder(F), Context(C) { SetInsertPoint(TheBB, IP); }
5055
5156 /// getFolder - Get the constant folder being used.
5257 const T& getFolder() { return Folder; }
124129 ///
125130 ReturnInst *CreateAggregateRet(Value * const* retVals, unsigned N) {
126131 const Type *RetType = BB->getParent()->getReturnType();
127 Value *V = UndefValue::get(RetType);
132 Value *V = Context.getUndef(RetType);
128133 for (unsigned i = 0; i != N; ++i)
129134 V = CreateInsertValue(V, retVals[i], i, "mrv");
130135 return Insert(ReturnInst::Create(V));
348353 return Insert(GetElementPtrInst::Create(Ptr, Idx), Name);
349354 }
350355 Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const char *Name = "") {
351 Value *Idx = ConstantInt::get(Type::Int32Ty, Idx0);
356 Value *Idx = Context.getConstantInt(Type::Int32Ty, Idx0);
352357
353358 if (Constant *PC = dyn_cast(Ptr))
354359 return Folder.CreateGetElementPtr(PC, &Idx, 1);
358363 Value *CreateConstGEP2_32(Value *Ptr, unsigned Idx0, unsigned Idx1,
359364 const char *Name = "") {
360365 Value *Idxs[] = {
361 ConstantInt::get(Type::Int32Ty, Idx0),
362 ConstantInt::get(Type::Int32Ty, Idx1)
366 Context.getConstantInt(Type::Int32Ty, Idx0),
367 Context.getConstantInt(Type::Int32Ty, Idx1)
363368 };
364369
365370 if (Constant *PC = dyn_cast(Ptr))
368373 return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2), Name);
369374 }
370375 Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const char *Name = "") {
371 Value *Idx = ConstantInt::get(Type::Int64Ty, Idx0);
376 Value *Idx = Context.getConstantInt(Type::Int64Ty, Idx0);
372377
373378 if (Constant *PC = dyn_cast(Ptr))
374379 return Folder.CreateGetElementPtr(PC, &Idx, 1);
378383 Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
379384 const char *Name = "") {
380385 Value *Idxs[] = {
381 ConstantInt::get(Type::Int64Ty, Idx0),
382 ConstantInt::get(Type::Int64Ty, Idx1)
386 Context.getConstantInt(Type::Int64Ty, Idx0),
387 Context.getConstantInt(Type::Int64Ty, Idx1)
383388 };
384389
385390 if (Constant *PC = dyn_cast(Ptr))
391396 return CreateConstGEP2_32(Ptr, 0, Idx, Name);
392397 }
393398 Value *CreateGlobalString(const char *Str = "", const char *Name = "") {
394 Constant *StrConstant = ConstantArray::get(Str, true);
395 GlobalVariable *gv = new GlobalVariable(StrConstant->getType(),
399 Constant *StrConstant = Context.getConstantArray(Str, true);
400 GlobalVariable *gv = new GlobalVariable(Context,
401 StrConstant->getType(),
396402 true,
397403 GlobalValue::InternalLinkage,
398404 StrConstant,
404410 }
405411 Value *CreateGlobalStringPtr(const char *Str = "", const char *Name = "") {
406412 Value *gv = CreateGlobalString(Str, Name);
407 Value *zero = ConstantInt::get(Type::Int32Ty, 0);
413 Value *zero = Context.getConstantInt(Type::Int32Ty, 0);
408414 Value *Args[] = { zero, zero };
409415 return CreateGEP(gv, Args, Args+2, Name);
410416 }
696702
697703 /// CreateIsNull - Return an i1 value testing if \arg Arg is null.
698704 Value *CreateIsNull(Value *Arg, const char *Name = "") {
699 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
705 return CreateICmpEQ(Arg, Context.getNullValue(Arg->getType()),
700706 Name);
701707 }
702708
703709 /// CreateIsNotNull - Return an i1 value testing if \arg Arg is not null.
704710 Value *CreateIsNotNull(Value *Arg, const char *Name = "") {
705 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
711 return CreateICmpNE(Arg, Context.getNullValue(Arg->getType()),
706712 Name);
707713 }
708714
717723 Value *RHS_int = CreatePtrToInt(RHS, Type::Int64Ty);
718724 Value *Difference = CreateSub(LHS_int, RHS_int);
719725 return CreateSDiv(Difference,
720 ConstantExpr::getSizeOf(ArgType->getElementType()),
726 Context.getConstantExprSizeOf(ArgType->getElementType()),
721727 Name);
722728 }
723729 };
489489 Constant *ConstStr = VMContext.getConstantArray(String);
490490
491491 // Otherwise create and return a new string global.
492 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
492 GlobalVariable *StrGV = new GlobalVariable(VMContext,ConstStr->getType(), true,
493493 GlobalVariable::InternalLinkage,
494494 ConstStr, ".str", &M);
495495 StrGV->setSection("llvm.metadata");
515515 DIDescriptor &Entry = SimpleConstantCache[Init];
516516 if (!Entry.isNull()) return DIArray(Entry.getGV());
517517
518 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
518 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
519519 GlobalValue::InternalLinkage,
520520 Init, "llvm.dbg.array", &M);
521521 GV->setSection("llvm.metadata");
541541
542542 M.addTypeName("llvm.dbg.subrange.type", Init->getType());
543543
544 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
544 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
545545 GlobalValue::InternalLinkage,
546546 Init, "llvm.dbg.subrange", &M);
547547 GV->setSection("llvm.metadata");
578578 sizeof(Elts)/sizeof(Elts[0]));
579579
580580 M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
581 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
581 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
582582 GlobalValue::LinkOnceAnyLinkage,
583583 Init, "llvm.dbg.compile_unit", &M);
584584 GV->setSection("llvm.metadata");
597597 sizeof(Elts)/sizeof(Elts[0]));
598598
599599 M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
600 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
600 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
601601 GlobalValue::InternalLinkage,
602602 Init, "llvm.dbg.enumerator", &M);
603603 GV->setSection("llvm.metadata");
631631 sizeof(Elts)/sizeof(Elts[0]));
632632
633633 M.addTypeName("llvm.dbg.basictype.type", Init->getType());
634 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
634 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
635635 GlobalValue::InternalLinkage,
636636 Init, "llvm.dbg.basictype", &M);
637637 GV->setSection("llvm.metadata");
667667 sizeof(Elts)/sizeof(Elts[0]));
668668
669669 M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
670 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
670 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
671671 GlobalValue::InternalLinkage,
672672 Init, "llvm.dbg.derivedtype", &M);
673673 GV->setSection("llvm.metadata");
707707 sizeof(Elts)/sizeof(Elts[0]));
708708
709709 M.addTypeName("llvm.dbg.composite.type", Init->getType());
710 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
710 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
711711 GlobalValue::InternalLinkage,
712712 Init, "llvm.dbg.composite", &M);
713713 GV->setSection("llvm.metadata");
745745 sizeof(Elts)/sizeof(Elts[0]));
746746
747747 M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
748 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
748 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
749749 GlobalValue::LinkOnceAnyLinkage,
750750 Init, "llvm.dbg.subprogram", &M);
751751 GV->setSection("llvm.metadata");
779779 sizeof(Elts)/sizeof(Elts[0]));
780780
781781 M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
782 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
782 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
783783 GlobalValue::LinkOnceAnyLinkage,
784784 Init, "llvm.dbg.global_variable", &M);
785785 GV->setSection("llvm.metadata");
805805 sizeof(Elts)/sizeof(Elts[0]));
806806
807807 M.addTypeName("llvm.dbg.variable.type", Init->getType());
808 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
808 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
809809 GlobalValue::InternalLinkage,
810810 Init, "llvm.dbg.variable", &M);
811811 GV->setSection("llvm.metadata");
825825 sizeof(Elts)/sizeof(Elts[0]));
826826
827827 M.addTypeName("llvm.dbg.block.type", Init->getType());
828 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
828 GlobalVariable *GV = new GlobalVariable(VMContext, Init->getType(), true,
829829 GlobalValue::InternalLinkage,
830830 Init, "llvm.dbg.block", &M);
831831 GV->setSection("llvm.metadata");
515515 }
516516
517517 if (GV == 0) {
518 GV = new GlobalVariable(Ty, false, GlobalValue::ExternalLinkage, 0, Name,
518 GV = new GlobalVariable(Context, Ty, false,
519 GlobalValue::ExternalLinkage, 0, Name,
519520 M, false, AddrSpace);
520521 } else {
521522 if (GV->getType()->getElementType() != Ty)
606607
607608 FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
608609 } else {
609 FwdVal = new GlobalVariable(PTy->getElementType(), false,
610 FwdVal = new GlobalVariable(Context, PTy->getElementType(), false,
610611 GlobalValue::ExternalWeakLinkage, 0, Name, M);
611612 }
612613
650651 }
651652 FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
652653 } else {
653 FwdVal = new GlobalVariable(PTy->getElementType(), false,
654 FwdVal = new GlobalVariable(Context, PTy->getElementType(), false,
654655 GlobalValue::ExternalWeakLinkage, 0, "", M);
655656 }
656657
12571257 isThreadLocal = Record[7];
12581258
12591259 GlobalVariable *NewGV =
1260 new GlobalVariable(Ty, isConstant, Linkage, 0, "", TheModule,
1260 new GlobalVariable(Context, Ty, isConstant, Linkage, 0, "", TheModule,
12611261 isThreadLocal, AddressSpace);
12621262 NewGV->setAlignment(Alignment);
12631263 if (!Section.empty())
228228 // to be a ModulePass (which means it cannot be in the 'llc' pipeline
229229 // (which uses a FunctionPassManager (which segfaults (not asserts) if
230230 // provided a ModulePass))).
231 Constant *GV = new GlobalVariable(FrameMap->getType(), true,
231 Constant *GV = new GlobalVariable(*F.getContext(), FrameMap->getType(), true,
232232 GlobalVariable::InternalLinkage,
233233 FrameMap, "__gc_" + F.getName(),
234234 F.getParent());
291291 if (!Head) {
292292 // If the root chain does not exist, insert a new one with linkonce
293293 // linkage!
294 Head = new GlobalVariable(StackEntryPtrTy, false,
294 Head = new GlobalVariable(M.getContext(), StackEntryPtrTy, false,
295295 GlobalValue::LinkOnceAnyLinkage,
296296 Constant::getNullValue(StackEntryPtrTy),
297297 "llvm_gc_root_chain", &M);
572572 // symbol over in the dest module... the initializer will be filled in
573573 // later by LinkGlobalInits.
574574 GlobalVariable *NewDGV =
575 new GlobalVariable(SGV->getType()->getElementType(),
575 new GlobalVariable(Context, SGV->getType()->getElementType(),
576576 SGV->isConstant(), SGV->getLinkage(), /*init*/0,
577577 SGV->getName(), Dest, false,
578578 SGV->getType()->getAddressSpace());
605605 // AppendingVars map. The name is cleared out so that no linkage is
606606 // performed.
607607 GlobalVariable *NewDGV =
608 new GlobalVariable(SGV->getType()->getElementType(),
608 new GlobalVariable(Context, SGV->getType()->getElementType(),
609609 SGV->isConstant(), SGV->getLinkage(), /*init*/0,
610610 "", Dest, false,
611611 SGV->getType()->getAddressSpace());
633633 // we are replacing may be a function (if a prototype, weak, etc) or a
634634 // global variable.
635635 GlobalVariable *NewDGV =
636 new GlobalVariable(SGV->getType()->getElementType(), SGV->isConstant(),
637 NewLinkage, /*init*/0, DGV->getName(), Dest, false,
636 new GlobalVariable(Context, SGV->getType()->getElementType(),
637 SGV->isConstant(), NewLinkage, /*init*/0,
638 DGV->getName(), Dest, false,
638639 SGV->getType()->getAddressSpace());
639640
640641 // Propagate alignment, section, and visibility info.
11551156
11561157 // Create the new global variable...
11571158 GlobalVariable *NG =
1158 new GlobalVariable(NewType, G1->isConstant(), G1->getLinkage(),
1159 new GlobalVariable(Context, NewType, G1->isConstant(), G1->getLinkage(),
11591160 /*init*/0, First->first, M, G1->isThreadLocal(),
11601161 G1->getType()->getAddressSpace());
11611162
107107 }
108108 ArrayType *AT = Context->getArrayType(SBP, AUGs.size());
109109 Constant *Init = Context->getConstantArray(AT, AUGs);
110 GlobalValue *gv = new GlobalVariable(AT, false,
110 GlobalValue *gv = new GlobalVariable(M.getContext(), AT, false,
111111 GlobalValue::AppendingLinkage,
112112 Init, "llvm.used", &M);
113113 gv->setSection("llvm.metadata");
489489 Context->getConstantInt(Type::Int32Ty, i),
490490 Context);
491491 assert(In && "Couldn't get element of initializer?");
492 GlobalVariable *NGV = new GlobalVariable(STy->getElementType(i), false,
492 GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(i),
493 false,
493494 GlobalVariable::InternalLinkage,
494495 In, GV->getName()+"."+utostr(i),
495496 (Module *)NULL,
496497 GV->isThreadLocal(),
497 GV->getType()->getAddressSpace());
498 GV->getType()->getAddressSpace());
498499 Globals.insert(GV, NGV);
499500 NewGlobals.push_back(NGV);
500501
525526 Context);
526527 assert(In && "Couldn't get element of initializer?");
527528
528 GlobalVariable *NGV = new GlobalVariable(STy->getElementType(), false,
529 GlobalVariable *NGV = new GlobalVariable(*Context, STy->getElementType(),
530 false,
529531 GlobalVariable::InternalLinkage,
530532 In, GV->getName()+"."+utostr(i),
531533 (Module *)NULL,
840842 // Create the new global variable. The contents of the malloc'd memory is
841843 // undefined, so initialize with an undef value.
842844 Constant *Init = Context->getUndef(MI->getAllocatedType());
843 GlobalVariable *NewGV = new GlobalVariable(MI->getAllocatedType(), false,
845 GlobalVariable *NewGV = new GlobalVariable(*Context, MI->getAllocatedType(),
846 false,
844847 GlobalValue::InternalLinkage, Init,
845848 GV->getName()+".body",
846849 (Module *)NULL,
861864 // If there is a comparison against null, we will insert a global bool to
862865 // keep track of whether the global was initialized yet or not.
863866 GlobalVariable *InitBool =
864 new GlobalVariable(Type::Int1Ty, false, GlobalValue::InternalLinkage,
867 new GlobalVariable(*Context, Type::Int1Ty, false,
868 GlobalValue::InternalLinkage,
865869 Context->getConstantIntFalse(), GV->getName()+".init",
866870 (Module *)NULL, GV->isThreadLocal());
867871 bool InitBoolUsed = false;
12811285 const Type *PFieldTy = Context->getPointerTypeUnqual(FieldTy);
12821286
12831287 GlobalVariable *NGV =
1284 new GlobalVariable(PFieldTy, false, GlobalValue::InternalLinkage,
1288 new GlobalVariable(*Context, PFieldTy, false,
1289 GlobalValue::InternalLinkage,
12851290 Context->getNullValue(PFieldTy),
12861291 GV->getName() + ".f" + utostr(FieldNo), GV,
12871292 GV->isThreadLocal());
15781583 DOUT << " *** SHRINKING TO BOOL: " << *GV;
15791584
15801585 // Create the new global, initializing it to false.
1581 GlobalVariable *NewGV = new GlobalVariable(Type::Int1Ty, false,
1586 GlobalVariable *NewGV = new GlobalVariable(*Context, Type::Int1Ty, false,
15821587 GlobalValue::InternalLinkage, Context->getConstantIntFalse(),
15831588 GV->getName()+".b",
15841589 (Module *)NULL,
19731978 }
19741979
19751980 // Create the new global and insert it next to the existing list.
1976 GlobalVariable *NGV = new GlobalVariable(CA->getType(), GCL->isConstant(),
1981 GlobalVariable *NGV = new GlobalVariable(*Context, CA->getType(),
1982 GCL->isConstant(),
19771983 GCL->getLinkage(), CA, "",
19781984 (Module *)NULL,
19791985 GCL->isThreadLocal());
22212227 } else if (AllocaInst *AI = dyn_cast(CurInst)) {
22222228 if (AI->isArrayAllocation()) return false; // Cannot handle array allocs.
22232229 const Type *Ty = AI->getType()->getElementType();
2224 AllocaTmps.push_back(new GlobalVariable(Ty, false,
2230 AllocaTmps.push_back(new GlobalVariable(*Context, Ty, false,
22252231 GlobalValue::InternalLinkage,
22262232 Context->getUndef(Ty),
22272233 AI->getName()));
6464
6565 const Type *ATy = Context->getArrayType(Type::Int32Ty, NumFunctions);
6666 GlobalVariable *Counters =
67 new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
67 new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
6868 Context->getNullValue(ATy), "FuncProfCounters", &M);
6969
7070 // Instrument all of the functions...
109109
110110 const Type *ATy = Context->getArrayType(Type::Int32Ty, NumBlocks);
111111 GlobalVariable *Counters =
112 new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
112 new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
113113 Context->getNullValue(ATy), "BlockProfCounters", &M);
114114
115115 // Instrument all of the blocks...
6565
6666 const Type *ATy = Context->getArrayType(Type::Int32Ty, NumEdges);
6767 GlobalVariable *Counters =
68 new GlobalVariable(ATy, false, GlobalValue::InternalLinkage,
68 new GlobalVariable(M.getContext(), ATy, false, GlobalValue::InternalLinkage,
6969 Context->getNullValue(ATy), "EdgeProfCounters", &M);
7070
7171 // Instrument all of the edges...
197197 uint64_t resetval) : T(t) {
198198 ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
199199 ResetValue = Init;
200 Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
200 Counter = new GlobalVariable(M.getContext(), T, false,
201 GlobalValue::InternalLinkage,
201202 Init, "RandomSteeringCounter", &M);
202203 }
203204
236237 : AI(0), T(t) {
237238 ConstantInt* Init = M.getContext().getConstantInt(T, resetval);
238239 ResetValue = Init;
239 Counter = new GlobalVariable(T, false, GlobalValue::InternalLinkage,
240 Counter = new GlobalVariable(M.getContext(), T, false,
241 GlobalValue::InternalLinkage,
240242 Init, "RandomSteeringCounter", &M);
241243 }
242244
12891289 // pass to be run after this pass, to merge duplicate strings.
12901290 FormatStr.erase(FormatStr.end()-1);
12911291 Constant *C = Context->getConstantArray(FormatStr, true);
1292 C = new GlobalVariable(C->getType(), true,GlobalVariable::InternalLinkage,
1292 C = new GlobalVariable(*Context, C->getType(),
1293 true, GlobalVariable::InternalLinkage,
12931294 C, "str", Callee->getParent());
12941295 EmitPutS(C, B);
12951296 return CI->use_empty() ? (Value*)CI :
5555 //
5656 for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
5757 I != E; ++I) {
58 GlobalVariable *GV = new GlobalVariable(I->getType()->getElementType(),
58 GlobalVariable *GV = new GlobalVariable(M->getContext(),
59 I->getType()->getElementType(),
5960 false,
6061 GlobalValue::ExternalLinkage, 0,
6162 I->getName(), New);
138138 // Now that we've done that, insert the jmpbuf list head global, unless it
139139 // already exists.
140140 if (!(JBListHead = M.getGlobalVariable("llvm.sjljeh.jblist", PtrJBList))) {
141 JBListHead = new GlobalVariable(PtrJBList, false,
141 JBListHead = new GlobalVariable(M.getContext(),
142 PtrJBList, false,
142143 GlobalValue::LinkOnceAnyLinkage,
143144 Context->getNullValue(PtrJBList),
144145 "llvm.sjljeh.jblist", &M);
181182 Context->getConstantArray("ERROR: Exception thrown, but not caught!\n");
182183 AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
183184
184 GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
185 GlobalVariable *MsgGV = new GlobalVariable(M->getContext(),
186 Msg->getType(), true,
185187 GlobalValue::InternalLinkage,
186188 Msg, "abortmsg", M);
187189 std::vector GEPIdx(2, Context->getNullValue(Type::Int32Ty));
194196 "Recompile program with -enable-correct-eh-support.\n");
195197 AbortMessageLength = Msg->getNumOperands()-1; // don't include \0
196198
197 GlobalVariable *MsgGV = new GlobalVariable(Msg->getType(), true,
199 GlobalVariable *MsgGV = new GlobalVariable(M->getContext(),
200 Msg->getType(), true,
198201 GlobalValue::InternalLinkage,
199202 Msg, "abortmsg", M);
200203 std::vector GEPIdx(2, Context->getNullValue(Type::Int32Ty));
699699 /*--.. Operations on global variables ......................................--*/
700700
701701 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
702 return wrap(new GlobalVariable(unwrap(Ty), false,
702 LLVMContext &Context = unwrap(M)->getContext();
703 return wrap(new GlobalVariable(Context, unwrap(Ty), false,
703704 GlobalValue::ExternalLinkage, 0, Name,
704705 unwrap(M)));
705706 }
1515 #include "llvm/GlobalVariable.h"
1616 #include "llvm/GlobalAlias.h"
1717 #include "llvm/DerivedTypes.h"
18 #include "llvm/LLVMContext.h"
1819 #include "llvm/Module.h"
1920 #include "llvm/ADT/SmallPtrSet.h"
2021 #include "llvm/Support/LeakDetector.h"
9293 // GlobalVariable Implementation
9394 //===----------------------------------------------------------------------===//
9495
95 GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
96 GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
97 bool constant, LinkageTypes Link,
9698 Constant *InitVal, const std::string &Name,
9799 Module *ParentModule, bool ThreadLocal,
98100 unsigned AddressSpace)
99 : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
101 : GlobalValue(Context.getPointerType(Ty, AddressSpace),
102 Value::GlobalVariableVal,
100103 OperandTraits::op_begin(this),
101104 InitVal != 0, Link, Name),
102105 isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
112115 ParentModule->getGlobalList().push_back(this);
113116 }
114117
115 GlobalVariable::GlobalVariable(const Type *Ty, bool constant, LinkageTypes Link,
118 GlobalVariable::GlobalVariable(LLVMContext &Context, const Type *Ty,
119 bool constant, LinkageTypes Link,
116120 Constant *InitVal, const std::string &Name,
117121 GlobalVariable *Before, bool ThreadLocal,
118122 unsigned AddressSpace)
119 : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalVariableVal,
123 : GlobalValue(Context.getPointerType(Ty, AddressSpace),
124 Value::GlobalVariableVal,
120125 OperandTraits::op_begin(this),
121126 InitVal != 0, Link, Name),
122127 isConstantGlobal(constant), isThreadLocalSymbol(ThreadLocal) {
2727
2828 //===----------------------------------------------------------------------===//
2929 // Methods to implement the globals and functions lists.
30 // NOTE: It is ok to allocate the globals used for these methods from the
31 // global context, because all we ever do is use them to compare for equality.
3032 //
3133
3234 GlobalVariable *ilist_traits::createSentinel() {
33 GlobalVariable *Ret = new GlobalVariable(Type::Int32Ty, false,
35 GlobalVariable *Ret = new GlobalVariable(getGlobalContext(),
36 Type::Int32Ty, false,
3437 GlobalValue::ExternalLinkage);
3538 // This should not be garbage monitored.
3639 LeakDetector::removeGarbageObject(Ret);
3740 return Ret;
3841 }
3942 GlobalAlias *ilist_traits::createSentinel() {
40 GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
43 GlobalAlias *Ret = new GlobalAlias(Type::Int32Ty,
4144 GlobalValue::ExternalLinkage);
4245 // This should not be garbage monitored.
4346 LeakDetector::removeGarbageObject(Ret);
269272 if (GV == 0) {
270273 // Nope, add it
271274 GlobalVariable *New =
272 new GlobalVariable(Ty, false, GlobalVariable::ExternalLinkage, 0, Name);
275 new GlobalVariable(getContext(), Ty, false,
276 GlobalVariable::ExternalLinkage, 0, Name);
273277 GlobalList.push_back(New);
274278 return New; // Return the new declaration.
275279 }
235235 GV->eraseFromParent();
236236 if (!M1Tors.empty()) {
237237 Constant *M1Init = GetTorInit(M1Tors);
238 new GlobalVariable(M1Init->getType(), false, GlobalValue::AppendingLinkage,
238 new GlobalVariable(M1->getContext(), M1Init->getType(), false,
239 GlobalValue::AppendingLinkage,
239240 M1Init, GlobalName, M1);
240241 }
241242
246247 GV->eraseFromParent();
247248 if (!M2Tors.empty()) {
248249 Constant *M2Init = GetTorInit(M2Tors);
249 new GlobalVariable(M2Init->getType(), false, GlobalValue::AppendingLinkage,
250 new GlobalVariable(M2->getContext(), M2Init->getType(), false,
251 GlobalValue::AppendingLinkage,
250252 M2Init, GlobalName, M2);
251253 }
252254 }
702702 // 1. Add a string constant with its name to the global file
703703 Constant *InitArray = ConstantArray::get(F->getName());
704704 GlobalVariable *funcName =
705 new GlobalVariable(InitArray->getType(), true /*isConstant*/,
705 new GlobalVariable(Safe->getContext(),
706 InitArray->getType(), true /*isConstant*/,
706707 GlobalValue::InternalLinkage, InitArray,
707708 F->getName() + "_name", Safe);
708709
721722 // Create a new global to hold the cached function pointer.
722723 Constant *NullPtr = ConstantPointerNull::get(F->getType());
723724 GlobalVariable *Cache =
724 new GlobalVariable(F->getType(), false,GlobalValue::InternalLinkage,
725 new GlobalVariable(F->getParent()->getContext(),
726 F->getType(), false,GlobalValue::InternalLinkage,
725727 NullPtr,F->getName()+".fpcache", F->getParent());
726728
727729 // Construct a new stub function that will re-route calls to F