Instruction->mayReadFromMemory

Hi

I am currently trying to schedule instructions with my own algorithm. For that
i need to get the data dependency between the instructions. So currently i am
dooing s.t. like:
for(BasicBlock::iterator j=B.begin(),bbe=B.end();j!=bbe;++j) {
          InstructionList.push_back(j);
          if (const AllocaInst *AI = dyn_cast<AllocaInst>(j)) {
                        ValueList.push_back(AI);
          } else if(PHINode *PHI=dyn_cast<PHINode>(j)) {
                        ValueList.push_back(PHI);
          } else if(GetElementPtrInst *GEPI= dyn_cast<GetElementPtrInst>(j)) {
                        ValueList.push_back(GEPI);
          };
};
To find the first instructions which are not depending on others results. So
far it seems to be working but i am missing instructions like:
%tmp.1 = seteq int %argc, 2 ; <bool> [#uses=1]
There seems only an function like llvm::Instruction::mayWriteToMemory
but nothing like llvm::Instruction::mayReadFromMemory or s.t. with similiar
functionality?

Or else: if there is an even easier way to get the non data depending
instruction from a block i missed, i would be also happy.

Thanks
S.T.

I'm not sure what you're looking for. LLVM has effectively four types of instructions:

1. Instructions that read memory (load).
2. Instructions that write memory (store).
3. Instructions that may read or write memory (those that return true for
    mayWriteToMemory), e.g. calls.
4. Instructions without side effects, like seteq,add,and,getelementptr,
    etc. The data dependencies are the only thing you need to know here.

I'd suggest you test instructions in that order for the properties they have. Later, as a refinement, you can use the alias analysis interfaces to query mod/ref properties of function calls, which may make your analysis slightly more precise.

-Chris

Hi Chris and list

Thanks for your quick answer :-).

> To find the first instructions which are not depending on others results.
> So far it seems to be working but i am missing instructions like:
> %tmp.1 = seteq int %argc, 2 ; <bool> [#uses=1]
> There seems only an function like llvm::Instruction::mayWriteToMemory
> but nothing like llvm::Instruction::mayReadFromMemory or s.t. with
> similiar functionality?
>
> Or else: if there is an even easier way to get the non data depending
> instruction from a block i missed, i would be also happy.

I'm not sure what you're looking for.

Ok, i'll try to put it in different words: I am looking for the points where
data is flowing into the basic blocks (and later where data is going out). So
essentially i want to extract the dataflow out of the llvm internal
representation.

As Example i have the first block in a function:
int %main(int %argc, sbyte** %argv) {
entry:
        %tmp.1 = seteq int %argc, 2 ; <bool> [#uses=1]
        br bool %tmp.1, label %then, label %no_exit

At first i thought that %argc must be a memory access. But its a function
argument, so it is a register value. But looking locally at my block "entry"
i have currently no idea that %argc is a function argument an thus data
beeing readily available for usage. So i am looking at an way to find all the
variables which already contain valid data at the beginning, contrary to data
which is computed in the block.

Thank you
ST

Ok, i'll try to put it in different words: I am looking for the points where
data is flowing into the basic blocks (and later where data is going out). So
essentially i want to extract the dataflow out of the llvm internal
representation.

Ok

As Example i have the first block in a function:
int %main(int %argc, sbyte** %argv) {
entry:
       %tmp.1 = seteq int %argc, 2 ; <bool> [#uses=1]
       br bool %tmp.1, label %then, label %no_exit

At first i thought that %argc must be a memory access. But its a function
argument, so it is a register value.

Right. Memory is explicitly accessed with load/store. SSA values are not memory objects.

But looking locally at my block "entry" i have currently no idea that %argc is a function argument an thus data beeing readily available for usage. So i am looking at an way to find all the variables which already contain valid data at the beginning, contrary to data which is computed in the block.

If you have a Value*, you can use queries like:

isa<Argument>(V)
isa<Constant>(V)

etc. In practice, if you want to find things like in to a function, the predicate "if (!isa<Instruction>(V))" will work, because all non-instruction values dominate all instructions.

You might also want to check this information out, for traversing use/def def/use chains:
http://llvm.org/docs/ProgrammersManual.html#iterate_chains

there is lots of other good stuff in that document as well.

-Chris