Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions sys/risc-v/rv3264im.vadl
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,13 @@ instruction set architecture RV3264Base = {
}

model IShftInstr (name : Id, op : BinOp, funct3 : Bin, funct2 : Bin, lhsTy : Id) : IsaDefs = {
[ upcast access to : shamt, MLen ]
instruction $name : Ftype = // shift immediate instructions
X(rd) := ((X(rs1) as $lhsTy) $op shamt) as Regs
encoding $name = {opcode = 0b001'0011, zero = 0, funct3 = $funct3, funct2 = $funct2}
assembly $name = (mnemonic, " ", register(rd), ",", register(rs1), ",", udec(sft))
}

model WShftInstr (name : Id, op : BinOp, funct3 : Bin, funct7 : Bin, lhsTy : Id) : IsaDefs = {
[ upcast access to : shamt, MLen ]
instruction $name : Rtype = // shift immediate instructions word
X(rd) := (((X(rs1) as $lhsTy) $op shamt) as SInt) as SIntR
encoding $name = {opcode = 0b001'1011, funct3 = $funct3, funct7 = $funct7}
Expand Down
63 changes: 0 additions & 63 deletions vadl/main/vadl/ast/AnnotationTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import vadl.gcb.annotations.StatusRegisterAnnotation;
import vadl.types.BitsType;
import vadl.types.Type;
import vadl.types.UIntType;
import vadl.utils.Pair;
import vadl.utils.SourceLocation;
import vadl.utils.WithLocation;
Expand All @@ -68,7 +67,6 @@
import vadl.viam.annotations.BigEndianAnnotation;
import vadl.viam.annotations.DefineOperandAnnotation;
import vadl.viam.annotations.EnableHtifAnno;
import vadl.viam.annotations.FieldAccessAnnotation;
import vadl.viam.annotations.InstructionUndefinedAnno;
import vadl.viam.annotations.TbStateRegisterAnnotation;

Expand Down Expand Up @@ -335,16 +333,6 @@ public class AnnotationTable {
var lit = (StringLiteral) annotation.definition.values.getFirst();
def.addAnnotation(new RelocationSyntaxAnnotation(lit.value));
}).build();

annotationOn(InstructionDefinition.class, "upcast access to", UpcastAnnotation::new)
.applyViam((def, annotation, lowering) -> {
var field =
(Format.FieldAccess) ensurePresent(lowering.fetch((FormatField) annotation.targetDef),
() -> Diagnostic.error("Cannot find field", annotation.targetDef.location()));

def.addAnnotation(new FieldAccessAnnotation(field,
UIntType.unsignedInt(annotation.bitSize.value().intValue())));
}).build();
}

/**
Expand Down Expand Up @@ -1553,54 +1541,3 @@ void resolveName(AnnotationDefinition definition, SymbolTable.SymbolResolver res
super.resolveName(definition, resolver);
}
}

/**
* Provides the annotation {@code [ upcast access to : <ident>, <ex> ]} on an instruction that
* treats the field access of {@code <ident>} as being of type {@code <ex>}. {@code <ex>} has to
* evaluate to a positive integer.
* This is useful when there is a type mismatch between the field access and an LLVM type.
*/
class UpcastAnnotation extends Annotation {

@LazyInit
ConstantValue bitSize;

@LazyInit
Definition targetDef;

public UpcastAnnotation() {
super();
}

@Override
void resolveName(AnnotationDefinition definition, SymbolTable.SymbolResolver resolver) {
verifyValuesCnt(definition, 2);
for (var val : definition.values) {
val.accept(resolver);
}
}

@Override
void typeCheck(AnnotationDefinition definition, TypeChecker typeChecker) {

var def = definition.values.getFirst();
Diagnostic.ensure(def instanceof Identifier, () -> error("Invalid annotation value", def)
.description("A single identifier was expected.")
);
var target = ((Identifier) def).target();
Diagnostic.ensure(target instanceof Definition, () -> error("Invalid annotation value", def)
.description("The identifier must reference a definition."));
targetDef = ((Definition) target);

var valueExpr = definition.values.get(1);
typeChecker.check(valueExpr);
bitSize = typeChecker.constantEvaluator.eval(valueExpr);
Diagnostic.ensure(bitSize.value().signum() > 0,
() -> error("Bit size of type has to be bigger than zero", valueExpr));
}

@Override
public String usageString() {
return "[ " + name + " : <ident>, <int> ]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import vadl.types.BitsType;
import vadl.viam.Instruction;
import vadl.viam.Specification;
import vadl.viam.annotations.FieldAccessAnnotation;
import vadl.viam.graph.Graph;
import vadl.viam.graph.control.InstrCallNode;
import vadl.viam.graph.dependency.FieldAccessRefNode;
Expand Down Expand Up @@ -103,22 +102,11 @@ public List<TableGenImmediateRecord> execute(PassResults passResults,
"Compiler generator was not able to change the type to the architecture's "
+ "bit width: " + upcastedType.toString(),
fieldAccess.location()));
var upcastAnnotation = instruction.annotation(FieldAccessAnnotation.class);
if (upcastAnnotation != null) {
var upcastedCppType = CppTypeMap.upcast(upcastAnnotation.resultBitWidth());
upcastedValueType = ValueType.from(upcastedCppType.makeSigned())
.orElseThrow(() -> Diagnostic.error(
"Unable to cast access to requested bit width: "
+ upcastAnnotation.resultBitWidth(),
upcastAnnotation.location()).build());
} else {
var upcastedValueTypeBitwidth = upcastedValueType.getBitwidth();
var smallestRegisterClassBitwidth = smallestRegisterClassType.getBitwidth();
upcastedValueType = upcastedValueTypeBitwidth < smallestRegisterClassBitwidth
? smallestRegisterClassType
: upcastedValueType;
}

var upcastedValueTypeBitwidth = upcastedValueType.getBitwidth();
var smallestRegisterClassBitwidth = smallestRegisterClassType.getBitwidth();
upcastedValueType = upcastedValueTypeBitwidth < smallestRegisterClassBitwidth
? smallestRegisterClassType
: upcastedValueType;
immediates.add(new TableGenImmediateRecord(instruction,
fieldAccess,
upcastedValueType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
import vadl.viam.Instruction;
import vadl.viam.InstructionSetArchitecture;
import vadl.viam.PrintableInstruction;
import vadl.viam.annotations.FieldAccessAnnotation;
import vadl.viam.graph.Graph;
import vadl.viam.graph.Node;
import vadl.viam.graph.NodeList;
Expand Down Expand Up @@ -113,8 +112,8 @@ public abstract class LlvmInstructionLoweringStrategy {
protected final ValueType architectureType;
protected final ValueType smallestRegisterClassType;

public LlvmInstructionLoweringStrategy(ValueType architectureType,
ValueType smallestRegisterClassType) {
public LlvmInstructionLoweringStrategy(ValueType architectureType,
ValueType smallestRegisterClassType) {
this.architectureType = architectureType;
this.smallestRegisterClassType = smallestRegisterClassType;
}
Expand Down Expand Up @@ -242,33 +241,18 @@ protected List<GcbInstructionOperand> replaceOperands(
var llvmNode = ensureNonNull(fieldAccesses.get(immediateOperand.fieldAccess()),
() -> Diagnostic.error("There is no lowered field access",
instruction.location().join(immediateOperand.fieldAccess().location())));
var upcastAnnotation = instruction.annotation(FieldAccessAnnotation.class);

if (upcastAnnotation != null) {
var upcastedCppType = CppTypeMap.upcast(upcastAnnotation.resultBitWidth());
var upcastedType = ValueType.from(upcastedCppType)
.orElseThrow(
() -> Diagnostic.error("Cannot cast requested type",
upcastAnnotation.location()).build());
llvmNode =
new LlvmFieldAccessRefNode(instruction,
immediateOperand.fieldAccess(),
immediateOperand.fieldAccess().type(),
upcastedType,
LlvmFieldAccessRefNode.Usage.Immediate);
} else {
var llvmNodeBitwidth = llvmNode.type().asDataType().bitWidth();
var llvmType = llvmNodeBitwidth < this.smallestRegisterClassType.getBitwidth()
? this.smallestRegisterClassType
: ValueType.from(llvmNode.type().asDataType()).get();
llvmNode =
new LlvmFieldAccessRefNode(
instruction,
immediateOperand.fieldAccess(),
immediateOperand.fieldAccess().type(),
llvmType,
LlvmFieldAccessRefNode.Usage.Immediate);
}

var llvmNodeBitwidth = llvmNode.type().asDataType().bitWidth();
var llvmType = llvmNodeBitwidth < this.smallestRegisterClassType.getBitwidth()
? this.smallestRegisterClassType
: ValueType.from(llvmNode.type().asDataType()).get();
llvmNode =
new LlvmFieldAccessRefNode(
instruction,
immediateOperand.fieldAccess(),
immediateOperand.fieldAccess().type(),
llvmType,
LlvmFieldAccessRefNode.Usage.Immediate);

operands.set(i, new TableGenInstructionImmediateOperand(llvmNode));
} else if (operand instanceof GcbInstructionImmediateOperand immediateOperand
Expand Down Expand Up @@ -323,7 +307,7 @@ protected void replaceNode(PrintableInstruction instruction, Node node) {
}

protected LcbNodeReplacementHandler getReplacementHandler(PrintableInstruction instruction) {
return new LcbNodeReplacementHandler(instruction, architectureType,
return new LcbNodeReplacementHandler(instruction, architectureType,
this.smallestRegisterClassType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
import vadl.types.BuiltInTable;
import vadl.types.DataType;
import vadl.viam.Constant;
import vadl.viam.Instruction;
import vadl.viam.PrintableInstruction;
import vadl.viam.annotations.FieldAccessAnnotation;
import vadl.viam.graph.Node;
import vadl.viam.graph.control.BranchBeginNode;
import vadl.viam.graph.control.BranchEndNode;
Expand Down Expand Up @@ -437,19 +435,9 @@ public void handle(FieldAccessRefNode fieldAccessRefNode) {
var llvmType = ValueType.from(CppTypeMap.upcast(originalType)).orElseThrow(() ->
Diagnostic.error("Cannot construct LLVM type", fieldAccessRefNode.location()).build());

if (printableInstruction instanceof Instruction instruction && instruction.hasAnnotation(
FieldAccessAnnotation.class)) {
var annotation = instruction.annotation(FieldAccessAnnotation.class);
ensureNonNull(annotation,
() -> Diagnostic.error("Expected to have FieldAccessAnnotation", instruction.location()));

llvmType = ValueType.from(CppTypeMap.upcast(annotation.resultBitWidth())).orElseThrow(() ->
Diagnostic.error("Cannot construct LLVM type", fieldAccessRefNode.location()).build());
} else {
llvmType = llvmType.getBitwidth() < this.smallestRegisterClassType.getBitwidth()
llvmType = llvmType.getBitwidth() < this.smallestRegisterClassType.getBitwidth()
? this.smallestRegisterClassType
: llvmType;
}

fieldAccessRefNode.replaceAndDelete(
new LlvmFieldAccessRefNode(
Expand Down
52 changes: 0 additions & 52 deletions vadl/main/vadl/viam/annotations/FieldAccessAnnotation.java

This file was deleted.

Loading