Skip to content

Commit 8daca47

Browse files
Fixing union types (#154)
* some fixes * progress of fixes * progress of fixes to union and null compare * more fixes to safe cast and global vars * progress of fixes * implemented safe type for field access * refactored tests * fix for safe cast test * progress of implementing safe type for field access * update test * improved safe type for field access * added some code to improve dbg experience * refactoring * added test * added code to support amp amp in safe types * progress of adding new internal commands * progress of adding inline asm * finished inline asm * added code for call intrinsic * added fence command * added test * added atomicrmw command * updated cmpxchg * refactoring and implementing atomic vars * progress of implementing atomic for vars * added initial atomic attributes * added alignment for load store when atomic * progress of adding attributes to load store * added load store attrs with correct values * updated build script
1 parent aa2aa6f commit 8daca47

22 files changed

+1466
-93
lines changed

tag.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
git tag -a v0.0-pre-alpha65 -m "pre alpha v0.0-65"
1+
git tag -a v0.0-pre-alpha66 -m "pre alpha v0.0-66"
22
git push origin --tags

tag_del.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
git push --delete origin v0.0-pre-alpha65
2-
git tag -d v0.0-pre-alpha65
1+
git push --delete origin v0.0-pre-alpha66
2+
git tag -d v0.0-pre-alpha66

tsc/include/TypeScript/DOM.h

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ class VariableDeclarationDOM
3535
using TypePtr = std::shared_ptr<VariableDeclarationDOM>;
3636

3737
VariableDeclarationDOM(StringRef name, mlir::Type type, mlir::Location loc, Expression initValue = undefined)
38-
: name(name), type(type), loc(loc), initValue(initValue), captured(false), ignoreCapturing(false), _using(false), readWrite(false)
38+
: name(name), type(type), loc(loc), initValue(initValue), captured(false), ignoreCapturing(false), _using(false), readWrite(false),
39+
atomic(false), ordering(0), syncscope(StringRef()), volatile_(false),
40+
nonTemporal(false), invariant(false)
3941
{
4042
}
4143

4244
StringRef getName() const
4345
{
4446
return name;
4547
}
48+
4649
const mlir::Type &getType() const
4750
{
4851
return type;
@@ -51,10 +54,12 @@ class VariableDeclarationDOM
5154
{
5255
type = type_;
5356
}
57+
5458
const mlir::Location &getLoc() const
5559
{
5660
return loc;
5761
}
62+
5863
const Expression &getInitValue() const
5964
{
6065
return initValue;
@@ -63,41 +68,97 @@ class VariableDeclarationDOM
6368
{
6469
return !!initValue;
6570
}
71+
6672
bool getReadWriteAccess() const
6773
{
6874
return readWrite;
69-
};
75+
}
7076
void setReadWriteAccess(bool value = true)
7177
{
7278
readWrite = value;
73-
};
79+
}
80+
7481
bool getCaptured() const
7582
{
7683
return captured;
77-
};
84+
}
7885
void setCaptured(bool value = true)
7986
{
8087
captured = value;
81-
};
88+
}
89+
8290
bool getIgnoreCapturing()
8391
{
8492
return ignoreCapturing;
85-
};
93+
}
8694
void setIgnoreCapturing(bool value = true)
8795
{
8896
ignoreCapturing = value;
89-
};
97+
}
98+
9099
bool getUsing() const
91100
{
92101
return _using;
93-
};
102+
}
94103
void setUsing(bool value = true)
95104
{
96105
_using = value;
106+
}
107+
108+
void setAtomic(int ordering_, StringRef syncscope_)
109+
{
110+
atomic = true;
111+
ordering = ordering_;
112+
syncscope = syncscope_;
113+
}
114+
bool getAtomic() const
115+
{
116+
return atomic;
117+
}
118+
int getOrdering() const
119+
{
120+
return ordering;
121+
}
122+
StringRef getSyncScope() const
123+
{
124+
return syncscope;
125+
}
126+
127+
bool getVolatile() const
128+
{
129+
return volatile_;
130+
}
131+
void setVolatile(bool value = true)
132+
{
133+
volatile_ = value;
134+
};
135+
136+
bool getNonTemporal() const
137+
{
138+
return nonTemporal;
139+
}
140+
void setNonTemporal(bool value = true)
141+
{
142+
nonTemporal = value;
143+
};
144+
145+
bool getInvariant() const
146+
{
147+
return invariant;
148+
}
149+
void setInvariant(bool value = true)
150+
{
151+
invariant = value;
97152
};
98153

