summaryrefslogtreecommitdiff
path: root/src/mesa/pipe
diff options
context:
space:
mode:
authorZack Rusin <zack@tungstengraphics.com>2008-02-12 05:35:51 -0500
committerZack Rusin <zack@tungstengraphics.com>2008-02-12 23:11:05 -0500
commitcad7bc74d69ee053452aa4bd20740dc79ad6eab6 (patch)
treedb9e47a4c2e904d55e42915764d8bbd70166e868 /src/mesa/pipe
parente20e89e48287808068086ec148920dd89495d813 (diff)
llvm ir code to fetch the elements
Diffstat (limited to 'src/mesa/pipe')
-rw-r--r--src/mesa/pipe/llvm/storagesoa.cpp59
-rw-r--r--src/mesa/pipe/llvm/storagesoa.h17
2 files changed, 76 insertions, 0 deletions
diff --git a/src/mesa/pipe/llvm/storagesoa.cpp b/src/mesa/pipe/llvm/storagesoa.cpp
index b2aca3557a..ff94307c85 100644
--- a/src/mesa/pipe/llvm/storagesoa.cpp
+++ b/src/mesa/pipe/llvm/storagesoa.cpp
@@ -45,6 +45,11 @@ StorageSoa::StorageSoa(llvm::BasicBlock *block,
llvm::Value *input,
llvm::Value *output,
llvm::Value *consts)
+ : m_block(block),
+ m_input(input),
+ m_output(output),
+ m_consts(consts),
+ m_idx(0)
{
}
@@ -62,6 +67,11 @@ std::vector<llvm::Value*> StorageSoa::inputElement(int idx, int swizzle,
{
std::vector<llvm::Value*> res(4);
+ res[0] = element(m_input, idx, 0);
+ res[1] = element(m_input, idx, 0);
+ res[2] = element(m_input, idx, 0);
+ res[3] = element(m_input, idx, 0);
+
return res;
}
@@ -78,6 +88,11 @@ std::vector<llvm::Value*> StorageSoa::outputElement(int idx, int swizzle,
{
std::vector<llvm::Value*> res(4);
+ res[0] = element(m_output, idx, 0);
+ res[1] = element(m_output, idx, 0);
+ res[2] = element(m_output, idx, 0);
+ res[3] = element(m_output, idx, 0);
+
return res;
}
@@ -115,3 +130,47 @@ void StorageSoa::storeAddress(int idx, const std::vector<llvm::Value*> &val,
int mask)
{
}
+
+llvm::Value * StorageSoa::elementPointer(llvm::Value *ptr, int index,
+ int channel) const
+{
+ std::vector<Value*> indices;
+ indices.push_back(constantInt(index));
+ indices.push_back(constantInt(0));//first element in the struct
+ indices.push_back(constantInt(channel));
+ indices.push_back(constantInt(0));//f channel
+ indices.push_back(constantInt(0));//first ptr in the f channel
+
+ GetElementPtrInst *getElem = new GetElementPtrInst(ptr,
+ indices.begin(),
+ indices.end(),
+ name("ptr"),
+ m_block);
+ return getElem;
+}
+
+llvm::Value * StorageSoa::element(llvm::Value *ptr, int index,
+ int channel) const
+{
+ llvm::Value *res = elementPointer(ptr, index, channel);
+ LoadInst *load = new LoadInst(res, name("element"), false, m_block);
+ //load->setAlignment(8);
+ return load;
+}
+
+const char * StorageSoa::name(const char *prefix) const
+{
+ ++m_idx;
+ snprintf(m_name, 32, "%s%d", prefix, m_idx);
+ return m_name;
+}
+
+llvm::ConstantInt * StorageSoa::constantInt(int idx) const
+{
+ if (m_constInts.find(idx) != m_constInts.end()) {
+ return m_constInts[idx];
+ }
+ ConstantInt *constInt = ConstantInt::get(APInt(32, idx));
+ m_constInts[idx] = constInt;
+ return constInt;
+}
diff --git a/src/mesa/pipe/llvm/storagesoa.h b/src/mesa/pipe/llvm/storagesoa.h
index 551b0b9734..9d5609f539 100644
--- a/src/mesa/pipe/llvm/storagesoa.h
+++ b/src/mesa/pipe/llvm/storagesoa.h
@@ -29,6 +29,7 @@
#define STORAGESOA_H
#include <vector>
+#include <map>
namespace llvm {
class BasicBlock;
@@ -65,7 +66,23 @@ public:
int mask);
void storeAddress(int idx, const std::vector<llvm::Value*> &val,
int mask);
+private:
+ llvm::Value *elementPointer(llvm::Value *ptr, int index,
+ int channel) const;
+ llvm::Value *element(llvm::Value *ptr, int index,
+ int channel) const;
+ const char *name(const char *prefix) const;
+ llvm::ConstantInt *constantInt(int) const;
+private:
+ llvm::BasicBlock *m_block;
+ llvm::Value *m_input;
+ llvm::Value *m_output;
+ llvm::Value *m_consts;
+
+ mutable std::map<int, llvm::ConstantInt*> m_constInts;
+ mutable char m_name[32];
+ mutable int m_idx;
};
#endif