llvm: How to get the label of Basic Blocks -
i have written pass observe , print label of basicblocks in function, want utilize splitbasicblock() further. wrote this:
virtual bool runonmodule(module &m) { for(module::iterator f = m.begin(), e = m.end(); f!= e; ++f) { errs()<<"function:"<<f->getname()<<"\n"; //for(function::iterator bb = f->begin(), e = f->end(); bb != e; ++bb) (iplist<basicblock>::iterator iter = f->getbasicblocklist().begin(); iter != f->getbasicblocklist().end(); iter++) { basicblock* currbb = iter; errs() << "basicblock: " << currbb->getname() << "\n"; } } homecoming true; } ir file looks this:
; <label>:63 ; preds = %43 %64 = load i32* %j, align 4 %65 = sext i32 %64 i64 %66 = load i8** %tempdst, align 8 %67 = getelementptr inbounds i8* %66, i64 %65 store i8 -1, i8* %67, align 1 br label %73 ; <label>:68 ; preds = %43 %69 = load i32* %j, align 4 %70 = sext i32 %69 i64 %71 = load i8** %tempdst, align 8 %72 = getelementptr inbounds i8* %71, i64 %70 store i8 0, i8* %72, align 1 br label %73 ; <label>:73 ; preds = %68, %63 br label %74 however, got nil label
function:main basicblock: basicblock: basicblock: what's wrong these "unnamed" basic block? should do?
values in llvm ir not required have name; , indeed, basic blocks don't have names, why empty string currbb->getname().
the reason have names in llvm ir printout because when print textual format of llvm ir (as appears in .ll files), have assign name them create them referable, printer assigns sequential numeric names basic blocks (and other values). numeric names created printer, though, , don't exist in module.
llvm llvm-c++-api
No comments:
Post a Comment