99154
protected:
100155
bool readWrite;
156+
bool atomic;
157+
int ordering;
158+
StringRef syncscope;
159+
bool volatile_;
160+
bool nonTemporal;
161+
bool invariant;
101162
};
102163

103164
class FunctionParamDOM : public VariableDeclarationDOM

tsc/include/TypeScript/Defines.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
#define IDENTIFIER_ATTR_NAME "identifier"
55
#define BUILTIN_FUNC_ATTR_NAME "__builtin"
66
#define GENERIC_ATTR_NAME "__generic"
7+
#define ATOMIC_ATTR_NAME "__atomic"
8+
#define ORDERING_ATTR_NAME "__ordering"
9+
#define SYNCSCOPE_ATTR_NAME "__syncscope"
10+
#define VOLATILE_ATTR_NAME "__volatile"
11+
#define NONTEMPORAL_ATTR_NAME "__nontemporal"
12+
#define INVARIANT_ATTR_NAME "__invariant"
713
#define INSTANCES_COUNT_ATTR_NAME "InstancesCount"
814
#define RETURN_VARIABLE_NAME ".return"
915
#define CAPTURED_NAME ".captured"

tsc/include/TypeScript/LowerToLLVM/UnaryBinLogicalOrHelper.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,24 @@ mlir::Value LogicOp(Operation *binOp, SyntaxKind op, mlir::Value left, mlir::Typ
153153
else if (isa<mlir_ts::AnyType>(leftType) || isa<mlir_ts::ClassType>(leftType) ||
154154
isa<mlir_ts::OpaqueType>(leftType) || isa<mlir_ts::NullType>(leftType))
155155
{
156+
// in case of UnionType
157+
if (auto unionType = dyn_cast<mlir_ts::UnionType>(rightType))
158+
{
159+
::typescript::MLIRTypeHelper mth(builder.getContext(), compileOptions);
160+
mlir::Type baseType;
161+
if (mth.isUnionTypeNeedsTag(loc, unionType, baseType))
162+
{
163+
auto tagValue = builder.create<LLVM::ExtractValueOp>(loc, llvmtch.typeConverter->convertType(mth.getStringType()), right,
164+
MLIRHelper::getStructIndex(builder, UNION_TAG_INDEX));
165+
auto nullStr = builder.create<mlir_ts::ConstantOp>(loc, mth.getStringType(), builder.getStringAttr("null"));
166+
auto cmpOp = builder.create<mlir_ts::StringCompareOp>(
167+
loc, mth.getBooleanType(), tagValue, nullStr, builder.getI32IntegerAttr((int)op));
168+
return cmpOp;
169+
}
170+
171+
return LogicOp<StdIOpTy, V1, v1, StdFOpTy, V2, v2>(binOp, op, left, baseType, right, rightType, builder, typeConverter, compileOptions);
172+
}
173+
156174
// excluded string
157175
auto intPtrType = llvmtch.getIntPtrType(0);
158176

@@ -227,7 +245,21 @@ mlir::Value LogicOp(Operation *binOp, SyntaxKind op, mlir::Value left, mlir::Typ
227245
mlir::Type baseType;
228246
if (mth.isUnionTypeNeedsTag(loc, unionType, baseType))
229247
{
248+
// add test to null value
249+
auto isRightNullValue =
250+
right.getDefiningOp<mlir_ts::NullOp>() || right.getDefiningOp<LLVM::ZeroOp>() || matchPattern(right, m_Zero());
251+
if (isRightNullValue)
252+
{
253+
auto tagValue = builder.create<LLVM::ExtractValueOp>(loc, llvmtch.typeConverter->convertType(mth.getStringType()), left,
254+
MLIRHelper::getStructIndex(builder, UNION_TAG_INDEX));
255+
auto nullStr = builder.create<mlir_ts::ConstantOp>(loc, mth.getStringType(), builder.getStringAttr("null"));
256+
auto cmpOp = builder.create<mlir_ts::StringCompareOp>(
257+
loc, mth.getBooleanType(), tagValue, nullStr, builder.getI32IntegerAttr((int)op));
258+
return cmpOp;
259+
}
260+
230261
emitError(loc, "Not applicable logical operator for type: '") << to_print<int>(leftType) << "'";
262+
return mlir::Value();
231263
}
232264

233265
return LogicOp<StdIOpTy, V1, v1, StdFOpTy, V2, v2>(binOp, op, left, baseType, right, rightType, builder, typeConverter, compileOptions);

0 commit comments

Comments
 (0)