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