@@ -33,20 +33,20 @@ class AnyLogic
3333 protected:
3434 mlir::Type indexType;
3535 mlir::Type llvmIndexType;
36- mlir::Type valuePtrType ;
36+ mlir::Type ptrTy ;
3737
3838 public:
3939 AnyLogic (Operation *op, PatternRewriter &rewriter, TypeConverterHelper &tch, Location loc, CompileOptions &compileOptions)
4040 : op(op), rewriter(rewriter), tch(tch), th(rewriter), ch(op, rewriter, tch.typeConverter, compileOptions), clh(op, rewriter), loc(loc)
4141 {
4242 indexType = th.getIndexType ();
4343 llvmIndexType = tch.convertType (indexType);
44- valuePtrType = th.getPtrType ();
44+ ptrTy = th.getPtrType ();
4545 }
4646
4747 LLVM ::LLVMStructType getStorageAnyType (mlir::Type llvmStorageType)
4848 {
49- return LLVM::LLVMStructType::getLiteral (rewriter.getContext (), {llvmIndexType, valuePtrType , llvmStorageType}, false );
49+ return LLVM::LLVMStructType::getLiteral (rewriter.getContext (), {llvmIndexType, ptrTy , llvmStorageType}, false );
5050 }
5151
5252 mlir::Value castToAny (mlir::Value in, mlir::Type inType, mlir::Type inLLVMType)
@@ -61,7 +61,6 @@ class AnyLogic
6161 mlir::Value castToAny (mlir::Value in, mlir::Value typeOfValue, mlir::Type inLLVMType)
6262 {
6363 // TODO: add type id to track data type
64- auto ptrTy = th.getPtrType ();
6564 auto llvmStorageType = inLLVMType;
6665 auto dataWithSizeType = getStorageAnyType (llvmStorageType);
6766
@@ -71,9 +70,9 @@ class AnyLogic
7170 auto sizeMLIR = rewriter.create <mlir_ts::SizeOfOp>(loc, indexType, llvmStorageType);
7271 auto size = rewriter.create <mlir_ts::DialectCastOp>(loc, llvmIndexType, sizeMLIR);
7372
74- auto zero = clh.createI32ConstantOf (0 );
75- auto one = clh.createI32ConstantOf (1 );
76- auto two = clh.createI32ConstantOf (2 );
73+ auto zero = clh.createI32ConstantOf (ANY_SIZE );
74+ auto one = clh.createI32ConstantOf (ANY_TYPE );
75+ auto two = clh.createI32ConstantOf (ANY_DATA );
7776
7877 auto ptrSize = rewriter.create <LLVM ::GEPOp>(loc, ptrTy, dataWithSizeType, memValue, ValueRange{zero, zero});
7978 rewriter.create <LLVM ::StoreOp>(loc, size, ptrSize);
@@ -92,15 +91,14 @@ class AnyLogic
9291 {
9392 // TODO: add type id to track data type
9493 // TODO: add data size check
95- auto ptrTy = th.getPtrType ();
9694 auto llvmStorageType = resLLVMType;
9795 auto dataWithSizeType = getStorageAnyType (llvmStorageType);
9896
9997 auto inDataWithSizeTypedValue = rewriter.create <LLVM ::BitcastOp>(loc, ptrTy, in);
10098
101- auto zero = clh.createI32ConstantOf (0 );
102- // auto one = clh.createI32ConstantOf(1 );
103- auto two = clh.createI32ConstantOf (2 );
99+ auto zero = clh.createI32ConstantOf (ANY_SIZE );
100+ // auto one = clh.createI32ConstantOf(ANY_TYPE );
101+ auto two = clh.createI32ConstantOf (ANY_DATA );
104102
105103 // set actual value
106104 auto ptrValue =
@@ -113,21 +111,60 @@ class AnyLogic
113111 // TODO: add type id to track data type
114112 // TODO: add data size check
115113 // any random type
116- auto ptrTy = th.getPtrType ();
117114 auto llvmStorageType = th.getI8Type ();
118115 auto dataWithSizeType = getStorageAnyType (llvmStorageType);
119116
120117 auto inDataWithSizeTypedValue = rewriter.create <LLVM ::BitcastOp>(loc, ptrTy, in);
121118
122- auto zero = clh.createI32ConstantOf (0 );
123- auto one = clh.createI32ConstantOf (1 );
124- // auto two = clh.createI32ConstantOf(2 );
119+ auto zero = clh.createI32ConstantOf (ANY_SIZE );
120+ auto one = clh.createI32ConstantOf (ANY_TYPE );
121+ // auto two = clh.createI32ConstantOf(ANY_DATA );
125122
126123 // set actual value
127124 auto ptrValue = rewriter.create <LLVM ::GEPOp>(loc, ptrTy, dataWithSizeType, inDataWithSizeTypedValue,
128125 ValueRange{zero, one});
129- return rewriter.create <LLVM ::LoadOp>(loc, valuePtrType , ptrValue);
126+ return rewriter.create <LLVM ::LoadOp>(loc, ptrTy , ptrValue);
130127 }
128+
129+ mlir::Value getDataSizeOfAny (mlir::Value in)
130+ {
131+ // TODO: add type id to track data type
132+ // TODO: add data size check
133+ // any random type
134+ auto llvmStorageType = th.getI8Type ();
135+ auto dataWithSizeType = getStorageAnyType (llvmStorageType);
136+
137+ auto inDataWithSizeTypedValue = rewriter.create <LLVM ::BitcastOp>(loc, ptrTy, in);
138+
139+ auto zero = clh.createI32ConstantOf (ANY_SIZE );
140+ // auto one = clh.createI32ConstantOf(ANY_TYPE);
141+ // auto two = clh.createI32ConstantOf(ANY_DATA);
142+
143+ // set actual value
144+ auto ptrValue = rewriter.create <LLVM ::GEPOp>(loc, ptrTy, dataWithSizeType, inDataWithSizeTypedValue,
145+ ValueRange{zero, zero});
146+ return rewriter.create <LLVM ::LoadOp>(loc, llvmIndexType, ptrValue);
147+ }
148+
149+ mlir::Value getDataPtrOfAny (mlir::Value in)
150+ {
151+ // TODO: add type id to track data type
152+ // TODO: add data size check
153+ // any random type
154+ auto llvmStorageType = th.getI8Type ();
155+ auto dataWithSizeType = getStorageAnyType (llvmStorageType);
156+
157+ auto inDataWithSizeTypedValue = rewriter.create <LLVM ::BitcastOp>(loc, ptrTy, in);
158+
159+ auto zero = clh.createI32ConstantOf (ANY_SIZE );
160+ // auto one = clh.createI32ConstantOf(ANY_TYPE);
161+ auto two = clh.createI32ConstantOf (ANY_DATA );
162+
163+ // set actual value
164+ auto ptrValue = rewriter.create <LLVM ::GEPOp>(loc, ptrTy, dataWithSizeType, inDataWithSizeTypedValue,
165+ ValueRange{zero, two});
166+ return ptrValue;
167+ }
131168};
132169} // namespace typescript
133170
0 commit comments