@@ -83,23 +83,55 @@ using namespace llvm;
83
83
namespace {
84
84
85
85
// All possible address modes, plus some.
86
- struct Address {
87
- enum {
86
+ class Address {
87
+ public:
88
+ using BaseKind = enum {
88
89
RegBase,
89
90
FrameIndexBase
90
- } BaseType = RegBase ;
91
+ };
91
92
93
+ private:
94
+ BaseKind Kind = RegBase;
92
95
union {
93
96
unsigned Reg;
94
97
int FI;
95
98
} Base;
96
99
97
100
int Offset = 0 ;
98
101
102
+ public:
99
103
// Innocuous defaults for our address.
100
104
Address () {
101
105
Base.Reg = 0 ;
102
106
}
107
+
108
+ void setKind (BaseKind K) { Kind = K; }
109
+ BaseKind getKind () const { return Kind; }
110
+ bool isRegBase () const { return Kind == RegBase; }
111
+ bool isFIBase () const { return Kind == FrameIndexBase; }
112
+
113
+ void setReg (Register Reg) {
114
+ assert (isRegBase () && " Invalid base register access!" );
115
+ Base.Reg = Reg.id ();
116
+ }
117
+
118
+ Register getReg () const {
119
+ assert (isRegBase () && " Invalid base register access!" );
120
+ return Base.Reg ;
121
+ }
122
+
123
+ void setFI (int FI) {
124
+ assert (isFIBase () && " Invalid base frame index access!" );
125
+ Base.FI = FI;
126
+ }
127
+
128
+ int getFI () const {
129
+ assert (isFIBase () && " Invalid base frame index access!" );
130
+ return Base.FI ;
131
+ }
132
+
133
+ void setOffset (int O) { Offset = O; }
134
+ int getOffset () { return Offset; }
103
135
};
104
136
105
137
class ARMFastISel final : public FastISel {
@@ -738,7 +770,7 @@ bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) {
738
770
break ;
739
771
case Instruction::GetElementPtr: {
740
772
Address SavedAddr = Addr;
741
- int TmpOffset = Addr.Offset ;
773
+ int TmpOffset = Addr.getOffset () ;
742
774
743
775
// Iterate through the GEP folding the constants into offsets where
744
776
// we can.
@@ -774,7 +806,7 @@ bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) {
774
806
}
775
807
776
808
// Try to grab the base operand now.
777
- Addr.Offset = TmpOffset;
809
+ Addr.setOffset ( TmpOffset) ;
778
810
if (ARMComputeAddress (U->getOperand (0 ), Addr)) return true ;
779
811
780
812
// We failed, restore everything and try the other options.
@@ -788,17 +820,17 @@ bool ARMFastISel::ARMComputeAddress(const Value *Obj, Address &Addr) {
788
820
DenseMap<const AllocaInst*, int >::iterator SI =
789
821
FuncInfo.StaticAllocaMap .find (AI);
790
822
if (SI != FuncInfo.StaticAllocaMap .end ()) {
791
- Addr.BaseType = Address::FrameIndexBase;
792
- Addr.Base . FI = SI->second ;
823
+ Addr.setKind ( Address::FrameIndexBase) ;
824
+ Addr.setFI ( SI->second ) ;
793
825
return true ;
794
826
}
795
827
break ;
796
828
}
797
829
}
798
830
799
831
// Try to get this in a register if nothing else has worked.
800
- if (Addr.Base . Reg == 0 ) Addr.Base . Reg = getRegForValue (Obj);
801
- return Addr.Base . Reg != 0 ;
832
+ if (! Addr.getReg ()) Addr.setReg ( getRegForValue (Obj) );
833
+ return Addr.getReg () ;
802
834
}
803
835
804
836
void ARMFastISel::ARMSimplifyAddress (Address &Addr, MVT VT, bool useAM3) {
@@ -811,45 +843,45 @@ void ARMFastISel::ARMSimplifyAddress(Address &Addr, MVT VT, bool useAM3) {
811
843
case MVT::i32:
812
844
if (!useAM3) {
813
845
// Integer loads/stores handle 12-bit offsets.
814
- needsLowering = ((Addr.Offset & 0xfff ) != Addr.Offset );
846
+ needsLowering = ((Addr.getOffset () & 0xfff ) != Addr.getOffset () );
815
847
// Handle negative offsets.
816
848
if (needsLowering && isThumb2)
817
- needsLowering = !(Subtarget->hasV6T2Ops () && Addr.Offset < 0 &&
818
- Addr.Offset > -256 );
849
+ needsLowering = !(Subtarget->hasV6T2Ops () && Addr.getOffset () < 0 &&
850
+ Addr.getOffset () > -256 );
819
851
} else {
820
852
// ARM halfword load/stores and signed byte loads use +/-imm8 offsets.
821
- needsLowering = (Addr.Offset > 255 || Addr.Offset < -255 );
853
+ needsLowering = (Addr.getOffset () > 255 || Addr.getOffset () < -255 );
822
854
}
823
855
break ;
824
856
case MVT::f32:
825
857
case MVT::f64:
826
858
// Floating point operands handle 8-bit offsets.
827
- needsLowering = ((Addr.Offset & 0xff ) != Addr.Offset );
859
+ needsLowering = ((Addr.getOffset () & 0xff ) != Addr.getOffset () );
828
860
break ;
829
861
}
830
862
831
863
// If this is a stack pointer and the offset needs to be simplified then
832
864
// put the alloca address into a register, set the base type back to
833
865
// register and continue. This should almost never happen.
834
- if (needsLowering && Addr.BaseType == Address::FrameIndexBase ) {
866
+ if (needsLowering && Addr.isFIBase () ) {
835
867
const TargetRegisterClass *RC = isThumb2 ? &ARM::tGPRRegClass
836
868
: &ARM::GPRRegClass;
837
869
Register ResultReg = createResultReg (RC);
838
870
unsigned Opc = isThumb2 ? ARM::t2ADDri : ARM::ADDri;
839
871
AddOptionalDefs (BuildMI (*FuncInfo.MBB , FuncInfo.InsertPt , MIMD,
840
872
TII.get (Opc), ResultReg)
841
- .addFrameIndex (Addr.Base . FI )
873
+ .addFrameIndex (Addr.getFI () )
842
874
.addImm (0 ));
843
- Addr.Base . Reg = ResultReg ;
844
- Addr.BaseType = Address::RegBase ;
875
+ Addr.setKind (Address::RegBase) ;
876
+ Addr.setReg (ResultReg) ;
845
877
}
846
878
847
879
// Since the offset is too large for the load/store instruction
848
880
// get the reg+offset into a register.
849
881
if (needsLowering) {
850
- Addr.Base . Reg = fastEmit_ri_ (MVT::i32, ISD::ADD, Addr.Base . Reg ,
851
- Addr.Offset , MVT::i32);
852
- Addr.Offset = 0 ;
882
+ Addr.setReg ( fastEmit_ri_ (MVT::i32, ISD::ADD, Addr.getReg () ,
883
+ Addr.getOffset () , MVT::i32) );
884
+ Addr.setOffset ( 0 ) ;
853
885
}
854
886
}
855
887
@@ -860,12 +892,12 @@ void ARMFastISel::AddLoadStoreOperands(MVT VT, Address &Addr,
860
892
// addrmode5 output depends on the selection dag addressing dividing the
861
893
// offset by 4 that it then later multiplies. Do this here as well.
862
894
if (VT.SimpleTy == MVT::f32 || VT.SimpleTy == MVT::f64)
863
- Addr.Offset /= 4 ;
895
+ Addr.setOffset (Addr. getOffset () / 4 ) ;
864
896
865
897
// Frame base works a bit differently. Handle it separately.
866
- if (Addr.BaseType == Address::FrameIndexBase ) {
867
- int FI = Addr.Base . FI ;
868
- int Offset = Addr.Offset ;
898
+ if (Addr.isFIBase () ) {
899
+ int FI = Addr.getFI () ;
900
+ int Offset = Addr.getOffset () ;
869
901
MachineMemOperand *MMO = FuncInfo.MF ->getMachineMemOperand (
870
902
MachinePointerInfo::getFixedStack (*FuncInfo.MF , FI, Offset), Flags,
871
903
MFI.getObjectSize (FI), MFI.getObjectAlign (FI));
@@ -875,25 +907,25 @@ void ARMFastISel::AddLoadStoreOperands(MVT VT, Address &Addr,
875
907
// ARM halfword load/stores and signed byte loads need an additional
876
908
// operand.
877
909
if (useAM3) {
878
- int Imm = (Addr.Offset < 0 ) ? (0x100 | -Addr.Offset ) : Addr.Offset ;
910
+ int Imm = (Addr.getOffset () < 0 ) ? (0x100 | -Addr.getOffset ()) : Addr.getOffset () ;
879
911
MIB.addReg (0 );
880
912
MIB.addImm (Imm);
881
913
} else {
882
- MIB.addImm (Addr.Offset );
914
+ MIB.addImm (Addr.getOffset () );
883
915
}
884
916
MIB.addMemOperand (MMO);
885
917
} else {
886
918
// Now add the rest of the operands.
887
- MIB.addReg (Addr.Base . Reg );
919
+ MIB.addReg (Addr.getReg () );
888
920
889
921
// ARM halfword load/stores and signed byte loads need an additional
890
922
// operand.
891
923
if (useAM3) {
892
- int Imm = (Addr.Offset < 0 ) ? (0x100 | -Addr.Offset ) : Addr.Offset ;
924
+ int Imm = (Addr.getOffset () < 0 ) ? (0x100 | -Addr.getOffset ()) : Addr.getOffset () ;
893
925
MIB.addReg (0 );
894
926
MIB.addImm (Imm);
895
927
} else {
896
- MIB.addImm (Addr.Offset );
928
+ MIB.addImm (Addr.getOffset () );
897
929
}
898
930
}
899
931
AddOptionalDefs (MIB);
@@ -912,7 +944,7 @@ bool ARMFastISel::ARMEmitLoad(MVT VT, Register &ResultReg, Address &Addr,
912
944
case MVT::i1:
913
945
case MVT::i8:
914
946
if (isThumb2) {
915
- if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops ())
947
+ if (Addr.getOffset () < 0 && Addr.getOffset () > -256 && Subtarget->hasV6T2Ops ())
916
948
Opc = isZExt ? ARM::t2LDRBi8 : ARM::t2LDRSBi8;
917
949
else
918
950
Opc = isZExt ? ARM::t2LDRBi12 : ARM::t2LDRSBi12;
@@ -932,7 +964,7 @@ bool ARMFastISel::ARMEmitLoad(MVT VT, Register &ResultReg, Address &Addr,
932
964
return false ;
933
965
934
966
if (isThumb2) {
935
- if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops ())
967
+ if (Addr.getOffset () < 0 && Addr.getOffset () > -256 && Subtarget->hasV6T2Ops ())
936
968
Opc = isZExt ? ARM::t2LDRHi8 : ARM::t2LDRSHi8;
937
969
else
938
970
Opc = isZExt ? ARM::t2LDRHi12 : ARM::t2LDRSHi12;
@@ -948,7 +980,7 @@ bool ARMFastISel::ARMEmitLoad(MVT VT, Register &ResultReg, Address &Addr,
948
980
return false ;
949
981
950
982
if (isThumb2) {
951
- if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops ())
983
+ if (Addr.getOffset () < 0 && Addr.getOffset () > -256 && Subtarget->hasV6T2Ops ())
952
984
Opc = ARM::t2LDRi8;
953
985
else
954
986
Opc = ARM::t2LDRi12;
@@ -1061,7 +1093,7 @@ bool ARMFastISel::ARMEmitStore(MVT VT, Register SrcReg, Address &Addr,
1061
1093
}
1062
1094
case MVT::i8:
1063
1095
if (isThumb2) {
1064
- if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops ())
1096
+ if (Addr.getOffset () < 0 && Addr.getOffset () > -256 && Subtarget->hasV6T2Ops ())
1065
1097
StrOpc = ARM::t2STRBi8;
1066
1098
else
1067
1099
StrOpc = ARM::t2STRBi12;
@@ -1075,7 +1107,7 @@ bool ARMFastISel::ARMEmitStore(MVT VT, Register SrcReg, Address &Addr,
1075
1107
return false ;
1076
1108
1077
1109
if (isThumb2) {
1078
- if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops ())
1110
+ if (Addr.getOffset () < 0 && Addr.getOffset () > -256 && Subtarget->hasV6T2Ops ())
1079
1111
StrOpc = ARM::t2STRHi8;
1080
1112
else
1081
1113
StrOpc = ARM::t2STRHi12;
@@ -1090,7 +1122,7 @@ bool ARMFastISel::ARMEmitStore(MVT VT, Register SrcReg, Address &Addr,
1090
1122
return false ;
1091
1123
1092
1124
if (isThumb2) {
1093
- if (Addr.Offset < 0 && Addr.Offset > -256 && Subtarget->hasV6T2Ops ())
1125
+ if (Addr.getOffset () < 0 && Addr.getOffset () > -256 && Subtarget->hasV6T2Ops ())
1094
1126
StrOpc = ARM::t2STRi8;
1095
1127
else
1096
1128
StrOpc = ARM::t2STRi12;
@@ -2031,9 +2063,9 @@ bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args,
2031
2063
continue ;
2032
2064
2033
2065
Address Addr;
2034
- Addr.BaseType = Address::RegBase;
2035
- Addr.Base . Reg = ARM::SP;
2036
- Addr.Offset = VA.getLocMemOffset ();
2066
+ Addr.setKind ( Address::RegBase) ;
2067
+ Addr.setReg ( ARM::SP) ;
2068
+ Addr.setOffset ( VA.getLocMemOffset () );
2037
2069
2038
2070
bool EmitRet = ARMEmitStore (ArgVT, Arg, Addr); (void )EmitRet;
2039
2071
assert (EmitRet && " Could not emit a store for argument!" );
@@ -2506,8 +2538,8 @@ bool ARMFastISel::ARMTryEmitSmallMemCpy(Address Dest, Address Src, uint64_t Len,
2506
2538
2507
2539
unsigned Size = VT.getSizeInBits ()/8 ;
2508
2540
Len -= Size ;
2509
- Dest.Offset += Size ;
2510
- Src.Offset += Size ;
2541
+ Dest.setOffset (Dest. getOffset () + Size ) ;
2542
+ Src.setOffset (Src. getOffset () + Size ) ;
2511
2543
}
2512
2544
2513
2545
return true ;
0 commit comments