search for: getnamedglobal

Displaying 18 results from an estimated 18 matches for "getnamedglobal".

2020 Jun 03
2
Fwd: I cannot change value of global variable in LLVM IR using IRBuilder
...t calling printf function and passing my global variable as one of the arguments. My code: Instruction* InstructionVisitor::incrementGlobalKey(Instruction* I) { IRBuilder<> Builder(I->getContext()); Builder.SetInsertPoint(I->getNextNode()); GlobalVariable* key = I->getModule()->getNamedGlobal("globalKey"); if (key) { LoadInst* load = Builder.CreateLoad(key); Value* inc = Builder.CreateAdd(load, Builder.getInt64(1)); StoreInst* store = Builder.CreateStore(inc, key); return store; } return I; } Instruction* InstructionVisitor::print(Instruction* I, const char* text, Value* arg...
2020 Jun 03
2
Fwd: I cannot change value of global variable in LLVM IR using IRBuilder
...dulePass: bool runOnModule(llvm::Module &M) { IRBuilder<> Builder(M.getContext()); Instruction *I = &*inst_begin(M.getFunction("main")); Builder.SetInsertPoint(I); M.getOrInsertGlobal("globalKey", Builder.getInt64Ty()); GlobalVariable* gVar = M.getNamedGlobal("globalKey"); gVar->setLinkage(GlobalValue::InternalLinkage); gVar->setAlignment(Align(8)); gVar->setInitializer(Builder.getInt64(0)); gVar->setConstant(false); for (Function &F : M.functions()) { InstructionVisitor visitor(DL, getAnalysis<T...
2007 Sep 22
4
[LLVMdev] RFC: Patch
...nternal global" linkage, which is correct. The second time through, it tries to look up that variable in the module, but because it has "internal global" (and not "external global") linkage, the "getGlobalVariable()" method returns null. This patch uses the "getNamedGlobal" method, which ignores whether it's internally or externally global. My question is, is this liable to break something else down the line? Should it be modified to call the getNamedGlobal method only if it's an Objective-C property? Is this even the correct method for an Objective-C p...
2013 Jan 20
1
[LLVMdev] Get the value of a GlobalVariable
...IT. When the program exits, the control comes back to my program which initiates the JIT. Now, I want to read the value(not the LLVM nomenclature) of a global variable (not the LLVM nomenclature). I am able to get the global variable, using the following command: GlobalVariable *my_global = Mod->getNamedGlobal("MY_GLOBAL"); I want to know the value which was stored in this variable, I use the following command, but it gives error: APInt value = my_global->getValue(); Error is: llvm/lib/IR/Constants.cpp:1257: llvm::Constant *llvm::Constant::getSplatValue() const: Assertion `this->getType...
2017 May 30
2
llvm::GlobalVariable usage (newbie question)
...r to variable elsewhere in the runtime, but I'd like to understand what is going on here, and if there is a, um, nicer API that I'm missing? llvm::Value* C::getGlobalVariable(const char* name, llvm::Type* t) { auto global = _module->getNamedGlobal(name); if (!global) { new llvm::GlobalVariable( *_module, t, true, // constant llvm::GlobalValue::ExternalLinkage, nullptr, // no initializer name); global = _module->...
2007 Sep 22
0
[LLVMdev] RFC: Patch
On Sep 21, 2007, at 5:11 PM, Bill Wendling wrote: > > My question is, is this liable to break something else down the line? > Should it be modified to call the getNamedGlobal method only if it's > an Objective-C property? Is this even the correct method for an > Objective-C property? There is a bigger question here. One invariant that is useful is that there is only a single decl that corresponds to a given global variable. It sounds like the objc front...
2019 Dec 19
2
Moving to ORCv2 - Where are my global constructors and destructors?
...compiled to the bit code. I then wanted to get the address of that symbol - from the MCJIT times I remember, that those functions are the global constructors, but when calling lookup on that name, I was not able to find the symbol. So I tried a different way: llvm::GlobalVariable *var = module->getNamedGlobal("llvm.global_ctors"); if(var) { llvm::ConstantArray *InitList = (llvm::ConstantArray*)var->getInitializer(); for(unsigned int n = 0; n < InitList->getNumOperands(); n++) { llvm::ConstantStruct *CS = (llvm::ConstantStruct*)InitList->getOperand(...
2006 Nov 28
2
[LLVMdev] question about the LLVM JIT
..., name, gp_module); > gp_execution_engine->addGlobalMapping(&var, address); > } This is creating a new global variable on the stack, instead of finding the existing global variable in the module. Try something like this: gp_execution_engine->addGlobalMapping(YourModule->getNamedGlobal(name), address); > The 2nd question I have has to do with recompiling code. > > The 'library' I'm creating, that sits between llvm's (c++) libs and Python, > will remain minimal so I decided to use ParseAssemblyString to get .ll > sourcecode into the...
2012 Dec 05
0
[LLVMdev] how to get and modify a global variable inside a module
On 05/12/12 12:07, Dong Chen wrote: > recently, i use LLVM API to write a program to read *.ll and excute it > automatically. > Further more, i want to change some global variables inside a module. > i tried some functions provided by Module.h and ExecutionEngine.h but none > were seemed to match my need. > did someone have the experience or some advices? > thank you ;) You
2006 Mar 26
1
[LLVMdev] A question about Module::getGlobalVariable()
I want to find a global variable by name in some module , I find LLVM function Module::getGlobalVariable(string name,Type* ty); My question is , is it necessary to specify the global variable type (second param) ? Why not just getGlobalVariable(string name). I look up the source , and find that it depend on SymbolTable.find() and SymbolTable only support find with type .is it True ? or I make
2006 Nov 29
0
[LLVMdev] question about the LLVM JIT
...cution_engine->addGlobalMapping(&var, address); >> } > > This is creating a new global variable on the stack, instead of > finding the existing global variable in the module. Try something > like this: > > gp_execution_engine->addGlobalMapping(YourModule->getNamedGlobal > (name), > address); > Hi Chris, Thanks, that was simpler than I thought! I actually thought I had to create a new global so it would be available for the JIT when it gets to process the "%var = external global int" line. > <snip> > >> I do...
2012 Dec 05
3
[LLVMdev] how to get and modify a global variable inside a module
hi Duncan Sands, i have tried the functions: GlobalValue * getNamedValue (StringRef Name) const GlobalVariable * getGlobalVariable (StringRef Name, bool AllowInternal=false) const GlobalVariable * getNamedGlobal (StringRef Name) const but i think these functions just return the ID or something else (not the Global Variable's main memory address, i am not sure) here is the thing. i want to know the exact main memory address of the Global Varibale's address when ExecutionEngine execut the *.ll code...
2016 Aug 26
2
Use of array type in globals in LTO
Thanks for the test case! I can reproduce this, and see with the compiler I saved from just before r278338 that this is indeed a chance in behavior. Looking at why this changed... On Fri, Aug 26, 2016 at 1:42 PM, Mehdi Amini <mehdi.amini at apple.com> wrote: > >> On Aug 26, 2016, at 1:34 PM, junbuml at codeaurora.org wrote: >> >> On 2016-08-26 12:47, Mehdi Amini wrote:
2011 May 27
0
[LLVMdev] Precompiled templates
Hi Andreas, > I'm currently investigating the use of LLVM for a project. For example, > if I have a function like > > int a(int x, int y) { > if (P == 0) { > return x - y; > } else { > return y - x; > } > } > > and P could be considered constant, one of the code paths could be > optimized out. Now I want to load a compiled bitcode
2012 Dec 05
4
[LLVMdev] how to get and modify a global variable inside a module
recently, i use LLVM API to write a program to read *.ll and excute it automatically. Further more, i want to change some global variables inside a module. i tried some functions provided by Module.h and ExecutionEngine.h but none were seemed to match my need. did someone have the experience or some advices? thank you ;) -- View this message in context:
2019 Feb 05
2
IRBuilder constraints
...vm::IRBuilder<>& irb; llvm::Value* op1 = llvm::ConstantInt::getSigned(irb.getInt32Ty(), constVal); auto* pt = llvm::PointerType::get(op1->getType(), 0); auto* addr = irb.CreateIntToPtr(op1, pt); auto* loaded = irb.CreateLoad(addr); irb.CreateStore(loaded, module->getNamedGlobal(regname)); I cannot get LLVM to leave an llvm::Value as ConstantInt in every case, if I pass it to IRBuilder for processing(for example through a globalvariable storing instruction). Do you know how I can tell IRBuilder, or any other part of LLVM, to leave a supplied or retrieved llvm::Value as co...
2016 Aug 26
2
Use of array type in globals in LTO
...On Aug 26, 2016, at 2:06 PM, Teresa Johnson <tejohnson at google.com> wrote: > > Mehdi: I see what is going on: > > + ArrayType *Ty = > + ArrayType::get(Type::getInt8Ty(RegularLTO.Ctx), I.second.Size); > + GlobalVariable *OldGV = RegularLTO.CombinedModule->getNamedGlobal(I.first); > + if (OldGV && OldGV->getType()->getElementType() == Ty) { > + // Don't create a new global if the type is already correct, just make > + // sure the alignment is correct. > > We compare the existing type to an ArrayType constructed from th...
2011 May 25
2
[LLVMdev] Precompiled templates
Hello list, I'm currently investigating the use of LLVM for a project. For example, if I have a function like int a(int x, int y) { if (P == 0) { return x - y; } else { return y - x; } } and P could be considered constant, one of the code paths could be optimized out. Now I want to load a compiled bitcode file into a CFG, replace all occurrences of P with the value (either 0